buckyos 0.7.119 → 0.7.121
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/cli/README.md +24 -3
- package/cli/core/app.ts +28 -0
- package/cli/deno.json +2 -1
- package/cli/dist/cli.mjs +777 -169
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/modules/app.ts +213 -94
- package/cli/modules/provision.ts +690 -0
- package/cli/runtime/host.ts +25 -2
- package/cli/runtime/host_deno.ts +4 -0
- package/cli/runtime/host_node.ts +4 -0
- package/cli/version.ts +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.mjs +124 -124
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +124 -124
- package/dist/{ndm_proxy-c00bc561.mjs → ndm_proxy-8f547002.mjs} +113 -216
- package/dist/ndm_proxy-8f547002.mjs.map +1 -0
- package/dist/ndm_proxy-93a8869b.js +13 -0
- package/dist/ndm_proxy-93a8869b.js.map +1 -0
- package/dist/ndn_types-44c69036.js +2 -0
- package/dist/ndn_types-44c69036.js.map +1 -0
- package/dist/{ndn_types-f6c08d20.mjs → ndn_types-d768245f.mjs} +149 -39
- package/dist/ndn_types-d768245f.mjs.map +1 -0
- package/dist/node.cjs +1 -1
- package/dist/node.mjs +124 -124
- package/dist/provision.cjs +6 -6
- package/dist/provision.cjs.map +1 -1
- package/dist/provision.d.ts +2 -0
- package/dist/provision.d.ts.map +1 -1
- package/dist/provision.mjs +1084 -35
- package/dist/provision.mjs.map +1 -1
- package/dist/provision_activate.d.ts +146 -0
- package/dist/provision_activate.d.ts.map +1 -0
- package/dist/{tus_client-573066b3.mjs → tus_client-b1c35e8c.mjs} +2 -2
- package/dist/{tus_client-573066b3.mjs.map → tus_client-b1c35e8c.mjs.map} +1 -1
- package/dist/{tus_client-83ad0f4f.js → tus_client-d0798623.js} +2 -2
- package/dist/{tus_client-83ad0f4f.js.map → tus_client-d0798623.js.map} +1 -1
- package/package.json +1 -1
- package/dist/ndm_proxy-68354a89.js +0 -13
- package/dist/ndm_proxy-68354a89.js.map +0 -1
- package/dist/ndm_proxy-c00bc561.mjs.map +0 -1
- package/dist/ndn_types-859bbd48.js +0 -2
- package/dist/ndn_types-859bbd48.js.map +0 -1
- package/dist/ndn_types-f6c08d20.mjs.map +0 -1
package/dist/provision.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var e,t=Object.defineProperty,r=(e,r,i)=>(((e,r,i)=>{r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i})(e,"symbol"!=typeof r?r+"":r,i),i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./ndn_types-
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,r=(e,r,i)=>(((e,r,i)=>{r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i})(e,"symbol"!=typeof r?r+"":r,i),i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./ndn_types-44c69036.js"),n=require("node:buffer"),o=require("node:crypto"),s="device_doc.jwt",a="device_mini_doc.jwt",c="node_gateway_params.json";function u(e){const t=globalThis.process;if("function"==typeof(null==t?void 0:t.getBuiltinModule)){const r=t.getBuiltinModule(e);if(r)return r}if("function"==typeof require)return require(e);throw new Error(`buckyos device_identity cannot load builtin module ${e} in this runtime`)}function l(e){return e instanceof i.DID?e:i.DID.fromStr(e)}function p(e,t){const r=u("node:fs"),i=u("node:path");r.mkdirSync(i.dirname(e),{recursive:!0}),r.writeFileSync(e,JSON.stringify(t,null,2))}function h(e){return{schema:i.NODE_IDENTITY_SCHEMA_V2,zone_did:l(e.zoneDid).toString(),owner_did:l(e.ownerDid).toString(),owner_public_key:e.ownerPublicKey,device_name:e.deviceName,device_did:l(e.deviceDid).toString(),zone_iat:e.zoneIat}}function d(e){const t=u("node:fs"),r=JSON.parse(t.readFileSync(e,"utf8"));if(r.schema!==i.NODE_IDENTITY_SCHEMA_V2)throw new Error(`unsupported node_identity schema '${r.schema}', expected '${i.NODE_IDENTITY_SCHEMA_V2}'`);return r}function f(e,t){const r=u("node:path"),i=l(t).toString(),n=e.publicDir(i);return{publicDir:n,securityDir:e.securityDir(i),didJson:e.publicFile(i,"authentication","did-json"),deviceDocJwt:r.join(n,s),deviceMiniDocJwt:r.join(n,a),authenticationPrivateKey:e.securityFile(i,"authentication","private")}}function y(e,t){const r=e.trim();if(!r)throw new Error("device name is empty");const n=l(t),o="web"===n.method?n.toRawHostName():n.id.split(":")[0]??n.id;if(!o.trim())throw new Error(`zone DID ${n.toString()} has empty host/name`);return new i.DID(n.method,`${r}.${o}`)}function g(e,t){const r=l(t).toString();if(e.id=r,!Array.isArray(e.verificationMethod))throw new Error("device document verificationMethod is missing");for(const i of e.verificationMethod)i.controller=r;return e}function m(e,t,r,n){return g(i.newDeviceDocumentByJwk(e,t,n),r)}function v(e,t){return u("node:fs").readFileSync(f(e,t).deviceDocJwt,"utf8")}function w(e,t){p(u("node:path").join(e,c),{params:{device_did:l(t).toString()}})}function b(e,t,r,n,o,s,a){const c=u("node:fs"),l=u("node:path"),h=f(t,r.device_did);return c.mkdirSync(h.publicDir,{recursive:!0}),c.mkdirSync(h.securityDir,{recursive:!0}),p(l.join(e,"node_identity.json"),r),w(e,r.device_did),p(h.didJson,i.deviceDocumentToOrderedJson(n)),c.writeFileSync(h.deviceDocJwt,o),c.writeFileSync(h.deviceMiniDocJwt,s),c.writeFileSync(h.authenticationPrivateKey,a),h}function S(e){return i.decodeJwtClaimWithoutVerify(e)}
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (C) Microsoft. All rights reserved.
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -12,11 +12,11 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
12
12
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
15
|
-
***************************************************************************** */var A,x;x=A||(A={}),function(){var e="object"==typeof globalThis?globalThis:"object"==typeof i.commonjsGlobal?i.commonjsGlobal:"object"==typeof self?self:"object"==typeof this?this:function(){try{return Function("return this;")()}catch(e){}}()||function(){try{return(0,eval)("(function() { return this; })()")}catch(e){}}(),t=r(x);function r(e,t){return function(r,i){Object.defineProperty(e,r,{configurable:!0,writable:!0,value:i}),t&&t(r,i)}}void 0!==e.Reflect&&(t=r(e.Reflect,t)),function(e,t){var r=Object.prototype.hasOwnProperty,i="function"==typeof Symbol,n=i&&void 0!==Symbol.toPrimitive?Symbol.toPrimitive:"@@toPrimitive",o=i&&void 0!==Symbol.iterator?Symbol.iterator:"@@iterator",s="function"==typeof Object.create,a={__proto__:[]}instanceof Array,c=!s&&!a,u={create:s?function(){return he(Object.create(null))}:a?function(){return he({__proto__:null})}:function(){return he({})},has:c?function(e,t){return r.call(e,t)}:function(e,t){return t in e},get:c?function(e,t){return r.call(e,t)?e[t]:void 0}:function(e,t){return e[t]}},l=Object.getPrototypeOf(Function),h="function"==typeof Map&&"function"==typeof Map.prototype.entries?Map:ce(),p="function"==typeof Set&&"function"==typeof Set.prototype.entries?Set:ue(),f="function"==typeof WeakMap?WeakMap:le(),d=i?Symbol.for("@reflect-metadata:registry"):void 0,y=ne(),g=oe(y);function v(e,t,r,i){if(U(r)){if(!W(e))throw new TypeError;if(!J(t))throw new TypeError;return N(e,t)}if(!W(e))throw new TypeError;if(!V(t))throw new TypeError;if(!V(i)&&!U(i)&&!L(i))throw new TypeError;return L(i)&&(i=void 0),T(e,t,r=z(r),i)}function m(e,t){function r(r,i){if(!V(r))throw new TypeError;if(!U(i)&&!X(i))throw new TypeError;_(e,t,r,i)}return r}function w(e,t,r,i){if(!V(r))throw new TypeError;return U(i)||(i=z(i)),_(e,t,r,i)}function b(e,t,r){if(!V(t))throw new TypeError;return U(r)||(r=z(r)),I(e,t,r)}function S(e,t,r){if(!V(t))throw new TypeError;return U(r)||(r=z(r)),O(e,t,r)}function A(e,t,r){if(!V(t))throw new TypeError;return U(r)||(r=z(r)),C(e,t,r)}function x(e,t,r){if(!V(t))throw new TypeError;return U(r)||(r=z(r)),j(e,t,r)}function k(e,t){if(!V(e))throw new TypeError;return U(t)||(t=z(t)),D(e,t)}function E(e,t){if(!V(e))throw new TypeError;return U(t)||(t=z(t)),R(e,t)}function B(e,t,r){if(!V(t))throw new TypeError;if(U(r)||(r=z(r)),!V(t))throw new TypeError;U(r)||(r=z(r));var i=ae(t,r,!1);return!U(i)&&i.OrdinaryDeleteMetadata(e,t,r)}function N(e,t){for(var r=e.length-1;r>=0;--r){var i=(0,e[r])(t);if(!U(i)&&!L(i)){if(!J(i))throw new TypeError;t=i}}return t}function T(e,t,r,i){for(var n=e.length-1;n>=0;--n){var o=(0,e[n])(t,r,i);if(!U(o)&&!L(o)){if(!V(o))throw new TypeError;i=o}}return i}function I(e,t,r){if(O(e,t,r))return!0;var i=re(t);return!L(i)&&I(e,i,r)}function O(e,t,r){var i=ae(t,r,!1);return!U(i)&&K(i.OrdinaryHasOwnMetadata(e,t,r))}function C(e,t,r){if(O(e,t,r))return j(e,t,r);var i=re(t);return L(i)?void 0:C(e,i,r)}function j(e,t,r){var i=ae(t,r,!1);if(!U(i))return i.OrdinaryGetOwnMetadata(e,t,r)}function _(e,t,r,i){ae(r,i,!0).OrdinaryDefineOwnMetadata(e,t,r,i)}function D(e,t){var r=R(e,t),i=re(e);if(null===i)return r;var n=D(i,t);if(n.length<=0)return r;if(r.length<=0)return n;for(var o=new p,s=[],a=0,c=r;a<c.length;a++){var u=c[a];o.has(u)||(o.add(u),s.push(u))}for(var l=0,h=n;l<h.length;l++)u=h[l],o.has(u)||(o.add(u),s.push(u));return s}function R(e,t){var r=ae(e,t,!1);return r?r.OrdinaryOwnMetadataKeys(e,t):[]}function P(e){if(null===e)return 1;switch(typeof e){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return null===e?1:6;default:return 6}}function U(e){return void 0===e}function L(e){return null===e}function $(e){return"symbol"==typeof e}function V(e){return"object"==typeof e?null!==e:"function"==typeof e}function M(e,t){switch(P(e)){case 0:case 1:case 2:case 3:case 4:case 5:return e}var r=3===t?"string":5===t?"number":"default",i=Y(e,n);if(void 0!==i){var o=i.call(e,r);if(V(o))throw new TypeError;return o}return H(e,"default"===r?"number":r)}function H(e,t){if("string"===t){var r=e.toString;if(q(r)&&!V(n=r.call(e)))return n;if(q(i=e.valueOf)&&!V(n=i.call(e)))return n}else{var i;if(q(i=e.valueOf)&&!V(n=i.call(e)))return n;var n,o=e.toString;if(q(o)&&!V(n=o.call(e)))return n}throw new TypeError}function K(e){return!!e}function F(e){return""+e}function z(e){var t=M(e,3);return $(t)?t:F(t)}function W(e){return Array.isArray?Array.isArray(e):e instanceof Object?e instanceof Array:"[object Array]"===Object.prototype.toString.call(e)}function q(e){return"function"==typeof e}function J(e){return"function"==typeof e}function X(e){switch(P(e)){case 3:case 4:return!0;default:return!1}}function G(e,t){return e===t||e!=e&&t!=t}function Y(e,t){var r=e[t];if(null!=r){if(!q(r))throw new TypeError;return r}}function Z(e){var t=Y(e,o);if(!q(t))throw new TypeError;var r=t.call(e);if(!V(r))throw new TypeError;return r}function Q(e){return e.value}function ee(e){var t=e.next();return!t.done&&t}function te(e){var t=e.return;t&&t.call(e)}function re(e){var t=Object.getPrototypeOf(e);if("function"!=typeof e||e===l)return t;if(t!==l)return t;var r=e.prototype,i=r&&Object.getPrototypeOf(r);if(null==i||i===Object.prototype)return t;var n=i.constructor;return"function"!=typeof n||n===e?t:n}function ie(){var e,r,i,n;U(d)||void 0===t.Reflect||d in t.Reflect||"function"!=typeof t.Reflect.defineMetadata||(e=se(t.Reflect));var o=new f,s={registerProvider:a,getProvider:u,setProvider:y};return s;function a(t){if(!Object.isExtensible(s))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case e===t:break;case U(r):r=t;break;case r===t:break;case U(i):i=t;break;case i===t:break;default:void 0===n&&(n=new p),n.add(t)}}function c(t,o){if(!U(r)){if(r.isProviderFor(t,o))return r;if(!U(i)){if(i.isProviderFor(t,o))return r;if(!U(n))for(var s=Z(n);;){var a=ee(s);if(!a)return;var c=Q(a);if(c.isProviderFor(t,o))return te(s),c}}}if(!U(e)&&e.isProviderFor(t,o))return e}function u(e,t){var r,i=o.get(e);return U(i)||(r=i.get(t)),U(r)?(U(r=c(e,t))||(U(i)&&(i=new h,o.set(e,i)),i.set(t,r)),r):r}function l(e){if(U(e))throw new TypeError;return r===e||i===e||!U(n)&&n.has(e)}function y(e,t,r){if(!l(r))throw new Error("Metadata provider not registered.");var i=u(e,t);if(i!==r){if(!U(i))return!1;var n=o.get(e);U(n)&&(n=new h,o.set(e,n)),n.set(t,r)}return!0}}function ne(){var e;return!U(d)&&V(t.Reflect)&&Object.isExtensible(t.Reflect)&&(e=t.Reflect[d]),U(e)&&(e=ie()),!U(d)&&V(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,d,{enumerable:!1,configurable:!1,writable:!1,value:e}),e}function oe(e){var t=new f,r={isProviderFor:function(e,r){var i=t.get(e);return!U(i)&&i.has(r)},OrdinaryDefineOwnMetadata:s,OrdinaryHasOwnMetadata:n,OrdinaryGetOwnMetadata:o,OrdinaryOwnMetadataKeys:a,OrdinaryDeleteMetadata:c};return y.registerProvider(r),r;function i(i,n,o){var s=t.get(i),a=!1;if(U(s)){if(!o)return;s=new h,t.set(i,s),a=!0}var c=s.get(n);if(U(c)){if(!o)return;if(c=new h,s.set(n,c),!e.setProvider(i,n,r))throw s.delete(n),a&&t.delete(i),new Error("Wrong provider for target.")}return c}function n(e,t,r){var n=i(t,r,!1);return!U(n)&&K(n.has(e))}function o(e,t,r){var n=i(t,r,!1);if(!U(n))return n.get(e)}function s(e,t,r,n){i(r,n,!0).set(e,t)}function a(e,t){var r=[],n=i(e,t,!1);if(U(n))return r;for(var o=Z(n.keys()),s=0;;){var a=ee(o);if(!a)return r.length=s,r;var c=Q(a);try{r[s]=c}catch(u){try{te(o)}finally{throw u}}s++}}function c(e,r,n){var o=i(r,n,!1);if(U(o))return!1;if(!o.delete(e))return!1;if(0===o.size){var s=t.get(r);U(s)||(s.delete(n),0===s.size&&t.delete(s))}return!0}}function se(e){var t=e.defineMetadata,r=e.hasOwnMetadata,i=e.getOwnMetadata,n=e.getOwnMetadataKeys,o=e.deleteMetadata,s=new f;return{isProviderFor:function(e,t){var r=s.get(e);return!(U(r)||!r.has(t))||!!n(e,t).length&&(U(r)&&(r=new p,s.set(e,r)),r.add(t),!0)},OrdinaryDefineOwnMetadata:t,OrdinaryHasOwnMetadata:r,OrdinaryGetOwnMetadata:i,OrdinaryOwnMetadataKeys:n,OrdinaryDeleteMetadata:o}}function ae(e,t,r){var i=y.getProvider(e,t);if(!U(i))return i;if(r){if(y.setProvider(e,t,g))return g;throw new Error("Illegal state.")}}function ce(){var e={},t=[],r=function(){function e(e,t,r){this._index=0,this._keys=e,this._values=t,this._selector=r}return e.prototype["@@iterator"]=function(){return this},e.prototype[o]=function(){return this},e.prototype.next=function(){var e=this._index;if(e>=0&&e<this._keys.length){var r=this._selector(this._keys[e],this._values[e]);return e+1>=this._keys.length?(this._index=-1,this._keys=t,this._values=t):this._index++,{value:r,done:!1}}return{value:void 0,done:!0}},e.prototype.throw=function(e){throw this._index>=0&&(this._index=-1,this._keys=t,this._values=t),e},e.prototype.return=function(e){return this._index>=0&&(this._index=-1,this._keys=t,this._values=t),{value:e,done:!0}},e}();return function(){function t(){this._keys=[],this._values=[],this._cacheKey=e,this._cacheIndex=-2}return Object.defineProperty(t.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),t.prototype.has=function(e){return this._find(e,!1)>=0},t.prototype.get=function(e){var t=this._find(e,!1);return t>=0?this._values[t]:void 0},t.prototype.set=function(e,t){var r=this._find(e,!0);return this._values[r]=t,this},t.prototype.delete=function(t){var r=this._find(t,!1);if(r>=0){for(var i=this._keys.length,n=r+1;n<i;n++)this._keys[n-1]=this._keys[n],this._values[n-1]=this._values[n];return this._keys.length--,this._values.length--,G(t,this._cacheKey)&&(this._cacheKey=e,this._cacheIndex=-2),!0}return!1},t.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=e,this._cacheIndex=-2},t.prototype.keys=function(){return new r(this._keys,this._values,i)},t.prototype.values=function(){return new r(this._keys,this._values,n)},t.prototype.entries=function(){return new r(this._keys,this._values,s)},t.prototype["@@iterator"]=function(){return this.entries()},t.prototype[o]=function(){return this.entries()},t.prototype._find=function(e,t){if(!G(this._cacheKey,e)){this._cacheIndex=-1;for(var r=0;r<this._keys.length;r++)if(G(this._keys[r],e)){this._cacheIndex=r;break}}return this._cacheIndex<0&&t&&(this._cacheIndex=this._keys.length,this._keys.push(e),this._values.push(void 0)),this._cacheIndex},t}();function i(e,t){return e}function n(e,t){return t}function s(e,t){return[e,t]}}function ue(){return function(){function e(){this._map=new h}return Object.defineProperty(e.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),e.prototype.has=function(e){return this._map.has(e)},e.prototype.add=function(e){return this._map.set(e,e),this},e.prototype.delete=function(e){return this._map.delete(e)},e.prototype.clear=function(){this._map.clear()},e.prototype.keys=function(){return this._map.keys()},e.prototype.values=function(){return this._map.keys()},e.prototype.entries=function(){return this._map.entries()},e.prototype["@@iterator"]=function(){return this.keys()},e.prototype[o]=function(){return this.keys()},e}()}function le(){var e=16,t=u.create(),i=n();return function(){function e(){this._key=n()}return e.prototype.has=function(e){var t=o(e,!1);return void 0!==t&&u.has(t,this._key)},e.prototype.get=function(e){var t=o(e,!1);return void 0!==t?u.get(t,this._key):void 0},e.prototype.set=function(e,t){return o(e,!0)[this._key]=t,this},e.prototype.delete=function(e){var t=o(e,!1);return void 0!==t&&delete t[this._key]},e.prototype.clear=function(){this._key=n()},e}();function n(){var e;do{e="@@WeakMap@@"+c()}while(u.has(t,e));return t[e]=!0,e}function o(e,t){if(!r.call(e,i)){if(!t)return;Object.defineProperty(e,i,{value:u.create()})}return e[i]}function s(e,t){for(var r=0;r<t;++r)e[r]=255*Math.random()|0;return e}function a(e){if("function"==typeof Uint8Array){var t=new Uint8Array(e);return"undefined"!=typeof crypto?crypto.getRandomValues(t):"undefined"!=typeof msCrypto?msCrypto.getRandomValues(t):s(t,e),t}return s(new Array(e),e)}function c(){var t=a(e);t[6]=79&t[6]|64,t[8]=191&t[8]|128;for(var r="",i=0;i<e;++i){var n=t[i];4!==i&&6!==i&&8!==i||(r+="-"),n<16&&(r+="0"),r+=n.toString(16).toLowerCase()}return r}}function he(e){return e.__=void 0,delete e.__,e}e("decorate",v),e("metadata",m),e("defineMetadata",w),e("hasMetadata",b),e("hasOwnMetadata",S),e("getMetadata",A),e("getOwnMetadata",x),e("getMetadataKeys",k),e("getOwnMetadataKeys",E),e("deleteMetadata",B)}(t,e),void 0===e.Reflect&&(e.Reflect=x)}();class k{static isArrayBuffer(e){return"[object ArrayBuffer]"===Object.prototype.toString.call(e)}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||0===e.byteOffset&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){const r=k.toUint8Array(e),i=k.toUint8Array(t);if(r.length!==i.byteLength)return!1;for(let n=0;n<r.length;n++)if(r[n]!==i[n])return!1;return!0}static concat(...e){let t;t=!Array.isArray(e[0])||e[1]instanceof Function?Array.isArray(e[0])&&e[1]instanceof Function?e[0]:e[e.length-1]instanceof Function?e.slice(0,e.length-1):e:e[0];let r=0;for(const o of t)r+=o.byteLength;const i=new Uint8Array(r);let n=0;for(const o of t){const e=this.toUint8Array(o);i.set(e,n),n+=e.length}return e[e.length-1]instanceof Function?this.toView(i,e[e.length-1]):i.buffer}}const E="string",B=/^[0-9a-f\s]+$/i,N=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,T=/^[a-zA-Z0-9-_]+$/;class I{static fromString(e){const t=unescape(encodeURIComponent(e)),r=new Uint8Array(t.length);for(let i=0;i<t.length;i++)r[i]=t.charCodeAt(i);return r.buffer}static toString(e){const t=k.toUint8Array(e);let r="";for(let i=0;i<t.length;i++)r+=String.fromCharCode(t[i]);return decodeURIComponent(escape(r))}}class O{static toString(e,t=!1){const r=k.toArrayBuffer(e),i=new DataView(r);let n="";for(let o=0;o<r.byteLength;o+=2){const e=i.getUint16(o,t);n+=String.fromCharCode(e)}return n}static fromString(e,t=!1){const r=new ArrayBuffer(2*e.length),i=new DataView(r);for(let n=0;n<e.length;n++)i.setUint16(2*n,e.charCodeAt(n),t);return r}}class C{static isHex(e){return typeof e===E&&B.test(e)}static isBase64(e){return typeof e===E&&N.test(e)}static isBase64Url(e){return typeof e===E&&T.test(e)}static ToString(e,t="utf8"){const r=k.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(r);case"binary":return this.ToBinary(r);case"hex":return this.ToHex(r);case"base64":return this.ToBase64(r);case"base64url":return this.ToBase64Url(r);case"utf16le":return O.toString(r,!0);case"utf16":case"utf16be":return O.toString(r);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return O.fromString(e,!0);case"utf16":case"utf16be":return O.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){const t=k.toUint8Array(e);if("undefined"!=typeof btoa){const e=this.ToString(t,"binary");return btoa(e)}return Buffer.from(t).toString("base64")}static FromBase64(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!C.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return"undefined"!=typeof atob?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!C.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=C.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return I.fromString(e);case"utf16":case"utf16be":return O.fromString(e);case"utf16le":case"usc2":return O.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=C.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return I.toString(e);case"utf16":case"utf16be":return O.toString(e);case"utf16le":case"usc2":return O.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){const t=e.length,r=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=e.charCodeAt(i);return r.buffer}static ToBinary(e){const t=k.toUint8Array(e);let r="";for(let i=0;i<t.length;i++)r+=String.fromCharCode(t[i]);return r}static ToHex(e){const t=k.toUint8Array(e);let r="";const i=t.length;for(let n=0;n<i;n++){const e=t[n];e<16&&(r+="0"),r+=e.toString(16)}return r}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!C.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);const r=new Uint8Array(t.length/2);for(let i=0;i<t.length;i+=2){const e=t.slice(i,i+2);r[i/2]=parseInt(e,16)}return r.buffer}static ToUtf16String(e,t=!1){return O.toString(e,t)}static FromUtf16String(e,t=!1){return O.fromString(e,t)}static Base64Padding(e){const t=4-e.length%4;if(t<4)for(let r=0;r<t;r++)e+="=";return e}static formatString(e){return(null==e?void 0:e.replace(/[\n\r\t ]/g,""))||""}}
|
|
15
|
+
***************************************************************************** */var A,E;E=A||(A={}),function(){var e="object"==typeof globalThis?globalThis:"object"==typeof i.commonjsGlobal?i.commonjsGlobal:"object"==typeof self?self:"object"==typeof this?this:function(){try{return Function("return this;")()}catch(e){}}()||function(){try{return(0,eval)("(function() { return this; })()")}catch(e){}}(),t=r(E);function r(e,t){return function(r,i){Object.defineProperty(e,r,{configurable:!0,writable:!0,value:i}),t&&t(r,i)}}void 0!==e.Reflect&&(t=r(e.Reflect,t)),function(e,t){var r=Object.prototype.hasOwnProperty,i="function"==typeof Symbol,n=i&&void 0!==Symbol.toPrimitive?Symbol.toPrimitive:"@@toPrimitive",o=i&&void 0!==Symbol.iterator?Symbol.iterator:"@@iterator",s="function"==typeof Object.create,a={__proto__:[]}instanceof Array,c=!s&&!a,u={create:s?function(){return pe(Object.create(null))}:a?function(){return pe({__proto__:null})}:function(){return pe({})},has:c?function(e,t){return r.call(e,t)}:function(e,t){return t in e},get:c?function(e,t){return r.call(e,t)?e[t]:void 0}:function(e,t){return e[t]}},l=Object.getPrototypeOf(Function),p="function"==typeof Map&&"function"==typeof Map.prototype.entries?Map:ce(),h="function"==typeof Set&&"function"==typeof Set.prototype.entries?Set:ue(),d="function"==typeof WeakMap?WeakMap:le(),f=i?Symbol.for("@reflect-metadata:registry"):void 0,y=ne(),g=oe(y);function m(e,t,r,i){if(U(r)){if(!W(e))throw new TypeError;if(!q(t))throw new TypeError;return N(e,t)}if(!W(e))throw new TypeError;if(!L(t))throw new TypeError;if(!L(i)&&!U(i)&&!$(i))throw new TypeError;return $(i)&&(i=void 0),I(e,t,r=z(r),i)}function v(e,t){function r(r,i){if(!L(r))throw new TypeError;if(!U(i)&&!G(i))throw new TypeError;D(e,t,r,i)}return r}function w(e,t,r,i){if(!L(r))throw new TypeError;return U(i)||(i=z(i)),D(e,t,r,i)}function b(e,t,r){if(!L(t))throw new TypeError;return U(r)||(r=z(r)),T(e,t,r)}function S(e,t,r){if(!L(t))throw new TypeError;return U(r)||(r=z(r)),B(e,t,r)}function A(e,t,r){if(!L(t))throw new TypeError;return U(r)||(r=z(r)),O(e,t,r)}function E(e,t,r){if(!L(t))throw new TypeError;return U(r)||(r=z(r)),C(e,t,r)}function k(e,t){if(!L(e))throw new TypeError;return U(t)||(t=z(t)),j(e,t)}function x(e,t){if(!L(e))throw new TypeError;return U(t)||(t=z(t)),P(e,t)}function _(e,t,r){if(!L(t))throw new TypeError;if(U(r)||(r=z(r)),!L(t))throw new TypeError;U(r)||(r=z(r));var i=ae(t,r,!1);return!U(i)&&i.OrdinaryDeleteMetadata(e,t,r)}function N(e,t){for(var r=e.length-1;r>=0;--r){var i=(0,e[r])(t);if(!U(i)&&!$(i)){if(!q(i))throw new TypeError;t=i}}return t}function I(e,t,r,i){for(var n=e.length-1;n>=0;--n){var o=(0,e[n])(t,r,i);if(!U(o)&&!$(o)){if(!L(o))throw new TypeError;i=o}}return i}function T(e,t,r){if(B(e,t,r))return!0;var i=re(t);return!$(i)&&T(e,i,r)}function B(e,t,r){var i=ae(t,r,!1);return!U(i)&&K(i.OrdinaryHasOwnMetadata(e,t,r))}function O(e,t,r){if(B(e,t,r))return C(e,t,r);var i=re(t);return $(i)?void 0:O(e,i,r)}function C(e,t,r){var i=ae(t,r,!1);if(!U(i))return i.OrdinaryGetOwnMetadata(e,t,r)}function D(e,t,r,i){ae(r,i,!0).OrdinaryDefineOwnMetadata(e,t,r,i)}function j(e,t){var r=P(e,t),i=re(e);if(null===i)return r;var n=j(i,t);if(n.length<=0)return r;if(r.length<=0)return n;for(var o=new h,s=[],a=0,c=r;a<c.length;a++){var u=c[a];o.has(u)||(o.add(u),s.push(u))}for(var l=0,p=n;l<p.length;l++)u=p[l],o.has(u)||(o.add(u),s.push(u));return s}function P(e,t){var r=ae(e,t,!1);return r?r.OrdinaryOwnMetadataKeys(e,t):[]}function R(e){if(null===e)return 1;switch(typeof e){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return null===e?1:6;default:return 6}}function U(e){return void 0===e}function $(e){return null===e}function M(e){return"symbol"==typeof e}function L(e){return"object"==typeof e?null!==e:"function"==typeof e}function V(e,t){switch(R(e)){case 0:case 1:case 2:case 3:case 4:case 5:return e}var r=3===t?"string":5===t?"number":"default",i=Y(e,n);if(void 0!==i){var o=i.call(e,r);if(L(o))throw new TypeError;return o}return H(e,"default"===r?"number":r)}function H(e,t){if("string"===t){var r=e.toString;if(J(r)&&!L(n=r.call(e)))return n;if(J(i=e.valueOf)&&!L(n=i.call(e)))return n}else{var i;if(J(i=e.valueOf)&&!L(n=i.call(e)))return n;var n,o=e.toString;if(J(o)&&!L(n=o.call(e)))return n}throw new TypeError}function K(e){return!!e}function F(e){return""+e}function z(e){var t=V(e,3);return M(t)?t:F(t)}function W(e){return Array.isArray?Array.isArray(e):e instanceof Object?e instanceof Array:"[object Array]"===Object.prototype.toString.call(e)}function J(e){return"function"==typeof e}function q(e){return"function"==typeof e}function G(e){switch(R(e)){case 3:case 4:return!0;default:return!1}}function X(e,t){return e===t||e!=e&&t!=t}function Y(e,t){var r=e[t];if(null!=r){if(!J(r))throw new TypeError;return r}}function Z(e){var t=Y(e,o);if(!J(t))throw new TypeError;var r=t.call(e);if(!L(r))throw new TypeError;return r}function Q(e){return e.value}function ee(e){var t=e.next();return!t.done&&t}function te(e){var t=e.return;t&&t.call(e)}function re(e){var t=Object.getPrototypeOf(e);if("function"!=typeof e||e===l)return t;if(t!==l)return t;var r=e.prototype,i=r&&Object.getPrototypeOf(r);if(null==i||i===Object.prototype)return t;var n=i.constructor;return"function"!=typeof n||n===e?t:n}function ie(){var e,r,i,n;U(f)||void 0===t.Reflect||f in t.Reflect||"function"!=typeof t.Reflect.defineMetadata||(e=se(t.Reflect));var o=new d,s={registerProvider:a,getProvider:u,setProvider:y};return s;function a(t){if(!Object.isExtensible(s))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case e===t:break;case U(r):r=t;break;case r===t:break;case U(i):i=t;break;case i===t:break;default:void 0===n&&(n=new h),n.add(t)}}function c(t,o){if(!U(r)){if(r.isProviderFor(t,o))return r;if(!U(i)){if(i.isProviderFor(t,o))return r;if(!U(n))for(var s=Z(n);;){var a=ee(s);if(!a)return;var c=Q(a);if(c.isProviderFor(t,o))return te(s),c}}}if(!U(e)&&e.isProviderFor(t,o))return e}function u(e,t){var r,i=o.get(e);return U(i)||(r=i.get(t)),U(r)?(U(r=c(e,t))||(U(i)&&(i=new p,o.set(e,i)),i.set(t,r)),r):r}function l(e){if(U(e))throw new TypeError;return r===e||i===e||!U(n)&&n.has(e)}function y(e,t,r){if(!l(r))throw new Error("Metadata provider not registered.");var i=u(e,t);if(i!==r){if(!U(i))return!1;var n=o.get(e);U(n)&&(n=new p,o.set(e,n)),n.set(t,r)}return!0}}function ne(){var e;return!U(f)&&L(t.Reflect)&&Object.isExtensible(t.Reflect)&&(e=t.Reflect[f]),U(e)&&(e=ie()),!U(f)&&L(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,f,{enumerable:!1,configurable:!1,writable:!1,value:e}),e}function oe(e){var t=new d,r={isProviderFor:function(e,r){var i=t.get(e);return!U(i)&&i.has(r)},OrdinaryDefineOwnMetadata:s,OrdinaryHasOwnMetadata:n,OrdinaryGetOwnMetadata:o,OrdinaryOwnMetadataKeys:a,OrdinaryDeleteMetadata:c};return y.registerProvider(r),r;function i(i,n,o){var s=t.get(i),a=!1;if(U(s)){if(!o)return;s=new p,t.set(i,s),a=!0}var c=s.get(n);if(U(c)){if(!o)return;if(c=new p,s.set(n,c),!e.setProvider(i,n,r))throw s.delete(n),a&&t.delete(i),new Error("Wrong provider for target.")}return c}function n(e,t,r){var n=i(t,r,!1);return!U(n)&&K(n.has(e))}function o(e,t,r){var n=i(t,r,!1);if(!U(n))return n.get(e)}function s(e,t,r,n){i(r,n,!0).set(e,t)}function a(e,t){var r=[],n=i(e,t,!1);if(U(n))return r;for(var o=Z(n.keys()),s=0;;){var a=ee(o);if(!a)return r.length=s,r;var c=Q(a);try{r[s]=c}catch(u){try{te(o)}finally{throw u}}s++}}function c(e,r,n){var o=i(r,n,!1);if(U(o))return!1;if(!o.delete(e))return!1;if(0===o.size){var s=t.get(r);U(s)||(s.delete(n),0===s.size&&t.delete(s))}return!0}}function se(e){var t=e.defineMetadata,r=e.hasOwnMetadata,i=e.getOwnMetadata,n=e.getOwnMetadataKeys,o=e.deleteMetadata,s=new d;return{isProviderFor:function(e,t){var r=s.get(e);return!(U(r)||!r.has(t))||!!n(e,t).length&&(U(r)&&(r=new h,s.set(e,r)),r.add(t),!0)},OrdinaryDefineOwnMetadata:t,OrdinaryHasOwnMetadata:r,OrdinaryGetOwnMetadata:i,OrdinaryOwnMetadataKeys:n,OrdinaryDeleteMetadata:o}}function ae(e,t,r){var i=y.getProvider(e,t);if(!U(i))return i;if(r){if(y.setProvider(e,t,g))return g;throw new Error("Illegal state.")}}function ce(){var e={},t=[],r=function(){function e(e,t,r){this._index=0,this._keys=e,this._values=t,this._selector=r}return e.prototype["@@iterator"]=function(){return this},e.prototype[o]=function(){return this},e.prototype.next=function(){var e=this._index;if(e>=0&&e<this._keys.length){var r=this._selector(this._keys[e],this._values[e]);return e+1>=this._keys.length?(this._index=-1,this._keys=t,this._values=t):this._index++,{value:r,done:!1}}return{value:void 0,done:!0}},e.prototype.throw=function(e){throw this._index>=0&&(this._index=-1,this._keys=t,this._values=t),e},e.prototype.return=function(e){return this._index>=0&&(this._index=-1,this._keys=t,this._values=t),{value:e,done:!0}},e}();return function(){function t(){this._keys=[],this._values=[],this._cacheKey=e,this._cacheIndex=-2}return Object.defineProperty(t.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),t.prototype.has=function(e){return this._find(e,!1)>=0},t.prototype.get=function(e){var t=this._find(e,!1);return t>=0?this._values[t]:void 0},t.prototype.set=function(e,t){var r=this._find(e,!0);return this._values[r]=t,this},t.prototype.delete=function(t){var r=this._find(t,!1);if(r>=0){for(var i=this._keys.length,n=r+1;n<i;n++)this._keys[n-1]=this._keys[n],this._values[n-1]=this._values[n];return this._keys.length--,this._values.length--,X(t,this._cacheKey)&&(this._cacheKey=e,this._cacheIndex=-2),!0}return!1},t.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=e,this._cacheIndex=-2},t.prototype.keys=function(){return new r(this._keys,this._values,i)},t.prototype.values=function(){return new r(this._keys,this._values,n)},t.prototype.entries=function(){return new r(this._keys,this._values,s)},t.prototype["@@iterator"]=function(){return this.entries()},t.prototype[o]=function(){return this.entries()},t.prototype._find=function(e,t){if(!X(this._cacheKey,e)){this._cacheIndex=-1;for(var r=0;r<this._keys.length;r++)if(X(this._keys[r],e)){this._cacheIndex=r;break}}return this._cacheIndex<0&&t&&(this._cacheIndex=this._keys.length,this._keys.push(e),this._values.push(void 0)),this._cacheIndex},t}();function i(e,t){return e}function n(e,t){return t}function s(e,t){return[e,t]}}function ue(){return function(){function e(){this._map=new p}return Object.defineProperty(e.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),e.prototype.has=function(e){return this._map.has(e)},e.prototype.add=function(e){return this._map.set(e,e),this},e.prototype.delete=function(e){return this._map.delete(e)},e.prototype.clear=function(){this._map.clear()},e.prototype.keys=function(){return this._map.keys()},e.prototype.values=function(){return this._map.keys()},e.prototype.entries=function(){return this._map.entries()},e.prototype["@@iterator"]=function(){return this.keys()},e.prototype[o]=function(){return this.keys()},e}()}function le(){var e=16,t=u.create(),i=n();return function(){function e(){this._key=n()}return e.prototype.has=function(e){var t=o(e,!1);return void 0!==t&&u.has(t,this._key)},e.prototype.get=function(e){var t=o(e,!1);return void 0!==t?u.get(t,this._key):void 0},e.prototype.set=function(e,t){return o(e,!0)[this._key]=t,this},e.prototype.delete=function(e){var t=o(e,!1);return void 0!==t&&delete t[this._key]},e.prototype.clear=function(){this._key=n()},e}();function n(){var e;do{e="@@WeakMap@@"+c()}while(u.has(t,e));return t[e]=!0,e}function o(e,t){if(!r.call(e,i)){if(!t)return;Object.defineProperty(e,i,{value:u.create()})}return e[i]}function s(e,t){for(var r=0;r<t;++r)e[r]=255*Math.random()|0;return e}function a(e){if("function"==typeof Uint8Array){var t=new Uint8Array(e);return"undefined"!=typeof crypto?crypto.getRandomValues(t):"undefined"!=typeof msCrypto?msCrypto.getRandomValues(t):s(t,e),t}return s(new Array(e),e)}function c(){var t=a(e);t[6]=79&t[6]|64,t[8]=191&t[8]|128;for(var r="",i=0;i<e;++i){var n=t[i];4!==i&&6!==i&&8!==i||(r+="-"),n<16&&(r+="0"),r+=n.toString(16).toLowerCase()}return r}}function pe(e){return e.__=void 0,delete e.__,e}e("decorate",m),e("metadata",v),e("defineMetadata",w),e("hasMetadata",b),e("hasOwnMetadata",S),e("getMetadata",A),e("getOwnMetadata",E),e("getMetadataKeys",k),e("getOwnMetadataKeys",x),e("deleteMetadata",_)}(t,e),void 0===e.Reflect&&(e.Reflect=E)}();class k{static isArrayBuffer(e){return"[object ArrayBuffer]"===Object.prototype.toString.call(e)}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||0===e.byteOffset&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){const r=k.toUint8Array(e),i=k.toUint8Array(t);if(r.length!==i.byteLength)return!1;for(let n=0;n<r.length;n++)if(r[n]!==i[n])return!1;return!0}static concat(...e){let t;t=!Array.isArray(e[0])||e[1]instanceof Function?Array.isArray(e[0])&&e[1]instanceof Function?e[0]:e[e.length-1]instanceof Function?e.slice(0,e.length-1):e:e[0];let r=0;for(const o of t)r+=o.byteLength;const i=new Uint8Array(r);let n=0;for(const o of t){const e=this.toUint8Array(o);i.set(e,n),n+=e.length}return e[e.length-1]instanceof Function?this.toView(i,e[e.length-1]):i.buffer}}const x="string",_=/^[0-9a-f\s]+$/i,N=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,I=/^[a-zA-Z0-9-_]+$/;class T{static fromString(e){const t=unescape(encodeURIComponent(e)),r=new Uint8Array(t.length);for(let i=0;i<t.length;i++)r[i]=t.charCodeAt(i);return r.buffer}static toString(e){const t=k.toUint8Array(e);let r="";for(let i=0;i<t.length;i++)r+=String.fromCharCode(t[i]);return decodeURIComponent(escape(r))}}class B{static toString(e,t=!1){const r=k.toArrayBuffer(e),i=new DataView(r);let n="";for(let o=0;o<r.byteLength;o+=2){const e=i.getUint16(o,t);n+=String.fromCharCode(e)}return n}static fromString(e,t=!1){const r=new ArrayBuffer(2*e.length),i=new DataView(r);for(let n=0;n<e.length;n++)i.setUint16(2*n,e.charCodeAt(n),t);return r}}class O{static isHex(e){return typeof e===x&&_.test(e)}static isBase64(e){return typeof e===x&&N.test(e)}static isBase64Url(e){return typeof e===x&&I.test(e)}static ToString(e,t="utf8"){const r=k.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(r);case"binary":return this.ToBinary(r);case"hex":return this.ToHex(r);case"base64":return this.ToBase64(r);case"base64url":return this.ToBase64Url(r);case"utf16le":return B.toString(r,!0);case"utf16":case"utf16be":return B.toString(r);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return B.fromString(e,!0);case"utf16":case"utf16be":return B.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){const t=k.toUint8Array(e);if("undefined"!=typeof btoa){const e=this.ToString(t,"binary");return btoa(e)}return Buffer.from(t).toString("base64")}static FromBase64(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!O.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return"undefined"!=typeof atob?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!O.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=O.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return T.fromString(e);case"utf16":case"utf16be":return B.fromString(e);case"utf16le":case"usc2":return B.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=O.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return T.toString(e);case"utf16":case"utf16be":return B.toString(e);case"utf16le":case"usc2":return B.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){const t=e.length,r=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=e.charCodeAt(i);return r.buffer}static ToBinary(e){const t=k.toUint8Array(e);let r="";for(let i=0;i<t.length;i++)r+=String.fromCharCode(t[i]);return r}static ToHex(e){const t=k.toUint8Array(e);let r="";const i=t.length;for(let n=0;n<i;n++){const e=t[n];e<16&&(r+="0"),r+=e.toString(16)}return r}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!O.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);const r=new Uint8Array(t.length/2);for(let i=0;i<t.length;i+=2){const e=t.slice(i,i+2);r[i/2]=parseInt(e,16)}return r.buffer}static ToUtf16String(e,t=!1){return B.toString(e,t)}static FromUtf16String(e,t=!1){return B.fromString(e,t)}static Base64Padding(e){const t=4-e.length%4;if(t<4)for(let r=0;r<t;r++)e+="=";return e}static formatString(e){return(null==e?void 0:e.replace(/[\n\r\t ]/g,""))||""}}
|
|
16
16
|
/*!
|
|
17
17
|
Copyright (c) Peculiar Ventures, LLC
|
|
18
18
|
*/
|
|
19
|
-
function
|
|
19
|
+
function C(e,t){let r=0;if(1===e.length)return e[0];for(let i=e.length-1;i>=0;i--)r+=e[e.length-1-i]*Math.pow(2,t*i);return r}function D(e,t,r=-1){const i=r;let n=e,o=0,s=Math.pow(2,t);for(let a=1;a<8;a++){if(e<s){let e;if(i<0)e=new ArrayBuffer(a),o=a;else{if(i<a)return new ArrayBuffer(0);e=new ArrayBuffer(i),o=i}const r=new Uint8Array(e);for(let i=a-1;i>=0;i--){const e=Math.pow(2,i*t);r[o-i-1]=Math.floor(n/e),n-=r[o-i-1]*e}return e}s*=Math.pow(2,t)}return new ArrayBuffer(0)}function j(...e){let t=0,r=0;for(const o of e)t+=o.length;const i=new ArrayBuffer(t),n=new Uint8Array(i);for(const o of e)n.set(o,r),r+=o.length;return n}function P(){const e=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){const t=255===e[0]&&128&e[1],r=0===e[0]&&!(128&e[1]);(t||r)&&this.warnings.push("Needlessly long format")}const t=new ArrayBuffer(this.valueHex.byteLength),r=new Uint8Array(t);for(let s=0;s<this.valueHex.byteLength;s++)r[s]=0;r[0]=128&e[0];const i=C(r,8),n=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(n);for(let s=0;s<this.valueHex.byteLength;s++)o[s]=e[s];o[0]&=127;return C(o,8)-i}function R(e,t){const r=e.toString(10);if(t<r.length)return"";const i=t-r.length,n=new Array(i);for(let o=0;o<i;o++)n[o]="0";return n.join("").concat(r)}
|
|
20
20
|
/*!
|
|
21
21
|
* Copyright (c) 2014, GMO GlobalSign
|
|
22
22
|
* Copyright (c) 2015-2022, Peculiar Ventures
|
|
@@ -49,7 +49,7 @@ function j(e,t){let r=0;if(1===e.length)return e[0];for(let i=e.length-1;i>=0;i-
|
|
|
49
49
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
50
50
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
51
51
|
*
|
|
52
|
-
*/function U(){if("undefined"==typeof BigInt)throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function L(e){let t=0,r=0;for(let n=0;n<e.length;n++){t+=e[n].byteLength}const i=new Uint8Array(t);for(let n=0;n<e.length;n++){const t=e[n];i.set(new Uint8Array(t),r),r+=t.byteLength}return i.buffer}function $(e,t,r,i){return t instanceof Uint8Array?t.byteLength?r<0?(e.error="Wrong parameter: inputOffset less than zero",!1):i<0?(e.error="Wrong parameter: inputLength less than zero",!1):!(t.byteLength-r-i<0)||(e.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):(e.error="Wrong parameter: inputBuffer has zero length",!1):(e.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}C.DEFAULT_UTF8_ENCODING="utf8";class V{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return L(this.items)}}const M=[new Uint8Array([1])],H="0123456789",K="name",F="valueHexView",z="",W=new ArrayBuffer(0),q=new Uint8Array(0),J="EndOfContent",X="OCTET STRING",G="BIT STRING";function Y(e){var t;return(t=class extends e{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(e){this.valueHexView=new Uint8Array(e)}constructor(...e){var t;super(...e);const r=e[0]||{};this.isHexOnly=null!==(t=r.isHexOnly)&&void 0!==t&&t,this.valueHexView=r.valueHex?k.toUint8Array(r.valueHex):q}fromBER(e,t,r,i){const n=e instanceof ArrayBuffer?new Uint8Array(e):e;if(!$(this,n,t,r))return-1;const o=t+r;return this.valueHexView=n.subarray(t,o),this.valueHexView.length?(this.blockLength=r,o):(this.warnings.push("Zero buffer length"),t)}toBER(e=!1){return this.isHexOnly?e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",W)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:C.ToHex(this.valueHexView)}}}).NAME="hexBlock",t}class Z{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:t="",warnings:r=[],valueBeforeDecode:i=q}={}){this.blockLength=e,this.error=t,this.warnings=r,this.valueBeforeDecodeView=k.toUint8Array(i)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:C.ToHex(this.valueBeforeDecodeView)}}}Z.NAME="baseBlock";class Q extends Z{fromBER(e,t,r,i){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}}Q.NAME="valueBlock";class ee extends(Y(Z)){constructor({idBlock:e={}}={}){var t,r,i,n;super(),e?(this.isHexOnly=null!==(t=e.isHexOnly)&&void 0!==t&&t,this.valueHexView=e.valueHex?k.toUint8Array(e.valueHex):q,this.tagClass=null!==(r=e.tagClass)&&void 0!==r?r:-1,this.tagNumber=null!==(i=e.tagNumber)&&void 0!==i?i:-1,this.isConstructed=null!==(n=e.isConstructed)&&void 0!==n&&n):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",W}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){const r=new Uint8Array(1);if(!e){let e=this.tagNumber;e&=31,t|=e,r[0]=t}return r.buffer}if(!this.isHexOnly){const r=_(this.tagNumber,7),i=new Uint8Array(r),n=r.byteLength,o=new Uint8Array(n+1);if(o[0]=31|t,!e){for(let e=0;e<n-1;e++)o[e+1]=128|i[e];o[n]=i[n-1]}return o.buffer}const r=new Uint8Array(this.valueHexView.byteLength+1);if(r[0]=31|t,!e){const e=this.valueHexView;for(let t=0;t<e.length-1;t++)r[t+1]=128|e[t];r[this.valueHexView.byteLength]=e[e.length-1]}return r.buffer}fromBER(e,t,r){const i=k.toUint8Array(e);if(!$(this,i,t,r))return-1;const n=i.subarray(t,t+r);if(0===n.length)return this.error="Zero buffer length",-1;switch(192&n[0]){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=!(32&~n[0]),this.isHexOnly=!1;const o=31&n[0];if(31!==o)this.tagNumber=o,this.blockLength=1;else{let e=0;for(;;){const t=e+1;if(t>=n.length)return this.error="End of input reached before message was fully decoded",-1;if(e++,!(128&n[t]))break}this.blockLength=e+1;const t=this.valueHexView=new Uint8Array(e);for(let r=0;r<e;r++)t[r]=127&n[r+1];this.blockLength<=9?this.tagNumber=j(t,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(1===this.tagClass&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}}ee.NAME="identificationBlock";class te extends Z{constructor({lenBlock:e={}}={}){var t,r,i;super(),this.isIndefiniteForm=null!==(t=e.isIndefiniteForm)&&void 0!==t&&t,this.longFormUsed=null!==(r=e.longFormUsed)&&void 0!==r&&r,this.length=null!==(i=e.length)&&void 0!==i?i:0}fromBER(e,t,r){const i=k.toUint8Array(e);if(!$(this,i,t,r))return-1;const n=i.subarray(t,t+r);if(0===n.length)return this.error="Zero buffer length",-1;if(255===n[0])return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=128===n[0],this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(128&n[0]),!1===this.longFormUsed)return this.length=n[0],this.blockLength=1,t+this.blockLength;const o=127&n[0];if(o>8)return this.error="Too big integer",-1;if(o+1>n.length)return this.error="End of input reached before message was fully decoded",-1;const s=t+1,a=i.subarray(s,s+o);return 0===a[o-1]&&this.warnings.push("Needlessly long encoded length"),this.length=j(a,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,r;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),!1===e&&(r=new Uint8Array(t),r[0]=128),t;if(this.longFormUsed){const i=_(this.length,8);if(i.byteLength>127)return this.error="Too big length",W;if(t=new ArrayBuffer(i.byteLength+1),e)return t;const n=new Uint8Array(i);r=new Uint8Array(t),r[0]=128|i.byteLength;for(let e=0;e<i.byteLength;e++)r[e+1]=n[e];return t}return t=new ArrayBuffer(1),!1===e&&(r=new Uint8Array(t),r[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}}te.NAME="lengthBlock";const re={};class ie extends Z{constructor({name:e="",optional:t=!1,primitiveSchema:r,...i}={},n){super(i),this.name=e,this.optional=t,r&&(this.primitiveSchema=r),this.idBlock=new ee(i),this.lenBlock=new te(i),this.valueBlock=n?new n(i):new Q(i)}fromBER(e,t,r,i){const n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length,i);return-1===n?(this.error=this.valueBlock.error,n):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),n)}toBER(e,t){const r=t||new V;t||ne(this);const i=this.idBlock.toBER(e);if(r.write(i),this.lenBlock.isIndefiniteForm)r.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,r),r.write(new ArrayBuffer(2));else{const t=this.valueBlock.toBER(e);this.lenBlock.length=t.byteLength;const i=this.lenBlock.toBER(e);r.write(i),r.write(t)}return t?W:r.final()}toJSON(){const e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return"ascii"===e?this.onAsciiEncoding():C.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${C.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;return function(e,t){if(e.byteLength!==t.byteLength)return!1;const r=new Uint8Array(e),i=new Uint8Array(t);for(let n=0;n<r.length;n++)if(r[n]!==i[n])return!1;return!0}(this.toBER(),e.toBER())}}function ne(e){var t;if(e instanceof re.Constructed)for(const r of e.valueBlock.value)ne(r)&&(e.lenBlock.isIndefiniteForm=!0);return!!(null===(t=e.lenBlock)||void 0===t?void 0:t.isIndefiniteForm)}ie.NAME="BaseBlock";class oe extends ie{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e="",...t}={},r){super(t,r),e&&this.fromString(e)}fromBER(e,t,r){const i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return-1===i?(this.error=this.valueBlock.error,i):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}}oe.NAME="BaseStringBlock";class se extends(Y(Q)){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}}var ae;se.NAME="PrimitiveValueBlock";class ce extends ie{constructor(e={}){super(e,se),this.idBlock.isConstructed=!1}}ae=ce,re.Primitive=ae,ce.NAME="PRIMITIVE";const ue=16777216;function le(e={}){var t,r,i;return{depth:0,maxDepth:null!==(t=e.maxDepth)&&void 0!==t?t:100,nodesCount:0,maxNodes:null!==(r=e.maxNodes)&&void 0!==r?r:1e4,maxContentLength:null!==(i=e.maxContentLength)&&void 0!==i?i:ue}}function he(e,t,r,i){const n=i.depth+1;if(n>i.maxDepth)return function(e){const t=new ie({},Q);return t.error=e,{offset:-1,result:t}}("Maximum ASN.1 nesting depth exceeded");i.depth=n;try{return pe(e,t,r,i)}finally{i.depth-=1}}function pe(e,t=0,r=e.length,i=le()){const n=t;let o=new ie({},Q);const s=new Z;if(!$(s,e,t,r))return o.error=s.error,{offset:-1,result:o};if(!e.subarray(t,t+r).length)return o.error="Zero buffer length",{offset:-1,result:o};const a=function(e){if(e.nodesCount+=1,e.nodesCount>e.maxNodes)return"Maximum ASN.1 node count exceeded"}(i);if(a)return o.error=a,{offset:-1,result:o};let c=o.idBlock.fromBER(e,t,r);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),-1===c)return o.error=o.idBlock.error,{offset:-1,result:o};if(t=c,r-=o.idBlock.blockLength,c=o.lenBlock.fromBER(e,t,r),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),-1===c)return o.error=o.lenBlock.error,{offset:-1,result:o};t=c,r-=o.lenBlock.blockLength;const u=o.lenBlock.isIndefiniteForm?r:o.lenBlock.length,l=function(e,t){if(e>t.maxContentLength)return"Maximum ASN.1 content length exceeded"}(u,i);if(l)return o.error=l,{offset:-1,result:o};if(!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let h=ie;if(1===o.idBlock.tagClass){if(o.idBlock.tagNumber>=37&&!1===o.idBlock.isHexOnly)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};h=re.EndOfContent;break;case 1:h=re.Boolean;break;case 2:h=re.Integer;break;case 3:h=re.BitString;break;case 4:h=re.OctetString;break;case 5:h=re.Null;break;case 6:h=re.ObjectIdentifier;break;case 10:h=re.Enumerated;break;case 12:h=re.Utf8String;break;case 13:h=re.RelativeObjectIdentifier;break;case 14:h=re.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:h=re.Sequence;break;case 17:h=re.Set;break;case 18:h=re.NumericString;break;case 19:h=re.PrintableString;break;case 20:h=re.TeletexString;break;case 21:h=re.VideotexString;break;case 22:h=re.IA5String;break;case 23:h=re.UTCTime;break;case 24:h=re.GeneralizedTime;break;case 25:h=re.GraphicString;break;case 26:h=re.VisibleString;break;case 27:h=re.GeneralString;break;case 28:h=re.UniversalString;break;case 29:h=re.CharacterString;break;case 30:h=re.BmpString;break;case 31:h=re.DATE;break;case 32:h=re.TimeOfDay;break;case 33:h=re.DateTime;break;case 34:h=re.Duration;break;default:{const e=o.idBlock.isConstructed?new re.Constructed:new re.Primitive;e.idBlock=o.idBlock,e.lenBlock=o.lenBlock,e.warnings=o.warnings,o=e}}}else h=o.idBlock.isConstructed?re.Constructed:re.Primitive;return o=function(e,t){if(e instanceof t)return e;const r=new t;return r.idBlock=e.idBlock,r.lenBlock=e.lenBlock,r.warnings=e.warnings,r.valueBeforeDecodeView=e.valueBeforeDecodeView,r}(o,h),c=o.fromBER(e,t,u,i),o.valueBeforeDecodeView=e.subarray(n,n+o.blockLength),{offset:c,result:o}}function fe(e,t={}){if(!e.byteLength){const e=new ie({},Q);return e.error="Input buffer has zero length",{offset:-1,result:e}}return pe(k.toUint8Array(e).slice(),0,e.byteLength,le(t))}class de extends Q{constructor({value:e=[],isIndefiniteForm:t=!1,...r}={}){super(r),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,r,i){const n=k.toUint8Array(e),o=null!=i?i:le();if(!$(this,n,t,r))return-1;if(this.valueBeforeDecodeView=n.subarray(t,t+r),0===this.valueBeforeDecodeView.length)return this.warnings.push("Zero buffer length"),t;let s=t;for(;a=this.isIndefiniteForm,c=r,(a?1:c)>0;){const e=he(n,s,r,o);if(-1===e.offset)return this.error=e.result.error,this.warnings.concat(e.result.warnings),-1;if(s=e.offset,this.blockLength+=e.result.blockLength,r-=e.result.blockLength,this.value.push(e.result),this.isIndefiniteForm&&e.result.constructor.NAME===J)break}var a,c;return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===J?this.value.pop():this.warnings.push("No EndOfContent block encoded")),s}toBER(e,t){const r=t||new V;for(let i=0;i<this.value.length;i++)this.value[i].toBER(e,r);return t?W:r.final()}toJSON(){const e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(const t of this.value)e.value.push(t.toJSON());return e}}var ye,ge,ve,me,we;de.NAME="ConstructedValueBlock";class be extends ie{constructor(e={}){super(e,de),this.idBlock.isConstructed=!0}fromBER(e,t,r,i){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;const n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length,i);return-1===n?(this.error=this.valueBlock.error,n):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),n)}onAsciiEncoding(){const e=[];for(const r of this.valueBlock.value)e.push(r.toString("ascii").split("\n").map((e=>` ${e}`)).join("\n"));const t=3===this.idBlock.tagClass?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :\n${e.join("\n")}`:`${t} :`}}ye=be,re.Constructed=ye,be.NAME="CONSTRUCTED";class Se extends Q{fromBER(e,t,r){return t}toBER(e){return W}}Se.override="EndOfContentValueBlock";class Ae extends ie{constructor(e={}){super(e,Se),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}ge=Ae,re.EndOfContent=ge,Ae.NAME=J;class xe extends ie{constructor(e={}){super(e,Q),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,r){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=r,t+r>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+r}toBER(e,t){const r=new ArrayBuffer(2);if(!e){const e=new Uint8Array(r);e[0]=5,e[1]=0}return t&&t.write(r),r}onAsciiEncoding(){return`${this.constructor.NAME}`}}ve=xe,re.Null=ve,xe.NAME="NULL";class ke extends(Y(Q)){get value(){for(const e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=k.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,r){const i=k.toUint8Array(e);return $(this,i,t,r)?(this.valueHexView=i.subarray(t,t+r),r>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,R.call(this),this.blockLength=r,t+r):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}ke.NAME="BooleanValueBlock";class Ee extends ie{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,ke),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}me=Ee,re.Boolean=me,Ee.NAME="BOOLEAN";class Be extends(Y(de)){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,r,i){let n=0;if(this.isConstructed){if(this.isHexOnly=!1,n=de.prototype.fromBER.call(this,e,t,r,i),-1===n)return n;for(let e=0;e<this.value.length;e++){const t=this.value[e].constructor.NAME;if(t===J){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(t!==X)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,n=super.fromBER(e,t,r),this.blockLength=r;return n}toBER(e,t){return this.isConstructed?de.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}Be.NAME="OctetStringValueBlock";let Ne=class extends ie{constructor({idBlock:e={},lenBlock:t={},...r}={}){var i,n;null!==(i=r.isConstructed)&&void 0!==i||(r.isConstructed=!!(null===(n=r.value)||void 0===n?void 0:n.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},Be),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,r,i){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,0===r)return 0===this.idBlock.error.length&&(this.blockLength+=this.idBlock.blockLength),0===this.lenBlock.error.length&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){const n=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+r);try{if(n.byteLength){const e=null!=i?i:le(),t=he(n,0,n.byteLength,e);-1!==t.offset&&t.offset===r&&(this.valueBlock.value=[t.result])}}catch{}}return super.fromBER(e,t,r,i)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return be.prototype.onAsciiEncoding.call(this);return`${this.constructor.NAME} : ${C.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;const e=[];for(const t of this.valueBlock.value)t instanceof we&&e.push(t.valueBlock.valueHexView);return k.concat(e)}};we=Ne,re.OctetString=we,Ne.NAME=X;class Te extends(Y(de)){constructor({unusedBits:e=0,isConstructed:t=!1,...r}={}){super(r),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,r,i){if(!r)return t;let n=-1;if(this.isConstructed){if(n=de.prototype.fromBER.call(this,e,t,r,i),-1===n)return n;for(const e of this.value){const t=e.constructor.NAME;if(t===J){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(t!==G)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const r=e.valueBlock;if(this.unusedBits>0&&r.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=r.unusedBits}return n}const o=k.toUint8Array(e);if(!$(this,o,t,r))return-1;const s=o.subarray(t,t+r);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){const e=s.subarray(1);try{if(e.byteLength){const t=null!=i?i:le(),n=he(e,0,e.byteLength,t);-1!==n.offset&&n.offset===r-1&&(this.value=[n.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+r}toBER(e,t){if(this.isConstructed)return de.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength){const e=new Uint8Array(1);return e[0]=0,e.buffer}const r=new Uint8Array(this.valueHexView.length+1);return r[0]=this.unusedBits,r.set(this.valueHexView,1),r.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}}var Ie;Te.NAME="BitStringValueBlock";let Oe=class extends ie{constructor({idBlock:e={},lenBlock:t={},...r}={}){var i,n;null!==(i=r.isConstructed)&&void 0!==i||(r.isConstructed=!!(null===(n=r.value)||void 0===n?void 0:n.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},Te),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,r,i){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,r,i)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return be.prototype.onAsciiEncoding.call(this);{const e=[],t=this.valueBlock.valueHexView;for(const i of t)e.push(i.toString(2).padStart(8,"0"));const r=e.join("");return`${this.constructor.NAME} : ${r.substring(0,r.length-this.valueBlock.unusedBits)}`}}};var Ce,je,_e,De,Re,Pe,Ue;function Le(e,t){const r=new Uint8Array([0]),i=new Uint8Array(e),n=new Uint8Array(t);let o=i.slice(0);const s=o.length-1,a=n.slice(0),c=a.length-1;let u=0;let l=0;for(let h=c<s?s:c;h>=0;h--,l++){if(!0==l<a.length)u=o[s-l]+a[c-l]+r[0];else u=o[s-l]+r[0];if(r[0]=u/10,!0==l>=o.length)o=D(new Uint8Array([u%10]),o);else o[s-l]=u%10}return r[0]>0&&(o=D(r,o)),o}function $e(e){if(e>=M.length)for(let t=M.length;t<=e;t++){const e=new Uint8Array([0]);let r=M[t-1].slice(0);for(let t=r.length-1;t>=0;t--){const i=new Uint8Array([(r[t]<<1)+e[0]]);e[0]=i[0]/10,r[t]=i[0]%10}e[0]>0&&(r=D(e,r)),M.push(r)}return M[e]}function Ve(e,t){let r=0;const i=new Uint8Array(e),n=new Uint8Array(t),o=i.slice(0),s=o.length-1,a=n.slice(0),c=a.length-1;let u,l=0;for(let h=c;h>=0;h--,l++)if(u=o[s-l]-a[c-l]-r,!0==u<0)r=1,o[s-l]=u+10;else r=0,o[s-l]=u;if(r>0)for(let h=s-c+1;h>=0;h--,l++){if(u=o[s-l]-r,!(u<0)){r=0,o[s-l]=u;break}r=1,o[s-l]=u+10}return o.slice()}Ie=Oe,re.BitString=Ie,Oe.NAME=G;class Me extends(Y(Q)){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=R.call(this)))}constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),void 0!==e&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(function(e){const t=e<0?-1*e:e;let r=128;for(let i=1;i<8;i++){if(t<=r){if(e<0){const e=_(r-t,8,i);return new Uint8Array(e)[0]|=128,e}let n=_(t,8,i),o=new Uint8Array(n);if(128&o[0]){const e=n.slice(0),t=new Uint8Array(e);n=new ArrayBuffer(n.byteLength+1),o=new Uint8Array(n);for(let r=0;r<e.byteLength;r++)o[r+1]=t[r];o[0]=0}return n}r*=Math.pow(2,8)}return new ArrayBuffer(0)}(e))}get valueDec(){return this._valueDec}fromDER(e,t,r,i=0){const n=this.fromBER(e,t,r);if(-1===n)return n;const o=this.valueHexView;return 0===o[0]&&128&o[1]?this.valueHexView=o.subarray(1):0!==i&&o.length<i&&(i-o.length>1&&(i=o.length+1),this.valueHexView=o.subarray(i-o.length)),n}toDER(e=!1){const t=this.valueHexView;switch(!0){case!!(128&t[0]):{const e=new Uint8Array(this.valueHexView.length+1);e[0]=0,e.set(t,1),this.valueHexView=e}break;case 0===t[0]&&!(128&t[1]):this.valueHexView=this.valueHexView.subarray(1)}return this.toBER(e)}fromBER(e,t,r){const i=super.fromBER(e,t,r);return-1===i||this.setValueHex(),i}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){const e=8*this.valueHexView.length-1;let t,r=new Uint8Array(8*this.valueHexView.length/3),i=0;const n=this.valueHexView;let o="",s=!1;for(let a=n.byteLength-1;a>=0;a--){t=n[a];for(let n=0;n<8;n++){if(!(1&~t))if(i===e)r=Ve($e(i),r),o="-";else r=Le(r,$e(i));i++,t>>=1}}for(let a=0;a<r.length;a++)r[a]&&(s=!0),s&&(o+=H.charAt(r[a]));return!1===s&&(o+=H.charAt(0)),o}}Ce=Me,Me.NAME="IntegerValueBlock",Object.defineProperty(Ce.prototype,"valueHex",{set:function(e){this.valueHexView=new Uint8Array(e),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});class He extends ie{constructor(e={}){super(e,Me),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return U(),BigInt(this.valueBlock.toString())}static fromBigInt(e){U();const t=BigInt(e),r=new V,i=t.toString(16).replace(/^-/,""),n=new Uint8Array(C.FromHex(i));if(t<0){const e=new Uint8Array(n.length+(128&n[0]?1:0));e[0]|=128;const i=BigInt(`0x${C.ToHex(e)}`)+t,o=k.toUint8Array(C.FromHex(i.toString(16)));o[0]|=128,r.write(o)}else 128&n[0]&&r.write(new Uint8Array([0])),r.write(n);return new je({valueHex:r.final()})}convertToDER(){const e=new je({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new je({valueHex:0===this.valueBlock.valueHexView[0]?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}je=He,re.Integer=je,He.NAME="INTEGER";class Ke extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}_e=Ke,re.Enumerated=_e,Ke.NAME="ENUMERATED";class Fe extends(Y(Q)){constructor({valueDec:e=-1,isFirstSid:t=!1,...r}={}){super(r),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,r){if(!r)return t;const i=k.toUint8Array(e);if(!$(this,i,t,r))return-1;const n=i.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let s=0;s<r&&(this.valueHexView[s]=127&n[s],this.blockLength++,128&n[s]);s++);const o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength;s++)o[s]=this.valueHexView[s];return this.valueHexView=o,128&n[this.blockLength-1]?(this.error="End of input reached before message was fully decoded",-1):(0===this.valueHexView[0]&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=j(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){U();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;const r=new Uint8Array(t.length/7);for(let i=0;i<r.length;i++)r[i]=parseInt(t.slice(7*i,7*i+7),2)+(i+1<r.length?128:0);this.fromBER(r.buffer,0,r.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const t=this.valueHexView,r=new Uint8Array(this.blockLength);for(let e=0;e<this.blockLength-1;e++)r[e]=128|t[e];return r[this.blockLength-1]=t[this.blockLength-1],r.buffer}const t=_(this.valueDec,7);if(0===t.byteLength)return this.error="Error during encoding SID value",W;const r=new Uint8Array(t.byteLength);if(!e){const e=new Uint8Array(t),i=t.byteLength-1;for(let t=0;t<i;t++)r[t]=128|e[t];r[i]=e[i]}return r}toString(){let e="";if(this.isHexOnly)e=C.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}}Fe.NAME="sidBlock";class ze extends Q{constructor({value:e="",...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let i=t;for(;r>0;){const t=new Fe;if(i=t.fromBER(e,i,r),-1===i)return this.blockLength=0,this.error=t.error,i;0===this.value.length&&(t.isFirstSid=!0),this.blockLength+=t.blockLength,r-=t.blockLength,this.value.push(t)}return i}toBER(e){const t=[];for(let r=0;r<this.value.length;r++){const i=this.value[r].toBER(e);if(0===i.byteLength)return this.error=this.value[r].error,W;t.push(i)}return L(t)}fromString(e){this.value=[];let t=0,r=0,i="",n=!1;do{if(r=e.indexOf(".",t),i=-1===r?e.substring(t):e.substring(t,r),t=r+1,n){const e=this.value[0];let t=0;switch(e.valueDec){case 0:break;case 1:t=40;break;case 2:t=80;break;default:return void(this.value=[])}const r=parseInt(i,10);if(isNaN(r))return;e.valueDec=r+t,n=!1}else{const e=new Fe;if(i>Number.MAX_SAFE_INTEGER){U();const t=BigInt(i);e.valueBigInt=t}else if(e.valueDec=parseInt(i,10),isNaN(e.valueDec))return;this.value.length||(e.isFirstSid=!0,n=!0),this.value.push(e)}}while(-1!==r)}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let i=this.value[r].toString();0!==r&&(e=`${e}.`),t?(i=`{${i}}`,this.value[r].isFirstSid?e=`2.{${i} - 80}`:e+=i):e+=i}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}ze.NAME="ObjectIdentifierValueBlock";class We extends ie{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,ze),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}De=We,re.ObjectIdentifier=De,We.NAME="OBJECT IDENTIFIER";class qe extends(Y(Z)){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,r){if(0===r)return t;const i=k.toUint8Array(e);if(!$(this,i,t,r))return-1;const n=i.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let s=0;s<r&&(this.valueHexView[s]=127&n[s],this.blockLength++,128&n[s]);s++);const o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength;s++)o[s]=this.valueHexView[s];return this.valueHexView=o,128&n[this.blockLength-1]?(this.error="End of input reached before message was fully decoded",-1):(0===this.valueHexView[0]&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=j(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const t=this.valueHexView,r=new Uint8Array(this.blockLength);for(let e=0;e<this.blockLength-1;e++)r[e]=128|t[e];return r[this.blockLength-1]=t[this.blockLength-1],r.buffer}const t=_(this.valueDec,7);if(0===t.byteLength)return this.error="Error during encoding SID value",W;const r=new Uint8Array(t.byteLength);if(!e){const e=new Uint8Array(t),i=t.byteLength-1;for(let t=0;t<i;t++)r[t]=128|e[t];r[i]=e[i]}return r.buffer}toString(){let e="";return e=this.isHexOnly?C.ToHex(this.valueHexView):this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}qe.NAME="relativeSidBlock";class Je extends Q{constructor({value:e="",...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let i=t;for(;r>0;){const t=new qe;if(i=t.fromBER(e,i,r),-1===i)return this.blockLength=0,this.error=t.error,i;this.blockLength+=t.blockLength,r-=t.blockLength,this.value.push(t)}return i}toBER(e,t){const r=[];for(let i=0;i<this.value.length;i++){const t=this.value[i].toBER(e);if(0===t.byteLength)return this.error=this.value[i].error,W;r.push(t)}return L(r)}fromString(e){this.value=[];let t=0,r=0,i="";do{r=e.indexOf(".",t),i=-1===r?e.substring(t):e.substring(t,r),t=r+1;const n=new qe;if(n.valueDec=parseInt(i,10),isNaN(n.valueDec))return!0;this.value.push(n)}while(-1!==r);return!0}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let i=this.value[r].toString();0!==r&&(e=`${e}.`),t?(i=`{${i}}`,e+=i):e+=i}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}Je.NAME="RelativeObjectIdentifierValueBlock";class Xe extends ie{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Je),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}Re=Xe,re.RelativeObjectIdentifier=Re,Xe.NAME="RelativeObjectIdentifier";class Ge extends be{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}Pe=Ge,re.Sequence=Pe,Ge.NAME="SEQUENCE";let Ye=class extends be{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Ue=Ye,re.Set=Ue,Ye.NAME="SET";class Ze extends(Y(Q)){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=z}toJSON(){return{...super.toJSON(),value:this.value}}}Ze.NAME="StringValueBlock";class Qe extends Ze{}Qe.NAME="SimpleStringValueBlock";class et extends oe{constructor({...e}={}){super(e,Qe)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,k.toUint8Array(e))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=e.charCodeAt(i);this.valueBlock.value=e}}et.NAME="SIMPLE STRING";class tt extends et{fromBuffer(e){this.valueBlock.valueHexView=k.toUint8Array(e);try{this.valueBlock.value=C.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=C.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(C.FromUtf8String(e)),this.valueBlock.value=e}}var rt,it,nt,ot,st,at,ct,ut,lt,ht,pt,ft,dt,yt,gt,vt,mt,wt,bt;tt.NAME="Utf8StringValueBlock";class St extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}rt=St,re.Utf8String=rt,St.NAME="UTF8String";class At extends et{fromBuffer(e){this.valueBlock.value=C.ToUtf16String(e),this.valueBlock.valueHexView=k.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(C.FromUtf16String(e))}}At.NAME="BmpStringValueBlock";class xt extends At{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}it=xt,re.BmpString=it,xt.NAME="BMPString";class kt extends et{fromBuffer(e){const t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),r=new Uint8Array(t);for(let i=0;i<r.length;i+=4)r[i]=r[i+3],r[i+1]=r[i+2],r[i+2]=0,r[i+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(4*t);for(let i=0;i<t;i++){const t=_(e.charCodeAt(i),8),n=new Uint8Array(t);if(n.length>4)continue;const o=4-n.length;for(let e=n.length-1;e>=0;e--)r[4*i+e+o]=n[e]}this.valueBlock.value=e}}kt.NAME="UniversalStringValueBlock";class Et extends kt{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}nt=Et,re.UniversalString=nt,Et.NAME="UniversalString";class Bt extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}ot=Bt,re.NumericString=ot,Bt.NAME="NumericString";class Nt extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}st=Nt,re.PrintableString=st,Nt.NAME="PrintableString";class Tt extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}at=Tt,re.TeletexString=at,Tt.NAME="TeletexString";class It extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}ct=It,re.VideotexString=ct,It.NAME="VideotexString";class Ot extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}ut=Ot,re.IA5String=ut,Ot.NAME="IA5String";class Ct extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}lt=Ct,re.GraphicString=lt,Ct.NAME="GraphicString";class jt extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}ht=jt,re.VisibleString=ht,jt.NAME="VisibleString";class _t extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}pt=_t,re.GeneralString=pt,_t.NAME="GeneralString";class Dt extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}ft=Dt,re.CharacterString=ft,Dt.NAME="CharacterString";class Rt extends jt{constructor({value:e,valueDate:t,...r}={}){if(super(r),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let t=0;t<e.length;t++)this.valueBlock.valueHexView[t]=e.charCodeAt(t)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,k.toUint8Array(e)))}toBuffer(){const e=this.toString(),t=new ArrayBuffer(e.length),r=new Uint8Array(t);for(let i=0;i<e.length;i++)r[i]=e.charCodeAt(i);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){const t=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/gi.exec(e);if(null===t)return void(this.error="Wrong input string for conversion");const r=parseInt(t[1],10);this.year=r>=50?1900+r:2e3+r,this.month=parseInt(t[2],10),this.day=parseInt(t[3],10),this.hour=parseInt(t[4],10),this.minute=parseInt(t[5],10),this.second=parseInt(t[6],10)}toString(e="iso"){if("iso"===e){const e=new Array(7);return e[0]=P(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=P(this.month,2),e[2]=P(this.day,2),e[3]=P(this.hour,2),e[4]=P(this.minute,2),e[5]=P(this.second,2),e[6]="Z",e.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}}dt=Rt,re.UTCTime=dt,Rt.NAME="UTCTime";class Pt extends Rt{constructor(e={}){var t;super(e),null!==(t=this.millisecond)&&void 0!==t||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){const e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t,r=!1,i="",n="",o=0,s=0,a=0;if("Z"===e[e.length-1])i=e.substring(0,e.length-1),r=!0;else{const t=new Number(e[e.length-1]);if(isNaN(t.valueOf()))throw new Error("Wrong input string for conversion");i=e}if(r){if(-1!==i.indexOf("+"))throw new Error("Wrong input string for conversion");if(-1!==i.indexOf("-"))throw new Error("Wrong input string for conversion")}else{let e=1,t=i.indexOf("+"),r="";if(-1===t&&(t=i.indexOf("-"),e=-1),-1!==t){if(r=i.substring(t+1),i=i.substring(0,t),2!==r.length&&4!==r.length)throw new Error("Wrong input string for conversion");let n=parseInt(r.substring(0,2),10);if(isNaN(n.valueOf()))throw new Error("Wrong input string for conversion");if(s=e*n,4===r.length){if(n=parseInt(r.substring(2,4),10),isNaN(n.valueOf()))throw new Error("Wrong input string for conversion");a=e*n}}}let c=i.indexOf(".");if(-1===c&&(c=i.indexOf(",")),-1!==c){const e=new Number(`0${i.substring(c)}`);if(isNaN(e.valueOf()))throw new Error("Wrong input string for conversion");o=e.valueOf(),n=i.substring(0,c)}else n=i;switch(!0){case 8===n.length:if(t=/(\d{4})(\d{2})(\d{2})/gi,-1!==c)throw new Error("Wrong input string for conversion");break;case 10===n.length:if(t=/(\d{4})(\d{2})(\d{2})(\d{2})/gi,-1!==c){let e=60*o;this.minute=Math.floor(e),e=60*(e-this.minute),this.second=Math.floor(e),e=1e3*(e-this.second),this.millisecond=Math.floor(e)}break;case 12===n.length:if(t=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/gi,-1!==c){let e=60*o;this.second=Math.floor(e),e=1e3*(e-this.second),this.millisecond=Math.floor(e)}break;case 14===n.length:if(t=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/gi,-1!==c){const e=1e3*o;this.millisecond=Math.floor(e)}break;default:throw new Error("Wrong input string for conversion")}const u=t.exec(n);if(null===u)throw new Error("Wrong input string for conversion");for(let l=1;l<u.length;l++)switch(l){case 1:this.year=parseInt(u[l],10);break;case 2:this.month=parseInt(u[l],10);break;case 3:this.day=parseInt(u[l],10);break;case 4:this.hour=parseInt(u[l],10)+s;break;case 5:this.minute=parseInt(u[l],10)+a;break;case 6:this.second=parseInt(u[l],10);break;default:throw new Error("Wrong input string for conversion")}if(!1===r){const e=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=e.getUTCFullYear(),this.month=e.getUTCMonth(),this.day=e.getUTCDay(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds(),this.millisecond=e.getUTCMilliseconds()}}toString(e="iso"){if("iso"===e){const e=[];return e.push(P(this.year,4)),e.push(P(this.month,2)),e.push(P(this.day,2)),e.push(P(this.hour,2)),e.push(P(this.minute,2)),e.push(P(this.second,2)),0!==this.millisecond&&(e.push("."),e.push(P(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}yt=Pt,re.GeneralizedTime=yt,Pt.NAME="GeneralizedTime";class Ut extends St{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}}gt=Ut,re.DATE=gt,Ut.NAME="DATE";class Lt extends St{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}vt=Lt,re.TimeOfDay=vt,Lt.NAME="TimeOfDay";class $t extends St{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}mt=$t,re.DateTime=mt,$t.NAME="DateTime";class Vt extends St{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}wt=Vt,re.Duration=wt,Vt.NAME="Duration";class Mt extends St{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}bt=Mt,re.TIME=bt,Mt.NAME="TIME";class Ht{constructor({name:e="",optional:t=!1}={}){this.name=e,this.optional=t}}class Kt extends Ht{constructor({value:e=[],...t}={}){super(t),this.value=e}}class Ft extends Ht{constructor({value:e=new Ht,local:t=!1,...r}={}){super(r),this.value=e,this.local=t}}function zt(e,t,r){if(r instanceof Kt){for(const i of r.value){if(zt(e,t,i).verified)return{verified:!0,result:e}}{const e={verified:!1,result:{error:"Wrong values for Choice type"}};return r.hasOwnProperty(K)&&(e.name=r.name),e}}if(r instanceof Ht)return r.hasOwnProperty(K)&&(e[r.name]=t),{verified:!0,result:e};if(e instanceof Object==!1)return{verified:!1,result:{error:"Wrong root object"}};if(t instanceof Object==!1)return{verified:!1,result:{error:"Wrong ASN.1 data"}};if(r instanceof Object==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if("idBlock"in r==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if("fromBER"in r.idBlock==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if("toBER"in r.idBlock==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};const i=r.idBlock.toBER(!1);if(0===i.byteLength)return{verified:!1,result:{error:"Error encoding idBlock for ASN.1 schema"}};if(-1===r.idBlock.fromBER(i,0,i.byteLength))return{verified:!1,result:{error:"Error decoding idBlock for ASN.1 schema"}};if(!1===r.idBlock.hasOwnProperty("tagClass"))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(r.idBlock.tagClass!==t.idBlock.tagClass)return{verified:!1,result:e};if(!1===r.idBlock.hasOwnProperty("tagNumber"))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(r.idBlock.tagNumber!==t.idBlock.tagNumber)return{verified:!1,result:e};if(!1===r.idBlock.hasOwnProperty("isConstructed"))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(r.idBlock.isConstructed!==t.idBlock.isConstructed)return{verified:!1,result:e};if(!("isHexOnly"in r.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(r.idBlock.isHexOnly!==t.idBlock.isHexOnly)return{verified:!1,result:e};if(r.idBlock.isHexOnly){if(F in r.idBlock==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};const i=r.idBlock.valueHexView,n=t.idBlock.valueHexView;if(i.length!==n.length)return{verified:!1,result:e};for(let t=0;t<i.length;t++)if(i[t]!==n[1])return{verified:!1,result:e}}if(r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&(e[r.name]=t)),r instanceof re.Constructed){let i=0,n={verified:!1,result:{error:"Unknown error"}},o=r.valueBlock.value.length;if(o>0&&r.valueBlock.value[0]instanceof Ft&&(o=t.valueBlock.value.length),0===o)return{verified:!0,result:e};if(0===t.valueBlock.value.length&&0!==r.valueBlock.value.length){let t=!0;for(let e=0;e<r.valueBlock.value.length;e++)t=t&&(r.valueBlock.value[e].optional||!1);return t?{verified:!0,result:e}:(r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&delete e[r.name]),e.error="Inconsistent object length",{verified:!1,result:e})}for(let s=0;s<o;s++)if(s-i>=t.valueBlock.value.length){if(!1===r.valueBlock.value[s].optional){const t={verified:!1,result:e};return e.error="Inconsistent length between ASN.1 data and schema",r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&(delete e[r.name],t.name=r.name)),t}}else if(r.valueBlock.value[0]instanceof Ft){if(n=zt(e,t.valueBlock.value[s],r.valueBlock.value[0].value),!1===n.verified){if(!r.valueBlock.value[0].optional)return r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&delete e[r.name]),n;i++}if(K in r.valueBlock.value[0]&&r.valueBlock.value[0].name.length>0){let i={};i="local"in r.valueBlock.value[0]&&r.valueBlock.value[0].local?t:e,void 0===i[r.valueBlock.value[0].name]&&(i[r.valueBlock.value[0].name]=[]),i[r.valueBlock.value[0].name].push(t.valueBlock.value[s])}}else if(n=zt(e,t.valueBlock.value[s-i],r.valueBlock.value[s]),!1===n.verified){if(!r.valueBlock.value[s].optional)return r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&delete e[r.name]),n;i++}if(!1===n.verified){const t={verified:!1,result:e};return r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&(delete e[r.name],t.name=r.name)),t}return{verified:!0,result:e}}if(r.primitiveSchema&&F in t.valueBlock){const i=pe(t.valueBlock.valueHexView);if(-1===i.offset){const t={verified:!1,result:i.result};return r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&(delete e[r.name],t.name=r.name)),t}return zt(e,i.result,r.primitiveSchema)}return{verified:!0,result:e}}const Wt=Object.freeze(Object.defineProperty({__proto__:null,Any:Ht,BaseBlock:ie,BaseStringBlock:oe,BitString:Oe,BmpString:xt,Boolean:Ee,CharacterString:Dt,Choice:Kt,Constructed:be,DATE:Ut,DEFAULT_MAX_CONTENT_LENGTH:ue,DEFAULT_MAX_DEPTH:100,DEFAULT_MAX_NODES:1e4,DateTime:$t,Duration:Vt,EndOfContent:Ae,Enumerated:Ke,GeneralString:_t,GeneralizedTime:Pt,GraphicString:Ct,HexBlock:Y,IA5String:Ot,Integer:He,Null:xe,NumericString:Bt,ObjectIdentifier:We,OctetString:Ne,Primitive:ce,PrintableString:Nt,RawData:class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=k.toUint8Array(e)}constructor({data:e=q}={}){this.dataView=k.toUint8Array(e)}fromBER(e,t,r){const i=t+r;return this.dataView=k.toUint8Array(e).subarray(t,i),i}toBER(e){return this.dataView.slice().buffer}},RelativeObjectIdentifier:Xe,Repeated:Ft,Sequence:Ge,Set:Ye,TIME:Mt,TeletexString:Tt,TimeOfDay:Lt,UTCTime:Rt,UniversalString:Et,Utf8String:St,ValueBlock:Q,VideotexString:It,ViewWriter:V,VisibleString:jt,compareSchema:zt,fromBER:fe,verifySchema:function(e,t){if(t instanceof Object==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};const r=pe(k.toUint8Array(e));return-1===r.offset?{verified:!1,result:r.result}:zt(r.result,r.result,t)}},Symbol.toStringTag,{value:"Module"}));function qt(e){return Object.prototype.toString.call(e)}function Jt(e){return"[object ArrayBuffer]"===qt(e)}function Xt(e){return Jt(e)||function(e){return"undefined"!=typeof SharedArrayBuffer&&"[object SharedArrayBuffer]"===qt(e)}(e)}function Gt(e){return function(e){if(ArrayBuffer.isView(e))return!0;if(!e||"object"!=typeof e)return!1;const t=e;return"number"==typeof t.byteOffset&&"number"==typeof t.byteLength&&Xt(t.buffer)}(e)}function Yt(e){return Xt(e)||Gt(e)}function Zt(e){if(!Yt(e))throw new TypeError("Expected ArrayBuffer, SharedArrayBuffer, or ArrayBufferView")}function Qt(e){return Zt(e),Xt(e)?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function er(e){if(Zt(e),Jt(e))return e;const t=new ArrayBuffer(e.byteLength);return new Uint8Array(t).set(Qt(e)),t}var tr,rr,ir,nr;(rr=tr||(tr={}))[rr.Sequence=0]="Sequence",rr[rr.Set=1]="Set",rr[rr.Choice=2]="Choice",(nr=ir||(ir={}))[nr.Any=1]="Any",nr[nr.Boolean=2]="Boolean",nr[nr.OctetString=3]="OctetString",nr[nr.BitString=4]="BitString",nr[nr.Integer=5]="Integer",nr[nr.Enumerated=6]="Enumerated",nr[nr.ObjectIdentifier=7]="ObjectIdentifier",nr[nr.Utf8String=8]="Utf8String",nr[nr.BmpString=9]="BmpString",nr[nr.UniversalString=10]="UniversalString",nr[nr.NumericString=11]="NumericString",nr[nr.PrintableString=12]="PrintableString",nr[nr.TeletexString=13]="TeletexString",nr[nr.VideotexString=14]="VideotexString",nr[nr.IA5String=15]="IA5String",nr[nr.GraphicString=16]="GraphicString",nr[nr.VisibleString=17]="VisibleString",nr[nr.GeneralString=18]="GeneralString",nr[nr.CharacterString=19]="CharacterString",nr[nr.UTCTime=20]="UTCTime",nr[nr.GeneralizedTime=21]="GeneralizedTime",nr[nr.DATE=22]="DATE",nr[nr.TimeOfDay=23]="TimeOfDay",nr[nr.DateTime=24]="DateTime",nr[nr.Duration=25]="Duration",nr[nr.TIME=26]="TIME",nr[nr.Null=27]="Null";class or{constructor(e,t=0){if(r(this,"unusedBits",0),r(this,"value",new ArrayBuffer(0)),e)if("number"==typeof e)this.fromNumber(e);else{if(!Yt(e))throw TypeError("Unsupported type of 'params' argument for BitString");this.unusedBits=t,this.value=er(e)}}fromASN(e){if(!(e instanceof Oe))throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=e.valueBlock.unusedBits,this.value=er(e.valueBlock.valueHex),this}toASN(){return new Oe({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Oe({name:e})}toNumber(){let e="";const t=new Uint8Array(this.value);for(const r of t)e+=r.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let t=e.toString(2);const r=t.length+7>>3;this.unusedBits=(r<<3)-t.length;const i=new Uint8Array(r);t=t.padStart(r<<3,"0").split("").reverse().join("");let n=0;for(;n<r;)i[n]=parseInt(t.slice(n<<3,8+(n<<3)),2),n++;this.value=i.buffer}}class sr{constructor(e){r(this,"buffer"),"number"==typeof e?this.buffer=new ArrayBuffer(e):Yt(e)?this.buffer=er(e):Array.isArray(e)?this.buffer=new Uint8Array(e).buffer:this.buffer=new ArrayBuffer(0)}get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}fromASN(e){if(!(e instanceof Ne))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=er(e.valueBlock.valueHex),this}toASN(){return new Ne({valueHex:this.buffer})}toSchema(e){return new Ne({name:e})}}const ar={fromASN:e=>e instanceof xe?null:er(e.valueBeforeDecodeView),toASN:e=>{if(null===e)return new xe;const t=fe(e);if(t.result.error)throw new Error(t.result.error);return t.result}},cr={fromASN:e=>e.valueBlock.valueHexView.byteLength>=4?e.valueBlock.toString():e.valueBlock.valueDec,toASN:e=>new He({value:+e})},ur={fromASN:e=>e.valueBlock.valueDec,toASN:e=>new Ke({value:e})},lr={fromASN:e=>er(e.valueBlock.valueHexView),toASN:e=>new He({valueHex:e})},hr={fromASN:e=>er(e.valueBlock.valueHexView),toASN:e=>new Oe({valueHex:e})},pr={fromASN:e=>e.valueBlock.toString(),toASN:e=>new We({value:e})},fr={fromASN:e=>e.valueBlock.value,toASN:e=>new Ee({value:e})},dr={fromASN:e=>er(e.valueBlock.valueHexView),toASN:e=>new Ne({valueHex:e})},yr={fromASN:e=>new sr(e.getValue()),toASN:e=>e.toASN()};function gr(e){return{fromASN:e=>e.valueBlock.value,toASN:t=>new e({value:t})}}const vr=gr(St),mr=gr(xt),wr=gr(Et),br=gr(Bt),Sr=gr(Nt),Ar=gr(Tt),xr=gr(It),kr=gr(Ot),Er=gr(Ct),Br=gr(jt),Nr=gr(_t),Tr=gr(Dt),Ir={fromASN:e=>e.toDate(),toASN:e=>new Rt({valueDate:e})},Or={fromASN:e=>e.toDate(),toASN:e=>new Pt({valueDate:e})},Cr={fromASN:()=>null,toASN:()=>new xe};function jr(e){switch(e){case ir.Any:return ar;case ir.BitString:return hr;case ir.BmpString:return mr;case ir.Boolean:return fr;case ir.CharacterString:return Tr;case ir.Enumerated:return ur;case ir.GeneralString:return Nr;case ir.GeneralizedTime:return Or;case ir.GraphicString:return Er;case ir.IA5String:return kr;case ir.Integer:return cr;case ir.Null:return Cr;case ir.NumericString:return br;case ir.ObjectIdentifier:return pr;case ir.OctetString:return dr;case ir.PrintableString:return Sr;case ir.TeletexString:return Ar;case ir.UTCTime:return Ir;case ir.UniversalString:return wr;case ir.Utf8String:return vr;case ir.VideotexString:return xr;case ir.VisibleString:return Br;default:return null}}function _r(e){return"function"==typeof e&&e.prototype?!(!e.prototype.toASN||!e.prototype.fromASN)||_r(e.prototype):!!(e&&"object"==typeof e&&"toASN"in e&&"fromASN"in e)}function Dr(e){var t;if(e){const r=Object.getPrototypeOf(e);return(null==(t=null==r?void 0:r.prototype)?void 0:t.constructor)===Array||Dr(r)}return!1}function Rr(e,t){if(!e||!t)return!1;if(e.byteLength!==t.byteLength)return!1;const r=new Uint8Array(e),i=new Uint8Array(t);for(let n=0;n<e.byteLength;n++)if(r[n]!==i[n])return!1;return!0}const Pr=new class{constructor(){r(this,"items",new WeakMap)}has(e){return this.items.has(e)}get(e,t=!1){const r=this.items.get(e);if(!r)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(t&&!r.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return r}cache(e){const t=this.get(e);t.schema||(t.schema=this.create(e,!0))}createDefault(e){const t={type:tr.Sequence,items:{}},r=this.findParentSchema(e);return r&&(Object.assign(t,r),t.items=Object.assign({},t.items,r.items)),t}create(e,t){const r=this.items.get(e)||this.createDefault(e),i=[];for(const n in r.items){const e=r.items[n],o=t?n:"";let s;if("number"==typeof e.type){const t=ir[e.type],r=Wt[t];if(!r)throw new Error(`Cannot get ASN1 class by name '${t}'`);s=new r({name:o})}else if(_r(e.type)){s=(new e.type).toSchema(o)}else if(e.optional){this.get(e.type).type===tr.Choice?s=new Ht({name:o}):(s=this.create(e.type,!1),s.name=o)}else s=new Ht({name:o});const a=!!e.optional||void 0!==e.defaultValue;if(e.repeated){s.name="";s=new("set"===e.repeated?Ye:Ge)({name:"",value:[new Ft({name:o,value:s})]})}if(null!==e.context&&void 0!==e.context)if(e.implicit)if("number"==typeof e.type||_r(e.type)){const t=e.repeated?be:ce;i.push(new t({name:o,optional:a,idBlock:{tagClass:3,tagNumber:e.context}}))}else{this.cache(e.type);const t=!!e.repeated;let r=t?s:this.get(e.type,!0).schema;r="valueBlock"in r?r.valueBlock.value:r.value,i.push(new be({name:t?"":o,optional:a,idBlock:{tagClass:3,tagNumber:e.context},value:r}))}else i.push(new be({optional:a,idBlock:{tagClass:3,tagNumber:e.context},value:[s]}));else s.optional=a,i.push(s)}switch(r.type){case tr.Sequence:return new Ge({value:i,name:""});case tr.Set:return new Ye({value:i,name:""});case tr.Choice:return new Kt({value:i,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,t){return this.items.set(e,t),this}findParentSchema(e){const t=Object.getPrototypeOf(e);if(t){return this.items.get(t)||this.findParentSchema(t)}return null}},Ur=e=>t=>{let r;Pr.has(t)?r=Pr.get(t):(r=Pr.createDefault(t),Pr.set(t,r)),Object.assign(r,e)},Lr=e=>(t,r)=>{let i;Pr.has(t.constructor)?i=Pr.get(t.constructor):(i=Pr.createDefault(t.constructor),Pr.set(t.constructor,i));const n=Object.assign({},e);if("number"==typeof n.type&&!n.converter){const i=jr(e.type);if(!i)throw new Error(`Cannot get default converter for property '${r}' of ${t.constructor.name}`);n.converter=i}n.raw=e.raw,i.items[r]=n};class $r extends Error{constructor(){super(...arguments),r(this,"schemas",[])}}class Vr{static parse(e,t,r){const i=fe(er(e),null==r?void 0:r.berOptions);if(i.result.error)throw new Error(i.result.error);return this.fromASN(i.result,t,r)}static fromASN(e,t,r){try{if(_r(t)){return(new t).fromASN(e)}const i=Pr.get(t);Pr.cache(t);let n=i.schema;const o=this.handleChoiceTypes(e,i,t,n,r);if(null==o?void 0:o.result)return o.result;(null==o?void 0:o.targetSchema)&&(n=o.targetSchema);const s=this.handleSequenceTypes(e,i,t,n),a=new t;return Dr(t)?this.handleArrayTypes(e,i,t,r):(this.processSchemaItems(i,s,a,r),a)}catch(i){throw i instanceof $r&&i.schemas.push(t.name),i}}static handleChoiceTypes(e,t,r,i,n){if(e.constructor===be&&t.type===tr.Choice&&3===e.idBlock.tagClass)for(const o in t.items){const i=t.items[o];if(i.context===e.idBlock.tagNumber&&i.implicit&&"function"==typeof i.type&&Pr.has(i.type)){const t=Pr.get(i.type);if(t&&t.type===tr.Sequence){const t=new Ge;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in t.valueBlock){t.valueBlock.value=e.valueBlock.value;const s=this.fromASN(t,i.type,n),a=new r;return a[o]=s,{result:a}}}}}else if(e.constructor===be&&t.type!==tr.Choice){const r=new be({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:t.schema.valueBlock.value});for(const i in t.items)delete e[i];return{targetSchema:r}}return null}static handleSequenceTypes(e,t,r,i){if(t.type===tr.Sequence){const t=zt({},e,i);if(!t.verified)throw new $r(`Data does not match to ${r.name} ASN1 schema.${t.result.error?` ${t.result.error}`:""}`);return t}{const t=zt({},e,i);if(!t.verified)throw new $r(`Data does not match to ${r.name} ASN1 schema.${t.result.error?` ${t.result.error}`:""}`);return t}}static processRepeatedField(e,t,r){let i=e.slice(t);if(1===i.length&&"Sequence"===i[0].constructor.name){const e=i[0];e.valueBlock&&e.valueBlock.value&&Array.isArray(e.valueBlock.value)&&(i=e.valueBlock.value)}if("number"==typeof r.type){const e=jr(r.type);if(!e)throw new Error(`No converter for ASN.1 type ${r.type}`);return i.filter((e=>e&&e.valueBlock)).map((t=>{try{return e.fromASN(t)}catch{return}})).filter((e=>void 0!==e))}return i.filter((e=>e&&e.valueBlock)).map((e=>{try{return this.fromASN(e,r.type)}catch{return}})).filter((e=>void 0!==e))}static processPrimitiveField(e,t){const r=jr(t.type);if(!r)throw new Error(`No converter for ASN.1 type ${t.type}`);return r.fromASN(e)}static isOptionalChoiceField(e){return e.optional&&"function"==typeof e.type&&Pr.has(e.type)&&Pr.get(e.type).type===tr.Choice}static processOptionalChoiceField(e,t){try{return{processed:!0,value:this.fromASN(e,t.type)}}catch(r){if(r instanceof $r&&/Wrong values for Choice type/.test(r.message))return{processed:!1};throw r}}static handleArrayTypes(e,t,r,i){if(!("value"in e.valueBlock)||!Array.isArray(e.valueBlock.value))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");const n=t.itemType;if("number"==typeof n){const t=jr(n);if(!t)throw new Error(`Cannot get default converter for array item of ${r.name} ASN1 schema`);return r.from(e.valueBlock.value,(e=>t.fromASN(e)))}return r.from(e.valueBlock.value,(e=>this.fromASN(e,n,i)))}static processSchemaItems(e,t,r,i){for(const n in e.items){const o=t.result[n];if(!o)continue;const s=e.items[n],a=s.type;let c;c="number"==typeof a||_r(a)?this.processPrimitiveSchemaItem(o,s,a,i):this.processComplexSchemaItem(o,s,a,i),c&&"object"==typeof c&&"value"in c&&"raw"in c?(r[n]=c.value,r[`${n}Raw`]=c.raw):r[n]=c}}static processPrimitiveSchemaItem(e,t,r,i){const n=t.converter??(_r(r)?new r:null);if(!n)throw new Error("Converter is empty");return t.repeated?this.processRepeatedPrimitiveItem(e,t,n,i):this.processSinglePrimitiveItem(e,t,r,n,i)}static processRepeatedPrimitiveItem(e,t,r,i){if(t.implicit){const n=new("sequence"===t.repeated?Ge:Ye);n.valueBlock=e.valueBlock;const o=fe(n.toBER(!1),null==i?void 0:i.berOptions);if(-1===o.offset)throw new Error(`Cannot parse the child item. ${o.result.error}`);if(!("value"in o.result.valueBlock)||!Array.isArray(o.result.valueBlock.value))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");const s=o.result.valueBlock.value;return Array.from(s,(e=>r.fromASN(e)))}return Array.from(e,(e=>r.fromASN(e)))}static processSinglePrimitiveItem(e,t,r,i,n){let o=e;if(t.implicit){let e;if(_r(r))e=(new r).toSchema("");else{const t=ir[r],i=Wt[t];if(!i)throw new Error(`Cannot get '${t}' class from asn1js module`);e=new i}e.valueBlock=o.valueBlock,o=fe(e.toBER(!1),null==n?void 0:n.berOptions).result}return i.fromASN(o)}static processComplexSchemaItem(e,t,r,i){if(t.repeated){if(!Array.isArray(e))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(e,(e=>this.fromASN(e,r,i)))}{const o=this.handleImplicitTagging(e,t,r);if(!this.isOptionalChoiceField(t)){const n=this.fromASN(o,r,i);return t.raw?{value:n,raw:e.valueBeforeDecodeView}:n}try{return this.fromASN(o,r,i)}catch(n){if(n instanceof $r&&/Wrong values for Choice type/.test(n.message))return;throw n}}}static handleImplicitTagging(e,t,r){if(t.implicit&&"number"==typeof t.context){const t=Pr.get(r);if(t.type===tr.Sequence){const t=new Ge;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in t.valueBlock)return t.valueBlock.value=e.valueBlock.value,t}else if(t.type===tr.Set){const t=new Ye;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in t.valueBlock)return t.valueBlock.value=e.valueBlock.value,t}}return e}}class Mr{static serialize(e){return e instanceof ie?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&"object"==typeof e&&_r(e))return e.toASN();if(!e||"object"!=typeof e)throw new TypeError("Parameter 1 should be type of Object.");const t=e.constructor,r=Pr.get(t);Pr.cache(t);let i,n=[];if(r.itemType){if(!Array.isArray(e))throw new TypeError("Parameter 1 should be type of Array.");if("number"==typeof r.itemType){const i=jr(r.itemType);if(!i)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);n=e.map((e=>i.toASN(e)))}else n=e.map((e=>this.toAsnItem({type:r.itemType},"[]",t,e)))}else for(const o in r.items){const i=r.items[o],s=e[o];if(void 0===s||i.defaultValue===s||"object"==typeof i.defaultValue&&"object"==typeof s&&Rr(this.serialize(i.defaultValue),this.serialize(s)))continue;const a=Mr.toAsnItem(i,o,t,s);if("number"==typeof i.context)if(i.implicit)if(i.repeated||"number"!=typeof i.type&&!_r(i.type))n.push(new be({optional:i.optional,idBlock:{tagClass:3,tagNumber:i.context},value:a.valueBlock.value}));else{const e={};e.valueHex=a instanceof xe?er(a.valueBeforeDecodeView):a.valueBlock.toBER(),n.push(new ce({optional:i.optional,idBlock:{tagClass:3,tagNumber:i.context},...e}))}else n.push(new be({optional:i.optional,idBlock:{tagClass:3,tagNumber:i.context},value:[a]}));else i.repeated?n=n.concat(a):n.push(a)}switch(r.type){case tr.Sequence:i=new Ge({value:n});break;case tr.Set:i=new Ye({value:n});break;case tr.Choice:if(!n[0])throw new Error(`Schema '${t.name}' has wrong data. Choice cannot be empty.`);i=n[0]}return i}static toAsnItem(e,t,r,i){let n;if("number"==typeof e.type){const o=e.converter;if(!o)throw new Error(`Property '${t}' doesn't have converter for type ${ir[e.type]} in schema '${r.name}'`);if(e.repeated){if(!Array.isArray(i))throw new TypeError("Parameter 'objProp' should be type of Array.");const t=Array.from(i,(e=>o.toASN(e)));n=new("sequence"===e.repeated?Ge:Ye)({value:t})}else n=o.toASN(i)}else if(e.repeated){if(!Array.isArray(i))throw new TypeError("Parameter 'objProp' should be type of Array.");const t=Array.from(i,(e=>this.toASN(e)));n=new("sequence"===e.repeated?Ge:Ye)({value:t})}else n=this.toASN(i);return n}}class Hr extends Array{constructor(e=[]){if("number"==typeof e)super(e);else{super();for(const t of e)this.push(t)}}}class Kr{static serialize(e){return Mr.serialize(e)}static parse(e,t,r){return Vr.parse(e,t,r)}static toString(e,t){const r=fe(Yt(e)?er(e):Kr.serialize(e),null==t?void 0:t.berOptions);if(-1===r.offset)throw new Error(`Cannot decode ASN.1 data. ${r.result.error}`);return r.result.toString()}}function Fr(e,t,r,i){var n,o=arguments.length,s=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,i);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(s=(o<3?n(s):o>3?n(t,r,s):n(t,r))||s);return o>3&&s&&Object.defineProperty(t,r,s),s}function zr(e,t,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(e):i?i.value:t.get(e)}function Wr(e,t,r,i,n){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?n.call(e,r):n?n.value=r:t.set(e,r),r}function qr(e,t){if(!t)return e.join("");if(!Number.isInteger(t.size)||t.size<1)throw new RangeError("Hex group size must be a positive integer");const r=[];for(let i=0;i<e.length;i+=t.size)r.push(e.slice(i,i+t.size).join(""));return r.join(t.separator)}function Jr(e,t={}){const r=Qt(e),i=t.case??"lower",n=Array.from(r,(e=>{const t=e.toString(16).padStart(2,"0");return"upper"===i?t.toUpperCase():t}));let o="";if(t.line){const e=t.line.bytesPerLine;if(!Number.isInteger(e)||e<1)throw new RangeError("Hex bytesPerLine must be a positive integer");const r=t.line.separator??"\n",i=[];for(let o=0;o<n.length;o+=e)i.push(qr(n.slice(o,o+e),t.group));o=i.join(r)}else o=qr(n,t.group);return`${t.prefix??""}${o}`}"function"==typeof SuppressedError&&SuppressedError;class Xr{static isIPv4(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)}static parseIPv4(e){const t=e.split(".");if(4!==t.length)throw new Error("Invalid IPv4 address");return t.map((e=>{const t=parseInt(e,10);if(isNaN(t)||t<0||t>255)throw new Error("Invalid IPv4 address part");return t}))}static parseIPv6(e){const t=this.expandIPv6(e).split(":");if(8!==t.length)throw new Error("Invalid IPv6 address");return t.reduce(((e,t)=>{const r=parseInt(t,16);if(isNaN(r)||r<0||r>65535)throw new Error("Invalid IPv6 address part");return e.push(r>>8&255),e.push(255&r),e}),[])}static expandIPv6(e){if(!e.includes("::"))return e;const t=e.split("::");if(t.length>2)throw new Error("Invalid IPv6 address");const r=t[0]?t[0].split(":"):[],i=t[1]?t[1].split(":"):[],n=8-(r.length+i.length);if(n<0)throw new Error("Invalid IPv6 address");return[...r,...Array(n).fill("0"),...i].join(":")}static formatIPv6(e){const t=[];for(let r=0;r<16;r+=2)t.push((e[r]<<8|e[r+1]).toString(16));return this.compressIPv6(t.join(":"))}static compressIPv6(e){const t=e.split(":");let r=-1,i=0,n=-1,o=0;for(let s=0;s<t.length;s++)"0"===t[s]?(-1===n&&(n=s),o++):(o>i&&(r=n,i=o),n=-1,o=0);if(o>i&&(r=n,i=o),i>1){return`${t.slice(0,r).join(":")}::${t.slice(r+i).join(":")}`}return e}static parseCIDR(e){const[t,r]=e.split("/"),i=parseInt(r,10);if(this.isIPv4(t)){if(i<0||i>32)throw new Error("Invalid IPv4 prefix length");return[this.parseIPv4(t),i]}if(i<0||i>128)throw new Error("Invalid IPv6 prefix length");return[this.parseIPv6(t),i]}static decodeIP(e){if(64===e.length&&0===parseInt(e,16))return"::/0";if(16!==e.length)return e;const t=parseInt(e.slice(8),16).toString(2).split("").reduce(((e,t)=>e+ +t),0);let r=e.slice(0,8).replace(/(.{2})/g,(e=>`${parseInt(e,16)}.`));return r=r.slice(0,-1),`${r}/${t}`}static toString(e){const t=new Uint8Array(e);if(4===t.length)return Array.from(t).join(".");if(16===t.length)return this.formatIPv6(t);if(8===t.length||32===t.length){const e=t.length/2,r=t.slice(0,e),i=t.slice(e);if(t.every((e=>0===e)))return 8===t.length?"0.0.0.0/0":"::/0";const n=i.reduce(((e,t)=>e+(t.toString(2).match(/1/g)||[]).length),0);if(8===t.length){return`${Array.from(r).join(".")}/${n}`}return`${this.formatIPv6(r)}/${n}`}return this.decodeIP(Jr(e))}static fromString(e){if(e.includes("/")){const[t,r]=this.parseCIDR(e),i=new Uint8Array(t.length);let n=r;for(let e=0;e<i.length;e++)n>=8?(i[e]=255,n-=8):n>0&&(i[e]=255<<8-n,n=0);const o=new Uint8Array(2*t.length);return o.set(t,0),o.set(i,t.length),o.buffer}const t=this.isIPv4(e)?this.parseIPv4(e):this.parseIPv6(e);return new Uint8Array(t).buffer}}var Gr,Yr,Zr;let Qr=class{constructor(e={}){r(this,"teletexString"),r(this,"printableString"),r(this,"universalString"),r(this,"utf8String"),r(this,"bmpString"),Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};Fr([Lr({type:ir.TeletexString})],Qr.prototype,"teletexString",void 0),Fr([Lr({type:ir.PrintableString})],Qr.prototype,"printableString",void 0),Fr([Lr({type:ir.UniversalString})],Qr.prototype,"universalString",void 0),Fr([Lr({type:ir.Utf8String})],Qr.prototype,"utf8String",void 0),Fr([Lr({type:ir.BmpString})],Qr.prototype,"bmpString",void 0),Qr=Fr([Ur({type:tr.Choice})],Qr);let ei=class extends Qr{constructor(e={}){super(e),r(this,"ia5String"),r(this,"anyValue"),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?Jr(this.anyValue):super.toString())}};Fr([Lr({type:ir.IA5String})],ei.prototype,"ia5String",void 0),Fr([Lr({type:ir.Any})],ei.prototype,"anyValue",void 0),ei=Fr([Ur({type:tr.Choice})],ei);class ti{constructor(e={}){r(this,"type",""),r(this,"value",new ei),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],ti.prototype,"type",void 0),Fr([Lr({type:ei})],ti.prototype,"value",void 0);let ri=Gr=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Gr.prototype)}};ri=Gr=Fr([Ur({type:tr.Set,itemType:ti})],ri);let ii=Yr=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Yr.prototype)}};ii=Yr=Fr([Ur({type:tr.Sequence,itemType:ri})],ii);let ni=Zr=class extends ii{constructor(e){super(e),Object.setPrototypeOf(this,Zr.prototype)}};ni=Zr=Fr([Ur({type:tr.Sequence})],ni);const oi={fromASN:e=>Xr.toString(dr.fromASN(e)),toASN:e=>dr.toASN(Xr.fromString(e))};class si{constructor(e={}){r(this,"typeId",""),r(this,"value",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],si.prototype,"typeId",void 0),Fr([Lr({type:ir.Any,context:0})],si.prototype,"value",void 0);class ai{constructor(e={}){r(this,"nameAssigner"),r(this,"partyName",new Qr),Object.assign(this,e)}}Fr([Lr({type:Qr,optional:!0,context:0,implicit:!0})],ai.prototype,"nameAssigner",void 0),Fr([Lr({type:Qr,context:1,implicit:!0})],ai.prototype,"partyName",void 0);let ci=class{constructor(e={}){r(this,"otherName"),r(this,"rfc822Name"),r(this,"dNSName"),r(this,"x400Address"),r(this,"directoryName"),r(this,"ediPartyName"),r(this,"uniformResourceIdentifier"),r(this,"iPAddress"),r(this,"registeredID"),Object.assign(this,e)}};Fr([Lr({type:si,context:0,implicit:!0})],ci.prototype,"otherName",void 0),Fr([Lr({type:ir.IA5String,context:1,implicit:!0})],ci.prototype,"rfc822Name",void 0),Fr([Lr({type:ir.IA5String,context:2,implicit:!0})],ci.prototype,"dNSName",void 0),Fr([Lr({type:ir.Any,context:3,implicit:!0})],ci.prototype,"x400Address",void 0),Fr([Lr({type:ni,context:4,implicit:!1})],ci.prototype,"directoryName",void 0),Fr([Lr({type:ai,context:5})],ci.prototype,"ediPartyName",void 0),Fr([Lr({type:ir.IA5String,context:6,implicit:!0})],ci.prototype,"uniformResourceIdentifier",void 0),Fr([Lr({type:ir.OctetString,context:7,implicit:!0,converter:oi})],ci.prototype,"iPAddress",void 0),Fr([Lr({type:ir.ObjectIdentifier,context:8,implicit:!0})],ci.prototype,"registeredID",void 0),ci=Fr([Ur({type:tr.Choice})],ci);const ui="1.3.6.1.5.5.7",li=`${ui}.3`,hi=`${ui}.48`,pi=`${hi}.1`,fi=`${hi}.2`,di=`${hi}.3`,yi=`${hi}.5`,gi="2.5.29";var vi;const mi=`${`${ui}.1`}.1`;class wi{constructor(e={}){r(this,"accessMethod",""),r(this,"accessLocation",new ci),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],wi.prototype,"accessMethod",void 0),Fr([Lr({type:ci})],wi.prototype,"accessLocation",void 0);let bi=vi=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,vi.prototype)}};bi=vi=Fr([Ur({type:tr.Sequence,itemType:wi})],bi);const Si=`${gi}.35`;class Ai extends sr{}class xi{constructor(e={}){r(this,"keyIdentifier"),r(this,"authorityCertIssuer"),r(this,"authorityCertSerialNumber"),e&&Object.assign(this,e)}}Fr([Lr({type:Ai,context:0,optional:!0,implicit:!0})],xi.prototype,"keyIdentifier",void 0),Fr([Lr({type:ci,context:1,optional:!0,implicit:!0,repeated:"sequence"})],xi.prototype,"authorityCertIssuer",void 0),Fr([Lr({type:ir.Integer,context:2,optional:!0,implicit:!0,converter:lr})],xi.prototype,"authorityCertSerialNumber",void 0);const ki=`${gi}.19`;class Ei{constructor(e={}){r(this,"cA",!1),r(this,"pathLenConstraint"),Object.assign(this,e)}}var Bi;Fr([Lr({type:ir.Boolean,defaultValue:!1})],Ei.prototype,"cA",void 0),Fr([Lr({type:ir.Integer,optional:!0})],Ei.prototype,"pathLenConstraint",void 0);let Ni=Bi=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Bi.prototype)}};var Ti;Ni=Bi=Fr([Ur({type:tr.Sequence,itemType:ci})],Ni);let Ii=Ti=class extends Ni{constructor(e){super(e),Object.setPrototypeOf(this,Ti.prototype)}};var Oi;Ii=Ti=Fr([Ur({type:tr.Sequence})],Ii);const Ci=`${gi}.32`;let ji=class{constructor(e={}){r(this,"ia5String"),r(this,"visibleString"),r(this,"bmpString"),r(this,"utf8String"),Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};Fr([Lr({type:ir.IA5String})],ji.prototype,"ia5String",void 0),Fr([Lr({type:ir.VisibleString})],ji.prototype,"visibleString",void 0),Fr([Lr({type:ir.BmpString})],ji.prototype,"bmpString",void 0),Fr([Lr({type:ir.Utf8String})],ji.prototype,"utf8String",void 0),ji=Fr([Ur({type:tr.Choice})],ji);class _i{constructor(e={}){r(this,"organization",new ji),r(this,"noticeNumbers",[]),Object.assign(this,e)}}Fr([Lr({type:ji})],_i.prototype,"organization",void 0),Fr([Lr({type:ir.Integer,repeated:"sequence"})],_i.prototype,"noticeNumbers",void 0);class Di{constructor(e={}){r(this,"noticeRef"),r(this,"explicitText"),Object.assign(this,e)}}Fr([Lr({type:_i,optional:!0})],Di.prototype,"noticeRef",void 0),Fr([Lr({type:ji,optional:!0})],Di.prototype,"explicitText",void 0);let Ri=class{constructor(e={}){r(this,"cPSuri"),r(this,"userNotice"),Object.assign(this,e)}};Fr([Lr({type:ir.IA5String})],Ri.prototype,"cPSuri",void 0),Fr([Lr({type:Di})],Ri.prototype,"userNotice",void 0),Ri=Fr([Ur({type:tr.Choice})],Ri);class Pi{constructor(e={}){r(this,"policyQualifierId",""),r(this,"qualifier",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],Pi.prototype,"policyQualifierId",void 0),Fr([Lr({type:ir.Any})],Pi.prototype,"qualifier",void 0);class Ui{constructor(e={}){r(this,"policyIdentifier",""),r(this,"policyQualifiers"),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],Ui.prototype,"policyIdentifier",void 0),Fr([Lr({type:Pi,repeated:"sequence",optional:!0})],Ui.prototype,"policyQualifiers",void 0);let Li=Oi=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Oi.prototype)}};Li=Oi=Fr([Ur({type:tr.Sequence,itemType:Ui})],Li);let $i=class{constructor(e=0){r(this,"value"),this.value=e}};Fr([Lr({type:ir.Integer})],$i.prototype,"value",void 0),$i=Fr([Ur({type:tr.Choice})],$i);let Vi=class extends $i{};var Mi;Vi=Fr([Ur({type:tr.Choice})],Vi);const Hi=`${gi}.31`;var Ki,Fi;(Fi=Ki||(Ki={}))[Fi.unused=1]="unused",Fi[Fi.keyCompromise=2]="keyCompromise",Fi[Fi.cACompromise=4]="cACompromise",Fi[Fi.affiliationChanged=8]="affiliationChanged",Fi[Fi.superseded=16]="superseded",Fi[Fi.cessationOfOperation=32]="cessationOfOperation",Fi[Fi.certificateHold=64]="certificateHold",Fi[Fi.privilegeWithdrawn=128]="privilegeWithdrawn",Fi[Fi.aACompromise=256]="aACompromise";class zi extends or{toJSON(){const e=[],t=this.toNumber();return t&Ki.aACompromise&&e.push("aACompromise"),t&Ki.affiliationChanged&&e.push("affiliationChanged"),t&Ki.cACompromise&&e.push("cACompromise"),t&Ki.certificateHold&&e.push("certificateHold"),t&Ki.cessationOfOperation&&e.push("cessationOfOperation"),t&Ki.keyCompromise&&e.push("keyCompromise"),t&Ki.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Ki.superseded&&e.push("superseded"),t&Ki.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}}let Wi=class{constructor(e={}){r(this,"fullName"),r(this,"nameRelativeToCRLIssuer"),Object.assign(this,e)}};Fr([Lr({type:ci,context:0,repeated:"sequence",implicit:!0})],Wi.prototype,"fullName",void 0),Fr([Lr({type:ri,context:1,implicit:!0})],Wi.prototype,"nameRelativeToCRLIssuer",void 0),Wi=Fr([Ur({type:tr.Choice})],Wi);class qi{constructor(e={}){r(this,"distributionPoint"),r(this,"reasons"),r(this,"cRLIssuer"),Object.assign(this,e)}}Fr([Lr({type:Wi,context:0,optional:!0})],qi.prototype,"distributionPoint",void 0),Fr([Lr({type:zi,context:1,optional:!0,implicit:!0})],qi.prototype,"reasons",void 0),Fr([Lr({type:ci,context:2,optional:!0,repeated:"sequence",implicit:!0})],qi.prototype,"cRLIssuer",void 0);let Ji=Mi=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Mi.prototype)}};var Xi;Ji=Mi=Fr([Ur({type:tr.Sequence,itemType:qi})],Ji);let Gi=Xi=class extends Ji{constructor(e){super(e),Object.setPrototypeOf(this,Xi.prototype)}};Gi=Xi=Fr([Ur({type:tr.Sequence,itemType:qi})],Gi);const Yi=class e{constructor(t={}){r(this,"distributionPoint"),r(this,"onlyContainsUserCerts",e.ONLY),r(this,"onlyContainsCACerts",e.ONLY),r(this,"onlySomeReasons"),r(this,"indirectCRL",e.ONLY),r(this,"onlyContainsAttributeCerts",e.ONLY),Object.assign(this,t)}};r(Yi,"ONLY",!1);let Zi=Yi;var Qi,en;Fr([Lr({type:Wi,context:0,optional:!0})],Zi.prototype,"distributionPoint",void 0),Fr([Lr({type:ir.Boolean,context:1,defaultValue:Zi.ONLY,implicit:!0})],Zi.prototype,"onlyContainsUserCerts",void 0),Fr([Lr({type:ir.Boolean,context:2,defaultValue:Zi.ONLY,implicit:!0})],Zi.prototype,"onlyContainsCACerts",void 0),Fr([Lr({type:zi,context:3,optional:!0,implicit:!0})],Zi.prototype,"onlySomeReasons",void 0),Fr([Lr({type:ir.Boolean,context:4,defaultValue:Zi.ONLY,implicit:!0})],Zi.prototype,"indirectCRL",void 0),Fr([Lr({type:ir.Boolean,context:5,defaultValue:Zi.ONLY,implicit:!0})],Zi.prototype,"onlyContainsAttributeCerts",void 0),(en=Qi||(Qi={}))[en.unspecified=0]="unspecified",en[en.keyCompromise=1]="keyCompromise",en[en.cACompromise=2]="cACompromise",en[en.affiliationChanged=3]="affiliationChanged",en[en.superseded=4]="superseded",en[en.cessationOfOperation=5]="cessationOfOperation",en[en.certificateHold=6]="certificateHold",en[en.removeFromCRL=8]="removeFromCRL",en[en.privilegeWithdrawn=9]="privilegeWithdrawn",en[en.aACompromise=10]="aACompromise";let tn=class{constructor(e=Qi.unspecified){r(this,"reason",Qi.unspecified),this.reason=e}toJSON(){return Qi[this.reason]}toString(){return this.toJSON()}};var rn;Fr([Lr({type:ir.Enumerated})],tn.prototype,"reason",void 0),tn=Fr([Ur({type:tr.Choice})],tn);const nn=`${gi}.37`;let on=rn=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,rn.prototype)}};on=rn=Fr([Ur({type:tr.Sequence,itemType:ir.ObjectIdentifier})],on);const sn=`${li}.1`,an=`${li}.2`,cn=`${li}.3`,un=`${li}.4`,ln=`${li}.8`,hn=`${li}.9`;let pn=class{constructor(e=new ArrayBuffer(0)){r(this,"value"),this.value=e}};Fr([Lr({type:ir.Integer,converter:lr})],pn.prototype,"value",void 0),pn=Fr([Ur({type:tr.Choice})],pn);let fn=class{constructor(e){r(this,"value",new Date),e&&(this.value=e)}};var dn;Fr([Lr({type:ir.GeneralizedTime})],fn.prototype,"value",void 0),fn=Fr([Ur({type:tr.Choice})],fn);const yn=`${gi}.18`;let gn=dn=class extends Ni{constructor(e){super(e),Object.setPrototypeOf(this,dn.prototype)}};gn=dn=Fr([Ur({type:tr.Sequence})],gn);const vn=`${gi}.15`;var mn,wn,bn;(wn=mn||(mn={}))[wn.digitalSignature=1]="digitalSignature",wn[wn.nonRepudiation=2]="nonRepudiation",wn[wn.keyEncipherment=4]="keyEncipherment",wn[wn.dataEncipherment=8]="dataEncipherment",wn[wn.keyAgreement=16]="keyAgreement",wn[wn.keyCertSign=32]="keyCertSign",wn[wn.cRLSign=64]="cRLSign",wn[wn.encipherOnly=128]="encipherOnly",wn[wn.decipherOnly=256]="decipherOnly";class Sn extends or{toJSON(){const e=this.toNumber(),t=[];return e&mn.cRLSign&&t.push("crlSign"),e&mn.dataEncipherment&&t.push("dataEncipherment"),e&mn.decipherOnly&&t.push("decipherOnly"),e&mn.digitalSignature&&t.push("digitalSignature"),e&mn.encipherOnly&&t.push("encipherOnly"),e&mn.keyAgreement&&t.push("keyAgreement"),e&mn.keyCertSign&&t.push("keyCertSign"),e&mn.keyEncipherment&&t.push("keyEncipherment"),e&mn.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}}class An{constructor(e={}){r(this,"base",new ci),r(this,"minimum",0),r(this,"maximum"),Object.assign(this,e)}}Fr([Lr({type:ci})],An.prototype,"base",void 0),Fr([Lr({type:ir.Integer,context:0,defaultValue:0,implicit:!0})],An.prototype,"minimum",void 0),Fr([Lr({type:ir.Integer,context:1,optional:!0,implicit:!0})],An.prototype,"maximum",void 0);let xn=bn=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,bn.prototype)}};xn=bn=Fr([Ur({type:tr.Sequence,itemType:An})],xn);class kn{constructor(e={}){r(this,"permittedSubtrees"),r(this,"excludedSubtrees"),Object.assign(this,e)}}Fr([Lr({type:xn,context:0,optional:!0,implicit:!0})],kn.prototype,"permittedSubtrees",void 0),Fr([Lr({type:xn,context:1,optional:!0,implicit:!0})],kn.prototype,"excludedSubtrees",void 0);class En{constructor(e={}){r(this,"requireExplicitPolicy"),r(this,"inhibitPolicyMapping"),Object.assign(this,e)}}var Bn;Fr([Lr({type:ir.Integer,context:0,implicit:!0,optional:!0,converter:lr})],En.prototype,"requireExplicitPolicy",void 0),Fr([Lr({type:ir.Integer,context:1,implicit:!0,optional:!0,converter:lr})],En.prototype,"inhibitPolicyMapping",void 0);class Nn{constructor(e={}){r(this,"issuerDomainPolicy",""),r(this,"subjectDomainPolicy",""),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],Nn.prototype,"issuerDomainPolicy",void 0),Fr([Lr({type:ir.ObjectIdentifier})],Nn.prototype,"subjectDomainPolicy",void 0);let Tn=Bn=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Bn.prototype)}};var In;Tn=Bn=Fr([Ur({type:tr.Sequence,itemType:Nn})],Tn);const On=`${gi}.17`;let Cn=In=class extends Ni{constructor(e){super(e),Object.setPrototypeOf(this,In.prototype)}};Cn=In=Fr([Ur({type:tr.Sequence})],Cn);let jn=class{constructor(e={}){r(this,"type",""),r(this,"values",[]),Object.assign(this,e)}};var _n;Fr([Lr({type:ir.ObjectIdentifier})],jn.prototype,"type",void 0),Fr([Lr({type:ir.Any,repeated:"set"})],jn.prototype,"values",void 0);let Dn=_n=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,_n.prototype)}};Dn=_n=Fr([Ur({type:tr.Sequence,itemType:jn})],Dn);const Rn=`${gi}.14`;class Pn extends Ai{}class Un{constructor(e={}){r(this,"notBefore"),r(this,"notAfter"),Object.assign(this,e)}}var Ln,$n,Vn;Fr([Lr({type:ir.GeneralizedTime,context:0,implicit:!0,optional:!0})],Un.prototype,"notBefore",void 0),Fr([Lr({type:ir.GeneralizedTime,context:1,implicit:!0,optional:!0})],Un.prototype,"notAfter",void 0),($n=Ln||(Ln={}))[$n.keyUpdateAllowed=1]="keyUpdateAllowed",$n[$n.newExtensions=2]="newExtensions",$n[$n.pKIXCertificate=4]="pKIXCertificate";class Mn extends or{toJSON(){const e=[],t=this.toNumber();return t&Ln.pKIXCertificate&&e.push("pKIXCertificate"),t&Ln.newExtensions&&e.push("newExtensions"),t&Ln.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}}class Hn{constructor(e={}){r(this,"entrustVers",""),r(this,"entrustInfoFlags",new Mn),Object.assign(this,e)}}Fr([Lr({type:ir.GeneralString})],Hn.prototype,"entrustVers",void 0),Fr([Lr({type:Mn})],Hn.prototype,"entrustInfoFlags",void 0);let Kn=Vn=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Vn.prototype)}};Kn=Vn=Fr([Ur({type:tr.Sequence,itemType:wi})],Kn);class Fn{constructor(e={}){r(this,"algorithm",""),r(this,"parameters"),Object.assign(this,e)}isEqual(e){return e instanceof Fn&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&function(e,t,r={}){const i=Qt(e),n=Qt(t);if(!r.constantTime&&i.byteLength!==n.byteLength)return!1;const o=Math.max(i.byteLength,n.byteLength);let s=i.byteLength^n.byteLength;for(let a=0;a<o;a++)s|=(i[a]??0)^(n[a]??0);return 0===s}(e.parameters,this.parameters)||e.parameters===this.parameters)}}Fr([Lr({type:ir.ObjectIdentifier})],Fn.prototype,"algorithm",void 0),Fr([Lr({type:ir.Any,optional:!0})],Fn.prototype,"parameters",void 0);class zn{constructor(e={}){r(this,"algorithm",new Fn),r(this,"subjectPublicKey",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:Fn})],zn.prototype,"algorithm",void 0),Fr([Lr({type:ir.BitString})],zn.prototype,"subjectPublicKey",void 0);let Wn=class{constructor(e){if(r(this,"utcTime"),r(this,"generalTime"),e)if("string"==typeof e||"number"==typeof e||e instanceof Date){const t=new Date(e);t.setMilliseconds(0),t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){const e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};Fr([Lr({type:ir.UTCTime})],Wn.prototype,"utcTime",void 0),Fr([Lr({type:ir.GeneralizedTime})],Wn.prototype,"generalTime",void 0),Wn=Fr([Ur({type:tr.Choice})],Wn);class qn{constructor(e){r(this,"notBefore",new Wn(new Date)),r(this,"notAfter",new Wn(new Date)),e&&(this.notBefore=new Wn(e.notBefore),this.notAfter=new Wn(e.notAfter))}}var Jn;Fr([Lr({type:Wn})],qn.prototype,"notBefore",void 0),Fr([Lr({type:Wn})],qn.prototype,"notAfter",void 0);let Xn=(e=class{constructor(t={}){r(this,"extnID",""),r(this,"critical",e.CRITICAL),r(this,"extnValue",new sr),Object.assign(this,t)}},r(e,"CRITICAL",!1),e);Fr([Lr({type:ir.ObjectIdentifier})],Xn.prototype,"extnID",void 0),Fr([Lr({type:ir.Boolean,defaultValue:Xn.CRITICAL})],Xn.prototype,"critical",void 0),Fr([Lr({type:sr})],Xn.prototype,"extnValue",void 0);let Gn=Jn=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Jn.prototype)}};var Yn,Zn;Gn=Jn=Fr([Ur({type:tr.Sequence,itemType:Xn})],Gn),(Zn=Yn||(Yn={}))[Zn.v1=0]="v1",Zn[Zn.v2=1]="v2",Zn[Zn.v3=2]="v3";class Qn{constructor(e={}){r(this,"version",Yn.v1),r(this,"serialNumber",new ArrayBuffer(0)),r(this,"signature",new Fn),r(this,"issuer",new ni),r(this,"validity",new qn),r(this,"subject",new ni),r(this,"subjectPublicKeyInfo",new zn),r(this,"issuerUniqueID"),r(this,"subjectUniqueID"),r(this,"extensions"),Object.assign(this,e)}}Fr([Lr({type:ir.Integer,context:0,defaultValue:Yn.v1})],Qn.prototype,"version",void 0),Fr([Lr({type:ir.Integer,converter:lr})],Qn.prototype,"serialNumber",void 0),Fr([Lr({type:Fn})],Qn.prototype,"signature",void 0),Fr([Lr({type:ni})],Qn.prototype,"issuer",void 0),Fr([Lr({type:qn})],Qn.prototype,"validity",void 0),Fr([Lr({type:ni})],Qn.prototype,"subject",void 0),Fr([Lr({type:zn})],Qn.prototype,"subjectPublicKeyInfo",void 0),Fr([Lr({type:ir.BitString,context:1,implicit:!0,optional:!0})],Qn.prototype,"issuerUniqueID",void 0),Fr([Lr({type:ir.BitString,context:2,implicit:!0,optional:!0})],Qn.prototype,"subjectUniqueID",void 0),Fr([Lr({type:Gn,context:3,optional:!0})],Qn.prototype,"extensions",void 0);class eo{constructor(e={}){r(this,"tbsCertificate",new Qn),r(this,"tbsCertificateRaw"),r(this,"signatureAlgorithm",new Fn),r(this,"signatureValue",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:Qn,raw:!0})],eo.prototype,"tbsCertificate",void 0),Fr([Lr({type:Fn})],eo.prototype,"signatureAlgorithm",void 0),Fr([Lr({type:ir.BitString})],eo.prototype,"signatureValue",void 0);class to{constructor(e={}){r(this,"userCertificate",new ArrayBuffer(0)),r(this,"revocationDate",new Wn),r(this,"crlEntryExtensions"),Object.assign(this,e)}}Fr([Lr({type:ir.Integer,converter:lr})],to.prototype,"userCertificate",void 0),Fr([Lr({type:Wn})],to.prototype,"revocationDate",void 0),Fr([Lr({type:Xn,optional:!0,repeated:"sequence"})],to.prototype,"crlEntryExtensions",void 0);class ro{constructor(e={}){r(this,"version"),r(this,"signature",new Fn),r(this,"issuer",new ni),r(this,"thisUpdate",new Wn),r(this,"nextUpdate"),r(this,"revokedCertificates"),r(this,"crlExtensions"),Object.assign(this,e)}}Fr([Lr({type:ir.Integer,optional:!0})],ro.prototype,"version",void 0),Fr([Lr({type:Fn})],ro.prototype,"signature",void 0),Fr([Lr({type:ni})],ro.prototype,"issuer",void 0),Fr([Lr({type:Wn})],ro.prototype,"thisUpdate",void 0),Fr([Lr({type:Wn,optional:!0})],ro.prototype,"nextUpdate",void 0),Fr([Lr({type:to,repeated:"sequence",optional:!0})],ro.prototype,"revokedCertificates",void 0),Fr([Lr({type:Xn,optional:!0,context:0,repeated:"sequence"})],ro.prototype,"crlExtensions",void 0);class io{constructor(e={}){r(this,"tbsCertList",new ro),r(this,"tbsCertListRaw"),r(this,"signatureAlgorithm",new Fn),r(this,"signature",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ro,raw:!0})],io.prototype,"tbsCertList",void 0),Fr([Lr({type:Fn})],io.prototype,"signatureAlgorithm",void 0),Fr([Lr({type:ir.BitString})],io.prototype,"signature",void 0);class no{constructor(e={}){r(this,"issuer",new ni),r(this,"serialNumber",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ni})],no.prototype,"issuer",void 0),Fr([Lr({type:ir.Integer,converter:lr})],no.prototype,"serialNumber",void 0);let oo=class{constructor(e={}){r(this,"subjectKeyIdentifier"),r(this,"issuerAndSerialNumber"),Object.assign(this,e)}};var so,ao;Fr([Lr({type:Pn,context:0,implicit:!0})],oo.prototype,"subjectKeyIdentifier",void 0),Fr([Lr({type:no})],oo.prototype,"issuerAndSerialNumber",void 0),oo=Fr([Ur({type:tr.Choice})],oo),(ao=so||(so={}))[ao.v0=0]="v0",ao[ao.v1=1]="v1",ao[ao.v2=2]="v2",ao[ao.v3=3]="v3",ao[ao.v4=4]="v4",ao[ao.v5=5]="v5";let co=class extends Fn{};co=Fr([Ur({type:tr.Sequence})],co);let uo=class extends Fn{};uo=Fr([Ur({type:tr.Sequence})],uo);let lo=class extends Fn{};lo=Fr([Ur({type:tr.Sequence})],lo);let ho=class extends Fn{};ho=Fr([Ur({type:tr.Sequence})],ho);let po=class extends Fn{};po=Fr([Ur({type:tr.Sequence})],po);let fo=class extends Fn{};fo=Fr([Ur({type:tr.Sequence})],fo);let yo=class{constructor(e={}){r(this,"attrType",""),r(this,"attrValues",[]),Object.assign(this,e)}};var go;Fr([Lr({type:ir.ObjectIdentifier})],yo.prototype,"attrType",void 0),Fr([Lr({type:ir.Any,repeated:"set"})],yo.prototype,"attrValues",void 0);class vo{constructor(e={}){r(this,"version",so.v0),r(this,"sid",new oo),r(this,"digestAlgorithm",new co),r(this,"signedAttrs"),r(this,"signedAttrsRaw"),r(this,"signatureAlgorithm",new uo),r(this,"signature",new sr),r(this,"unsignedAttrs"),Object.assign(this,e)}}Fr([Lr({type:ir.Integer})],vo.prototype,"version",void 0),Fr([Lr({type:oo})],vo.prototype,"sid",void 0),Fr([Lr({type:co})],vo.prototype,"digestAlgorithm",void 0),Fr([Lr({type:yo,repeated:"set",context:0,implicit:!0,optional:!0,raw:!0})],vo.prototype,"signedAttrs",void 0),Fr([Lr({type:uo})],vo.prototype,"signatureAlgorithm",void 0),Fr([Lr({type:sr})],vo.prototype,"signature",void 0),Fr([Lr({type:yo,repeated:"set",context:1,implicit:!0,optional:!0})],vo.prototype,"unsignedAttrs",void 0);let mo=go=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,go.prototype)}};mo=go=Fr([Ur({type:tr.Set,itemType:vo})],mo);let wo=class extends vo{};wo=Fr([Ur({type:tr.Sequence})],wo);let bo=class extends Wn{};bo=Fr([Ur({type:tr.Choice})],bo);class So{constructor(e={}){r(this,"acIssuer",new ci),r(this,"acSerial",0),r(this,"attrs",[]),Object.assign(this,e)}}var Ao;Fr([Lr({type:ci})],So.prototype,"acIssuer",void 0),Fr([Lr({type:ir.Integer})],So.prototype,"acSerial",void 0),Fr([Lr({type:jn,repeated:"sequence"})],So.prototype,"attrs",void 0);let xo=Ao=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Ao.prototype)}};xo=Ao=Fr([Ur({type:tr.Sequence,itemType:ir.ObjectIdentifier})],xo);class ko{constructor(e={}){r(this,"pathLenConstraint"),r(this,"permittedAttrs"),r(this,"excludedAttrs"),r(this,"permitUnSpecified",!0),Object.assign(this,e)}}Fr([Lr({type:ir.Integer,optional:!0})],ko.prototype,"pathLenConstraint",void 0),Fr([Lr({type:xo,implicit:!0,context:0,optional:!0})],ko.prototype,"permittedAttrs",void 0),Fr([Lr({type:xo,implicit:!0,context:1,optional:!0})],ko.prototype,"excludedAttrs",void 0),Fr([Lr({type:ir.Boolean,defaultValue:!0})],ko.prototype,"permitUnSpecified",void 0);class Eo{constructor(e={}){r(this,"issuer",new Ni),r(this,"serial",new ArrayBuffer(0)),r(this,"issuerUID",new ArrayBuffer(0)),Object.assign(this,e)}}var Bo,No;Fr([Lr({type:Ni})],Eo.prototype,"issuer",void 0),Fr([Lr({type:ir.Integer,converter:lr})],Eo.prototype,"serial",void 0),Fr([Lr({type:ir.BitString,optional:!0})],Eo.prototype,"issuerUID",void 0),(No=Bo||(Bo={}))[No.publicKey=0]="publicKey",No[No.publicKeyCert=1]="publicKeyCert",No[No.otherObjectTypes=2]="otherObjectTypes";class To{constructor(e={}){r(this,"digestedObjectType",Bo.publicKey),r(this,"otherObjectTypeID"),r(this,"digestAlgorithm",new Fn),r(this,"objectDigest",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.Enumerated})],To.prototype,"digestedObjectType",void 0),Fr([Lr({type:ir.ObjectIdentifier,optional:!0})],To.prototype,"otherObjectTypeID",void 0),Fr([Lr({type:Fn})],To.prototype,"digestAlgorithm",void 0),Fr([Lr({type:ir.BitString})],To.prototype,"objectDigest",void 0);class Io{constructor(e={}){r(this,"issuerName"),r(this,"baseCertificateID"),r(this,"objectDigestInfo"),Object.assign(this,e)}}Fr([Lr({type:Ni,optional:!0})],Io.prototype,"issuerName",void 0),Fr([Lr({type:Eo,context:0,implicit:!0,optional:!0})],Io.prototype,"baseCertificateID",void 0),Fr([Lr({type:To,context:1,implicit:!0,optional:!0})],Io.prototype,"objectDigestInfo",void 0);let Oo=class{constructor(e={}){r(this,"v1Form"),r(this,"v2Form"),Object.assign(this,e)}};Fr([Lr({type:ci,repeated:"sequence"})],Oo.prototype,"v1Form",void 0),Fr([Lr({type:Io,context:0,implicit:!0})],Oo.prototype,"v2Form",void 0),Oo=Fr([Ur({type:tr.Choice})],Oo);class Co{constructor(e={}){r(this,"notBeforeTime",new Date),r(this,"notAfterTime",new Date),Object.assign(this,e)}}Fr([Lr({type:ir.GeneralizedTime})],Co.prototype,"notBeforeTime",void 0),Fr([Lr({type:ir.GeneralizedTime})],Co.prototype,"notAfterTime",void 0);class jo{constructor(e={}){r(this,"baseCertificateID"),r(this,"entityName"),r(this,"objectDigestInfo"),Object.assign(this,e)}}var _o,Do,Ro,Po,Uo;Fr([Lr({type:Eo,implicit:!0,context:0,optional:!0})],jo.prototype,"baseCertificateID",void 0),Fr([Lr({type:Ni,implicit:!0,context:1,optional:!0})],jo.prototype,"entityName",void 0),Fr([Lr({type:To,implicit:!0,context:2,optional:!0})],jo.prototype,"objectDigestInfo",void 0),(Do=_o||(_o={}))[Do.v2=1]="v2";class Lo{constructor(e={}){r(this,"version",_o.v2),r(this,"holder",new jo),r(this,"issuer",new Oo),r(this,"signature",new Fn),r(this,"serialNumber",new ArrayBuffer(0)),r(this,"attrCertValidityPeriod",new Co),r(this,"attributes",[]),r(this,"issuerUniqueID"),r(this,"extensions"),Object.assign(this,e)}}Fr([Lr({type:ir.Integer})],Lo.prototype,"version",void 0),Fr([Lr({type:jo})],Lo.prototype,"holder",void 0),Fr([Lr({type:Oo})],Lo.prototype,"issuer",void 0),Fr([Lr({type:Fn})],Lo.prototype,"signature",void 0),Fr([Lr({type:ir.Integer,converter:lr})],Lo.prototype,"serialNumber",void 0),Fr([Lr({type:Co})],Lo.prototype,"attrCertValidityPeriod",void 0),Fr([Lr({type:jn,repeated:"sequence"})],Lo.prototype,"attributes",void 0),Fr([Lr({type:ir.BitString,optional:!0})],Lo.prototype,"issuerUniqueID",void 0),Fr([Lr({type:Gn,optional:!0})],Lo.prototype,"extensions",void 0);class $o{constructor(e={}){r(this,"acinfo",new Lo),r(this,"signatureAlgorithm",new Fn),r(this,"signatureValue",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:Lo})],$o.prototype,"acinfo",void 0),Fr([Lr({type:Fn})],$o.prototype,"signatureAlgorithm",void 0),Fr([Lr({type:ir.BitString})],$o.prototype,"signatureValue",void 0),(Po=Ro||(Ro={}))[Po.unmarked=1]="unmarked",Po[Po.unclassified=2]="unclassified",Po[Po.restricted=4]="restricted",Po[Po.confidential=8]="confidential",Po[Po.secret=16]="secret",Po[Po.topSecret=32]="topSecret";class Vo extends or{}class Mo{constructor(e={}){r(this,"type",""),r(this,"value",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier,implicit:!0,context:0})],Mo.prototype,"type",void 0),Fr([Lr({type:ir.Any,implicit:!0,context:1})],Mo.prototype,"value",void 0);class Ho{constructor(e={}){r(this,"policyId",""),r(this,"classList",new Vo(Ro.unclassified)),r(this,"securityCategories"),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],Ho.prototype,"policyId",void 0),Fr([Lr({type:Vo,defaultValue:new Vo(Ro.unclassified)})],Ho.prototype,"classList",void 0),Fr([Lr({type:Mo,repeated:"set"})],Ho.prototype,"securityCategories",void 0);class Ko{constructor(e={}){r(this,"cotets"),r(this,"oid"),r(this,"string"),Object.assign(this,e)}}Fr([Lr({type:sr})],Ko.prototype,"cotets",void 0),Fr([Lr({type:ir.ObjectIdentifier})],Ko.prototype,"oid",void 0),Fr([Lr({type:ir.Utf8String})],Ko.prototype,"string",void 0);class Fo{constructor(e={}){r(this,"policyAuthority"),r(this,"values",[]),Object.assign(this,e)}}Fr([Lr({type:Ni,implicit:!0,context:0,optional:!0})],Fo.prototype,"policyAuthority",void 0),Fr([Lr({type:Ko,repeated:"sequence"})],Fo.prototype,"values",void 0);class zo{constructor(e={}){r(this,"targetCertificate",new Eo),r(this,"targetName"),r(this,"certDigestInfo"),Object.assign(this,e)}}Fr([Lr({type:Eo})],zo.prototype,"targetCertificate",void 0),Fr([Lr({type:ci,optional:!0})],zo.prototype,"targetName",void 0),Fr([Lr({type:To,optional:!0})],zo.prototype,"certDigestInfo",void 0);let Wo=class{constructor(e={}){r(this,"targetName"),r(this,"targetGroup"),r(this,"targetCert"),Object.assign(this,e)}};Fr([Lr({type:ci,context:0,implicit:!0})],Wo.prototype,"targetName",void 0),Fr([Lr({type:ci,context:1,implicit:!0})],Wo.prototype,"targetGroup",void 0),Fr([Lr({type:zo,context:2,implicit:!0})],Wo.prototype,"targetCert",void 0),Wo=Fr([Ur({type:tr.Choice})],Wo);let qo=Uo=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Uo.prototype)}};var Jo;qo=Uo=Fr([Ur({type:tr.Sequence,itemType:Wo})],qo);let Xo=Jo=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Jo.prototype)}};Xo=Jo=Fr([Ur({type:tr.Sequence,itemType:qo})],Xo);class Go{constructor(e={}){r(this,"roleAuthority"),r(this,"roleName"),Object.assign(this,e)}}Fr([Lr({type:Ni,implicit:!0,context:0,optional:!0})],Go.prototype,"roleAuthority",void 0),Fr([Lr({type:ci,implicit:!0,context:1})],Go.prototype,"roleName",void 0);class Yo{constructor(e={}){r(this,"service",new ci),r(this,"ident",new ci),r(this,"authInfo"),Object.assign(this,e)}}var Zo;Fr([Lr({type:ci})],Yo.prototype,"service",void 0),Fr([Lr({type:ci})],Yo.prototype,"ident",void 0),Fr([Lr({type:sr,optional:!0})],Yo.prototype,"authInfo",void 0);class Qo{constructor(e={}){r(this,"otherCertFormat",""),r(this,"otherCert",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],Qo.prototype,"otherCertFormat",void 0),Fr([Lr({type:ir.Any})],Qo.prototype,"otherCert",void 0);let es=class{constructor(e={}){r(this,"certificate"),r(this,"v2AttrCert"),r(this,"other"),Object.assign(this,e)}};Fr([Lr({type:eo})],es.prototype,"certificate",void 0),Fr([Lr({type:$o,context:2,implicit:!0})],es.prototype,"v2AttrCert",void 0),Fr([Lr({type:Qo,context:3,implicit:!0})],es.prototype,"other",void 0),es=Fr([Ur({type:tr.Choice})],es);let ts=Zo=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Zo.prototype)}};ts=Zo=Fr([Ur({type:tr.Set,itemType:es})],ts);class rs{constructor(e={}){r(this,"contentType",""),r(this,"content",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],rs.prototype,"contentType",void 0),Fr([Lr({type:ir.Any,context:0})],rs.prototype,"content",void 0);let is=class{constructor(e={}){r(this,"single"),r(this,"any"),Object.assign(this,e)}};Fr([Lr({type:sr})],is.prototype,"single",void 0),Fr([Lr({type:ir.Any})],is.prototype,"any",void 0),is=Fr([Ur({type:tr.Choice})],is);class ns{constructor(e={}){r(this,"eContentType",""),r(this,"eContent"),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],ns.prototype,"eContentType",void 0),Fr([Lr({type:is,context:0,optional:!0})],ns.prototype,"eContent",void 0);let os=class{constructor(e={}){r(this,"value"),r(this,"constructedValue"),Object.assign(this,e)}};Fr([Lr({type:sr,context:0,implicit:!0,optional:!0})],os.prototype,"value",void 0),Fr([Lr({type:sr,converter:yr,context:0,implicit:!0,optional:!0,repeated:"sequence"})],os.prototype,"constructedValue",void 0),os=Fr([Ur({type:tr.Choice})],os);class ss{constructor(e={}){r(this,"contentType",""),r(this,"contentEncryptionAlgorithm",new ho),r(this,"encryptedContent"),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],ss.prototype,"contentType",void 0),Fr([Lr({type:ho})],ss.prototype,"contentEncryptionAlgorithm",void 0),Fr([Lr({type:os,optional:!0})],ss.prototype,"encryptedContent",void 0);class as{constructor(e={}){r(this,"keyAttrId",""),r(this,"keyAttr"),Object.assign(this,e)}}var cs;Fr([Lr({type:ir.ObjectIdentifier})],as.prototype,"keyAttrId",void 0),Fr([Lr({type:ir.Any,optional:!0})],as.prototype,"keyAttr",void 0);class us{constructor(e={}){r(this,"subjectKeyIdentifier",new Pn),r(this,"date"),r(this,"other"),Object.assign(this,e)}}Fr([Lr({type:Pn})],us.prototype,"subjectKeyIdentifier",void 0),Fr([Lr({type:ir.GeneralizedTime,optional:!0})],us.prototype,"date",void 0),Fr([Lr({type:as,optional:!0})],us.prototype,"other",void 0);let ls=class{constructor(e={}){r(this,"rKeyId"),r(this,"issuerAndSerialNumber"),Object.assign(this,e)}};Fr([Lr({type:us,context:0,implicit:!0,optional:!0})],ls.prototype,"rKeyId",void 0),Fr([Lr({type:no,optional:!0})],ls.prototype,"issuerAndSerialNumber",void 0),ls=Fr([Ur({type:tr.Choice})],ls);class hs{constructor(e={}){r(this,"rid",new ls),r(this,"encryptedKey",new sr),Object.assign(this,e)}}Fr([Lr({type:ls})],hs.prototype,"rid",void 0),Fr([Lr({type:sr})],hs.prototype,"encryptedKey",void 0);let ps=cs=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,cs.prototype)}};ps=cs=Fr([Ur({type:tr.Sequence,itemType:hs})],ps);class fs{constructor(e={}){r(this,"algorithm",new Fn),r(this,"publicKey",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:Fn})],fs.prototype,"algorithm",void 0),Fr([Lr({type:ir.BitString})],fs.prototype,"publicKey",void 0);let ds=class{constructor(e={}){r(this,"subjectKeyIdentifier"),r(this,"originatorKey"),r(this,"issuerAndSerialNumber"),Object.assign(this,e)}};Fr([Lr({type:Pn,context:0,implicit:!0,optional:!0})],ds.prototype,"subjectKeyIdentifier",void 0),Fr([Lr({type:fs,context:1,implicit:!0,optional:!0})],ds.prototype,"originatorKey",void 0),Fr([Lr({type:no,optional:!0})],ds.prototype,"issuerAndSerialNumber",void 0),ds=Fr([Ur({type:tr.Choice})],ds);class ys{constructor(e={}){r(this,"version",so.v3),r(this,"originator",new ds),r(this,"ukm"),r(this,"keyEncryptionAlgorithm",new lo),r(this,"recipientEncryptedKeys",new ps),Object.assign(this,e)}}Fr([Lr({type:ir.Integer})],ys.prototype,"version",void 0),Fr([Lr({type:ds,context:0})],ys.prototype,"originator",void 0),Fr([Lr({type:sr,context:1,optional:!0})],ys.prototype,"ukm",void 0),Fr([Lr({type:lo})],ys.prototype,"keyEncryptionAlgorithm",void 0),Fr([Lr({type:ps})],ys.prototype,"recipientEncryptedKeys",void 0);let gs=class{constructor(e={}){r(this,"subjectKeyIdentifier"),r(this,"issuerAndSerialNumber"),Object.assign(this,e)}};Fr([Lr({type:Pn,context:0,implicit:!0})],gs.prototype,"subjectKeyIdentifier",void 0),Fr([Lr({type:no})],gs.prototype,"issuerAndSerialNumber",void 0),gs=Fr([Ur({type:tr.Choice})],gs);class vs{constructor(e={}){r(this,"version",so.v0),r(this,"rid",new gs),r(this,"keyEncryptionAlgorithm",new lo),r(this,"encryptedKey",new sr),Object.assign(this,e)}}Fr([Lr({type:ir.Integer})],vs.prototype,"version",void 0),Fr([Lr({type:gs})],vs.prototype,"rid",void 0),Fr([Lr({type:lo})],vs.prototype,"keyEncryptionAlgorithm",void 0),Fr([Lr({type:sr})],vs.prototype,"encryptedKey",void 0);class ms{constructor(e={}){r(this,"keyIdentifier",new sr),r(this,"date"),r(this,"other"),Object.assign(this,e)}}Fr([Lr({type:sr})],ms.prototype,"keyIdentifier",void 0),Fr([Lr({type:ir.GeneralizedTime,optional:!0})],ms.prototype,"date",void 0),Fr([Lr({type:as,optional:!0})],ms.prototype,"other",void 0);class ws{constructor(e={}){r(this,"version",so.v4),r(this,"kekid",new ms),r(this,"keyEncryptionAlgorithm",new lo),r(this,"encryptedKey",new sr),Object.assign(this,e)}}Fr([Lr({type:ir.Integer})],ws.prototype,"version",void 0),Fr([Lr({type:ms})],ws.prototype,"kekid",void 0),Fr([Lr({type:lo})],ws.prototype,"keyEncryptionAlgorithm",void 0),Fr([Lr({type:sr})],ws.prototype,"encryptedKey",void 0);class bs{constructor(e={}){r(this,"version",so.v0),r(this,"keyDerivationAlgorithm"),r(this,"keyEncryptionAlgorithm",new lo),r(this,"encryptedKey",new sr),Object.assign(this,e)}}Fr([Lr({type:ir.Integer})],bs.prototype,"version",void 0),Fr([Lr({type:fo,context:0,optional:!0})],bs.prototype,"keyDerivationAlgorithm",void 0),Fr([Lr({type:lo})],bs.prototype,"keyEncryptionAlgorithm",void 0),Fr([Lr({type:sr})],bs.prototype,"encryptedKey",void 0);class Ss{constructor(e={}){r(this,"oriType",""),r(this,"oriValue",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],Ss.prototype,"oriType",void 0),Fr([Lr({type:ir.Any})],Ss.prototype,"oriValue",void 0);let As=class{constructor(e={}){r(this,"ktri"),r(this,"kari"),r(this,"kekri"),r(this,"pwri"),r(this,"ori"),Object.assign(this,e)}};var xs;Fr([Lr({type:vs,optional:!0})],As.prototype,"ktri",void 0),Fr([Lr({type:ys,context:1,implicit:!0,optional:!0})],As.prototype,"kari",void 0),Fr([Lr({type:ws,context:2,implicit:!0,optional:!0})],As.prototype,"kekri",void 0),Fr([Lr({type:bs,context:3,implicit:!0,optional:!0})],As.prototype,"pwri",void 0),Fr([Lr({type:Ss,context:4,implicit:!0,optional:!0})],As.prototype,"ori",void 0),As=Fr([Ur({type:tr.Choice})],As);let ks=xs=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,xs.prototype)}};var Es;ks=xs=Fr([Ur({type:tr.Set,itemType:As})],ks);class Bs{constructor(e={}){r(this,"otherRevInfoFormat",""),r(this,"otherRevInfo",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],Bs.prototype,"otherRevInfoFormat",void 0),Fr([Lr({type:ir.Any})],Bs.prototype,"otherRevInfo",void 0);let Ns=class{constructor(e={}){r(this,"other",new Bs),Object.assign(this,e)}};Fr([Lr({type:Bs,context:1,implicit:!0})],Ns.prototype,"other",void 0),Ns=Fr([Ur({type:tr.Choice})],Ns);let Ts=Es=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Es.prototype)}};Ts=Es=Fr([Ur({type:tr.Set,itemType:Ns})],Ts);class Is{constructor(e={}){r(this,"certs"),r(this,"crls"),Object.assign(this,e)}}var Os;Fr([Lr({type:ts,context:0,implicit:!0,optional:!0})],Is.prototype,"certs",void 0),Fr([Lr({type:Ts,context:1,implicit:!0,optional:!0})],Is.prototype,"crls",void 0);let Cs=Os=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Os.prototype)}};Cs=Os=Fr([Ur({type:tr.Set,itemType:yo})],Cs);class js{constructor(e={}){r(this,"version",so.v0),r(this,"originatorInfo"),r(this,"recipientInfos",new ks),r(this,"encryptedContentInfo",new ss),r(this,"unprotectedAttrs"),Object.assign(this,e)}}Fr([Lr({type:ir.Integer})],js.prototype,"version",void 0),Fr([Lr({type:Is,context:0,implicit:!0,optional:!0})],js.prototype,"originatorInfo",void 0),Fr([Lr({type:ks})],js.prototype,"recipientInfos",void 0),Fr([Lr({type:ss})],js.prototype,"encryptedContentInfo",void 0),Fr([Lr({type:Cs,context:1,implicit:!0,optional:!0})],js.prototype,"unprotectedAttrs",void 0);const _s="1.2.840.113549.1.7.2";var Ds;let Rs=Ds=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Ds.prototype)}};Rs=Ds=Fr([Ur({type:tr.Set,itemType:co})],Rs);class Ps{constructor(e={}){r(this,"version",so.v0),r(this,"digestAlgorithms",new Rs),r(this,"encapContentInfo",new ns),r(this,"certificates"),r(this,"crls"),r(this,"signerInfos",new mo),Object.assign(this,e)}}Fr([Lr({type:ir.Integer})],Ps.prototype,"version",void 0),Fr([Lr({type:Rs})],Ps.prototype,"digestAlgorithms",void 0),Fr([Lr({type:ns})],Ps.prototype,"encapContentInfo",void 0),Fr([Lr({type:ts,context:0,implicit:!0,optional:!0})],Ps.prototype,"certificates",void 0),Fr([Lr({type:Ts,context:1,implicit:!0,optional:!0})],Ps.prototype,"crls",void 0),Fr([Lr({type:mo})],Ps.prototype,"signerInfos",void 0);const Us="1.2.840.10045.2.1",Ls="1.2.840.10045.4.1",$s="1.2.840.10045.4.3.1",Vs="1.2.840.10045.4.3.2",Ms="1.2.840.10045.4.3.3",Hs="1.2.840.10045.4.3.4",Ks="1.2.840.10045.3.1.7",Fs="1.3.132.0.34",zs="1.3.132.0.35";function Ws(e){return new Fn({algorithm:e})}const qs=Ws(Ls);Ws($s);const Js=Ws(Vs),Xs=Ws(Ms),Gs=Ws(Hs);let Ys=class{constructor(e={}){r(this,"fieldType"),r(this,"parameters"),Object.assign(this,e)}};Fr([Lr({type:ir.ObjectIdentifier})],Ys.prototype,"fieldType",void 0),Fr([Lr({type:ir.Any})],Ys.prototype,"parameters",void 0),Ys=Fr([Ur({type:tr.Sequence})],Ys);let Zs=class{constructor(e={}){r(this,"a"),r(this,"b"),r(this,"seed"),Object.assign(this,e)}};var Qs,ea;Fr([Lr({type:ir.OctetString})],Zs.prototype,"a",void 0),Fr([Lr({type:ir.OctetString})],Zs.prototype,"b",void 0),Fr([Lr({type:ir.BitString,optional:!0})],Zs.prototype,"seed",void 0),Zs=Fr([Ur({type:tr.Sequence})],Zs),(ea=Qs||(Qs={}))[ea.ecpVer1=1]="ecpVer1";let ta=class{constructor(e={}){r(this,"version",Qs.ecpVer1),r(this,"fieldID"),r(this,"curve"),r(this,"base"),r(this,"order"),r(this,"cofactor"),Object.assign(this,e)}};Fr([Lr({type:ir.Integer})],ta.prototype,"version",void 0),Fr([Lr({type:Ys})],ta.prototype,"fieldID",void 0),Fr([Lr({type:Zs})],ta.prototype,"curve",void 0),Fr([Lr({type:class extends sr{}})],ta.prototype,"base",void 0),Fr([Lr({type:ir.Integer,converter:lr})],ta.prototype,"order",void 0),Fr([Lr({type:ir.Integer,optional:!0})],ta.prototype,"cofactor",void 0),ta=Fr([Ur({type:tr.Sequence})],ta);let ra=class{constructor(e={}){r(this,"namedCurve"),r(this,"implicitCurve"),r(this,"specifiedCurve"),Object.assign(this,e)}};Fr([Lr({type:ir.ObjectIdentifier})],ra.prototype,"namedCurve",void 0),Fr([Lr({type:ir.Null})],ra.prototype,"implicitCurve",void 0),Fr([Lr({type:ta})],ra.prototype,"specifiedCurve",void 0),ra=Fr([Ur({type:tr.Choice})],ra);class ia{constructor(e={}){r(this,"version",1),r(this,"privateKey",new sr),r(this,"parameters"),r(this,"publicKey"),Object.assign(this,e)}}Fr([Lr({type:ir.Integer})],ia.prototype,"version",void 0),Fr([Lr({type:sr})],ia.prototype,"privateKey",void 0),Fr([Lr({type:ra,context:0,optional:!0})],ia.prototype,"parameters",void 0),Fr([Lr({type:ir.BitString,context:1,optional:!0})],ia.prototype,"publicKey",void 0);class na{constructor(e={}){r(this,"r",new ArrayBuffer(0)),r(this,"s",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.Integer,converter:lr})],na.prototype,"r",void 0),Fr([Lr({type:ir.Integer,converter:lr})],na.prototype,"s",void 0);const oa="1.2.840.113549.1.1",sa=`${oa}.1`,aa=`${oa}.7`,ca=`${oa}.9`,ua=`${oa}.10`,la=`${oa}.2`,ha=`${oa}.4`,pa=`${oa}.5`,fa=`${oa}.14`,da=`${oa}.11`,ya=`${oa}.12`,ga=`${oa}.13`,va=`${oa}.15`,ma=`${oa}.16`,wa="1.3.14.3.2.26",ba="2.16.840.1.101.3.4.2.4",Sa="2.16.840.1.101.3.4.2.1",Aa="2.16.840.1.101.3.4.2.2",xa="2.16.840.1.101.3.4.2.3",ka=`${oa}.8`;function Ea(e){return new Fn({algorithm:e,parameters:null})}Ea("1.2.840.113549.2.2"),Ea("1.2.840.113549.2.5");const Ba=Ea(wa);Ea(ba),Ea(Sa),Ea(Aa),Ea(xa),Ea("2.16.840.1.101.3.4.2.5"),Ea("2.16.840.1.101.3.4.2.6");const Na=new Fn({algorithm:ka,parameters:Kr.serialize(Ba)}),Ta=new Fn({algorithm:ca,parameters:Kr.serialize(dr.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))});Ea(sa),Ea(la),Ea(ha),Ea(pa),Ea(va),Ea(ma),Ea(ya),Ea(ga),Ea(va),Ea(ma);class Ia{constructor(e={}){r(this,"hashAlgorithm",new Fn(Ba)),r(this,"maskGenAlgorithm",new Fn({algorithm:ka,parameters:Kr.serialize(Ba)})),r(this,"pSourceAlgorithm",new Fn(Ta)),Object.assign(this,e)}}Fr([Lr({type:Fn,context:0,defaultValue:Ba})],Ia.prototype,"hashAlgorithm",void 0),Fr([Lr({type:Fn,context:1,defaultValue:Na})],Ia.prototype,"maskGenAlgorithm",void 0),Fr([Lr({type:Fn,context:2,defaultValue:Ta})],Ia.prototype,"pSourceAlgorithm",void 0),new Fn({algorithm:aa,parameters:Kr.serialize(new Ia)});class Oa{constructor(e={}){r(this,"hashAlgorithm",new Fn(Ba)),r(this,"maskGenAlgorithm",new Fn({algorithm:ka,parameters:Kr.serialize(Ba)})),r(this,"saltLength",20),r(this,"trailerField",1),Object.assign(this,e)}}Fr([Lr({type:Fn,context:0,defaultValue:Ba})],Oa.prototype,"hashAlgorithm",void 0),Fr([Lr({type:Fn,context:1,defaultValue:Na})],Oa.prototype,"maskGenAlgorithm",void 0),Fr([Lr({type:ir.Integer,context:2,defaultValue:20})],Oa.prototype,"saltLength",void 0),Fr([Lr({type:ir.Integer,context:3,defaultValue:1})],Oa.prototype,"trailerField",void 0),new Fn({algorithm:ua,parameters:Kr.serialize(new Oa)});class Ca{constructor(e={}){r(this,"digestAlgorithm",new Fn),r(this,"digest",new sr),Object.assign(this,e)}}var ja;Fr([Lr({type:Fn})],Ca.prototype,"digestAlgorithm",void 0),Fr([Lr({type:sr})],Ca.prototype,"digest",void 0);class _a{constructor(e={}){r(this,"prime",new ArrayBuffer(0)),r(this,"exponent",new ArrayBuffer(0)),r(this,"coefficient",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.Integer,converter:lr})],_a.prototype,"prime",void 0),Fr([Lr({type:ir.Integer,converter:lr})],_a.prototype,"exponent",void 0),Fr([Lr({type:ir.Integer,converter:lr})],_a.prototype,"coefficient",void 0);let Da=ja=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,ja.prototype)}};Da=ja=Fr([Ur({type:tr.Sequence,itemType:_a})],Da);class Ra{constructor(e={}){r(this,"version",0),r(this,"modulus",new ArrayBuffer(0)),r(this,"publicExponent",new ArrayBuffer(0)),r(this,"privateExponent",new ArrayBuffer(0)),r(this,"prime1",new ArrayBuffer(0)),r(this,"prime2",new ArrayBuffer(0)),r(this,"exponent1",new ArrayBuffer(0)),r(this,"exponent2",new ArrayBuffer(0)),r(this,"coefficient",new ArrayBuffer(0)),r(this,"otherPrimeInfos"),Object.assign(this,e)}}Fr([Lr({type:ir.Integer})],Ra.prototype,"version",void 0),Fr([Lr({type:ir.Integer,converter:lr})],Ra.prototype,"modulus",void 0),Fr([Lr({type:ir.Integer,converter:lr})],Ra.prototype,"publicExponent",void 0),Fr([Lr({type:ir.Integer,converter:lr})],Ra.prototype,"privateExponent",void 0),Fr([Lr({type:ir.Integer,converter:lr})],Ra.prototype,"prime1",void 0),Fr([Lr({type:ir.Integer,converter:lr})],Ra.prototype,"prime2",void 0),Fr([Lr({type:ir.Integer,converter:lr})],Ra.prototype,"exponent1",void 0),Fr([Lr({type:ir.Integer,converter:lr})],Ra.prototype,"exponent2",void 0),Fr([Lr({type:ir.Integer,converter:lr})],Ra.prototype,"coefficient",void 0),Fr([Lr({type:Da,optional:!0})],Ra.prototype,"otherPrimeInfos",void 0);class Pa{constructor(e={}){r(this,"modulus",new ArrayBuffer(0)),r(this,"publicExponent",new ArrayBuffer(0)),Object.assign(this,e)}}var Ua,La;Fr([Lr({type:ir.Integer,converter:lr})],Pa.prototype,"modulus",void 0),Fr([Lr({type:ir.Integer,converter:lr})],Pa.prototype,"publicExponent",void 0),(La=Ua||(Ua={}))[La.Transient=0]="Transient",La[La.Singleton=1]="Singleton",La[La.ResolutionScoped=2]="ResolutionScoped",La[La.ContainerScoped=3]="ContainerScoped";const $a=Ua;
|
|
52
|
+
*/function U(){if("undefined"==typeof BigInt)throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function $(e){let t=0,r=0;for(let n=0;n<e.length;n++){t+=e[n].byteLength}const i=new Uint8Array(t);for(let n=0;n<e.length;n++){const t=e[n];i.set(new Uint8Array(t),r),r+=t.byteLength}return i.buffer}function M(e,t,r,i){return t instanceof Uint8Array?t.byteLength?r<0?(e.error="Wrong parameter: inputOffset less than zero",!1):i<0?(e.error="Wrong parameter: inputLength less than zero",!1):!(t.byteLength-r-i<0)||(e.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):(e.error="Wrong parameter: inputBuffer has zero length",!1):(e.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}O.DEFAULT_UTF8_ENCODING="utf8";class L{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return $(this.items)}}const V=[new Uint8Array([1])],H="0123456789",K="name",F="valueHexView",z="",W=new ArrayBuffer(0),J=new Uint8Array(0),q="EndOfContent",G="OCTET STRING",X="BIT STRING";function Y(e){var t;return(t=class extends e{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(e){this.valueHexView=new Uint8Array(e)}constructor(...e){var t;super(...e);const r=e[0]||{};this.isHexOnly=null!==(t=r.isHexOnly)&&void 0!==t&&t,this.valueHexView=r.valueHex?k.toUint8Array(r.valueHex):J}fromBER(e,t,r,i){const n=e instanceof ArrayBuffer?new Uint8Array(e):e;if(!M(this,n,t,r))return-1;const o=t+r;return this.valueHexView=n.subarray(t,o),this.valueHexView.length?(this.blockLength=r,o):(this.warnings.push("Zero buffer length"),t)}toBER(e=!1){return this.isHexOnly?e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",W)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:O.ToHex(this.valueHexView)}}}).NAME="hexBlock",t}class Z{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:t="",warnings:r=[],valueBeforeDecode:i=J}={}){this.blockLength=e,this.error=t,this.warnings=r,this.valueBeforeDecodeView=k.toUint8Array(i)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:O.ToHex(this.valueBeforeDecodeView)}}}Z.NAME="baseBlock";class Q extends Z{fromBER(e,t,r,i){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}}Q.NAME="valueBlock";class ee extends(Y(Z)){constructor({idBlock:e={}}={}){var t,r,i,n;super(),e?(this.isHexOnly=null!==(t=e.isHexOnly)&&void 0!==t&&t,this.valueHexView=e.valueHex?k.toUint8Array(e.valueHex):J,this.tagClass=null!==(r=e.tagClass)&&void 0!==r?r:-1,this.tagNumber=null!==(i=e.tagNumber)&&void 0!==i?i:-1,this.isConstructed=null!==(n=e.isConstructed)&&void 0!==n&&n):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",W}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){const r=new Uint8Array(1);if(!e){let e=this.tagNumber;e&=31,t|=e,r[0]=t}return r.buffer}if(!this.isHexOnly){const r=D(this.tagNumber,7),i=new Uint8Array(r),n=r.byteLength,o=new Uint8Array(n+1);if(o[0]=31|t,!e){for(let e=0;e<n-1;e++)o[e+1]=128|i[e];o[n]=i[n-1]}return o.buffer}const r=new Uint8Array(this.valueHexView.byteLength+1);if(r[0]=31|t,!e){const e=this.valueHexView;for(let t=0;t<e.length-1;t++)r[t+1]=128|e[t];r[this.valueHexView.byteLength]=e[e.length-1]}return r.buffer}fromBER(e,t,r){const i=k.toUint8Array(e);if(!M(this,i,t,r))return-1;const n=i.subarray(t,t+r);if(0===n.length)return this.error="Zero buffer length",-1;switch(192&n[0]){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=!(32&~n[0]),this.isHexOnly=!1;const o=31&n[0];if(31!==o)this.tagNumber=o,this.blockLength=1;else{let e=0;for(;;){const t=e+1;if(t>=n.length)return this.error="End of input reached before message was fully decoded",-1;if(e++,!(128&n[t]))break}this.blockLength=e+1;const t=this.valueHexView=new Uint8Array(e);for(let r=0;r<e;r++)t[r]=127&n[r+1];this.blockLength<=9?this.tagNumber=C(t,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(1===this.tagClass&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}}ee.NAME="identificationBlock";class te extends Z{constructor({lenBlock:e={}}={}){var t,r,i;super(),this.isIndefiniteForm=null!==(t=e.isIndefiniteForm)&&void 0!==t&&t,this.longFormUsed=null!==(r=e.longFormUsed)&&void 0!==r&&r,this.length=null!==(i=e.length)&&void 0!==i?i:0}fromBER(e,t,r){const i=k.toUint8Array(e);if(!M(this,i,t,r))return-1;const n=i.subarray(t,t+r);if(0===n.length)return this.error="Zero buffer length",-1;if(255===n[0])return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=128===n[0],this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(128&n[0]),!1===this.longFormUsed)return this.length=n[0],this.blockLength=1,t+this.blockLength;const o=127&n[0];if(o>8)return this.error="Too big integer",-1;if(o+1>n.length)return this.error="End of input reached before message was fully decoded",-1;const s=t+1,a=i.subarray(s,s+o);return 0===a[o-1]&&this.warnings.push("Needlessly long encoded length"),this.length=C(a,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,r;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),!1===e&&(r=new Uint8Array(t),r[0]=128),t;if(this.longFormUsed){const i=D(this.length,8);if(i.byteLength>127)return this.error="Too big length",W;if(t=new ArrayBuffer(i.byteLength+1),e)return t;const n=new Uint8Array(i);r=new Uint8Array(t),r[0]=128|i.byteLength;for(let e=0;e<i.byteLength;e++)r[e+1]=n[e];return t}return t=new ArrayBuffer(1),!1===e&&(r=new Uint8Array(t),r[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}}te.NAME="lengthBlock";const re={};class ie extends Z{constructor({name:e="",optional:t=!1,primitiveSchema:r,...i}={},n){super(i),this.name=e,this.optional=t,r&&(this.primitiveSchema=r),this.idBlock=new ee(i),this.lenBlock=new te(i),this.valueBlock=n?new n(i):new Q(i)}fromBER(e,t,r,i){const n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length,i);return-1===n?(this.error=this.valueBlock.error,n):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),n)}toBER(e,t){const r=t||new L;t||ne(this);const i=this.idBlock.toBER(e);if(r.write(i),this.lenBlock.isIndefiniteForm)r.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,r),r.write(new ArrayBuffer(2));else{const t=this.valueBlock.toBER(e);this.lenBlock.length=t.byteLength;const i=this.lenBlock.toBER(e);r.write(i),r.write(t)}return t?W:r.final()}toJSON(){const e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return"ascii"===e?this.onAsciiEncoding():O.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${O.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;return function(e,t){if(e.byteLength!==t.byteLength)return!1;const r=new Uint8Array(e),i=new Uint8Array(t);for(let n=0;n<r.length;n++)if(r[n]!==i[n])return!1;return!0}(this.toBER(),e.toBER())}}function ne(e){var t;if(e instanceof re.Constructed)for(const r of e.valueBlock.value)ne(r)&&(e.lenBlock.isIndefiniteForm=!0);return!!(null===(t=e.lenBlock)||void 0===t?void 0:t.isIndefiniteForm)}ie.NAME="BaseBlock";class oe extends ie{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e="",...t}={},r){super(t,r),e&&this.fromString(e)}fromBER(e,t,r){const i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return-1===i?(this.error=this.valueBlock.error,i):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}}oe.NAME="BaseStringBlock";class se extends(Y(Q)){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}}var ae;se.NAME="PrimitiveValueBlock";class ce extends ie{constructor(e={}){super(e,se),this.idBlock.isConstructed=!1}}ae=ce,re.Primitive=ae,ce.NAME="PRIMITIVE";const ue=16777216;function le(e={}){var t,r,i;return{depth:0,maxDepth:null!==(t=e.maxDepth)&&void 0!==t?t:100,nodesCount:0,maxNodes:null!==(r=e.maxNodes)&&void 0!==r?r:1e4,maxContentLength:null!==(i=e.maxContentLength)&&void 0!==i?i:ue}}function pe(e,t,r,i){const n=i.depth+1;if(n>i.maxDepth)return function(e){const t=new ie({},Q);return t.error=e,{offset:-1,result:t}}("Maximum ASN.1 nesting depth exceeded");i.depth=n;try{return he(e,t,r,i)}finally{i.depth-=1}}function he(e,t=0,r=e.length,i=le()){const n=t;let o=new ie({},Q);const s=new Z;if(!M(s,e,t,r))return o.error=s.error,{offset:-1,result:o};if(!e.subarray(t,t+r).length)return o.error="Zero buffer length",{offset:-1,result:o};const a=function(e){if(e.nodesCount+=1,e.nodesCount>e.maxNodes)return"Maximum ASN.1 node count exceeded"}(i);if(a)return o.error=a,{offset:-1,result:o};let c=o.idBlock.fromBER(e,t,r);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),-1===c)return o.error=o.idBlock.error,{offset:-1,result:o};if(t=c,r-=o.idBlock.blockLength,c=o.lenBlock.fromBER(e,t,r),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),-1===c)return o.error=o.lenBlock.error,{offset:-1,result:o};t=c,r-=o.lenBlock.blockLength;const u=o.lenBlock.isIndefiniteForm?r:o.lenBlock.length,l=function(e,t){if(e>t.maxContentLength)return"Maximum ASN.1 content length exceeded"}(u,i);if(l)return o.error=l,{offset:-1,result:o};if(!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let p=ie;if(1===o.idBlock.tagClass){if(o.idBlock.tagNumber>=37&&!1===o.idBlock.isHexOnly)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};p=re.EndOfContent;break;case 1:p=re.Boolean;break;case 2:p=re.Integer;break;case 3:p=re.BitString;break;case 4:p=re.OctetString;break;case 5:p=re.Null;break;case 6:p=re.ObjectIdentifier;break;case 10:p=re.Enumerated;break;case 12:p=re.Utf8String;break;case 13:p=re.RelativeObjectIdentifier;break;case 14:p=re.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:p=re.Sequence;break;case 17:p=re.Set;break;case 18:p=re.NumericString;break;case 19:p=re.PrintableString;break;case 20:p=re.TeletexString;break;case 21:p=re.VideotexString;break;case 22:p=re.IA5String;break;case 23:p=re.UTCTime;break;case 24:p=re.GeneralizedTime;break;case 25:p=re.GraphicString;break;case 26:p=re.VisibleString;break;case 27:p=re.GeneralString;break;case 28:p=re.UniversalString;break;case 29:p=re.CharacterString;break;case 30:p=re.BmpString;break;case 31:p=re.DATE;break;case 32:p=re.TimeOfDay;break;case 33:p=re.DateTime;break;case 34:p=re.Duration;break;default:{const e=o.idBlock.isConstructed?new re.Constructed:new re.Primitive;e.idBlock=o.idBlock,e.lenBlock=o.lenBlock,e.warnings=o.warnings,o=e}}}else p=o.idBlock.isConstructed?re.Constructed:re.Primitive;return o=function(e,t){if(e instanceof t)return e;const r=new t;return r.idBlock=e.idBlock,r.lenBlock=e.lenBlock,r.warnings=e.warnings,r.valueBeforeDecodeView=e.valueBeforeDecodeView,r}(o,p),c=o.fromBER(e,t,u,i),o.valueBeforeDecodeView=e.subarray(n,n+o.blockLength),{offset:c,result:o}}function de(e,t={}){if(!e.byteLength){const e=new ie({},Q);return e.error="Input buffer has zero length",{offset:-1,result:e}}return he(k.toUint8Array(e).slice(),0,e.byteLength,le(t))}class fe extends Q{constructor({value:e=[],isIndefiniteForm:t=!1,...r}={}){super(r),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,r,i){const n=k.toUint8Array(e),o=null!=i?i:le();if(!M(this,n,t,r))return-1;if(this.valueBeforeDecodeView=n.subarray(t,t+r),0===this.valueBeforeDecodeView.length)return this.warnings.push("Zero buffer length"),t;let s=t;for(;a=this.isIndefiniteForm,c=r,(a?1:c)>0;){const e=pe(n,s,r,o);if(-1===e.offset)return this.error=e.result.error,this.warnings.concat(e.result.warnings),-1;if(s=e.offset,this.blockLength+=e.result.blockLength,r-=e.result.blockLength,this.value.push(e.result),this.isIndefiniteForm&&e.result.constructor.NAME===q)break}var a,c;return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===q?this.value.pop():this.warnings.push("No EndOfContent block encoded")),s}toBER(e,t){const r=t||new L;for(let i=0;i<this.value.length;i++)this.value[i].toBER(e,r);return t?W:r.final()}toJSON(){const e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(const t of this.value)e.value.push(t.toJSON());return e}}var ye,ge,me,ve,we;fe.NAME="ConstructedValueBlock";class be extends ie{constructor(e={}){super(e,fe),this.idBlock.isConstructed=!0}fromBER(e,t,r,i){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;const n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length,i);return-1===n?(this.error=this.valueBlock.error,n):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),n)}onAsciiEncoding(){const e=[];for(const r of this.valueBlock.value)e.push(r.toString("ascii").split("\n").map((e=>` ${e}`)).join("\n"));const t=3===this.idBlock.tagClass?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :\n${e.join("\n")}`:`${t} :`}}ye=be,re.Constructed=ye,be.NAME="CONSTRUCTED";class Se extends Q{fromBER(e,t,r){return t}toBER(e){return W}}Se.override="EndOfContentValueBlock";class Ae extends ie{constructor(e={}){super(e,Se),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}ge=Ae,re.EndOfContent=ge,Ae.NAME=q;class Ee extends ie{constructor(e={}){super(e,Q),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,r){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=r,t+r>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+r}toBER(e,t){const r=new ArrayBuffer(2);if(!e){const e=new Uint8Array(r);e[0]=5,e[1]=0}return t&&t.write(r),r}onAsciiEncoding(){return`${this.constructor.NAME}`}}me=Ee,re.Null=me,Ee.NAME="NULL";class ke extends(Y(Q)){get value(){for(const e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=k.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,r){const i=k.toUint8Array(e);return M(this,i,t,r)?(this.valueHexView=i.subarray(t,t+r),r>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,P.call(this),this.blockLength=r,t+r):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}ke.NAME="BooleanValueBlock";class xe extends ie{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,ke),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}ve=xe,re.Boolean=ve,xe.NAME="BOOLEAN";class _e extends(Y(fe)){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,r,i){let n=0;if(this.isConstructed){if(this.isHexOnly=!1,n=fe.prototype.fromBER.call(this,e,t,r,i),-1===n)return n;for(let e=0;e<this.value.length;e++){const t=this.value[e].constructor.NAME;if(t===q){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(t!==G)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,n=super.fromBER(e,t,r),this.blockLength=r;return n}toBER(e,t){return this.isConstructed?fe.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}_e.NAME="OctetStringValueBlock";let Ne=class extends ie{constructor({idBlock:e={},lenBlock:t={},...r}={}){var i,n;null!==(i=r.isConstructed)&&void 0!==i||(r.isConstructed=!!(null===(n=r.value)||void 0===n?void 0:n.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},_e),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,r,i){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,0===r)return 0===this.idBlock.error.length&&(this.blockLength+=this.idBlock.blockLength),0===this.lenBlock.error.length&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){const n=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+r);try{if(n.byteLength){const e=null!=i?i:le(),t=pe(n,0,n.byteLength,e);-1!==t.offset&&t.offset===r&&(this.valueBlock.value=[t.result])}}catch{}}return super.fromBER(e,t,r,i)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return be.prototype.onAsciiEncoding.call(this);return`${this.constructor.NAME} : ${O.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;const e=[];for(const t of this.valueBlock.value)t instanceof we&&e.push(t.valueBlock.valueHexView);return k.concat(e)}};we=Ne,re.OctetString=we,Ne.NAME=G;class Ie extends(Y(fe)){constructor({unusedBits:e=0,isConstructed:t=!1,...r}={}){super(r),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,r,i){if(!r)return t;let n=-1;if(this.isConstructed){if(n=fe.prototype.fromBER.call(this,e,t,r,i),-1===n)return n;for(const e of this.value){const t=e.constructor.NAME;if(t===q){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(t!==X)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const r=e.valueBlock;if(this.unusedBits>0&&r.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=r.unusedBits}return n}const o=k.toUint8Array(e);if(!M(this,o,t,r))return-1;const s=o.subarray(t,t+r);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){const e=s.subarray(1);try{if(e.byteLength){const t=null!=i?i:le(),n=pe(e,0,e.byteLength,t);-1!==n.offset&&n.offset===r-1&&(this.value=[n.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+r}toBER(e,t){if(this.isConstructed)return fe.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength){const e=new Uint8Array(1);return e[0]=0,e.buffer}const r=new Uint8Array(this.valueHexView.length+1);return r[0]=this.unusedBits,r.set(this.valueHexView,1),r.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}}var Te;Ie.NAME="BitStringValueBlock";let Be=class extends ie{constructor({idBlock:e={},lenBlock:t={},...r}={}){var i,n;null!==(i=r.isConstructed)&&void 0!==i||(r.isConstructed=!!(null===(n=r.value)||void 0===n?void 0:n.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},Ie),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,r,i){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,r,i)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return be.prototype.onAsciiEncoding.call(this);{const e=[],t=this.valueBlock.valueHexView;for(const i of t)e.push(i.toString(2).padStart(8,"0"));const r=e.join("");return`${this.constructor.NAME} : ${r.substring(0,r.length-this.valueBlock.unusedBits)}`}}};var Oe,Ce,De,je,Pe,Re,Ue;function $e(e,t){const r=new Uint8Array([0]),i=new Uint8Array(e),n=new Uint8Array(t);let o=i.slice(0);const s=o.length-1,a=n.slice(0),c=a.length-1;let u=0;let l=0;for(let p=c<s?s:c;p>=0;p--,l++){if(!0==l<a.length)u=o[s-l]+a[c-l]+r[0];else u=o[s-l]+r[0];if(r[0]=u/10,!0==l>=o.length)o=j(new Uint8Array([u%10]),o);else o[s-l]=u%10}return r[0]>0&&(o=j(r,o)),o}function Me(e){if(e>=V.length)for(let t=V.length;t<=e;t++){const e=new Uint8Array([0]);let r=V[t-1].slice(0);for(let t=r.length-1;t>=0;t--){const i=new Uint8Array([(r[t]<<1)+e[0]]);e[0]=i[0]/10,r[t]=i[0]%10}e[0]>0&&(r=j(e,r)),V.push(r)}return V[e]}function Le(e,t){let r=0;const i=new Uint8Array(e),n=new Uint8Array(t),o=i.slice(0),s=o.length-1,a=n.slice(0),c=a.length-1;let u,l=0;for(let p=c;p>=0;p--,l++)if(u=o[s-l]-a[c-l]-r,!0==u<0)r=1,o[s-l]=u+10;else r=0,o[s-l]=u;if(r>0)for(let p=s-c+1;p>=0;p--,l++){if(u=o[s-l]-r,!(u<0)){r=0,o[s-l]=u;break}r=1,o[s-l]=u+10}return o.slice()}Te=Be,re.BitString=Te,Be.NAME=X;class Ve extends(Y(Q)){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=P.call(this)))}constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),void 0!==e&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(function(e){const t=e<0?-1*e:e;let r=128;for(let i=1;i<8;i++){if(t<=r){if(e<0){const e=D(r-t,8,i);return new Uint8Array(e)[0]|=128,e}let n=D(t,8,i),o=new Uint8Array(n);if(128&o[0]){const e=n.slice(0),t=new Uint8Array(e);n=new ArrayBuffer(n.byteLength+1),o=new Uint8Array(n);for(let r=0;r<e.byteLength;r++)o[r+1]=t[r];o[0]=0}return n}r*=Math.pow(2,8)}return new ArrayBuffer(0)}(e))}get valueDec(){return this._valueDec}fromDER(e,t,r,i=0){const n=this.fromBER(e,t,r);if(-1===n)return n;const o=this.valueHexView;return 0===o[0]&&128&o[1]?this.valueHexView=o.subarray(1):0!==i&&o.length<i&&(i-o.length>1&&(i=o.length+1),this.valueHexView=o.subarray(i-o.length)),n}toDER(e=!1){const t=this.valueHexView;switch(!0){case!!(128&t[0]):{const e=new Uint8Array(this.valueHexView.length+1);e[0]=0,e.set(t,1),this.valueHexView=e}break;case 0===t[0]&&!(128&t[1]):this.valueHexView=this.valueHexView.subarray(1)}return this.toBER(e)}fromBER(e,t,r){const i=super.fromBER(e,t,r);return-1===i||this.setValueHex(),i}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){const e=8*this.valueHexView.length-1;let t,r=new Uint8Array(8*this.valueHexView.length/3),i=0;const n=this.valueHexView;let o="",s=!1;for(let a=n.byteLength-1;a>=0;a--){t=n[a];for(let n=0;n<8;n++){if(!(1&~t))if(i===e)r=Le(Me(i),r),o="-";else r=$e(r,Me(i));i++,t>>=1}}for(let a=0;a<r.length;a++)r[a]&&(s=!0),s&&(o+=H.charAt(r[a]));return!1===s&&(o+=H.charAt(0)),o}}Oe=Ve,Ve.NAME="IntegerValueBlock",Object.defineProperty(Oe.prototype,"valueHex",{set:function(e){this.valueHexView=new Uint8Array(e),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});class He extends ie{constructor(e={}){super(e,Ve),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return U(),BigInt(this.valueBlock.toString())}static fromBigInt(e){U();const t=BigInt(e),r=new L,i=t.toString(16).replace(/^-/,""),n=new Uint8Array(O.FromHex(i));if(t<0){const e=new Uint8Array(n.length+(128&n[0]?1:0));e[0]|=128;const i=BigInt(`0x${O.ToHex(e)}`)+t,o=k.toUint8Array(O.FromHex(i.toString(16)));o[0]|=128,r.write(o)}else 128&n[0]&&r.write(new Uint8Array([0])),r.write(n);return new Ce({valueHex:r.final()})}convertToDER(){const e=new Ce({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new Ce({valueHex:0===this.valueBlock.valueHexView[0]?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}Ce=He,re.Integer=Ce,He.NAME="INTEGER";class Ke extends He{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}De=Ke,re.Enumerated=De,Ke.NAME="ENUMERATED";class Fe extends(Y(Q)){constructor({valueDec:e=-1,isFirstSid:t=!1,...r}={}){super(r),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,r){if(!r)return t;const i=k.toUint8Array(e);if(!M(this,i,t,r))return-1;const n=i.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let s=0;s<r&&(this.valueHexView[s]=127&n[s],this.blockLength++,128&n[s]);s++);const o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength;s++)o[s]=this.valueHexView[s];return this.valueHexView=o,128&n[this.blockLength-1]?(this.error="End of input reached before message was fully decoded",-1):(0===this.valueHexView[0]&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=C(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){U();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;const r=new Uint8Array(t.length/7);for(let i=0;i<r.length;i++)r[i]=parseInt(t.slice(7*i,7*i+7),2)+(i+1<r.length?128:0);this.fromBER(r.buffer,0,r.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const t=this.valueHexView,r=new Uint8Array(this.blockLength);for(let e=0;e<this.blockLength-1;e++)r[e]=128|t[e];return r[this.blockLength-1]=t[this.blockLength-1],r.buffer}const t=D(this.valueDec,7);if(0===t.byteLength)return this.error="Error during encoding SID value",W;const r=new Uint8Array(t.byteLength);if(!e){const e=new Uint8Array(t),i=t.byteLength-1;for(let t=0;t<i;t++)r[t]=128|e[t];r[i]=e[i]}return r}toString(){let e="";if(this.isHexOnly)e=O.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}}Fe.NAME="sidBlock";class ze extends Q{constructor({value:e="",...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let i=t;for(;r>0;){const t=new Fe;if(i=t.fromBER(e,i,r),-1===i)return this.blockLength=0,this.error=t.error,i;0===this.value.length&&(t.isFirstSid=!0),this.blockLength+=t.blockLength,r-=t.blockLength,this.value.push(t)}return i}toBER(e){const t=[];for(let r=0;r<this.value.length;r++){const i=this.value[r].toBER(e);if(0===i.byteLength)return this.error=this.value[r].error,W;t.push(i)}return $(t)}fromString(e){this.value=[];let t=0,r=0,i="",n=!1;do{if(r=e.indexOf(".",t),i=-1===r?e.substring(t):e.substring(t,r),t=r+1,n){const e=this.value[0];let t=0;switch(e.valueDec){case 0:break;case 1:t=40;break;case 2:t=80;break;default:return void(this.value=[])}const r=parseInt(i,10);if(isNaN(r))return;e.valueDec=r+t,n=!1}else{const e=new Fe;if(i>Number.MAX_SAFE_INTEGER){U();const t=BigInt(i);e.valueBigInt=t}else if(e.valueDec=parseInt(i,10),isNaN(e.valueDec))return;this.value.length||(e.isFirstSid=!0,n=!0),this.value.push(e)}}while(-1!==r)}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let i=this.value[r].toString();0!==r&&(e=`${e}.`),t?(i=`{${i}}`,this.value[r].isFirstSid?e=`2.{${i} - 80}`:e+=i):e+=i}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}ze.NAME="ObjectIdentifierValueBlock";class We extends ie{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,ze),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}je=We,re.ObjectIdentifier=je,We.NAME="OBJECT IDENTIFIER";class Je extends(Y(Z)){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,r){if(0===r)return t;const i=k.toUint8Array(e);if(!M(this,i,t,r))return-1;const n=i.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let s=0;s<r&&(this.valueHexView[s]=127&n[s],this.blockLength++,128&n[s]);s++);const o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength;s++)o[s]=this.valueHexView[s];return this.valueHexView=o,128&n[this.blockLength-1]?(this.error="End of input reached before message was fully decoded",-1):(0===this.valueHexView[0]&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=C(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const t=this.valueHexView,r=new Uint8Array(this.blockLength);for(let e=0;e<this.blockLength-1;e++)r[e]=128|t[e];return r[this.blockLength-1]=t[this.blockLength-1],r.buffer}const t=D(this.valueDec,7);if(0===t.byteLength)return this.error="Error during encoding SID value",W;const r=new Uint8Array(t.byteLength);if(!e){const e=new Uint8Array(t),i=t.byteLength-1;for(let t=0;t<i;t++)r[t]=128|e[t];r[i]=e[i]}return r.buffer}toString(){let e="";return e=this.isHexOnly?O.ToHex(this.valueHexView):this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}Je.NAME="relativeSidBlock";class qe extends Q{constructor({value:e="",...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let i=t;for(;r>0;){const t=new Je;if(i=t.fromBER(e,i,r),-1===i)return this.blockLength=0,this.error=t.error,i;this.blockLength+=t.blockLength,r-=t.blockLength,this.value.push(t)}return i}toBER(e,t){const r=[];for(let i=0;i<this.value.length;i++){const t=this.value[i].toBER(e);if(0===t.byteLength)return this.error=this.value[i].error,W;r.push(t)}return $(r)}fromString(e){this.value=[];let t=0,r=0,i="";do{r=e.indexOf(".",t),i=-1===r?e.substring(t):e.substring(t,r),t=r+1;const n=new Je;if(n.valueDec=parseInt(i,10),isNaN(n.valueDec))return!0;this.value.push(n)}while(-1!==r);return!0}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let i=this.value[r].toString();0!==r&&(e=`${e}.`),t?(i=`{${i}}`,e+=i):e+=i}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}qe.NAME="RelativeObjectIdentifierValueBlock";class Ge extends ie{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,qe),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}Pe=Ge,re.RelativeObjectIdentifier=Pe,Ge.NAME="RelativeObjectIdentifier";class Xe extends be{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}Re=Xe,re.Sequence=Re,Xe.NAME="SEQUENCE";let Ye=class extends be{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};Ue=Ye,re.Set=Ue,Ye.NAME="SET";class Ze extends(Y(Q)){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=z}toJSON(){return{...super.toJSON(),value:this.value}}}Ze.NAME="StringValueBlock";class Qe extends Ze{}Qe.NAME="SimpleStringValueBlock";class et extends oe{constructor({...e}={}){super(e,Qe)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,k.toUint8Array(e))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=e.charCodeAt(i);this.valueBlock.value=e}}et.NAME="SIMPLE STRING";class tt extends et{fromBuffer(e){this.valueBlock.valueHexView=k.toUint8Array(e);try{this.valueBlock.value=O.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=O.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(O.FromUtf8String(e)),this.valueBlock.value=e}}var rt,it,nt,ot,st,at,ct,ut,lt,pt,ht,dt,ft,yt,gt,mt,vt,wt,bt;tt.NAME="Utf8StringValueBlock";class St extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}rt=St,re.Utf8String=rt,St.NAME="UTF8String";class At extends et{fromBuffer(e){this.valueBlock.value=O.ToUtf16String(e),this.valueBlock.valueHexView=k.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(O.FromUtf16String(e))}}At.NAME="BmpStringValueBlock";class Et extends At{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}it=Et,re.BmpString=it,Et.NAME="BMPString";class kt extends et{fromBuffer(e){const t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),r=new Uint8Array(t);for(let i=0;i<r.length;i+=4)r[i]=r[i+3],r[i+1]=r[i+2],r[i+2]=0,r[i+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(4*t);for(let i=0;i<t;i++){const t=D(e.charCodeAt(i),8),n=new Uint8Array(t);if(n.length>4)continue;const o=4-n.length;for(let e=n.length-1;e>=0;e--)r[4*i+e+o]=n[e]}this.valueBlock.value=e}}kt.NAME="UniversalStringValueBlock";class xt extends kt{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}nt=xt,re.UniversalString=nt,xt.NAME="UniversalString";class _t extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}ot=_t,re.NumericString=ot,_t.NAME="NumericString";class Nt extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}st=Nt,re.PrintableString=st,Nt.NAME="PrintableString";class It extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}at=It,re.TeletexString=at,It.NAME="TeletexString";class Tt extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}ct=Tt,re.VideotexString=ct,Tt.NAME="VideotexString";class Bt extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}ut=Bt,re.IA5String=ut,Bt.NAME="IA5String";class Ot extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}lt=Ot,re.GraphicString=lt,Ot.NAME="GraphicString";class Ct extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}pt=Ct,re.VisibleString=pt,Ct.NAME="VisibleString";class Dt extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}ht=Dt,re.GeneralString=ht,Dt.NAME="GeneralString";class jt extends et{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}dt=jt,re.CharacterString=dt,jt.NAME="CharacterString";class Pt extends Ct{constructor({value:e,valueDate:t,...r}={}){if(super(r),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let t=0;t<e.length;t++)this.valueBlock.valueHexView[t]=e.charCodeAt(t)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,k.toUint8Array(e)))}toBuffer(){const e=this.toString(),t=new ArrayBuffer(e.length),r=new Uint8Array(t);for(let i=0;i<e.length;i++)r[i]=e.charCodeAt(i);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){const t=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/gi.exec(e);if(null===t)return void(this.error="Wrong input string for conversion");const r=parseInt(t[1],10);this.year=r>=50?1900+r:2e3+r,this.month=parseInt(t[2],10),this.day=parseInt(t[3],10),this.hour=parseInt(t[4],10),this.minute=parseInt(t[5],10),this.second=parseInt(t[6],10)}toString(e="iso"){if("iso"===e){const e=new Array(7);return e[0]=R(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=R(this.month,2),e[2]=R(this.day,2),e[3]=R(this.hour,2),e[4]=R(this.minute,2),e[5]=R(this.second,2),e[6]="Z",e.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}}ft=Pt,re.UTCTime=ft,Pt.NAME="UTCTime";class Rt extends Pt{constructor(e={}){var t;super(e),null!==(t=this.millisecond)&&void 0!==t||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){const e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t,r=!1,i="",n="",o=0,s=0,a=0;if("Z"===e[e.length-1])i=e.substring(0,e.length-1),r=!0;else{const t=new Number(e[e.length-1]);if(isNaN(t.valueOf()))throw new Error("Wrong input string for conversion");i=e}if(r){if(-1!==i.indexOf("+"))throw new Error("Wrong input string for conversion");if(-1!==i.indexOf("-"))throw new Error("Wrong input string for conversion")}else{let e=1,t=i.indexOf("+"),r="";if(-1===t&&(t=i.indexOf("-"),e=-1),-1!==t){if(r=i.substring(t+1),i=i.substring(0,t),2!==r.length&&4!==r.length)throw new Error("Wrong input string for conversion");let n=parseInt(r.substring(0,2),10);if(isNaN(n.valueOf()))throw new Error("Wrong input string for conversion");if(s=e*n,4===r.length){if(n=parseInt(r.substring(2,4),10),isNaN(n.valueOf()))throw new Error("Wrong input string for conversion");a=e*n}}}let c=i.indexOf(".");if(-1===c&&(c=i.indexOf(",")),-1!==c){const e=new Number(`0${i.substring(c)}`);if(isNaN(e.valueOf()))throw new Error("Wrong input string for conversion");o=e.valueOf(),n=i.substring(0,c)}else n=i;switch(!0){case 8===n.length:if(t=/(\d{4})(\d{2})(\d{2})/gi,-1!==c)throw new Error("Wrong input string for conversion");break;case 10===n.length:if(t=/(\d{4})(\d{2})(\d{2})(\d{2})/gi,-1!==c){let e=60*o;this.minute=Math.floor(e),e=60*(e-this.minute),this.second=Math.floor(e),e=1e3*(e-this.second),this.millisecond=Math.floor(e)}break;case 12===n.length:if(t=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/gi,-1!==c){let e=60*o;this.second=Math.floor(e),e=1e3*(e-this.second),this.millisecond=Math.floor(e)}break;case 14===n.length:if(t=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/gi,-1!==c){const e=1e3*o;this.millisecond=Math.floor(e)}break;default:throw new Error("Wrong input string for conversion")}const u=t.exec(n);if(null===u)throw new Error("Wrong input string for conversion");for(let l=1;l<u.length;l++)switch(l){case 1:this.year=parseInt(u[l],10);break;case 2:this.month=parseInt(u[l],10);break;case 3:this.day=parseInt(u[l],10);break;case 4:this.hour=parseInt(u[l],10)+s;break;case 5:this.minute=parseInt(u[l],10)+a;break;case 6:this.second=parseInt(u[l],10);break;default:throw new Error("Wrong input string for conversion")}if(!1===r){const e=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=e.getUTCFullYear(),this.month=e.getUTCMonth(),this.day=e.getUTCDay(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds(),this.millisecond=e.getUTCMilliseconds()}}toString(e="iso"){if("iso"===e){const e=[];return e.push(R(this.year,4)),e.push(R(this.month,2)),e.push(R(this.day,2)),e.push(R(this.hour,2)),e.push(R(this.minute,2)),e.push(R(this.second,2)),0!==this.millisecond&&(e.push("."),e.push(R(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}yt=Rt,re.GeneralizedTime=yt,Rt.NAME="GeneralizedTime";class Ut extends St{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}}gt=Ut,re.DATE=gt,Ut.NAME="DATE";class $t extends St{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}mt=$t,re.TimeOfDay=mt,$t.NAME="TimeOfDay";class Mt extends St{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}vt=Mt,re.DateTime=vt,Mt.NAME="DateTime";class Lt extends St{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}wt=Lt,re.Duration=wt,Lt.NAME="Duration";class Vt extends St{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}bt=Vt,re.TIME=bt,Vt.NAME="TIME";class Ht{constructor({name:e="",optional:t=!1}={}){this.name=e,this.optional=t}}class Kt extends Ht{constructor({value:e=[],...t}={}){super(t),this.value=e}}class Ft extends Ht{constructor({value:e=new Ht,local:t=!1,...r}={}){super(r),this.value=e,this.local=t}}function zt(e,t,r){if(r instanceof Kt){for(const i of r.value){if(zt(e,t,i).verified)return{verified:!0,result:e}}{const e={verified:!1,result:{error:"Wrong values for Choice type"}};return r.hasOwnProperty(K)&&(e.name=r.name),e}}if(r instanceof Ht)return r.hasOwnProperty(K)&&(e[r.name]=t),{verified:!0,result:e};if(e instanceof Object==!1)return{verified:!1,result:{error:"Wrong root object"}};if(t instanceof Object==!1)return{verified:!1,result:{error:"Wrong ASN.1 data"}};if(r instanceof Object==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if("idBlock"in r==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if("fromBER"in r.idBlock==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if("toBER"in r.idBlock==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};const i=r.idBlock.toBER(!1);if(0===i.byteLength)return{verified:!1,result:{error:"Error encoding idBlock for ASN.1 schema"}};if(-1===r.idBlock.fromBER(i,0,i.byteLength))return{verified:!1,result:{error:"Error decoding idBlock for ASN.1 schema"}};if(!1===r.idBlock.hasOwnProperty("tagClass"))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(r.idBlock.tagClass!==t.idBlock.tagClass)return{verified:!1,result:e};if(!1===r.idBlock.hasOwnProperty("tagNumber"))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(r.idBlock.tagNumber!==t.idBlock.tagNumber)return{verified:!1,result:e};if(!1===r.idBlock.hasOwnProperty("isConstructed"))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(r.idBlock.isConstructed!==t.idBlock.isConstructed)return{verified:!1,result:e};if(!("isHexOnly"in r.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(r.idBlock.isHexOnly!==t.idBlock.isHexOnly)return{verified:!1,result:e};if(r.idBlock.isHexOnly){if(F in r.idBlock==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};const i=r.idBlock.valueHexView,n=t.idBlock.valueHexView;if(i.length!==n.length)return{verified:!1,result:e};for(let t=0;t<i.length;t++)if(i[t]!==n[1])return{verified:!1,result:e}}if(r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&(e[r.name]=t)),r instanceof re.Constructed){let i=0,n={verified:!1,result:{error:"Unknown error"}},o=r.valueBlock.value.length;if(o>0&&r.valueBlock.value[0]instanceof Ft&&(o=t.valueBlock.value.length),0===o)return{verified:!0,result:e};if(0===t.valueBlock.value.length&&0!==r.valueBlock.value.length){let t=!0;for(let e=0;e<r.valueBlock.value.length;e++)t=t&&(r.valueBlock.value[e].optional||!1);return t?{verified:!0,result:e}:(r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&delete e[r.name]),e.error="Inconsistent object length",{verified:!1,result:e})}for(let s=0;s<o;s++)if(s-i>=t.valueBlock.value.length){if(!1===r.valueBlock.value[s].optional){const t={verified:!1,result:e};return e.error="Inconsistent length between ASN.1 data and schema",r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&(delete e[r.name],t.name=r.name)),t}}else if(r.valueBlock.value[0]instanceof Ft){if(n=zt(e,t.valueBlock.value[s],r.valueBlock.value[0].value),!1===n.verified){if(!r.valueBlock.value[0].optional)return r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&delete e[r.name]),n;i++}if(K in r.valueBlock.value[0]&&r.valueBlock.value[0].name.length>0){let i={};i="local"in r.valueBlock.value[0]&&r.valueBlock.value[0].local?t:e,void 0===i[r.valueBlock.value[0].name]&&(i[r.valueBlock.value[0].name]=[]),i[r.valueBlock.value[0].name].push(t.valueBlock.value[s])}}else if(n=zt(e,t.valueBlock.value[s-i],r.valueBlock.value[s]),!1===n.verified){if(!r.valueBlock.value[s].optional)return r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&delete e[r.name]),n;i++}if(!1===n.verified){const t={verified:!1,result:e};return r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&(delete e[r.name],t.name=r.name)),t}return{verified:!0,result:e}}if(r.primitiveSchema&&F in t.valueBlock){const i=he(t.valueBlock.valueHexView);if(-1===i.offset){const t={verified:!1,result:i.result};return r.name&&(r.name=r.name.replace(/^\s+|\s+$/g,z),r.name&&(delete e[r.name],t.name=r.name)),t}return zt(e,i.result,r.primitiveSchema)}return{verified:!0,result:e}}const Wt=Object.freeze(Object.defineProperty({__proto__:null,Any:Ht,BaseBlock:ie,BaseStringBlock:oe,BitString:Be,BmpString:Et,Boolean:xe,CharacterString:jt,Choice:Kt,Constructed:be,DATE:Ut,DEFAULT_MAX_CONTENT_LENGTH:ue,DEFAULT_MAX_DEPTH:100,DEFAULT_MAX_NODES:1e4,DateTime:Mt,Duration:Lt,EndOfContent:Ae,Enumerated:Ke,GeneralString:Dt,GeneralizedTime:Rt,GraphicString:Ot,HexBlock:Y,IA5String:Bt,Integer:He,Null:Ee,NumericString:_t,ObjectIdentifier:We,OctetString:Ne,Primitive:ce,PrintableString:Nt,RawData:class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=k.toUint8Array(e)}constructor({data:e=J}={}){this.dataView=k.toUint8Array(e)}fromBER(e,t,r){const i=t+r;return this.dataView=k.toUint8Array(e).subarray(t,i),i}toBER(e){return this.dataView.slice().buffer}},RelativeObjectIdentifier:Ge,Repeated:Ft,Sequence:Xe,Set:Ye,TIME:Vt,TeletexString:It,TimeOfDay:$t,UTCTime:Pt,UniversalString:xt,Utf8String:St,ValueBlock:Q,VideotexString:Tt,ViewWriter:L,VisibleString:Ct,compareSchema:zt,fromBER:de,verifySchema:function(e,t){if(t instanceof Object==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};const r=he(k.toUint8Array(e));return-1===r.offset?{verified:!1,result:r.result}:zt(r.result,r.result,t)}},Symbol.toStringTag,{value:"Module"}));function Jt(e){return Object.prototype.toString.call(e)}function qt(e){return"[object ArrayBuffer]"===Jt(e)}function Gt(e){return qt(e)||function(e){return"undefined"!=typeof SharedArrayBuffer&&"[object SharedArrayBuffer]"===Jt(e)}(e)}function Xt(e){return function(e){if(ArrayBuffer.isView(e))return!0;if(!e||"object"!=typeof e)return!1;const t=e;return"number"==typeof t.byteOffset&&"number"==typeof t.byteLength&&Gt(t.buffer)}(e)}function Yt(e){return Gt(e)||Xt(e)}function Zt(e){if(!Yt(e))throw new TypeError("Expected ArrayBuffer, SharedArrayBuffer, or ArrayBufferView")}function Qt(e){return Zt(e),Gt(e)?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function er(e){if(Zt(e),qt(e))return e;const t=new ArrayBuffer(e.byteLength);return new Uint8Array(t).set(Qt(e)),t}var tr,rr,ir,nr;(rr=tr||(tr={}))[rr.Sequence=0]="Sequence",rr[rr.Set=1]="Set",rr[rr.Choice=2]="Choice",(nr=ir||(ir={}))[nr.Any=1]="Any",nr[nr.Boolean=2]="Boolean",nr[nr.OctetString=3]="OctetString",nr[nr.BitString=4]="BitString",nr[nr.Integer=5]="Integer",nr[nr.Enumerated=6]="Enumerated",nr[nr.ObjectIdentifier=7]="ObjectIdentifier",nr[nr.Utf8String=8]="Utf8String",nr[nr.BmpString=9]="BmpString",nr[nr.UniversalString=10]="UniversalString",nr[nr.NumericString=11]="NumericString",nr[nr.PrintableString=12]="PrintableString",nr[nr.TeletexString=13]="TeletexString",nr[nr.VideotexString=14]="VideotexString",nr[nr.IA5String=15]="IA5String",nr[nr.GraphicString=16]="GraphicString",nr[nr.VisibleString=17]="VisibleString",nr[nr.GeneralString=18]="GeneralString",nr[nr.CharacterString=19]="CharacterString",nr[nr.UTCTime=20]="UTCTime",nr[nr.GeneralizedTime=21]="GeneralizedTime",nr[nr.DATE=22]="DATE",nr[nr.TimeOfDay=23]="TimeOfDay",nr[nr.DateTime=24]="DateTime",nr[nr.Duration=25]="Duration",nr[nr.TIME=26]="TIME",nr[nr.Null=27]="Null";class or{constructor(e,t=0){if(r(this,"unusedBits",0),r(this,"value",new ArrayBuffer(0)),e)if("number"==typeof e)this.fromNumber(e);else{if(!Yt(e))throw TypeError("Unsupported type of 'params' argument for BitString");this.unusedBits=t,this.value=er(e)}}fromASN(e){if(!(e instanceof Be))throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=e.valueBlock.unusedBits,this.value=er(e.valueBlock.valueHex),this}toASN(){return new Be({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new Be({name:e})}toNumber(){let e="";const t=new Uint8Array(this.value);for(const r of t)e+=r.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let t=e.toString(2);const r=t.length+7>>3;this.unusedBits=(r<<3)-t.length;const i=new Uint8Array(r);t=t.padStart(r<<3,"0").split("").reverse().join("");let n=0;for(;n<r;)i[n]=parseInt(t.slice(n<<3,8+(n<<3)),2),n++;this.value=i.buffer}}class sr{constructor(e){r(this,"buffer"),"number"==typeof e?this.buffer=new ArrayBuffer(e):Yt(e)?this.buffer=er(e):Array.isArray(e)?this.buffer=new Uint8Array(e).buffer:this.buffer=new ArrayBuffer(0)}get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}fromASN(e){if(!(e instanceof Ne))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=er(e.valueBlock.valueHex),this}toASN(){return new Ne({valueHex:this.buffer})}toSchema(e){return new Ne({name:e})}}const ar={fromASN:e=>e instanceof Ee?null:er(e.valueBeforeDecodeView),toASN:e=>{if(null===e)return new Ee;const t=de(e);if(t.result.error)throw new Error(t.result.error);return t.result}},cr={fromASN:e=>e.valueBlock.valueHexView.byteLength>=4?e.valueBlock.toString():e.valueBlock.valueDec,toASN:e=>new He({value:+e})},ur={fromASN:e=>e.valueBlock.valueDec,toASN:e=>new Ke({value:e})},lr={fromASN:e=>er(e.valueBlock.valueHexView),toASN:e=>new He({valueHex:e})},pr={fromASN:e=>er(e.valueBlock.valueHexView),toASN:e=>new Be({valueHex:e})},hr={fromASN:e=>e.valueBlock.toString(),toASN:e=>new We({value:e})},dr={fromASN:e=>e.valueBlock.value,toASN:e=>new xe({value:e})},fr={fromASN:e=>er(e.valueBlock.valueHexView),toASN:e=>new Ne({valueHex:e})},yr={fromASN:e=>new sr(e.getValue()),toASN:e=>e.toASN()};function gr(e){return{fromASN:e=>e.valueBlock.value,toASN:t=>new e({value:t})}}const mr=gr(St),vr=gr(Et),wr=gr(xt),br=gr(_t),Sr=gr(Nt),Ar=gr(It),Er=gr(Tt),kr=gr(Bt),xr=gr(Ot),_r=gr(Ct),Nr=gr(Dt),Ir=gr(jt),Tr={fromASN:e=>e.toDate(),toASN:e=>new Pt({valueDate:e})},Br={fromASN:e=>e.toDate(),toASN:e=>new Rt({valueDate:e})},Or={fromASN:()=>null,toASN:()=>new Ee};function Cr(e){switch(e){case ir.Any:return ar;case ir.BitString:return pr;case ir.BmpString:return vr;case ir.Boolean:return dr;case ir.CharacterString:return Ir;case ir.Enumerated:return ur;case ir.GeneralString:return Nr;case ir.GeneralizedTime:return Br;case ir.GraphicString:return xr;case ir.IA5String:return kr;case ir.Integer:return cr;case ir.Null:return Or;case ir.NumericString:return br;case ir.ObjectIdentifier:return hr;case ir.OctetString:return fr;case ir.PrintableString:return Sr;case ir.TeletexString:return Ar;case ir.UTCTime:return Tr;case ir.UniversalString:return wr;case ir.Utf8String:return mr;case ir.VideotexString:return Er;case ir.VisibleString:return _r;default:return null}}function Dr(e){return"function"==typeof e&&e.prototype?!(!e.prototype.toASN||!e.prototype.fromASN)||Dr(e.prototype):!!(e&&"object"==typeof e&&"toASN"in e&&"fromASN"in e)}function jr(e){var t;if(e){const r=Object.getPrototypeOf(e);return(null==(t=null==r?void 0:r.prototype)?void 0:t.constructor)===Array||jr(r)}return!1}function Pr(e,t){if(!e||!t)return!1;if(e.byteLength!==t.byteLength)return!1;const r=new Uint8Array(e),i=new Uint8Array(t);for(let n=0;n<e.byteLength;n++)if(r[n]!==i[n])return!1;return!0}const Rr=new class{constructor(){r(this,"items",new WeakMap)}has(e){return this.items.has(e)}get(e,t=!1){const r=this.items.get(e);if(!r)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(t&&!r.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return r}cache(e){const t=this.get(e);t.schema||(t.schema=this.create(e,!0))}createDefault(e){const t={type:tr.Sequence,items:{}},r=this.findParentSchema(e);return r&&(Object.assign(t,r),t.items=Object.assign({},t.items,r.items)),t}create(e,t){const r=this.items.get(e)||this.createDefault(e),i=[];for(const n in r.items){const e=r.items[n],o=t?n:"";let s;if("number"==typeof e.type){const t=ir[e.type],r=Wt[t];if(!r)throw new Error(`Cannot get ASN1 class by name '${t}'`);s=new r({name:o})}else if(Dr(e.type)){s=(new e.type).toSchema(o)}else if(e.optional){this.get(e.type).type===tr.Choice?s=new Ht({name:o}):(s=this.create(e.type,!1),s.name=o)}else s=new Ht({name:o});const a=!!e.optional||void 0!==e.defaultValue;if(e.repeated){s.name="";s=new("set"===e.repeated?Ye:Xe)({name:"",value:[new Ft({name:o,value:s})]})}if(null!==e.context&&void 0!==e.context)if(e.implicit)if("number"==typeof e.type||Dr(e.type)){const t=e.repeated?be:ce;i.push(new t({name:o,optional:a,idBlock:{tagClass:3,tagNumber:e.context}}))}else{this.cache(e.type);const t=!!e.repeated;let r=t?s:this.get(e.type,!0).schema;r="valueBlock"in r?r.valueBlock.value:r.value,i.push(new be({name:t?"":o,optional:a,idBlock:{tagClass:3,tagNumber:e.context},value:r}))}else i.push(new be({optional:a,idBlock:{tagClass:3,tagNumber:e.context},value:[s]}));else s.optional=a,i.push(s)}switch(r.type){case tr.Sequence:return new Xe({value:i,name:""});case tr.Set:return new Ye({value:i,name:""});case tr.Choice:return new Kt({value:i,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,t){return this.items.set(e,t),this}findParentSchema(e){const t=Object.getPrototypeOf(e);if(t){return this.items.get(t)||this.findParentSchema(t)}return null}},Ur=e=>t=>{let r;Rr.has(t)?r=Rr.get(t):(r=Rr.createDefault(t),Rr.set(t,r)),Object.assign(r,e)},$r=e=>(t,r)=>{let i;Rr.has(t.constructor)?i=Rr.get(t.constructor):(i=Rr.createDefault(t.constructor),Rr.set(t.constructor,i));const n=Object.assign({},e);if("number"==typeof n.type&&!n.converter){const i=Cr(e.type);if(!i)throw new Error(`Cannot get default converter for property '${r}' of ${t.constructor.name}`);n.converter=i}n.raw=e.raw,i.items[r]=n};class Mr extends Error{constructor(){super(...arguments),r(this,"schemas",[])}}class Lr{static parse(e,t,r){const i=de(er(e),null==r?void 0:r.berOptions);if(i.result.error)throw new Error(i.result.error);return this.fromASN(i.result,t,r)}static fromASN(e,t,r){try{if(Dr(t)){return(new t).fromASN(e)}const i=Rr.get(t);Rr.cache(t);let n=i.schema;const o=this.handleChoiceTypes(e,i,t,n,r);if(null==o?void 0:o.result)return o.result;(null==o?void 0:o.targetSchema)&&(n=o.targetSchema);const s=this.handleSequenceTypes(e,i,t,n),a=new t;return jr(t)?this.handleArrayTypes(e,i,t,r):(this.processSchemaItems(i,s,a,r),a)}catch(i){throw i instanceof Mr&&i.schemas.push(t.name),i}}static handleChoiceTypes(e,t,r,i,n){if(e.constructor===be&&t.type===tr.Choice&&3===e.idBlock.tagClass)for(const o in t.items){const i=t.items[o];if(i.context===e.idBlock.tagNumber&&i.implicit&&"function"==typeof i.type&&Rr.has(i.type)){const t=Rr.get(i.type);if(t&&t.type===tr.Sequence){const t=new Xe;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in t.valueBlock){t.valueBlock.value=e.valueBlock.value;const s=this.fromASN(t,i.type,n),a=new r;return a[o]=s,{result:a}}}}}else if(e.constructor===be&&t.type!==tr.Choice){const r=new be({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:t.schema.valueBlock.value});for(const i in t.items)delete e[i];return{targetSchema:r}}return null}static handleSequenceTypes(e,t,r,i){if(t.type===tr.Sequence){const t=zt({},e,i);if(!t.verified)throw new Mr(`Data does not match to ${r.name} ASN1 schema.${t.result.error?` ${t.result.error}`:""}`);return t}{const t=zt({},e,i);if(!t.verified)throw new Mr(`Data does not match to ${r.name} ASN1 schema.${t.result.error?` ${t.result.error}`:""}`);return t}}static processRepeatedField(e,t,r){let i=e.slice(t);if(1===i.length&&"Sequence"===i[0].constructor.name){const e=i[0];e.valueBlock&&e.valueBlock.value&&Array.isArray(e.valueBlock.value)&&(i=e.valueBlock.value)}if("number"==typeof r.type){const e=Cr(r.type);if(!e)throw new Error(`No converter for ASN.1 type ${r.type}`);return i.filter((e=>e&&e.valueBlock)).map((t=>{try{return e.fromASN(t)}catch{return}})).filter((e=>void 0!==e))}return i.filter((e=>e&&e.valueBlock)).map((e=>{try{return this.fromASN(e,r.type)}catch{return}})).filter((e=>void 0!==e))}static processPrimitiveField(e,t){const r=Cr(t.type);if(!r)throw new Error(`No converter for ASN.1 type ${t.type}`);return r.fromASN(e)}static isOptionalChoiceField(e){return e.optional&&"function"==typeof e.type&&Rr.has(e.type)&&Rr.get(e.type).type===tr.Choice}static processOptionalChoiceField(e,t){try{return{processed:!0,value:this.fromASN(e,t.type)}}catch(r){if(r instanceof Mr&&/Wrong values for Choice type/.test(r.message))return{processed:!1};throw r}}static handleArrayTypes(e,t,r,i){if(!("value"in e.valueBlock)||!Array.isArray(e.valueBlock.value))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");const n=t.itemType;if("number"==typeof n){const t=Cr(n);if(!t)throw new Error(`Cannot get default converter for array item of ${r.name} ASN1 schema`);return r.from(e.valueBlock.value,(e=>t.fromASN(e)))}return r.from(e.valueBlock.value,(e=>this.fromASN(e,n,i)))}static processSchemaItems(e,t,r,i){for(const n in e.items){const o=t.result[n];if(!o)continue;const s=e.items[n],a=s.type;let c;c="number"==typeof a||Dr(a)?this.processPrimitiveSchemaItem(o,s,a,i):this.processComplexSchemaItem(o,s,a,i),c&&"object"==typeof c&&"value"in c&&"raw"in c?(r[n]=c.value,r[`${n}Raw`]=c.raw):r[n]=c}}static processPrimitiveSchemaItem(e,t,r,i){const n=t.converter??(Dr(r)?new r:null);if(!n)throw new Error("Converter is empty");return t.repeated?this.processRepeatedPrimitiveItem(e,t,n,i):this.processSinglePrimitiveItem(e,t,r,n,i)}static processRepeatedPrimitiveItem(e,t,r,i){if(t.implicit){const n=new("sequence"===t.repeated?Xe:Ye);n.valueBlock=e.valueBlock;const o=de(n.toBER(!1),null==i?void 0:i.berOptions);if(-1===o.offset)throw new Error(`Cannot parse the child item. ${o.result.error}`);if(!("value"in o.result.valueBlock)||!Array.isArray(o.result.valueBlock.value))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");const s=o.result.valueBlock.value;return Array.from(s,(e=>r.fromASN(e)))}return Array.from(e,(e=>r.fromASN(e)))}static processSinglePrimitiveItem(e,t,r,i,n){let o=e;if(t.implicit){let e;if(Dr(r))e=(new r).toSchema("");else{const t=ir[r],i=Wt[t];if(!i)throw new Error(`Cannot get '${t}' class from asn1js module`);e=new i}e.valueBlock=o.valueBlock,o=de(e.toBER(!1),null==n?void 0:n.berOptions).result}return i.fromASN(o)}static processComplexSchemaItem(e,t,r,i){if(t.repeated){if(!Array.isArray(e))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(e,(e=>this.fromASN(e,r,i)))}{const o=this.handleImplicitTagging(e,t,r);if(!this.isOptionalChoiceField(t)){const n=this.fromASN(o,r,i);return t.raw?{value:n,raw:e.valueBeforeDecodeView}:n}try{return this.fromASN(o,r,i)}catch(n){if(n instanceof Mr&&/Wrong values for Choice type/.test(n.message))return;throw n}}}static handleImplicitTagging(e,t,r){if(t.implicit&&"number"==typeof t.context){const t=Rr.get(r);if(t.type===tr.Sequence){const t=new Xe;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in t.valueBlock)return t.valueBlock.value=e.valueBlock.value,t}else if(t.type===tr.Set){const t=new Ye;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in t.valueBlock)return t.valueBlock.value=e.valueBlock.value,t}}return e}}class Vr{static serialize(e){return e instanceof ie?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&"object"==typeof e&&Dr(e))return e.toASN();if(!e||"object"!=typeof e)throw new TypeError("Parameter 1 should be type of Object.");const t=e.constructor,r=Rr.get(t);Rr.cache(t);let i,n=[];if(r.itemType){if(!Array.isArray(e))throw new TypeError("Parameter 1 should be type of Array.");if("number"==typeof r.itemType){const i=Cr(r.itemType);if(!i)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);n=e.map((e=>i.toASN(e)))}else n=e.map((e=>this.toAsnItem({type:r.itemType},"[]",t,e)))}else for(const o in r.items){const i=r.items[o],s=e[o];if(void 0===s||i.defaultValue===s||"object"==typeof i.defaultValue&&"object"==typeof s&&Pr(this.serialize(i.defaultValue),this.serialize(s)))continue;const a=Vr.toAsnItem(i,o,t,s);if("number"==typeof i.context)if(i.implicit)if(i.repeated||"number"!=typeof i.type&&!Dr(i.type))n.push(new be({optional:i.optional,idBlock:{tagClass:3,tagNumber:i.context},value:a.valueBlock.value}));else{const e={};e.valueHex=a instanceof Ee?er(a.valueBeforeDecodeView):a.valueBlock.toBER(),n.push(new ce({optional:i.optional,idBlock:{tagClass:3,tagNumber:i.context},...e}))}else n.push(new be({optional:i.optional,idBlock:{tagClass:3,tagNumber:i.context},value:[a]}));else i.repeated?n=n.concat(a):n.push(a)}switch(r.type){case tr.Sequence:i=new Xe({value:n});break;case tr.Set:i=new Ye({value:n});break;case tr.Choice:if(!n[0])throw new Error(`Schema '${t.name}' has wrong data. Choice cannot be empty.`);i=n[0]}return i}static toAsnItem(e,t,r,i){let n;if("number"==typeof e.type){const o=e.converter;if(!o)throw new Error(`Property '${t}' doesn't have converter for type ${ir[e.type]} in schema '${r.name}'`);if(e.repeated){if(!Array.isArray(i))throw new TypeError("Parameter 'objProp' should be type of Array.");const t=Array.from(i,(e=>o.toASN(e)));n=new("sequence"===e.repeated?Xe:Ye)({value:t})}else n=o.toASN(i)}else if(e.repeated){if(!Array.isArray(i))throw new TypeError("Parameter 'objProp' should be type of Array.");const t=Array.from(i,(e=>this.toASN(e)));n=new("sequence"===e.repeated?Xe:Ye)({value:t})}else n=this.toASN(i);return n}}class Hr extends Array{constructor(e=[]){if("number"==typeof e)super(e);else{super();for(const t of e)this.push(t)}}}class Kr{static serialize(e){return Vr.serialize(e)}static parse(e,t,r){return Lr.parse(e,t,r)}static toString(e,t){const r=de(Yt(e)?er(e):Kr.serialize(e),null==t?void 0:t.berOptions);if(-1===r.offset)throw new Error(`Cannot decode ASN.1 data. ${r.result.error}`);return r.result.toString()}}function Fr(e,t,r,i){var n,o=arguments.length,s=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,i);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(s=(o<3?n(s):o>3?n(t,r,s):n(t,r))||s);return o>3&&s&&Object.defineProperty(t,r,s),s}function zr(e,t,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(e):i?i.value:t.get(e)}function Wr(e,t,r,i,n){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?n.call(e,r):n?n.value=r:t.set(e,r),r}function Jr(e,t){if(!t)return e.join("");if(!Number.isInteger(t.size)||t.size<1)throw new RangeError("Hex group size must be a positive integer");const r=[];for(let i=0;i<e.length;i+=t.size)r.push(e.slice(i,i+t.size).join(""));return r.join(t.separator)}function qr(e,t={}){const r=Qt(e),i=t.case??"lower",n=Array.from(r,(e=>{const t=e.toString(16).padStart(2,"0");return"upper"===i?t.toUpperCase():t}));let o="";if(t.line){const e=t.line.bytesPerLine;if(!Number.isInteger(e)||e<1)throw new RangeError("Hex bytesPerLine must be a positive integer");const r=t.line.separator??"\n",i=[];for(let o=0;o<n.length;o+=e)i.push(Jr(n.slice(o,o+e),t.group));o=i.join(r)}else o=Jr(n,t.group);return`${t.prefix??""}${o}`}"function"==typeof SuppressedError&&SuppressedError;class Gr{static isIPv4(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)}static parseIPv4(e){const t=e.split(".");if(4!==t.length)throw new Error("Invalid IPv4 address");return t.map((e=>{const t=parseInt(e,10);if(isNaN(t)||t<0||t>255)throw new Error("Invalid IPv4 address part");return t}))}static parseIPv6(e){const t=this.expandIPv6(e).split(":");if(8!==t.length)throw new Error("Invalid IPv6 address");return t.reduce(((e,t)=>{const r=parseInt(t,16);if(isNaN(r)||r<0||r>65535)throw new Error("Invalid IPv6 address part");return e.push(r>>8&255),e.push(255&r),e}),[])}static expandIPv6(e){if(!e.includes("::"))return e;const t=e.split("::");if(t.length>2)throw new Error("Invalid IPv6 address");const r=t[0]?t[0].split(":"):[],i=t[1]?t[1].split(":"):[],n=8-(r.length+i.length);if(n<0)throw new Error("Invalid IPv6 address");return[...r,...Array(n).fill("0"),...i].join(":")}static formatIPv6(e){const t=[];for(let r=0;r<16;r+=2)t.push((e[r]<<8|e[r+1]).toString(16));return this.compressIPv6(t.join(":"))}static compressIPv6(e){const t=e.split(":");let r=-1,i=0,n=-1,o=0;for(let s=0;s<t.length;s++)"0"===t[s]?(-1===n&&(n=s),o++):(o>i&&(r=n,i=o),n=-1,o=0);if(o>i&&(r=n,i=o),i>1){return`${t.slice(0,r).join(":")}::${t.slice(r+i).join(":")}`}return e}static parseCIDR(e){const[t,r]=e.split("/"),i=parseInt(r,10);if(this.isIPv4(t)){if(i<0||i>32)throw new Error("Invalid IPv4 prefix length");return[this.parseIPv4(t),i]}if(i<0||i>128)throw new Error("Invalid IPv6 prefix length");return[this.parseIPv6(t),i]}static decodeIP(e){if(64===e.length&&0===parseInt(e,16))return"::/0";if(16!==e.length)return e;const t=parseInt(e.slice(8),16).toString(2).split("").reduce(((e,t)=>e+ +t),0);let r=e.slice(0,8).replace(/(.{2})/g,(e=>`${parseInt(e,16)}.`));return r=r.slice(0,-1),`${r}/${t}`}static toString(e){const t=new Uint8Array(e);if(4===t.length)return Array.from(t).join(".");if(16===t.length)return this.formatIPv6(t);if(8===t.length||32===t.length){const e=t.length/2,r=t.slice(0,e),i=t.slice(e);if(t.every((e=>0===e)))return 8===t.length?"0.0.0.0/0":"::/0";const n=i.reduce(((e,t)=>e+(t.toString(2).match(/1/g)||[]).length),0);if(8===t.length){return`${Array.from(r).join(".")}/${n}`}return`${this.formatIPv6(r)}/${n}`}return this.decodeIP(qr(e))}static fromString(e){if(e.includes("/")){const[t,r]=this.parseCIDR(e),i=new Uint8Array(t.length);let n=r;for(let e=0;e<i.length;e++)n>=8?(i[e]=255,n-=8):n>0&&(i[e]=255<<8-n,n=0);const o=new Uint8Array(2*t.length);return o.set(t,0),o.set(i,t.length),o.buffer}const t=this.isIPv4(e)?this.parseIPv4(e):this.parseIPv6(e);return new Uint8Array(t).buffer}}var Xr,Yr,Zr;let Qr=class{constructor(e={}){r(this,"teletexString"),r(this,"printableString"),r(this,"universalString"),r(this,"utf8String"),r(this,"bmpString"),Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};Fr([$r({type:ir.TeletexString})],Qr.prototype,"teletexString",void 0),Fr([$r({type:ir.PrintableString})],Qr.prototype,"printableString",void 0),Fr([$r({type:ir.UniversalString})],Qr.prototype,"universalString",void 0),Fr([$r({type:ir.Utf8String})],Qr.prototype,"utf8String",void 0),Fr([$r({type:ir.BmpString})],Qr.prototype,"bmpString",void 0),Qr=Fr([Ur({type:tr.Choice})],Qr);let ei=class extends Qr{constructor(e={}){super(e),r(this,"ia5String"),r(this,"anyValue"),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?qr(this.anyValue):super.toString())}};Fr([$r({type:ir.IA5String})],ei.prototype,"ia5String",void 0),Fr([$r({type:ir.Any})],ei.prototype,"anyValue",void 0),ei=Fr([Ur({type:tr.Choice})],ei);class ti{constructor(e={}){r(this,"type",""),r(this,"value",new ei),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],ti.prototype,"type",void 0),Fr([$r({type:ei})],ti.prototype,"value",void 0);let ri=Xr=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Xr.prototype)}};ri=Xr=Fr([Ur({type:tr.Set,itemType:ti})],ri);let ii=Yr=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Yr.prototype)}};ii=Yr=Fr([Ur({type:tr.Sequence,itemType:ri})],ii);let ni=Zr=class extends ii{constructor(e){super(e),Object.setPrototypeOf(this,Zr.prototype)}};ni=Zr=Fr([Ur({type:tr.Sequence})],ni);const oi={fromASN:e=>Gr.toString(fr.fromASN(e)),toASN:e=>fr.toASN(Gr.fromString(e))};class si{constructor(e={}){r(this,"typeId",""),r(this,"value",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],si.prototype,"typeId",void 0),Fr([$r({type:ir.Any,context:0})],si.prototype,"value",void 0);class ai{constructor(e={}){r(this,"nameAssigner"),r(this,"partyName",new Qr),Object.assign(this,e)}}Fr([$r({type:Qr,optional:!0,context:0,implicit:!0})],ai.prototype,"nameAssigner",void 0),Fr([$r({type:Qr,context:1,implicit:!0})],ai.prototype,"partyName",void 0);let ci=class{constructor(e={}){r(this,"otherName"),r(this,"rfc822Name"),r(this,"dNSName"),r(this,"x400Address"),r(this,"directoryName"),r(this,"ediPartyName"),r(this,"uniformResourceIdentifier"),r(this,"iPAddress"),r(this,"registeredID"),Object.assign(this,e)}};Fr([$r({type:si,context:0,implicit:!0})],ci.prototype,"otherName",void 0),Fr([$r({type:ir.IA5String,context:1,implicit:!0})],ci.prototype,"rfc822Name",void 0),Fr([$r({type:ir.IA5String,context:2,implicit:!0})],ci.prototype,"dNSName",void 0),Fr([$r({type:ir.Any,context:3,implicit:!0})],ci.prototype,"x400Address",void 0),Fr([$r({type:ni,context:4,implicit:!1})],ci.prototype,"directoryName",void 0),Fr([$r({type:ai,context:5})],ci.prototype,"ediPartyName",void 0),Fr([$r({type:ir.IA5String,context:6,implicit:!0})],ci.prototype,"uniformResourceIdentifier",void 0),Fr([$r({type:ir.OctetString,context:7,implicit:!0,converter:oi})],ci.prototype,"iPAddress",void 0),Fr([$r({type:ir.ObjectIdentifier,context:8,implicit:!0})],ci.prototype,"registeredID",void 0),ci=Fr([Ur({type:tr.Choice})],ci);const ui="1.3.6.1.5.5.7",li=`${ui}.3`,pi=`${ui}.48`,hi=`${pi}.1`,di=`${pi}.2`,fi=`${pi}.3`,yi=`${pi}.5`,gi="2.5.29";var mi;const vi=`${`${ui}.1`}.1`;class wi{constructor(e={}){r(this,"accessMethod",""),r(this,"accessLocation",new ci),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],wi.prototype,"accessMethod",void 0),Fr([$r({type:ci})],wi.prototype,"accessLocation",void 0);let bi=mi=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,mi.prototype)}};bi=mi=Fr([Ur({type:tr.Sequence,itemType:wi})],bi);const Si=`${gi}.35`;class Ai extends sr{}class Ei{constructor(e={}){r(this,"keyIdentifier"),r(this,"authorityCertIssuer"),r(this,"authorityCertSerialNumber"),e&&Object.assign(this,e)}}Fr([$r({type:Ai,context:0,optional:!0,implicit:!0})],Ei.prototype,"keyIdentifier",void 0),Fr([$r({type:ci,context:1,optional:!0,implicit:!0,repeated:"sequence"})],Ei.prototype,"authorityCertIssuer",void 0),Fr([$r({type:ir.Integer,context:2,optional:!0,implicit:!0,converter:lr})],Ei.prototype,"authorityCertSerialNumber",void 0);const ki=`${gi}.19`;class xi{constructor(e={}){r(this,"cA",!1),r(this,"pathLenConstraint"),Object.assign(this,e)}}var _i;Fr([$r({type:ir.Boolean,defaultValue:!1})],xi.prototype,"cA",void 0),Fr([$r({type:ir.Integer,optional:!0})],xi.prototype,"pathLenConstraint",void 0);let Ni=_i=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,_i.prototype)}};var Ii;Ni=_i=Fr([Ur({type:tr.Sequence,itemType:ci})],Ni);let Ti=Ii=class extends Ni{constructor(e){super(e),Object.setPrototypeOf(this,Ii.prototype)}};var Bi;Ti=Ii=Fr([Ur({type:tr.Sequence})],Ti);const Oi=`${gi}.32`;let Ci=class{constructor(e={}){r(this,"ia5String"),r(this,"visibleString"),r(this,"bmpString"),r(this,"utf8String"),Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};Fr([$r({type:ir.IA5String})],Ci.prototype,"ia5String",void 0),Fr([$r({type:ir.VisibleString})],Ci.prototype,"visibleString",void 0),Fr([$r({type:ir.BmpString})],Ci.prototype,"bmpString",void 0),Fr([$r({type:ir.Utf8String})],Ci.prototype,"utf8String",void 0),Ci=Fr([Ur({type:tr.Choice})],Ci);class Di{constructor(e={}){r(this,"organization",new Ci),r(this,"noticeNumbers",[]),Object.assign(this,e)}}Fr([$r({type:Ci})],Di.prototype,"organization",void 0),Fr([$r({type:ir.Integer,repeated:"sequence"})],Di.prototype,"noticeNumbers",void 0);class ji{constructor(e={}){r(this,"noticeRef"),r(this,"explicitText"),Object.assign(this,e)}}Fr([$r({type:Di,optional:!0})],ji.prototype,"noticeRef",void 0),Fr([$r({type:Ci,optional:!0})],ji.prototype,"explicitText",void 0);let Pi=class{constructor(e={}){r(this,"cPSuri"),r(this,"userNotice"),Object.assign(this,e)}};Fr([$r({type:ir.IA5String})],Pi.prototype,"cPSuri",void 0),Fr([$r({type:ji})],Pi.prototype,"userNotice",void 0),Pi=Fr([Ur({type:tr.Choice})],Pi);class Ri{constructor(e={}){r(this,"policyQualifierId",""),r(this,"qualifier",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],Ri.prototype,"policyQualifierId",void 0),Fr([$r({type:ir.Any})],Ri.prototype,"qualifier",void 0);class Ui{constructor(e={}){r(this,"policyIdentifier",""),r(this,"policyQualifiers"),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],Ui.prototype,"policyIdentifier",void 0),Fr([$r({type:Ri,repeated:"sequence",optional:!0})],Ui.prototype,"policyQualifiers",void 0);let $i=Bi=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Bi.prototype)}};$i=Bi=Fr([Ur({type:tr.Sequence,itemType:Ui})],$i);let Mi=class{constructor(e=0){r(this,"value"),this.value=e}};Fr([$r({type:ir.Integer})],Mi.prototype,"value",void 0),Mi=Fr([Ur({type:tr.Choice})],Mi);let Li=class extends Mi{};var Vi;Li=Fr([Ur({type:tr.Choice})],Li);const Hi=`${gi}.31`;var Ki,Fi;(Fi=Ki||(Ki={}))[Fi.unused=1]="unused",Fi[Fi.keyCompromise=2]="keyCompromise",Fi[Fi.cACompromise=4]="cACompromise",Fi[Fi.affiliationChanged=8]="affiliationChanged",Fi[Fi.superseded=16]="superseded",Fi[Fi.cessationOfOperation=32]="cessationOfOperation",Fi[Fi.certificateHold=64]="certificateHold",Fi[Fi.privilegeWithdrawn=128]="privilegeWithdrawn",Fi[Fi.aACompromise=256]="aACompromise";class zi extends or{toJSON(){const e=[],t=this.toNumber();return t&Ki.aACompromise&&e.push("aACompromise"),t&Ki.affiliationChanged&&e.push("affiliationChanged"),t&Ki.cACompromise&&e.push("cACompromise"),t&Ki.certificateHold&&e.push("certificateHold"),t&Ki.cessationOfOperation&&e.push("cessationOfOperation"),t&Ki.keyCompromise&&e.push("keyCompromise"),t&Ki.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Ki.superseded&&e.push("superseded"),t&Ki.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}}let Wi=class{constructor(e={}){r(this,"fullName"),r(this,"nameRelativeToCRLIssuer"),Object.assign(this,e)}};Fr([$r({type:ci,context:0,repeated:"sequence",implicit:!0})],Wi.prototype,"fullName",void 0),Fr([$r({type:ri,context:1,implicit:!0})],Wi.prototype,"nameRelativeToCRLIssuer",void 0),Wi=Fr([Ur({type:tr.Choice})],Wi);class Ji{constructor(e={}){r(this,"distributionPoint"),r(this,"reasons"),r(this,"cRLIssuer"),Object.assign(this,e)}}Fr([$r({type:Wi,context:0,optional:!0})],Ji.prototype,"distributionPoint",void 0),Fr([$r({type:zi,context:1,optional:!0,implicit:!0})],Ji.prototype,"reasons",void 0),Fr([$r({type:ci,context:2,optional:!0,repeated:"sequence",implicit:!0})],Ji.prototype,"cRLIssuer",void 0);let qi=Vi=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Vi.prototype)}};var Gi;qi=Vi=Fr([Ur({type:tr.Sequence,itemType:Ji})],qi);let Xi=Gi=class extends qi{constructor(e){super(e),Object.setPrototypeOf(this,Gi.prototype)}};Xi=Gi=Fr([Ur({type:tr.Sequence,itemType:Ji})],Xi);const Yi=class e{constructor(t={}){r(this,"distributionPoint"),r(this,"onlyContainsUserCerts",e.ONLY),r(this,"onlyContainsCACerts",e.ONLY),r(this,"onlySomeReasons"),r(this,"indirectCRL",e.ONLY),r(this,"onlyContainsAttributeCerts",e.ONLY),Object.assign(this,t)}};r(Yi,"ONLY",!1);let Zi=Yi;var Qi,en;Fr([$r({type:Wi,context:0,optional:!0})],Zi.prototype,"distributionPoint",void 0),Fr([$r({type:ir.Boolean,context:1,defaultValue:Zi.ONLY,implicit:!0})],Zi.prototype,"onlyContainsUserCerts",void 0),Fr([$r({type:ir.Boolean,context:2,defaultValue:Zi.ONLY,implicit:!0})],Zi.prototype,"onlyContainsCACerts",void 0),Fr([$r({type:zi,context:3,optional:!0,implicit:!0})],Zi.prototype,"onlySomeReasons",void 0),Fr([$r({type:ir.Boolean,context:4,defaultValue:Zi.ONLY,implicit:!0})],Zi.prototype,"indirectCRL",void 0),Fr([$r({type:ir.Boolean,context:5,defaultValue:Zi.ONLY,implicit:!0})],Zi.prototype,"onlyContainsAttributeCerts",void 0),(en=Qi||(Qi={}))[en.unspecified=0]="unspecified",en[en.keyCompromise=1]="keyCompromise",en[en.cACompromise=2]="cACompromise",en[en.affiliationChanged=3]="affiliationChanged",en[en.superseded=4]="superseded",en[en.cessationOfOperation=5]="cessationOfOperation",en[en.certificateHold=6]="certificateHold",en[en.removeFromCRL=8]="removeFromCRL",en[en.privilegeWithdrawn=9]="privilegeWithdrawn",en[en.aACompromise=10]="aACompromise";let tn=class{constructor(e=Qi.unspecified){r(this,"reason",Qi.unspecified),this.reason=e}toJSON(){return Qi[this.reason]}toString(){return this.toJSON()}};var rn;Fr([$r({type:ir.Enumerated})],tn.prototype,"reason",void 0),tn=Fr([Ur({type:tr.Choice})],tn);const nn=`${gi}.37`;let on=rn=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,rn.prototype)}};on=rn=Fr([Ur({type:tr.Sequence,itemType:ir.ObjectIdentifier})],on);const sn=`${li}.1`,an=`${li}.2`,cn=`${li}.3`,un=`${li}.4`,ln=`${li}.8`,pn=`${li}.9`;let hn=class{constructor(e=new ArrayBuffer(0)){r(this,"value"),this.value=e}};Fr([$r({type:ir.Integer,converter:lr})],hn.prototype,"value",void 0),hn=Fr([Ur({type:tr.Choice})],hn);let dn=class{constructor(e){r(this,"value",new Date),e&&(this.value=e)}};var fn;Fr([$r({type:ir.GeneralizedTime})],dn.prototype,"value",void 0),dn=Fr([Ur({type:tr.Choice})],dn);const yn=`${gi}.18`;let gn=fn=class extends Ni{constructor(e){super(e),Object.setPrototypeOf(this,fn.prototype)}};gn=fn=Fr([Ur({type:tr.Sequence})],gn);const mn=`${gi}.15`;var vn,wn,bn;(wn=vn||(vn={}))[wn.digitalSignature=1]="digitalSignature",wn[wn.nonRepudiation=2]="nonRepudiation",wn[wn.keyEncipherment=4]="keyEncipherment",wn[wn.dataEncipherment=8]="dataEncipherment",wn[wn.keyAgreement=16]="keyAgreement",wn[wn.keyCertSign=32]="keyCertSign",wn[wn.cRLSign=64]="cRLSign",wn[wn.encipherOnly=128]="encipherOnly",wn[wn.decipherOnly=256]="decipherOnly";class Sn extends or{toJSON(){const e=this.toNumber(),t=[];return e&vn.cRLSign&&t.push("crlSign"),e&vn.dataEncipherment&&t.push("dataEncipherment"),e&vn.decipherOnly&&t.push("decipherOnly"),e&vn.digitalSignature&&t.push("digitalSignature"),e&vn.encipherOnly&&t.push("encipherOnly"),e&vn.keyAgreement&&t.push("keyAgreement"),e&vn.keyCertSign&&t.push("keyCertSign"),e&vn.keyEncipherment&&t.push("keyEncipherment"),e&vn.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}}class An{constructor(e={}){r(this,"base",new ci),r(this,"minimum",0),r(this,"maximum"),Object.assign(this,e)}}Fr([$r({type:ci})],An.prototype,"base",void 0),Fr([$r({type:ir.Integer,context:0,defaultValue:0,implicit:!0})],An.prototype,"minimum",void 0),Fr([$r({type:ir.Integer,context:1,optional:!0,implicit:!0})],An.prototype,"maximum",void 0);let En=bn=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,bn.prototype)}};En=bn=Fr([Ur({type:tr.Sequence,itemType:An})],En);class kn{constructor(e={}){r(this,"permittedSubtrees"),r(this,"excludedSubtrees"),Object.assign(this,e)}}Fr([$r({type:En,context:0,optional:!0,implicit:!0})],kn.prototype,"permittedSubtrees",void 0),Fr([$r({type:En,context:1,optional:!0,implicit:!0})],kn.prototype,"excludedSubtrees",void 0);class xn{constructor(e={}){r(this,"requireExplicitPolicy"),r(this,"inhibitPolicyMapping"),Object.assign(this,e)}}var _n;Fr([$r({type:ir.Integer,context:0,implicit:!0,optional:!0,converter:lr})],xn.prototype,"requireExplicitPolicy",void 0),Fr([$r({type:ir.Integer,context:1,implicit:!0,optional:!0,converter:lr})],xn.prototype,"inhibitPolicyMapping",void 0);class Nn{constructor(e={}){r(this,"issuerDomainPolicy",""),r(this,"subjectDomainPolicy",""),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],Nn.prototype,"issuerDomainPolicy",void 0),Fr([$r({type:ir.ObjectIdentifier})],Nn.prototype,"subjectDomainPolicy",void 0);let In=_n=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,_n.prototype)}};var Tn;In=_n=Fr([Ur({type:tr.Sequence,itemType:Nn})],In);const Bn=`${gi}.17`;let On=Tn=class extends Ni{constructor(e){super(e),Object.setPrototypeOf(this,Tn.prototype)}};On=Tn=Fr([Ur({type:tr.Sequence})],On);let Cn=class{constructor(e={}){r(this,"type",""),r(this,"values",[]),Object.assign(this,e)}};var Dn;Fr([$r({type:ir.ObjectIdentifier})],Cn.prototype,"type",void 0),Fr([$r({type:ir.Any,repeated:"set"})],Cn.prototype,"values",void 0);let jn=Dn=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Dn.prototype)}};jn=Dn=Fr([Ur({type:tr.Sequence,itemType:Cn})],jn);const Pn=`${gi}.14`;class Rn extends Ai{}class Un{constructor(e={}){r(this,"notBefore"),r(this,"notAfter"),Object.assign(this,e)}}var $n,Mn,Ln;Fr([$r({type:ir.GeneralizedTime,context:0,implicit:!0,optional:!0})],Un.prototype,"notBefore",void 0),Fr([$r({type:ir.GeneralizedTime,context:1,implicit:!0,optional:!0})],Un.prototype,"notAfter",void 0),(Mn=$n||($n={}))[Mn.keyUpdateAllowed=1]="keyUpdateAllowed",Mn[Mn.newExtensions=2]="newExtensions",Mn[Mn.pKIXCertificate=4]="pKIXCertificate";class Vn extends or{toJSON(){const e=[],t=this.toNumber();return t&$n.pKIXCertificate&&e.push("pKIXCertificate"),t&$n.newExtensions&&e.push("newExtensions"),t&$n.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}}class Hn{constructor(e={}){r(this,"entrustVers",""),r(this,"entrustInfoFlags",new Vn),Object.assign(this,e)}}Fr([$r({type:ir.GeneralString})],Hn.prototype,"entrustVers",void 0),Fr([$r({type:Vn})],Hn.prototype,"entrustInfoFlags",void 0);let Kn=Ln=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Ln.prototype)}};Kn=Ln=Fr([Ur({type:tr.Sequence,itemType:wi})],Kn);class Fn{constructor(e={}){r(this,"algorithm",""),r(this,"parameters"),Object.assign(this,e)}isEqual(e){return e instanceof Fn&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&function(e,t,r={}){const i=Qt(e),n=Qt(t);if(!r.constantTime&&i.byteLength!==n.byteLength)return!1;const o=Math.max(i.byteLength,n.byteLength);let s=i.byteLength^n.byteLength;for(let a=0;a<o;a++)s|=(i[a]??0)^(n[a]??0);return 0===s}(e.parameters,this.parameters)||e.parameters===this.parameters)}}Fr([$r({type:ir.ObjectIdentifier})],Fn.prototype,"algorithm",void 0),Fr([$r({type:ir.Any,optional:!0})],Fn.prototype,"parameters",void 0);class zn{constructor(e={}){r(this,"algorithm",new Fn),r(this,"subjectPublicKey",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:Fn})],zn.prototype,"algorithm",void 0),Fr([$r({type:ir.BitString})],zn.prototype,"subjectPublicKey",void 0);let Wn=class{constructor(e){if(r(this,"utcTime"),r(this,"generalTime"),e)if("string"==typeof e||"number"==typeof e||e instanceof Date){const t=new Date(e);t.setMilliseconds(0),t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){const e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};Fr([$r({type:ir.UTCTime})],Wn.prototype,"utcTime",void 0),Fr([$r({type:ir.GeneralizedTime})],Wn.prototype,"generalTime",void 0),Wn=Fr([Ur({type:tr.Choice})],Wn);class Jn{constructor(e){r(this,"notBefore",new Wn(new Date)),r(this,"notAfter",new Wn(new Date)),e&&(this.notBefore=new Wn(e.notBefore),this.notAfter=new Wn(e.notAfter))}}var qn;Fr([$r({type:Wn})],Jn.prototype,"notBefore",void 0),Fr([$r({type:Wn})],Jn.prototype,"notAfter",void 0);let Gn=(e=class{constructor(t={}){r(this,"extnID",""),r(this,"critical",e.CRITICAL),r(this,"extnValue",new sr),Object.assign(this,t)}},r(e,"CRITICAL",!1),e);Fr([$r({type:ir.ObjectIdentifier})],Gn.prototype,"extnID",void 0),Fr([$r({type:ir.Boolean,defaultValue:Gn.CRITICAL})],Gn.prototype,"critical",void 0),Fr([$r({type:sr})],Gn.prototype,"extnValue",void 0);let Xn=qn=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,qn.prototype)}};var Yn,Zn;Xn=qn=Fr([Ur({type:tr.Sequence,itemType:Gn})],Xn),(Zn=Yn||(Yn={}))[Zn.v1=0]="v1",Zn[Zn.v2=1]="v2",Zn[Zn.v3=2]="v3";class Qn{constructor(e={}){r(this,"version",Yn.v1),r(this,"serialNumber",new ArrayBuffer(0)),r(this,"signature",new Fn),r(this,"issuer",new ni),r(this,"validity",new Jn),r(this,"subject",new ni),r(this,"subjectPublicKeyInfo",new zn),r(this,"issuerUniqueID"),r(this,"subjectUniqueID"),r(this,"extensions"),Object.assign(this,e)}}Fr([$r({type:ir.Integer,context:0,defaultValue:Yn.v1})],Qn.prototype,"version",void 0),Fr([$r({type:ir.Integer,converter:lr})],Qn.prototype,"serialNumber",void 0),Fr([$r({type:Fn})],Qn.prototype,"signature",void 0),Fr([$r({type:ni})],Qn.prototype,"issuer",void 0),Fr([$r({type:Jn})],Qn.prototype,"validity",void 0),Fr([$r({type:ni})],Qn.prototype,"subject",void 0),Fr([$r({type:zn})],Qn.prototype,"subjectPublicKeyInfo",void 0),Fr([$r({type:ir.BitString,context:1,implicit:!0,optional:!0})],Qn.prototype,"issuerUniqueID",void 0),Fr([$r({type:ir.BitString,context:2,implicit:!0,optional:!0})],Qn.prototype,"subjectUniqueID",void 0),Fr([$r({type:Xn,context:3,optional:!0})],Qn.prototype,"extensions",void 0);class eo{constructor(e={}){r(this,"tbsCertificate",new Qn),r(this,"tbsCertificateRaw"),r(this,"signatureAlgorithm",new Fn),r(this,"signatureValue",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:Qn,raw:!0})],eo.prototype,"tbsCertificate",void 0),Fr([$r({type:Fn})],eo.prototype,"signatureAlgorithm",void 0),Fr([$r({type:ir.BitString})],eo.prototype,"signatureValue",void 0);class to{constructor(e={}){r(this,"userCertificate",new ArrayBuffer(0)),r(this,"revocationDate",new Wn),r(this,"crlEntryExtensions"),Object.assign(this,e)}}Fr([$r({type:ir.Integer,converter:lr})],to.prototype,"userCertificate",void 0),Fr([$r({type:Wn})],to.prototype,"revocationDate",void 0),Fr([$r({type:Gn,optional:!0,repeated:"sequence"})],to.prototype,"crlEntryExtensions",void 0);class ro{constructor(e={}){r(this,"version"),r(this,"signature",new Fn),r(this,"issuer",new ni),r(this,"thisUpdate",new Wn),r(this,"nextUpdate"),r(this,"revokedCertificates"),r(this,"crlExtensions"),Object.assign(this,e)}}Fr([$r({type:ir.Integer,optional:!0})],ro.prototype,"version",void 0),Fr([$r({type:Fn})],ro.prototype,"signature",void 0),Fr([$r({type:ni})],ro.prototype,"issuer",void 0),Fr([$r({type:Wn})],ro.prototype,"thisUpdate",void 0),Fr([$r({type:Wn,optional:!0})],ro.prototype,"nextUpdate",void 0),Fr([$r({type:to,repeated:"sequence",optional:!0})],ro.prototype,"revokedCertificates",void 0),Fr([$r({type:Gn,optional:!0,context:0,repeated:"sequence"})],ro.prototype,"crlExtensions",void 0);class io{constructor(e={}){r(this,"tbsCertList",new ro),r(this,"tbsCertListRaw"),r(this,"signatureAlgorithm",new Fn),r(this,"signature",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ro,raw:!0})],io.prototype,"tbsCertList",void 0),Fr([$r({type:Fn})],io.prototype,"signatureAlgorithm",void 0),Fr([$r({type:ir.BitString})],io.prototype,"signature",void 0);class no{constructor(e={}){r(this,"issuer",new ni),r(this,"serialNumber",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ni})],no.prototype,"issuer",void 0),Fr([$r({type:ir.Integer,converter:lr})],no.prototype,"serialNumber",void 0);let oo=class{constructor(e={}){r(this,"subjectKeyIdentifier"),r(this,"issuerAndSerialNumber"),Object.assign(this,e)}};var so,ao;Fr([$r({type:Rn,context:0,implicit:!0})],oo.prototype,"subjectKeyIdentifier",void 0),Fr([$r({type:no})],oo.prototype,"issuerAndSerialNumber",void 0),oo=Fr([Ur({type:tr.Choice})],oo),(ao=so||(so={}))[ao.v0=0]="v0",ao[ao.v1=1]="v1",ao[ao.v2=2]="v2",ao[ao.v3=3]="v3",ao[ao.v4=4]="v4",ao[ao.v5=5]="v5";let co=class extends Fn{};co=Fr([Ur({type:tr.Sequence})],co);let uo=class extends Fn{};uo=Fr([Ur({type:tr.Sequence})],uo);let lo=class extends Fn{};lo=Fr([Ur({type:tr.Sequence})],lo);let po=class extends Fn{};po=Fr([Ur({type:tr.Sequence})],po);let ho=class extends Fn{};ho=Fr([Ur({type:tr.Sequence})],ho);let fo=class extends Fn{};fo=Fr([Ur({type:tr.Sequence})],fo);let yo=class{constructor(e={}){r(this,"attrType",""),r(this,"attrValues",[]),Object.assign(this,e)}};var go;Fr([$r({type:ir.ObjectIdentifier})],yo.prototype,"attrType",void 0),Fr([$r({type:ir.Any,repeated:"set"})],yo.prototype,"attrValues",void 0);class mo{constructor(e={}){r(this,"version",so.v0),r(this,"sid",new oo),r(this,"digestAlgorithm",new co),r(this,"signedAttrs"),r(this,"signedAttrsRaw"),r(this,"signatureAlgorithm",new uo),r(this,"signature",new sr),r(this,"unsignedAttrs"),Object.assign(this,e)}}Fr([$r({type:ir.Integer})],mo.prototype,"version",void 0),Fr([$r({type:oo})],mo.prototype,"sid",void 0),Fr([$r({type:co})],mo.prototype,"digestAlgorithm",void 0),Fr([$r({type:yo,repeated:"set",context:0,implicit:!0,optional:!0,raw:!0})],mo.prototype,"signedAttrs",void 0),Fr([$r({type:uo})],mo.prototype,"signatureAlgorithm",void 0),Fr([$r({type:sr})],mo.prototype,"signature",void 0),Fr([$r({type:yo,repeated:"set",context:1,implicit:!0,optional:!0})],mo.prototype,"unsignedAttrs",void 0);let vo=go=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,go.prototype)}};vo=go=Fr([Ur({type:tr.Set,itemType:mo})],vo);let wo=class extends mo{};wo=Fr([Ur({type:tr.Sequence})],wo);let bo=class extends Wn{};bo=Fr([Ur({type:tr.Choice})],bo);class So{constructor(e={}){r(this,"acIssuer",new ci),r(this,"acSerial",0),r(this,"attrs",[]),Object.assign(this,e)}}var Ao;Fr([$r({type:ci})],So.prototype,"acIssuer",void 0),Fr([$r({type:ir.Integer})],So.prototype,"acSerial",void 0),Fr([$r({type:Cn,repeated:"sequence"})],So.prototype,"attrs",void 0);let Eo=Ao=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Ao.prototype)}};Eo=Ao=Fr([Ur({type:tr.Sequence,itemType:ir.ObjectIdentifier})],Eo);class ko{constructor(e={}){r(this,"pathLenConstraint"),r(this,"permittedAttrs"),r(this,"excludedAttrs"),r(this,"permitUnSpecified",!0),Object.assign(this,e)}}Fr([$r({type:ir.Integer,optional:!0})],ko.prototype,"pathLenConstraint",void 0),Fr([$r({type:Eo,implicit:!0,context:0,optional:!0})],ko.prototype,"permittedAttrs",void 0),Fr([$r({type:Eo,implicit:!0,context:1,optional:!0})],ko.prototype,"excludedAttrs",void 0),Fr([$r({type:ir.Boolean,defaultValue:!0})],ko.prototype,"permitUnSpecified",void 0);class xo{constructor(e={}){r(this,"issuer",new Ni),r(this,"serial",new ArrayBuffer(0)),r(this,"issuerUID",new ArrayBuffer(0)),Object.assign(this,e)}}var _o,No;Fr([$r({type:Ni})],xo.prototype,"issuer",void 0),Fr([$r({type:ir.Integer,converter:lr})],xo.prototype,"serial",void 0),Fr([$r({type:ir.BitString,optional:!0})],xo.prototype,"issuerUID",void 0),(No=_o||(_o={}))[No.publicKey=0]="publicKey",No[No.publicKeyCert=1]="publicKeyCert",No[No.otherObjectTypes=2]="otherObjectTypes";class Io{constructor(e={}){r(this,"digestedObjectType",_o.publicKey),r(this,"otherObjectTypeID"),r(this,"digestAlgorithm",new Fn),r(this,"objectDigest",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.Enumerated})],Io.prototype,"digestedObjectType",void 0),Fr([$r({type:ir.ObjectIdentifier,optional:!0})],Io.prototype,"otherObjectTypeID",void 0),Fr([$r({type:Fn})],Io.prototype,"digestAlgorithm",void 0),Fr([$r({type:ir.BitString})],Io.prototype,"objectDigest",void 0);class To{constructor(e={}){r(this,"issuerName"),r(this,"baseCertificateID"),r(this,"objectDigestInfo"),Object.assign(this,e)}}Fr([$r({type:Ni,optional:!0})],To.prototype,"issuerName",void 0),Fr([$r({type:xo,context:0,implicit:!0,optional:!0})],To.prototype,"baseCertificateID",void 0),Fr([$r({type:Io,context:1,implicit:!0,optional:!0})],To.prototype,"objectDigestInfo",void 0);let Bo=class{constructor(e={}){r(this,"v1Form"),r(this,"v2Form"),Object.assign(this,e)}};Fr([$r({type:ci,repeated:"sequence"})],Bo.prototype,"v1Form",void 0),Fr([$r({type:To,context:0,implicit:!0})],Bo.prototype,"v2Form",void 0),Bo=Fr([Ur({type:tr.Choice})],Bo);class Oo{constructor(e={}){r(this,"notBeforeTime",new Date),r(this,"notAfterTime",new Date),Object.assign(this,e)}}Fr([$r({type:ir.GeneralizedTime})],Oo.prototype,"notBeforeTime",void 0),Fr([$r({type:ir.GeneralizedTime})],Oo.prototype,"notAfterTime",void 0);class Co{constructor(e={}){r(this,"baseCertificateID"),r(this,"entityName"),r(this,"objectDigestInfo"),Object.assign(this,e)}}var Do,jo,Po,Ro,Uo;Fr([$r({type:xo,implicit:!0,context:0,optional:!0})],Co.prototype,"baseCertificateID",void 0),Fr([$r({type:Ni,implicit:!0,context:1,optional:!0})],Co.prototype,"entityName",void 0),Fr([$r({type:Io,implicit:!0,context:2,optional:!0})],Co.prototype,"objectDigestInfo",void 0),(jo=Do||(Do={}))[jo.v2=1]="v2";class $o{constructor(e={}){r(this,"version",Do.v2),r(this,"holder",new Co),r(this,"issuer",new Bo),r(this,"signature",new Fn),r(this,"serialNumber",new ArrayBuffer(0)),r(this,"attrCertValidityPeriod",new Oo),r(this,"attributes",[]),r(this,"issuerUniqueID"),r(this,"extensions"),Object.assign(this,e)}}Fr([$r({type:ir.Integer})],$o.prototype,"version",void 0),Fr([$r({type:Co})],$o.prototype,"holder",void 0),Fr([$r({type:Bo})],$o.prototype,"issuer",void 0),Fr([$r({type:Fn})],$o.prototype,"signature",void 0),Fr([$r({type:ir.Integer,converter:lr})],$o.prototype,"serialNumber",void 0),Fr([$r({type:Oo})],$o.prototype,"attrCertValidityPeriod",void 0),Fr([$r({type:Cn,repeated:"sequence"})],$o.prototype,"attributes",void 0),Fr([$r({type:ir.BitString,optional:!0})],$o.prototype,"issuerUniqueID",void 0),Fr([$r({type:Xn,optional:!0})],$o.prototype,"extensions",void 0);class Mo{constructor(e={}){r(this,"acinfo",new $o),r(this,"signatureAlgorithm",new Fn),r(this,"signatureValue",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:$o})],Mo.prototype,"acinfo",void 0),Fr([$r({type:Fn})],Mo.prototype,"signatureAlgorithm",void 0),Fr([$r({type:ir.BitString})],Mo.prototype,"signatureValue",void 0),(Ro=Po||(Po={}))[Ro.unmarked=1]="unmarked",Ro[Ro.unclassified=2]="unclassified",Ro[Ro.restricted=4]="restricted",Ro[Ro.confidential=8]="confidential",Ro[Ro.secret=16]="secret",Ro[Ro.topSecret=32]="topSecret";class Lo extends or{}class Vo{constructor(e={}){r(this,"type",""),r(this,"value",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier,implicit:!0,context:0})],Vo.prototype,"type",void 0),Fr([$r({type:ir.Any,implicit:!0,context:1})],Vo.prototype,"value",void 0);class Ho{constructor(e={}){r(this,"policyId",""),r(this,"classList",new Lo(Po.unclassified)),r(this,"securityCategories"),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],Ho.prototype,"policyId",void 0),Fr([$r({type:Lo,defaultValue:new Lo(Po.unclassified)})],Ho.prototype,"classList",void 0),Fr([$r({type:Vo,repeated:"set"})],Ho.prototype,"securityCategories",void 0);class Ko{constructor(e={}){r(this,"cotets"),r(this,"oid"),r(this,"string"),Object.assign(this,e)}}Fr([$r({type:sr})],Ko.prototype,"cotets",void 0),Fr([$r({type:ir.ObjectIdentifier})],Ko.prototype,"oid",void 0),Fr([$r({type:ir.Utf8String})],Ko.prototype,"string",void 0);class Fo{constructor(e={}){r(this,"policyAuthority"),r(this,"values",[]),Object.assign(this,e)}}Fr([$r({type:Ni,implicit:!0,context:0,optional:!0})],Fo.prototype,"policyAuthority",void 0),Fr([$r({type:Ko,repeated:"sequence"})],Fo.prototype,"values",void 0);class zo{constructor(e={}){r(this,"targetCertificate",new xo),r(this,"targetName"),r(this,"certDigestInfo"),Object.assign(this,e)}}Fr([$r({type:xo})],zo.prototype,"targetCertificate",void 0),Fr([$r({type:ci,optional:!0})],zo.prototype,"targetName",void 0),Fr([$r({type:Io,optional:!0})],zo.prototype,"certDigestInfo",void 0);let Wo=class{constructor(e={}){r(this,"targetName"),r(this,"targetGroup"),r(this,"targetCert"),Object.assign(this,e)}};Fr([$r({type:ci,context:0,implicit:!0})],Wo.prototype,"targetName",void 0),Fr([$r({type:ci,context:1,implicit:!0})],Wo.prototype,"targetGroup",void 0),Fr([$r({type:zo,context:2,implicit:!0})],Wo.prototype,"targetCert",void 0),Wo=Fr([Ur({type:tr.Choice})],Wo);let Jo=Uo=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Uo.prototype)}};var qo;Jo=Uo=Fr([Ur({type:tr.Sequence,itemType:Wo})],Jo);let Go=qo=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,qo.prototype)}};Go=qo=Fr([Ur({type:tr.Sequence,itemType:Jo})],Go);class Xo{constructor(e={}){r(this,"roleAuthority"),r(this,"roleName"),Object.assign(this,e)}}Fr([$r({type:Ni,implicit:!0,context:0,optional:!0})],Xo.prototype,"roleAuthority",void 0),Fr([$r({type:ci,implicit:!0,context:1})],Xo.prototype,"roleName",void 0);class Yo{constructor(e={}){r(this,"service",new ci),r(this,"ident",new ci),r(this,"authInfo"),Object.assign(this,e)}}var Zo;Fr([$r({type:ci})],Yo.prototype,"service",void 0),Fr([$r({type:ci})],Yo.prototype,"ident",void 0),Fr([$r({type:sr,optional:!0})],Yo.prototype,"authInfo",void 0);class Qo{constructor(e={}){r(this,"otherCertFormat",""),r(this,"otherCert",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],Qo.prototype,"otherCertFormat",void 0),Fr([$r({type:ir.Any})],Qo.prototype,"otherCert",void 0);let es=class{constructor(e={}){r(this,"certificate"),r(this,"v2AttrCert"),r(this,"other"),Object.assign(this,e)}};Fr([$r({type:eo})],es.prototype,"certificate",void 0),Fr([$r({type:Mo,context:2,implicit:!0})],es.prototype,"v2AttrCert",void 0),Fr([$r({type:Qo,context:3,implicit:!0})],es.prototype,"other",void 0),es=Fr([Ur({type:tr.Choice})],es);let ts=Zo=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Zo.prototype)}};ts=Zo=Fr([Ur({type:tr.Set,itemType:es})],ts);class rs{constructor(e={}){r(this,"contentType",""),r(this,"content",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],rs.prototype,"contentType",void 0),Fr([$r({type:ir.Any,context:0})],rs.prototype,"content",void 0);let is=class{constructor(e={}){r(this,"single"),r(this,"any"),Object.assign(this,e)}};Fr([$r({type:sr})],is.prototype,"single",void 0),Fr([$r({type:ir.Any})],is.prototype,"any",void 0),is=Fr([Ur({type:tr.Choice})],is);class ns{constructor(e={}){r(this,"eContentType",""),r(this,"eContent"),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],ns.prototype,"eContentType",void 0),Fr([$r({type:is,context:0,optional:!0})],ns.prototype,"eContent",void 0);let os=class{constructor(e={}){r(this,"value"),r(this,"constructedValue"),Object.assign(this,e)}};Fr([$r({type:sr,context:0,implicit:!0,optional:!0})],os.prototype,"value",void 0),Fr([$r({type:sr,converter:yr,context:0,implicit:!0,optional:!0,repeated:"sequence"})],os.prototype,"constructedValue",void 0),os=Fr([Ur({type:tr.Choice})],os);class ss{constructor(e={}){r(this,"contentType",""),r(this,"contentEncryptionAlgorithm",new po),r(this,"encryptedContent"),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],ss.prototype,"contentType",void 0),Fr([$r({type:po})],ss.prototype,"contentEncryptionAlgorithm",void 0),Fr([$r({type:os,optional:!0})],ss.prototype,"encryptedContent",void 0);class as{constructor(e={}){r(this,"keyAttrId",""),r(this,"keyAttr"),Object.assign(this,e)}}var cs;Fr([$r({type:ir.ObjectIdentifier})],as.prototype,"keyAttrId",void 0),Fr([$r({type:ir.Any,optional:!0})],as.prototype,"keyAttr",void 0);class us{constructor(e={}){r(this,"subjectKeyIdentifier",new Rn),r(this,"date"),r(this,"other"),Object.assign(this,e)}}Fr([$r({type:Rn})],us.prototype,"subjectKeyIdentifier",void 0),Fr([$r({type:ir.GeneralizedTime,optional:!0})],us.prototype,"date",void 0),Fr([$r({type:as,optional:!0})],us.prototype,"other",void 0);let ls=class{constructor(e={}){r(this,"rKeyId"),r(this,"issuerAndSerialNumber"),Object.assign(this,e)}};Fr([$r({type:us,context:0,implicit:!0,optional:!0})],ls.prototype,"rKeyId",void 0),Fr([$r({type:no,optional:!0})],ls.prototype,"issuerAndSerialNumber",void 0),ls=Fr([Ur({type:tr.Choice})],ls);class ps{constructor(e={}){r(this,"rid",new ls),r(this,"encryptedKey",new sr),Object.assign(this,e)}}Fr([$r({type:ls})],ps.prototype,"rid",void 0),Fr([$r({type:sr})],ps.prototype,"encryptedKey",void 0);let hs=cs=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,cs.prototype)}};hs=cs=Fr([Ur({type:tr.Sequence,itemType:ps})],hs);class ds{constructor(e={}){r(this,"algorithm",new Fn),r(this,"publicKey",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:Fn})],ds.prototype,"algorithm",void 0),Fr([$r({type:ir.BitString})],ds.prototype,"publicKey",void 0);let fs=class{constructor(e={}){r(this,"subjectKeyIdentifier"),r(this,"originatorKey"),r(this,"issuerAndSerialNumber"),Object.assign(this,e)}};Fr([$r({type:Rn,context:0,implicit:!0,optional:!0})],fs.prototype,"subjectKeyIdentifier",void 0),Fr([$r({type:ds,context:1,implicit:!0,optional:!0})],fs.prototype,"originatorKey",void 0),Fr([$r({type:no,optional:!0})],fs.prototype,"issuerAndSerialNumber",void 0),fs=Fr([Ur({type:tr.Choice})],fs);class ys{constructor(e={}){r(this,"version",so.v3),r(this,"originator",new fs),r(this,"ukm"),r(this,"keyEncryptionAlgorithm",new lo),r(this,"recipientEncryptedKeys",new hs),Object.assign(this,e)}}Fr([$r({type:ir.Integer})],ys.prototype,"version",void 0),Fr([$r({type:fs,context:0})],ys.prototype,"originator",void 0),Fr([$r({type:sr,context:1,optional:!0})],ys.prototype,"ukm",void 0),Fr([$r({type:lo})],ys.prototype,"keyEncryptionAlgorithm",void 0),Fr([$r({type:hs})],ys.prototype,"recipientEncryptedKeys",void 0);let gs=class{constructor(e={}){r(this,"subjectKeyIdentifier"),r(this,"issuerAndSerialNumber"),Object.assign(this,e)}};Fr([$r({type:Rn,context:0,implicit:!0})],gs.prototype,"subjectKeyIdentifier",void 0),Fr([$r({type:no})],gs.prototype,"issuerAndSerialNumber",void 0),gs=Fr([Ur({type:tr.Choice})],gs);class ms{constructor(e={}){r(this,"version",so.v0),r(this,"rid",new gs),r(this,"keyEncryptionAlgorithm",new lo),r(this,"encryptedKey",new sr),Object.assign(this,e)}}Fr([$r({type:ir.Integer})],ms.prototype,"version",void 0),Fr([$r({type:gs})],ms.prototype,"rid",void 0),Fr([$r({type:lo})],ms.prototype,"keyEncryptionAlgorithm",void 0),Fr([$r({type:sr})],ms.prototype,"encryptedKey",void 0);class vs{constructor(e={}){r(this,"keyIdentifier",new sr),r(this,"date"),r(this,"other"),Object.assign(this,e)}}Fr([$r({type:sr})],vs.prototype,"keyIdentifier",void 0),Fr([$r({type:ir.GeneralizedTime,optional:!0})],vs.prototype,"date",void 0),Fr([$r({type:as,optional:!0})],vs.prototype,"other",void 0);class ws{constructor(e={}){r(this,"version",so.v4),r(this,"kekid",new vs),r(this,"keyEncryptionAlgorithm",new lo),r(this,"encryptedKey",new sr),Object.assign(this,e)}}Fr([$r({type:ir.Integer})],ws.prototype,"version",void 0),Fr([$r({type:vs})],ws.prototype,"kekid",void 0),Fr([$r({type:lo})],ws.prototype,"keyEncryptionAlgorithm",void 0),Fr([$r({type:sr})],ws.prototype,"encryptedKey",void 0);class bs{constructor(e={}){r(this,"version",so.v0),r(this,"keyDerivationAlgorithm"),r(this,"keyEncryptionAlgorithm",new lo),r(this,"encryptedKey",new sr),Object.assign(this,e)}}Fr([$r({type:ir.Integer})],bs.prototype,"version",void 0),Fr([$r({type:fo,context:0,optional:!0})],bs.prototype,"keyDerivationAlgorithm",void 0),Fr([$r({type:lo})],bs.prototype,"keyEncryptionAlgorithm",void 0),Fr([$r({type:sr})],bs.prototype,"encryptedKey",void 0);class Ss{constructor(e={}){r(this,"oriType",""),r(this,"oriValue",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],Ss.prototype,"oriType",void 0),Fr([$r({type:ir.Any})],Ss.prototype,"oriValue",void 0);let As=class{constructor(e={}){r(this,"ktri"),r(this,"kari"),r(this,"kekri"),r(this,"pwri"),r(this,"ori"),Object.assign(this,e)}};var Es;Fr([$r({type:ms,optional:!0})],As.prototype,"ktri",void 0),Fr([$r({type:ys,context:1,implicit:!0,optional:!0})],As.prototype,"kari",void 0),Fr([$r({type:ws,context:2,implicit:!0,optional:!0})],As.prototype,"kekri",void 0),Fr([$r({type:bs,context:3,implicit:!0,optional:!0})],As.prototype,"pwri",void 0),Fr([$r({type:Ss,context:4,implicit:!0,optional:!0})],As.prototype,"ori",void 0),As=Fr([Ur({type:tr.Choice})],As);let ks=Es=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Es.prototype)}};var xs;ks=Es=Fr([Ur({type:tr.Set,itemType:As})],ks);class _s{constructor(e={}){r(this,"otherRevInfoFormat",""),r(this,"otherRevInfo",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],_s.prototype,"otherRevInfoFormat",void 0),Fr([$r({type:ir.Any})],_s.prototype,"otherRevInfo",void 0);let Ns=class{constructor(e={}){r(this,"other",new _s),Object.assign(this,e)}};Fr([$r({type:_s,context:1,implicit:!0})],Ns.prototype,"other",void 0),Ns=Fr([Ur({type:tr.Choice})],Ns);let Is=xs=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,xs.prototype)}};Is=xs=Fr([Ur({type:tr.Set,itemType:Ns})],Is);class Ts{constructor(e={}){r(this,"certs"),r(this,"crls"),Object.assign(this,e)}}var Bs;Fr([$r({type:ts,context:0,implicit:!0,optional:!0})],Ts.prototype,"certs",void 0),Fr([$r({type:Is,context:1,implicit:!0,optional:!0})],Ts.prototype,"crls",void 0);let Os=Bs=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Bs.prototype)}};Os=Bs=Fr([Ur({type:tr.Set,itemType:yo})],Os);class Cs{constructor(e={}){r(this,"version",so.v0),r(this,"originatorInfo"),r(this,"recipientInfos",new ks),r(this,"encryptedContentInfo",new ss),r(this,"unprotectedAttrs"),Object.assign(this,e)}}Fr([$r({type:ir.Integer})],Cs.prototype,"version",void 0),Fr([$r({type:Ts,context:0,implicit:!0,optional:!0})],Cs.prototype,"originatorInfo",void 0),Fr([$r({type:ks})],Cs.prototype,"recipientInfos",void 0),Fr([$r({type:ss})],Cs.prototype,"encryptedContentInfo",void 0),Fr([$r({type:Os,context:1,implicit:!0,optional:!0})],Cs.prototype,"unprotectedAttrs",void 0);const Ds="1.2.840.113549.1.7.2";var js;let Ps=js=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,js.prototype)}};Ps=js=Fr([Ur({type:tr.Set,itemType:co})],Ps);class Rs{constructor(e={}){r(this,"version",so.v0),r(this,"digestAlgorithms",new Ps),r(this,"encapContentInfo",new ns),r(this,"certificates"),r(this,"crls"),r(this,"signerInfos",new vo),Object.assign(this,e)}}Fr([$r({type:ir.Integer})],Rs.prototype,"version",void 0),Fr([$r({type:Ps})],Rs.prototype,"digestAlgorithms",void 0),Fr([$r({type:ns})],Rs.prototype,"encapContentInfo",void 0),Fr([$r({type:ts,context:0,implicit:!0,optional:!0})],Rs.prototype,"certificates",void 0),Fr([$r({type:Is,context:1,implicit:!0,optional:!0})],Rs.prototype,"crls",void 0),Fr([$r({type:vo})],Rs.prototype,"signerInfos",void 0);const Us="1.2.840.10045.2.1",$s="1.2.840.10045.4.1",Ms="1.2.840.10045.4.3.1",Ls="1.2.840.10045.4.3.2",Vs="1.2.840.10045.4.3.3",Hs="1.2.840.10045.4.3.4",Ks="1.2.840.10045.3.1.7",Fs="1.3.132.0.34",zs="1.3.132.0.35";function Ws(e){return new Fn({algorithm:e})}const Js=Ws($s);Ws(Ms);const qs=Ws(Ls),Gs=Ws(Vs),Xs=Ws(Hs);let Ys=class{constructor(e={}){r(this,"fieldType"),r(this,"parameters"),Object.assign(this,e)}};Fr([$r({type:ir.ObjectIdentifier})],Ys.prototype,"fieldType",void 0),Fr([$r({type:ir.Any})],Ys.prototype,"parameters",void 0),Ys=Fr([Ur({type:tr.Sequence})],Ys);let Zs=class{constructor(e={}){r(this,"a"),r(this,"b"),r(this,"seed"),Object.assign(this,e)}};var Qs,ea;Fr([$r({type:ir.OctetString})],Zs.prototype,"a",void 0),Fr([$r({type:ir.OctetString})],Zs.prototype,"b",void 0),Fr([$r({type:ir.BitString,optional:!0})],Zs.prototype,"seed",void 0),Zs=Fr([Ur({type:tr.Sequence})],Zs),(ea=Qs||(Qs={}))[ea.ecpVer1=1]="ecpVer1";let ta=class{constructor(e={}){r(this,"version",Qs.ecpVer1),r(this,"fieldID"),r(this,"curve"),r(this,"base"),r(this,"order"),r(this,"cofactor"),Object.assign(this,e)}};Fr([$r({type:ir.Integer})],ta.prototype,"version",void 0),Fr([$r({type:Ys})],ta.prototype,"fieldID",void 0),Fr([$r({type:Zs})],ta.prototype,"curve",void 0),Fr([$r({type:class extends sr{}})],ta.prototype,"base",void 0),Fr([$r({type:ir.Integer,converter:lr})],ta.prototype,"order",void 0),Fr([$r({type:ir.Integer,optional:!0})],ta.prototype,"cofactor",void 0),ta=Fr([Ur({type:tr.Sequence})],ta);let ra=class{constructor(e={}){r(this,"namedCurve"),r(this,"implicitCurve"),r(this,"specifiedCurve"),Object.assign(this,e)}};Fr([$r({type:ir.ObjectIdentifier})],ra.prototype,"namedCurve",void 0),Fr([$r({type:ir.Null})],ra.prototype,"implicitCurve",void 0),Fr([$r({type:ta})],ra.prototype,"specifiedCurve",void 0),ra=Fr([Ur({type:tr.Choice})],ra);class ia{constructor(e={}){r(this,"version",1),r(this,"privateKey",new sr),r(this,"parameters"),r(this,"publicKey"),Object.assign(this,e)}}Fr([$r({type:ir.Integer})],ia.prototype,"version",void 0),Fr([$r({type:sr})],ia.prototype,"privateKey",void 0),Fr([$r({type:ra,context:0,optional:!0})],ia.prototype,"parameters",void 0),Fr([$r({type:ir.BitString,context:1,optional:!0})],ia.prototype,"publicKey",void 0);class na{constructor(e={}){r(this,"r",new ArrayBuffer(0)),r(this,"s",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.Integer,converter:lr})],na.prototype,"r",void 0),Fr([$r({type:ir.Integer,converter:lr})],na.prototype,"s",void 0);const oa="1.2.840.113549.1.1",sa=`${oa}.1`,aa=`${oa}.7`,ca=`${oa}.9`,ua=`${oa}.10`,la=`${oa}.2`,pa=`${oa}.4`,ha=`${oa}.5`,da=`${oa}.14`,fa=`${oa}.11`,ya=`${oa}.12`,ga=`${oa}.13`,ma=`${oa}.15`,va=`${oa}.16`,wa="1.3.14.3.2.26",ba="2.16.840.1.101.3.4.2.4",Sa="2.16.840.1.101.3.4.2.1",Aa="2.16.840.1.101.3.4.2.2",Ea="2.16.840.1.101.3.4.2.3",ka=`${oa}.8`;function xa(e){return new Fn({algorithm:e,parameters:null})}xa("1.2.840.113549.2.2"),xa("1.2.840.113549.2.5");const _a=xa(wa);xa(ba),xa(Sa),xa(Aa),xa(Ea),xa("2.16.840.1.101.3.4.2.5"),xa("2.16.840.1.101.3.4.2.6");const Na=new Fn({algorithm:ka,parameters:Kr.serialize(_a)}),Ia=new Fn({algorithm:ca,parameters:Kr.serialize(fr.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))});xa(sa),xa(la),xa(pa),xa(ha),xa(ma),xa(va),xa(ya),xa(ga),xa(ma),xa(va);class Ta{constructor(e={}){r(this,"hashAlgorithm",new Fn(_a)),r(this,"maskGenAlgorithm",new Fn({algorithm:ka,parameters:Kr.serialize(_a)})),r(this,"pSourceAlgorithm",new Fn(Ia)),Object.assign(this,e)}}Fr([$r({type:Fn,context:0,defaultValue:_a})],Ta.prototype,"hashAlgorithm",void 0),Fr([$r({type:Fn,context:1,defaultValue:Na})],Ta.prototype,"maskGenAlgorithm",void 0),Fr([$r({type:Fn,context:2,defaultValue:Ia})],Ta.prototype,"pSourceAlgorithm",void 0),new Fn({algorithm:aa,parameters:Kr.serialize(new Ta)});class Ba{constructor(e={}){r(this,"hashAlgorithm",new Fn(_a)),r(this,"maskGenAlgorithm",new Fn({algorithm:ka,parameters:Kr.serialize(_a)})),r(this,"saltLength",20),r(this,"trailerField",1),Object.assign(this,e)}}Fr([$r({type:Fn,context:0,defaultValue:_a})],Ba.prototype,"hashAlgorithm",void 0),Fr([$r({type:Fn,context:1,defaultValue:Na})],Ba.prototype,"maskGenAlgorithm",void 0),Fr([$r({type:ir.Integer,context:2,defaultValue:20})],Ba.prototype,"saltLength",void 0),Fr([$r({type:ir.Integer,context:3,defaultValue:1})],Ba.prototype,"trailerField",void 0),new Fn({algorithm:ua,parameters:Kr.serialize(new Ba)});class Oa{constructor(e={}){r(this,"digestAlgorithm",new Fn),r(this,"digest",new sr),Object.assign(this,e)}}var Ca;Fr([$r({type:Fn})],Oa.prototype,"digestAlgorithm",void 0),Fr([$r({type:sr})],Oa.prototype,"digest",void 0);class Da{constructor(e={}){r(this,"prime",new ArrayBuffer(0)),r(this,"exponent",new ArrayBuffer(0)),r(this,"coefficient",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.Integer,converter:lr})],Da.prototype,"prime",void 0),Fr([$r({type:ir.Integer,converter:lr})],Da.prototype,"exponent",void 0),Fr([$r({type:ir.Integer,converter:lr})],Da.prototype,"coefficient",void 0);let ja=Ca=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Ca.prototype)}};ja=Ca=Fr([Ur({type:tr.Sequence,itemType:Da})],ja);class Pa{constructor(e={}){r(this,"version",0),r(this,"modulus",new ArrayBuffer(0)),r(this,"publicExponent",new ArrayBuffer(0)),r(this,"privateExponent",new ArrayBuffer(0)),r(this,"prime1",new ArrayBuffer(0)),r(this,"prime2",new ArrayBuffer(0)),r(this,"exponent1",new ArrayBuffer(0)),r(this,"exponent2",new ArrayBuffer(0)),r(this,"coefficient",new ArrayBuffer(0)),r(this,"otherPrimeInfos"),Object.assign(this,e)}}Fr([$r({type:ir.Integer})],Pa.prototype,"version",void 0),Fr([$r({type:ir.Integer,converter:lr})],Pa.prototype,"modulus",void 0),Fr([$r({type:ir.Integer,converter:lr})],Pa.prototype,"publicExponent",void 0),Fr([$r({type:ir.Integer,converter:lr})],Pa.prototype,"privateExponent",void 0),Fr([$r({type:ir.Integer,converter:lr})],Pa.prototype,"prime1",void 0),Fr([$r({type:ir.Integer,converter:lr})],Pa.prototype,"prime2",void 0),Fr([$r({type:ir.Integer,converter:lr})],Pa.prototype,"exponent1",void 0),Fr([$r({type:ir.Integer,converter:lr})],Pa.prototype,"exponent2",void 0),Fr([$r({type:ir.Integer,converter:lr})],Pa.prototype,"coefficient",void 0),Fr([$r({type:ja,optional:!0})],Pa.prototype,"otherPrimeInfos",void 0);class Ra{constructor(e={}){r(this,"modulus",new ArrayBuffer(0)),r(this,"publicExponent",new ArrayBuffer(0)),Object.assign(this,e)}}var Ua,$a;Fr([$r({type:ir.Integer,converter:lr})],Ra.prototype,"modulus",void 0),Fr([$r({type:ir.Integer,converter:lr})],Ra.prototype,"publicExponent",void 0),($a=Ua||(Ua={}))[$a.Transient=0]="Transient",$a[$a.Singleton=1]="Singleton",$a[$a.ResolutionScoped=2]="ResolutionScoped",$a[$a.ContainerScoped=3]="ContainerScoped";const Ma=Ua;
|
|
53
53
|
/*! *****************************************************************************
|
|
54
54
|
Copyright (c) Microsoft Corporation.
|
|
55
55
|
|
|
@@ -63,7 +63,7 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
63
63
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
64
64
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
65
65
|
PERFORMANCE OF THIS SOFTWARE.
|
|
66
|
-
***************************************************************************** */var Va=function(e,t){return(Va=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function Ma(e,t){function r(){this.constructor=e}Va(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function Ha(e,t,r,i){return new(r||(r=Promise))((function(n,o){function s(e){try{c(i.next(e))}catch(t){o(t)}}function a(e){try{c(i.throw(e))}catch(t){o(t)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}c((i=i.apply(e,t||[])).next())}))}function Ka(e,t){var r,i,n,o,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,i&&(n=2&o[0]?i.return:o[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,o[1])).done)return n;switch(i=0,n&&(o=[2&o[0],n.value]),o[0]){case 0:case 1:n=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(n=s.trys,(n=n.length>0&&n[n.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!n||o[1]>n[0]&&o[1]<n[3])){s.label=o[1];break}if(6===o[0]&&s.label<n[1]){s.label=n[1],n=o;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(o);break}n[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(a){o=[6,a],i=0}finally{r=n=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function Fa(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],i=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function za(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var i,n,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)s.push(i.value)}catch(a){n={error:a}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return s}function Wa(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(za(arguments[t]));return e}function qa(e){return!!e.useClass}function Ja(e){return!!e.useFactory}var Xa=function(){function e(e){this.wrap=e,this.reflectMethods=["get","getPrototypeOf","setPrototypeOf","getOwnPropertyDescriptor","defineProperty","has","set","deleteProperty","apply","construct","ownKeys"]}return e.prototype.createProxy=function(e){var t,r=this,i=!1;return new Proxy({},this.createHandler((function(){return i||(t=e(r.wrap()),i=!0),t})))},e.prototype.createHandler=function(e){var t={};return this.reflectMethods.forEach((function(r){t[r]=function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];return t[0]=e(),Reflect[r].apply(void 0,Wa(t))}})),t},e}();function Ga(e){return"string"==typeof e||"symbol"==typeof e}function Ya(e){return"object"==typeof e&&"token"in e&&"transform"in e}function Za(e){return!!e.useToken}function Qa(e){return null!=e.useValue}var ec=function(){function e(){this._registryMap=new Map}return e.prototype.entries=function(){return this._registryMap.entries()},e.prototype.getAll=function(e){return this.ensure(e),this._registryMap.get(e)},e.prototype.get=function(e){this.ensure(e);var t=this._registryMap.get(e);return t[t.length-1]||null},e.prototype.set=function(e,t){this.ensure(e),this._registryMap.get(e).push(t)},e.prototype.setAll=function(e,t){this._registryMap.set(e,t)},e.prototype.has=function(e){return this.ensure(e),this._registryMap.get(e).length>0},e.prototype.clear=function(){this._registryMap.clear()},e.prototype.ensure=function(e){this._registryMap.has(e)||this._registryMap.set(e,[])},e}(),tc=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Ma(t,e),t}(ec),rc=function(){this.scopedResolutions=new Map};function ic(e,t,r){var i,n,o=za(e.toString().match(/constructor\(([\w, ]+)\)/)||[],2)[1],s=function(e,t){return null===e?"at position #"+t:'"'+e.split(",")[t].trim()+'" at position #'+t}(void 0===o?null:o,t);return i="Cannot inject the dependency "+s+' of "'+e.name+'" constructor. Reason:',void 0===n&&(n=" "),Wa([i],r.message.split("\n").map((function(e){return n+e}))).join("\n")}var nc,oc=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Ma(t,e),t}(ec),sc=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Ma(t,e),t}(ec),ac=function(){this.preResolution=new oc,this.postResolution=new sc},cc=new Map,uc=new(function(){function e(e){this.parent=e,this._registry=new tc,this.interceptors=new ac,this.disposed=!1,this.disposables=new Set}return e.prototype.register=function(e,t,r){var i;if(void 0===r&&(r={lifecycle:$a.Transient}),this.ensureNotDisposed(),i=function(e){return qa(e)||Qa(e)||Za(e)||Ja(e)}(t)?t:{useClass:t},Za(i))for(var n=[e],o=i;null!=o;){var s=o.useToken;if(n.includes(s))throw new Error("Token registration cycle detected! "+Wa(n,[s]).join(" -> "));n.push(s);var a=this._registry.get(s);o=a&&Za(a.provider)?a.provider:null}if((r.lifecycle===$a.Singleton||r.lifecycle==$a.ContainerScoped||r.lifecycle==$a.ResolutionScoped)&&(Qa(i)||Ja(i)))throw new Error('Cannot use lifecycle "'+$a[r.lifecycle]+'" with ValueProviders or FactoryProviders');return this._registry.set(e,{provider:i,options:r}),this},e.prototype.registerType=function(e,t){return this.ensureNotDisposed(),Ga(t)?this.register(e,{useToken:t}):this.register(e,{useClass:t})},e.prototype.registerInstance=function(e,t){return this.ensureNotDisposed(),this.register(e,{useValue:t})},e.prototype.registerSingleton=function(e,t){if(this.ensureNotDisposed(),Ga(e)){if(Ga(t))return this.register(e,{useToken:t},{lifecycle:$a.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:$a.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var r=e;return t&&!Ga(t)&&(r=t),this.register(e,{useClass:r},{lifecycle:$a.Singleton})},e.prototype.resolve=function(e,t,r){void 0===t&&(t=new rc),void 0===r&&(r=!1),this.ensureNotDisposed();var i=this.getRegistration(e);if(!i&&Ga(e)){if(r)return;throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"Single"),i){var n=this.resolveRegistration(i,t);return this.executePostResolutionInterceptor(e,n,"Single"),n}if(function(e){return"function"==typeof e||e instanceof Xa}(e)){n=this.construct(e,t);return this.executePostResolutionInterceptor(e,n,"Single"),n}throw new Error("Attempted to construct an undefined constructor. Could mean a circular dependency problem. Try using `delay` function.")},e.prototype.executePreResolutionInterceptor=function(e,t){var r,i;if(this.interceptors.preResolution.has(e)){var n=[];try{for(var o=Fa(this.interceptors.preResolution.getAll(e)),s=o.next();!s.done;s=o.next()){var a=s.value;"Once"!=a.options.frequency&&n.push(a),a.callback(e,t)}}catch(c){r={error:c}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}this.interceptors.preResolution.setAll(e,n)}},e.prototype.executePostResolutionInterceptor=function(e,t,r){var i,n;if(this.interceptors.postResolution.has(e)){var o=[];try{for(var s=Fa(this.interceptors.postResolution.getAll(e)),a=s.next();!a.done;a=s.next()){var c=a.value;"Once"!=c.options.frequency&&o.push(c),c.callback(e,t,r)}}catch(u){i={error:u}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}this.interceptors.postResolution.setAll(e,o)}},e.prototype.resolveRegistration=function(e,t){if(this.ensureNotDisposed(),e.options.lifecycle===$a.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var r,i=e.options.lifecycle===$a.Singleton,n=e.options.lifecycle===$a.ContainerScoped,o=i||n;return r=Qa(e.provider)?e.provider.useValue:Za(e.provider)?o?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):qa(e.provider)?o?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):Ja(e.provider)?e.provider.useFactory(this):this.construct(e.provider,t),e.options.lifecycle===$a.ResolutionScoped&&t.scopedResolutions.set(e,r),r},e.prototype.resolveAll=function(e,t,r){var i=this;void 0===t&&(t=new rc),void 0===r&&(r=!1),this.ensureNotDisposed();var n=this.getAllRegistrations(e);if(!n&&Ga(e)){if(r)return[];throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"All"),n){var o=n.map((function(e){return i.resolveRegistration(e,t)}));return this.executePostResolutionInterceptor(e,o,"All"),o}var s=[this.construct(e,t)];return this.executePostResolutionInterceptor(e,s,"All"),s},e.prototype.isRegistered=function(e,t){return void 0===t&&(t=!1),this.ensureNotDisposed(),this._registry.has(e)||t&&(this.parent||!1)&&this.parent.isRegistered(e,!0)},e.prototype.reset=function(){this.ensureNotDisposed(),this._registry.clear(),this.interceptors.preResolution.clear(),this.interceptors.postResolution.clear()},e.prototype.clearInstances=function(){var e,t;this.ensureNotDisposed();try{for(var r=Fa(this._registry.entries()),i=r.next();!i.done;i=r.next()){var n=za(i.value,2),o=n[0],s=n[1];this._registry.setAll(o,s.filter((function(e){return!Qa(e.provider)})).map((function(e){return e.instance=void 0,e})))}}catch(a){e={error:a}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}},e.prototype.createChildContainer=function(){var t,r;this.ensureNotDisposed();var i=new e(this);try{for(var n=Fa(this._registry.entries()),o=n.next();!o.done;o=n.next()){var s=za(o.value,2),a=s[0],c=s[1];c.some((function(e){return e.options.lifecycle===$a.ContainerScoped}))&&i._registry.setAll(a,c.map((function(e){return e.options.lifecycle===$a.ContainerScoped?{provider:e.provider,options:e.options}:e})))}}catch(u){t={error:u}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(t)throw t.error}}return i},e.prototype.beforeResolution=function(e,t,r){void 0===r&&(r={frequency:"Always"}),this.interceptors.preResolution.set(e,{callback:t,options:r})},e.prototype.afterResolution=function(e,t,r){void 0===r&&(r={frequency:"Always"}),this.interceptors.postResolution.set(e,{callback:t,options:r})},e.prototype.dispose=function(){return Ha(this,void 0,void 0,(function(){var e;return Ka(this,(function(t){switch(t.label){case 0:return this.disposed=!0,e=[],this.disposables.forEach((function(t){var r=t.dispose();r&&e.push(r)})),[4,Promise.all(e)];case 1:return t.sent(),[2]}}))}))},e.prototype.getRegistration=function(e){return this.isRegistered(e)?this._registry.get(e):this.parent?this.parent.getRegistration(e):null},e.prototype.getAllRegistrations=function(e){return this.isRegistered(e)?this._registry.getAll(e):this.parent?this.parent.getAllRegistrations(e):null},e.prototype.construct=function(e,t){var r=this;if(e instanceof Xa)return e.createProxy((function(e){return r.resolve(e,t)}));var i,n=function(){var i=cc.get(e);if(!i||0===i.length){if(0===e.length)return new e;throw new Error('TypeInfo not known for "'+e.name+'"')}var n=i.map(r.resolveParams(t,e));return new(e.bind.apply(e,Wa([void 0],n)))}();return"function"!=typeof(i=n).dispose||i.dispose.length>0||this.disposables.add(n),n},e.prototype.resolveParams=function(e,t){var r=this;return function(i,n){var o,s,a,c;try{return"object"==typeof(c=i)&&"token"in c&&"multiple"in c?Ya(i)?i.multiple?(o=r.resolve(i.transform)).transform.apply(o,Wa([r.resolveAll(i.token,new rc,i.isOptional)],i.transformArgs)):(s=r.resolve(i.transform)).transform.apply(s,Wa([r.resolve(i.token,e,i.isOptional)],i.transformArgs)):i.multiple?r.resolveAll(i.token,new rc,i.isOptional):r.resolve(i.token,e,i.isOptional):Ya(i)?(a=r.resolve(i.transform,e)).transform.apply(a,Wa([r.resolve(i.token,e)],i.transformArgs)):r.resolve(i,e)}catch(u){throw new Error(ic(t,n,u))}}},e.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},e}());function lc(e){return function(t){cc.set(t,function(e){var t=Reflect.getMetadata("design:paramtypes",e)||[],r=Reflect.getOwnMetadata("injectionTokens",e)||{};return Object.keys(r).forEach((function(e){t[+e]=r[e]})),t}(t)),e&&e.token&&(Array.isArray(e.token)?e.token.forEach((function(e){uc.register(e,t)})):uc.register(e.token,t))}}if("undefined"==typeof Reflect||!Reflect.getMetadata)throw new Error("tsyringe requires a reflect polyfill. Please add 'import \"reflect-metadata\"' to the top of your entry point.");class hc{constructor(e={}){r(this,"attrId",""),r(this,"attrValues",[]),Object.assign(e)}}Fr([Lr({type:ir.ObjectIdentifier})],hc.prototype,"attrId",void 0),Fr([Lr({type:ir.Any,repeated:"set"})],hc.prototype,"attrValues",void 0);let pc=nc=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,nc.prototype)}};var fc;pc=nc=Fr([Ur({type:tr.Sequence,itemType:hc})],pc);let dc=fc=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,fc.prototype)}};dc=fc=Fr([Ur({type:tr.Sequence,itemType:rs})],dc);class yc{constructor(e={}){r(this,"certId",""),r(this,"certValue",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],yc.prototype,"certId",void 0),Fr([Lr({type:ir.Any,context:0})],yc.prototype,"certValue",void 0);class gc{constructor(e={}){r(this,"crlId",""),r(this,"crltValue",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],gc.prototype,"crlId",void 0),Fr([Lr({type:ir.Any,context:0})],gc.prototype,"crltValue",void 0);class vc extends sr{}let mc=class{constructor(e={}){r(this,"encryptionAlgorithm",new Fn),r(this,"encryptedData",new vc),Object.assign(this,e)}};var wc,bc;Fr([Lr({type:Fn})],mc.prototype,"encryptionAlgorithm",void 0),Fr([Lr({type:vc})],mc.prototype,"encryptedData",void 0),function(e){e[e.v1=0]="v1"}(bc||(bc={}));class Sc extends sr{}let Ac=wc=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,wc.prototype)}};Ac=wc=Fr([Ur({type:tr.Sequence,itemType:jn})],Ac);class xc{constructor(e={}){r(this,"version",bc.v1),r(this,"privateKeyAlgorithm",new Fn),r(this,"privateKey",new Sc),r(this,"attributes"),Object.assign(this,e)}}Fr([Lr({type:ir.Integer})],xc.prototype,"version",void 0),Fr([Lr({type:Fn})],xc.prototype,"privateKeyAlgorithm",void 0),Fr([Lr({type:Sc})],xc.prototype,"privateKey",void 0),Fr([Lr({type:Ac,implicit:!0,context:0,optional:!0})],xc.prototype,"attributes",void 0);let kc=class extends xc{};kc=Fr([Ur({type:tr.Sequence})],kc);let Ec=class extends mc{};Ec=Fr([Ur({type:tr.Sequence})],Ec);class Bc{constructor(e={}){r(this,"secretTypeId",""),r(this,"secretValue",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],Bc.prototype,"secretTypeId",void 0),Fr([Lr({type:ir.Any,context:0})],Bc.prototype,"secretValue",void 0);class Nc{constructor(e={}){r(this,"mac",new Ca),r(this,"macSalt",new sr),r(this,"iterations",1),Object.assign(this,e)}}Fr([Lr({type:Ca})],Nc.prototype,"mac",void 0),Fr([Lr({type:sr})],Nc.prototype,"macSalt",void 0),Fr([Lr({type:ir.Integer,defaultValue:1})],Nc.prototype,"iterations",void 0);class Tc{constructor(e={}){r(this,"version",3),r(this,"authSafe",new rs),r(this,"macData",new Nc),Object.assign(this,e)}}var Ic;Fr([Lr({type:ir.Integer})],Tc.prototype,"version",void 0),Fr([Lr({type:rs})],Tc.prototype,"authSafe",void 0),Fr([Lr({type:Nc,optional:!0})],Tc.prototype,"macData",void 0);class Oc{constructor(e={}){r(this,"bagId",""),r(this,"bagValue",new ArrayBuffer(0)),r(this,"bagAttributes"),Object.assign(this,e)}}Fr([Lr({type:ir.ObjectIdentifier})],Oc.prototype,"bagId",void 0),Fr([Lr({type:ir.Any,context:0})],Oc.prototype,"bagValue",void 0),Fr([Lr({type:hc,repeated:"set",optional:!0})],Oc.prototype,"bagAttributes",void 0);let Cc=Ic=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Ic.prototype)}};var jc,_c,Dc;Cc=Ic=Fr([Ur({type:tr.Sequence,itemType:Oc})],Cc);const Rc="1.2.840.113549.1.9",Pc=`${Rc}.7`,Uc=`${Rc}.14`;let Lc=class extends Qr{constructor(e={}){super(e),r(this,"ia5String")}toString(){return this.ia5String||super.toString()}};Fr([Lr({type:ir.IA5String})],Lc.prototype,"ia5String",void 0),Lc=Fr([Ur({type:tr.Choice})],Lc);let $c=class extends rs{};$c=Fr([Ur({type:tr.Sequence})],$c);let Vc=class extends Tc{};Vc=Fr([Ur({type:tr.Sequence})],Vc);let Mc=class extends mc{};Mc=Fr([Ur({type:tr.Sequence})],Mc);let Hc=class{constructor(e=""){r(this,"value"),this.value=e}toString(){return this.value}};Fr([Lr({type:ir.IA5String})],Hc.prototype,"value",void 0),Hc=Fr([Ur({type:tr.Choice})],Hc);let Kc=class extends Lc{};Kc=Fr([Ur({type:tr.Choice})],Kc);let Fc=class extends Qr{};Fc=Fr([Ur({type:tr.Choice})],Fc);let zc=class{constructor(e=new Date){r(this,"value"),this.value=e}};Fr([Lr({type:ir.GeneralizedTime})],zc.prototype,"value",void 0),zc=Fr([Ur({type:tr.Choice})],zc);let Wc=class extends Qr{};Wc=Fr([Ur({type:tr.Choice})],Wc);let qc=class{constructor(e="M"){r(this,"value"),this.value=e}toString(){return this.value}};Fr([Lr({type:ir.PrintableString})],qc.prototype,"value",void 0),qc=Fr([Ur({type:tr.Choice})],qc);let Jc=class{constructor(e=""){r(this,"value"),this.value=e}toString(){return this.value}};Fr([Lr({type:ir.PrintableString})],Jc.prototype,"value",void 0),Jc=Fr([Ur({type:tr.Choice})],Jc);let Xc=class extends Jc{};Xc=Fr([Ur({type:tr.Choice})],Xc);let Gc=class extends Qr{};Gc=Fr([Ur({type:tr.Choice})],Gc);let Yc=class{constructor(e=""){r(this,"value"),this.value=e}toString(){return this.value}};Fr([Lr({type:ir.ObjectIdentifier})],Yc.prototype,"value",void 0),Yc=Fr([Ur({type:tr.Choice})],Yc);let Zc=class extends Wn{};Zc=Fr([Ur({type:tr.Choice})],Zc);let Qc=class{constructor(e=0){r(this,"value"),this.value=e}toString(){return this.value.toString()}};Fr([Lr({type:ir.Integer})],Qc.prototype,"value",void 0),Qc=Fr([Ur({type:tr.Choice})],Qc);let eu=class extends vo{};eu=Fr([Ur({type:tr.Sequence})],eu);let tu=class extends Qr{};tu=Fr([Ur({type:tr.Choice})],tu);let ru=jc=class extends Gn{constructor(e){super(e),Object.setPrototypeOf(this,jc.prototype)}};ru=jc=Fr([Ur({type:tr.Sequence})],ru);let iu=_c=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,_c.prototype)}};iu=_c=Fr([Ur({type:tr.Set,itemType:yo})],iu);let nu=class{constructor(e=""){r(this,"value"),this.value=e}toString(){return this.value}};Fr([Lr({type:ir.BmpString})],nu.prototype,"value",void 0),nu=Fr([Ur({type:tr.Choice})],nu);let ou=class extends Fn{};ou=Fr([Ur({type:tr.Sequence})],ou);let su=Dc=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Dc.prototype)}};var au;su=Dc=Fr([Ur({type:tr.Sequence,itemType:ou})],su);let cu=au=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,au.prototype)}};cu=au=Fr([Ur({type:tr.Sequence,itemType:jn})],cu);class uu{constructor(e={}){r(this,"version",0),r(this,"subject",new ni),r(this,"subjectPKInfo",new zn),r(this,"attributes",new cu),Object.assign(this,e)}}Fr([Lr({type:ir.Integer})],uu.prototype,"version",void 0),Fr([Lr({type:ni})],uu.prototype,"subject",void 0),Fr([Lr({type:zn})],uu.prototype,"subjectPKInfo",void 0),Fr([Lr({type:cu,implicit:!0,context:0,optional:!0})],uu.prototype,"attributes",void 0);class lu{constructor(e={}){r(this,"certificationRequestInfo",new uu),r(this,"certificationRequestInfoRaw"),r(this,"signatureAlgorithm",new Fn),r(this,"signature",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([Lr({type:uu,raw:!0})],lu.prototype,"certificationRequestInfo",void 0),Fr([Lr({type:Fn})],lu.prototype,"signatureAlgorithm",void 0),Fr([Lr({type:ir.BitString})],lu.prototype,"signature",void 0);
|
|
66
|
+
***************************************************************************** */var La=function(e,t){return(La=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function Va(e,t){function r(){this.constructor=e}La(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function Ha(e,t,r,i){return new(r||(r=Promise))((function(n,o){function s(e){try{c(i.next(e))}catch(t){o(t)}}function a(e){try{c(i.throw(e))}catch(t){o(t)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}c((i=i.apply(e,t||[])).next())}))}function Ka(e,t){var r,i,n,o,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,i&&(n=2&o[0]?i.return:o[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,o[1])).done)return n;switch(i=0,n&&(o=[2&o[0],n.value]),o[0]){case 0:case 1:n=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(n=s.trys,(n=n.length>0&&n[n.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!n||o[1]>n[0]&&o[1]<n[3])){s.label=o[1];break}if(6===o[0]&&s.label<n[1]){s.label=n[1],n=o;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(o);break}n[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(a){o=[6,a],i=0}finally{r=n=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}}function Fa(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],i=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function za(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var i,n,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)s.push(i.value)}catch(a){n={error:a}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return s}function Wa(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(za(arguments[t]));return e}function Ja(e){return!!e.useClass}function qa(e){return!!e.useFactory}var Ga=function(){function e(e){this.wrap=e,this.reflectMethods=["get","getPrototypeOf","setPrototypeOf","getOwnPropertyDescriptor","defineProperty","has","set","deleteProperty","apply","construct","ownKeys"]}return e.prototype.createProxy=function(e){var t,r=this,i=!1;return new Proxy({},this.createHandler((function(){return i||(t=e(r.wrap()),i=!0),t})))},e.prototype.createHandler=function(e){var t={};return this.reflectMethods.forEach((function(r){t[r]=function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];return t[0]=e(),Reflect[r].apply(void 0,Wa(t))}})),t},e}();function Xa(e){return"string"==typeof e||"symbol"==typeof e}function Ya(e){return"object"==typeof e&&"token"in e&&"transform"in e}function Za(e){return!!e.useToken}function Qa(e){return null!=e.useValue}var ec=function(){function e(){this._registryMap=new Map}return e.prototype.entries=function(){return this._registryMap.entries()},e.prototype.getAll=function(e){return this.ensure(e),this._registryMap.get(e)},e.prototype.get=function(e){this.ensure(e);var t=this._registryMap.get(e);return t[t.length-1]||null},e.prototype.set=function(e,t){this.ensure(e),this._registryMap.get(e).push(t)},e.prototype.setAll=function(e,t){this._registryMap.set(e,t)},e.prototype.has=function(e){return this.ensure(e),this._registryMap.get(e).length>0},e.prototype.clear=function(){this._registryMap.clear()},e.prototype.ensure=function(e){this._registryMap.has(e)||this._registryMap.set(e,[])},e}(),tc=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Va(t,e),t}(ec),rc=function(){this.scopedResolutions=new Map};function ic(e,t,r){var i,n,o=za(e.toString().match(/constructor\(([\w, ]+)\)/)||[],2)[1],s=function(e,t){return null===e?"at position #"+t:'"'+e.split(",")[t].trim()+'" at position #'+t}(void 0===o?null:o,t);return i="Cannot inject the dependency "+s+' of "'+e.name+'" constructor. Reason:',void 0===n&&(n=" "),Wa([i],r.message.split("\n").map((function(e){return n+e}))).join("\n")}var nc,oc=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Va(t,e),t}(ec),sc=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Va(t,e),t}(ec),ac=function(){this.preResolution=new oc,this.postResolution=new sc},cc=new Map,uc=new(function(){function e(e){this.parent=e,this._registry=new tc,this.interceptors=new ac,this.disposed=!1,this.disposables=new Set}return e.prototype.register=function(e,t,r){var i;if(void 0===r&&(r={lifecycle:Ma.Transient}),this.ensureNotDisposed(),i=function(e){return Ja(e)||Qa(e)||Za(e)||qa(e)}(t)?t:{useClass:t},Za(i))for(var n=[e],o=i;null!=o;){var s=o.useToken;if(n.includes(s))throw new Error("Token registration cycle detected! "+Wa(n,[s]).join(" -> "));n.push(s);var a=this._registry.get(s);o=a&&Za(a.provider)?a.provider:null}if((r.lifecycle===Ma.Singleton||r.lifecycle==Ma.ContainerScoped||r.lifecycle==Ma.ResolutionScoped)&&(Qa(i)||qa(i)))throw new Error('Cannot use lifecycle "'+Ma[r.lifecycle]+'" with ValueProviders or FactoryProviders');return this._registry.set(e,{provider:i,options:r}),this},e.prototype.registerType=function(e,t){return this.ensureNotDisposed(),Xa(t)?this.register(e,{useToken:t}):this.register(e,{useClass:t})},e.prototype.registerInstance=function(e,t){return this.ensureNotDisposed(),this.register(e,{useValue:t})},e.prototype.registerSingleton=function(e,t){if(this.ensureNotDisposed(),Xa(e)){if(Xa(t))return this.register(e,{useToken:t},{lifecycle:Ma.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:Ma.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var r=e;return t&&!Xa(t)&&(r=t),this.register(e,{useClass:r},{lifecycle:Ma.Singleton})},e.prototype.resolve=function(e,t,r){void 0===t&&(t=new rc),void 0===r&&(r=!1),this.ensureNotDisposed();var i=this.getRegistration(e);if(!i&&Xa(e)){if(r)return;throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"Single"),i){var n=this.resolveRegistration(i,t);return this.executePostResolutionInterceptor(e,n,"Single"),n}if(function(e){return"function"==typeof e||e instanceof Ga}(e)){n=this.construct(e,t);return this.executePostResolutionInterceptor(e,n,"Single"),n}throw new Error("Attempted to construct an undefined constructor. Could mean a circular dependency problem. Try using `delay` function.")},e.prototype.executePreResolutionInterceptor=function(e,t){var r,i;if(this.interceptors.preResolution.has(e)){var n=[];try{for(var o=Fa(this.interceptors.preResolution.getAll(e)),s=o.next();!s.done;s=o.next()){var a=s.value;"Once"!=a.options.frequency&&n.push(a),a.callback(e,t)}}catch(c){r={error:c}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}this.interceptors.preResolution.setAll(e,n)}},e.prototype.executePostResolutionInterceptor=function(e,t,r){var i,n;if(this.interceptors.postResolution.has(e)){var o=[];try{for(var s=Fa(this.interceptors.postResolution.getAll(e)),a=s.next();!a.done;a=s.next()){var c=a.value;"Once"!=c.options.frequency&&o.push(c),c.callback(e,t,r)}}catch(u){i={error:u}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}this.interceptors.postResolution.setAll(e,o)}},e.prototype.resolveRegistration=function(e,t){if(this.ensureNotDisposed(),e.options.lifecycle===Ma.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var r,i=e.options.lifecycle===Ma.Singleton,n=e.options.lifecycle===Ma.ContainerScoped,o=i||n;return r=Qa(e.provider)?e.provider.useValue:Za(e.provider)?o?e.instance||(e.instance=this.resolve(e.provider.useToken,t)):this.resolve(e.provider.useToken,t):Ja(e.provider)?o?e.instance||(e.instance=this.construct(e.provider.useClass,t)):this.construct(e.provider.useClass,t):qa(e.provider)?e.provider.useFactory(this):this.construct(e.provider,t),e.options.lifecycle===Ma.ResolutionScoped&&t.scopedResolutions.set(e,r),r},e.prototype.resolveAll=function(e,t,r){var i=this;void 0===t&&(t=new rc),void 0===r&&(r=!1),this.ensureNotDisposed();var n=this.getAllRegistrations(e);if(!n&&Xa(e)){if(r)return[];throw new Error('Attempted to resolve unregistered dependency token: "'+e.toString()+'"')}if(this.executePreResolutionInterceptor(e,"All"),n){var o=n.map((function(e){return i.resolveRegistration(e,t)}));return this.executePostResolutionInterceptor(e,o,"All"),o}var s=[this.construct(e,t)];return this.executePostResolutionInterceptor(e,s,"All"),s},e.prototype.isRegistered=function(e,t){return void 0===t&&(t=!1),this.ensureNotDisposed(),this._registry.has(e)||t&&(this.parent||!1)&&this.parent.isRegistered(e,!0)},e.prototype.reset=function(){this.ensureNotDisposed(),this._registry.clear(),this.interceptors.preResolution.clear(),this.interceptors.postResolution.clear()},e.prototype.clearInstances=function(){var e,t;this.ensureNotDisposed();try{for(var r=Fa(this._registry.entries()),i=r.next();!i.done;i=r.next()){var n=za(i.value,2),o=n[0],s=n[1];this._registry.setAll(o,s.filter((function(e){return!Qa(e.provider)})).map((function(e){return e.instance=void 0,e})))}}catch(a){e={error:a}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}},e.prototype.createChildContainer=function(){var t,r;this.ensureNotDisposed();var i=new e(this);try{for(var n=Fa(this._registry.entries()),o=n.next();!o.done;o=n.next()){var s=za(o.value,2),a=s[0],c=s[1];c.some((function(e){return e.options.lifecycle===Ma.ContainerScoped}))&&i._registry.setAll(a,c.map((function(e){return e.options.lifecycle===Ma.ContainerScoped?{provider:e.provider,options:e.options}:e})))}}catch(u){t={error:u}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(t)throw t.error}}return i},e.prototype.beforeResolution=function(e,t,r){void 0===r&&(r={frequency:"Always"}),this.interceptors.preResolution.set(e,{callback:t,options:r})},e.prototype.afterResolution=function(e,t,r){void 0===r&&(r={frequency:"Always"}),this.interceptors.postResolution.set(e,{callback:t,options:r})},e.prototype.dispose=function(){return Ha(this,void 0,void 0,(function(){var e;return Ka(this,(function(t){switch(t.label){case 0:return this.disposed=!0,e=[],this.disposables.forEach((function(t){var r=t.dispose();r&&e.push(r)})),[4,Promise.all(e)];case 1:return t.sent(),[2]}}))}))},e.prototype.getRegistration=function(e){return this.isRegistered(e)?this._registry.get(e):this.parent?this.parent.getRegistration(e):null},e.prototype.getAllRegistrations=function(e){return this.isRegistered(e)?this._registry.getAll(e):this.parent?this.parent.getAllRegistrations(e):null},e.prototype.construct=function(e,t){var r=this;if(e instanceof Ga)return e.createProxy((function(e){return r.resolve(e,t)}));var i,n=function(){var i=cc.get(e);if(!i||0===i.length){if(0===e.length)return new e;throw new Error('TypeInfo not known for "'+e.name+'"')}var n=i.map(r.resolveParams(t,e));return new(e.bind.apply(e,Wa([void 0],n)))}();return"function"!=typeof(i=n).dispose||i.dispose.length>0||this.disposables.add(n),n},e.prototype.resolveParams=function(e,t){var r=this;return function(i,n){var o,s,a,c;try{return"object"==typeof(c=i)&&"token"in c&&"multiple"in c?Ya(i)?i.multiple?(o=r.resolve(i.transform)).transform.apply(o,Wa([r.resolveAll(i.token,new rc,i.isOptional)],i.transformArgs)):(s=r.resolve(i.transform)).transform.apply(s,Wa([r.resolve(i.token,e,i.isOptional)],i.transformArgs)):i.multiple?r.resolveAll(i.token,new rc,i.isOptional):r.resolve(i.token,e,i.isOptional):Ya(i)?(a=r.resolve(i.transform,e)).transform.apply(a,Wa([r.resolve(i.token,e)],i.transformArgs)):r.resolve(i,e)}catch(u){throw new Error(ic(t,n,u))}}},e.prototype.ensureNotDisposed=function(){if(this.disposed)throw new Error("This container has been disposed, you cannot interact with a disposed container")},e}());function lc(e){return function(t){cc.set(t,function(e){var t=Reflect.getMetadata("design:paramtypes",e)||[],r=Reflect.getOwnMetadata("injectionTokens",e)||{};return Object.keys(r).forEach((function(e){t[+e]=r[e]})),t}(t)),e&&e.token&&(Array.isArray(e.token)?e.token.forEach((function(e){uc.register(e,t)})):uc.register(e.token,t))}}if("undefined"==typeof Reflect||!Reflect.getMetadata)throw new Error("tsyringe requires a reflect polyfill. Please add 'import \"reflect-metadata\"' to the top of your entry point.");class pc{constructor(e={}){r(this,"attrId",""),r(this,"attrValues",[]),Object.assign(e)}}Fr([$r({type:ir.ObjectIdentifier})],pc.prototype,"attrId",void 0),Fr([$r({type:ir.Any,repeated:"set"})],pc.prototype,"attrValues",void 0);let hc=nc=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,nc.prototype)}};var dc;hc=nc=Fr([Ur({type:tr.Sequence,itemType:pc})],hc);let fc=dc=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,dc.prototype)}};fc=dc=Fr([Ur({type:tr.Sequence,itemType:rs})],fc);class yc{constructor(e={}){r(this,"certId",""),r(this,"certValue",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],yc.prototype,"certId",void 0),Fr([$r({type:ir.Any,context:0})],yc.prototype,"certValue",void 0);class gc{constructor(e={}){r(this,"crlId",""),r(this,"crltValue",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],gc.prototype,"crlId",void 0),Fr([$r({type:ir.Any,context:0})],gc.prototype,"crltValue",void 0);class mc extends sr{}let vc=class{constructor(e={}){r(this,"encryptionAlgorithm",new Fn),r(this,"encryptedData",new mc),Object.assign(this,e)}};var wc,bc;Fr([$r({type:Fn})],vc.prototype,"encryptionAlgorithm",void 0),Fr([$r({type:mc})],vc.prototype,"encryptedData",void 0),function(e){e[e.v1=0]="v1"}(bc||(bc={}));class Sc extends sr{}let Ac=wc=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,wc.prototype)}};Ac=wc=Fr([Ur({type:tr.Sequence,itemType:Cn})],Ac);class Ec{constructor(e={}){r(this,"version",bc.v1),r(this,"privateKeyAlgorithm",new Fn),r(this,"privateKey",new Sc),r(this,"attributes"),Object.assign(this,e)}}Fr([$r({type:ir.Integer})],Ec.prototype,"version",void 0),Fr([$r({type:Fn})],Ec.prototype,"privateKeyAlgorithm",void 0),Fr([$r({type:Sc})],Ec.prototype,"privateKey",void 0),Fr([$r({type:Ac,implicit:!0,context:0,optional:!0})],Ec.prototype,"attributes",void 0);let kc=class extends Ec{};kc=Fr([Ur({type:tr.Sequence})],kc);let xc=class extends vc{};xc=Fr([Ur({type:tr.Sequence})],xc);class _c{constructor(e={}){r(this,"secretTypeId",""),r(this,"secretValue",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],_c.prototype,"secretTypeId",void 0),Fr([$r({type:ir.Any,context:0})],_c.prototype,"secretValue",void 0);class Nc{constructor(e={}){r(this,"mac",new Oa),r(this,"macSalt",new sr),r(this,"iterations",1),Object.assign(this,e)}}Fr([$r({type:Oa})],Nc.prototype,"mac",void 0),Fr([$r({type:sr})],Nc.prototype,"macSalt",void 0),Fr([$r({type:ir.Integer,defaultValue:1})],Nc.prototype,"iterations",void 0);class Ic{constructor(e={}){r(this,"version",3),r(this,"authSafe",new rs),r(this,"macData",new Nc),Object.assign(this,e)}}var Tc;Fr([$r({type:ir.Integer})],Ic.prototype,"version",void 0),Fr([$r({type:rs})],Ic.prototype,"authSafe",void 0),Fr([$r({type:Nc,optional:!0})],Ic.prototype,"macData",void 0);class Bc{constructor(e={}){r(this,"bagId",""),r(this,"bagValue",new ArrayBuffer(0)),r(this,"bagAttributes"),Object.assign(this,e)}}Fr([$r({type:ir.ObjectIdentifier})],Bc.prototype,"bagId",void 0),Fr([$r({type:ir.Any,context:0})],Bc.prototype,"bagValue",void 0),Fr([$r({type:pc,repeated:"set",optional:!0})],Bc.prototype,"bagAttributes",void 0);let Oc=Tc=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Tc.prototype)}};var Cc,Dc,jc;Oc=Tc=Fr([Ur({type:tr.Sequence,itemType:Bc})],Oc);const Pc="1.2.840.113549.1.9",Rc=`${Pc}.7`,Uc=`${Pc}.14`;let $c=class extends Qr{constructor(e={}){super(e),r(this,"ia5String")}toString(){return this.ia5String||super.toString()}};Fr([$r({type:ir.IA5String})],$c.prototype,"ia5String",void 0),$c=Fr([Ur({type:tr.Choice})],$c);let Mc=class extends rs{};Mc=Fr([Ur({type:tr.Sequence})],Mc);let Lc=class extends Ic{};Lc=Fr([Ur({type:tr.Sequence})],Lc);let Vc=class extends vc{};Vc=Fr([Ur({type:tr.Sequence})],Vc);let Hc=class{constructor(e=""){r(this,"value"),this.value=e}toString(){return this.value}};Fr([$r({type:ir.IA5String})],Hc.prototype,"value",void 0),Hc=Fr([Ur({type:tr.Choice})],Hc);let Kc=class extends $c{};Kc=Fr([Ur({type:tr.Choice})],Kc);let Fc=class extends Qr{};Fc=Fr([Ur({type:tr.Choice})],Fc);let zc=class{constructor(e=new Date){r(this,"value"),this.value=e}};Fr([$r({type:ir.GeneralizedTime})],zc.prototype,"value",void 0),zc=Fr([Ur({type:tr.Choice})],zc);let Wc=class extends Qr{};Wc=Fr([Ur({type:tr.Choice})],Wc);let Jc=class{constructor(e="M"){r(this,"value"),this.value=e}toString(){return this.value}};Fr([$r({type:ir.PrintableString})],Jc.prototype,"value",void 0),Jc=Fr([Ur({type:tr.Choice})],Jc);let qc=class{constructor(e=""){r(this,"value"),this.value=e}toString(){return this.value}};Fr([$r({type:ir.PrintableString})],qc.prototype,"value",void 0),qc=Fr([Ur({type:tr.Choice})],qc);let Gc=class extends qc{};Gc=Fr([Ur({type:tr.Choice})],Gc);let Xc=class extends Qr{};Xc=Fr([Ur({type:tr.Choice})],Xc);let Yc=class{constructor(e=""){r(this,"value"),this.value=e}toString(){return this.value}};Fr([$r({type:ir.ObjectIdentifier})],Yc.prototype,"value",void 0),Yc=Fr([Ur({type:tr.Choice})],Yc);let Zc=class extends Wn{};Zc=Fr([Ur({type:tr.Choice})],Zc);let Qc=class{constructor(e=0){r(this,"value"),this.value=e}toString(){return this.value.toString()}};Fr([$r({type:ir.Integer})],Qc.prototype,"value",void 0),Qc=Fr([Ur({type:tr.Choice})],Qc);let eu=class extends mo{};eu=Fr([Ur({type:tr.Sequence})],eu);let tu=class extends Qr{};tu=Fr([Ur({type:tr.Choice})],tu);let ru=Cc=class extends Xn{constructor(e){super(e),Object.setPrototypeOf(this,Cc.prototype)}};ru=Cc=Fr([Ur({type:tr.Sequence})],ru);let iu=Dc=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,Dc.prototype)}};iu=Dc=Fr([Ur({type:tr.Set,itemType:yo})],iu);let nu=class{constructor(e=""){r(this,"value"),this.value=e}toString(){return this.value}};Fr([$r({type:ir.BmpString})],nu.prototype,"value",void 0),nu=Fr([Ur({type:tr.Choice})],nu);let ou=class extends Fn{};ou=Fr([Ur({type:tr.Sequence})],ou);let su=jc=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,jc.prototype)}};var au;su=jc=Fr([Ur({type:tr.Sequence,itemType:ou})],su);let cu=au=class extends Hr{constructor(e){super(e),Object.setPrototypeOf(this,au.prototype)}};cu=au=Fr([Ur({type:tr.Sequence,itemType:Cn})],cu);class uu{constructor(e={}){r(this,"version",0),r(this,"subject",new ni),r(this,"subjectPKInfo",new zn),r(this,"attributes",new cu),Object.assign(this,e)}}Fr([$r({type:ir.Integer})],uu.prototype,"version",void 0),Fr([$r({type:ni})],uu.prototype,"subject",void 0),Fr([$r({type:zn})],uu.prototype,"subjectPKInfo",void 0),Fr([$r({type:cu,implicit:!0,context:0,optional:!0})],uu.prototype,"attributes",void 0);class lu{constructor(e={}){r(this,"certificationRequestInfo",new uu),r(this,"certificationRequestInfoRaw"),r(this,"signatureAlgorithm",new Fn),r(this,"signature",new ArrayBuffer(0)),Object.assign(this,e)}}Fr([$r({type:uu,raw:!0})],lu.prototype,"certificationRequestInfo",void 0),Fr([$r({type:Fn})],lu.prototype,"signatureAlgorithm",void 0),Fr([$r({type:ir.BitString})],lu.prototype,"signature",void 0);
|
|
67
67
|
/*!
|
|
68
68
|
* MIT License
|
|
69
69
|
*
|
|
@@ -88,5 +88,5 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
88
88
|
* SOFTWARE.
|
|
89
89
|
*
|
|
90
90
|
*/
|
|
91
|
-
const hu="crypto.algorithm";const pu="crypto.algorithmProvider";var fu;uc.registerSingleton(pu,class{getAlgorithms(){return uc.resolveAll(hu)}toAsnAlgorithm(e){for(const t of this.getAlgorithms()){const r=t.toAsnAlgorithm(e);if(r)return r}if(/^[0-9.]+$/.test(e.name)){const t=new Fn({algorithm:e.name});if("parameters"in e){const r=e;t.parameters=r.parameters}return t}throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm")}toWebAlgorithm(e){for(const t of this.getAlgorithms()){const r=t.toWebAlgorithm(e);if(r)return r}return{name:e.algorithm,parameters:e.parameters}}});const du="1.3.36.3.3.2.8.1.1",yu=`${du}.1`,gu=`${du}.2`,vu=`${du}.3`,mu=`${du}.4`,wu=`${du}.5`,bu=`${du}.6`,Su=`${du}.7`,Au=`${du}.8`,xu=`${du}.9`,ku=`${du}.10`,Eu=`${du}.11`,Bu=`${du}.12`,Nu=`${du}.13`,Tu=`${du}.14`,Iu="brainpoolP160r1",Ou="brainpoolP160t1",Cu="brainpoolP192r1",ju="brainpoolP192t1",_u="brainpoolP224r1",Du="brainpoolP224t1",Ru="brainpoolP256r1",Pu="brainpoolP256t1",Uu="brainpoolP320r1",Lu="brainpoolP320t1",$u="brainpoolP384r1",Vu="brainpoolP384t1",Mu="brainpoolP512r1",Hu="brainpoolP512t1",Ku="ECDSA";let Fu=fu=class{toAsnAlgorithm(e){if(e.name.toLowerCase()===Ku.toLowerCase())if("hash"in e){switch(("string"==typeof e.hash?e.hash:e.hash.name).toLowerCase()){case"sha-1":return qs;case"sha-256":return Js;case"sha-384":return Xs;case"sha-512":return Gs}}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Ks;break;case"K-256":t=fu.SECP256K1;break;case"P-384":t=Fs;break;case"P-521":t=zs;break;case Iu:t=yu;break;case Ou:t=gu;break;case Cu:t=vu;break;case ju:t=mu;break;case _u:t=wu;break;case Du:t=bu;break;case Ru:t=Su;break;case Pu:t=Au;break;case Uu:t=xu;break;case Lu:t=ku;break;case $u:t=Eu;break;case Vu:t=Bu;break;case Mu:t=Nu;break;case Hu:t=Tu}if(t)return new Fn({algorithm:Us,parameters:Kr.serialize(new ra({namedCurve:t}))})}return null}toWebAlgorithm(e){switch(e.algorithm){case Ls:return{name:Ku,hash:{name:"SHA-1"}};case Vs:return{name:Ku,hash:{name:"SHA-256"}};case Ms:return{name:Ku,hash:{name:"SHA-384"}};case Hs:return{name:Ku,hash:{name:"SHA-512"}};case Us:if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(Kr.parse(e.parameters,ra).namedCurve){case Ks:return{name:Ku,namedCurve:"P-256"};case fu.SECP256K1:return{name:Ku,namedCurve:"K-256"};case Fs:return{name:Ku,namedCurve:"P-384"};case zs:return{name:Ku,namedCurve:"P-521"};case yu:return{name:Ku,namedCurve:Iu};case gu:return{name:Ku,namedCurve:Ou};case vu:return{name:Ku,namedCurve:Cu};case mu:return{name:Ku,namedCurve:ju};case wu:return{name:Ku,namedCurve:_u};case bu:return{name:Ku,namedCurve:Du};case Su:return{name:Ku,namedCurve:Ru};case Au:return{name:Ku,namedCurve:Pu};case xu:return{name:Ku,namedCurve:Uu};case ku:return{name:Ku,namedCurve:Lu};case Eu:return{name:Ku,namedCurve:$u};case Bu:return{name:Ku,namedCurve:Vu};case Nu:return{name:Ku,namedCurve:Mu};case Tu:return{name:Ku,namedCurve:Hu}}}return null}};Fu.SECP256K1="1.3.132.0.10",Fu=fu=Fr([lc()],Fu),uc.registerSingleton(hu,Fu);const zu=Symbol("name"),Wu=Symbol("value");class qu{constructor(e,t={},r=""){this[zu]=e,this[Wu]=r;for(const i in t)this[i]=t[i]}}qu.NAME=zu,qu.VALUE=Wu;class Ju{static toString(e){const t=this.items[e];return t||e}}Ju.items={[wa]:"sha1",[ba]:"sha224",[Sa]:"sha256",[Aa]:"sha384",[xa]:"sha512",[sa]:"rsaEncryption",[pa]:"sha1WithRSAEncryption",[fa]:"sha224WithRSAEncryption",[da]:"sha256WithRSAEncryption",[ya]:"sha384WithRSAEncryption",[ga]:"sha512WithRSAEncryption",[Us]:"ecPublicKey",[Ls]:"ecdsaWithSHA1",[$s]:"ecdsaWithSHA224",[Vs]:"ecdsaWithSHA256",[Ms]:"ecdsaWithSHA384",[Hs]:"ecdsaWithSHA512",[sn]:"TLS WWW server authentication",[an]:"TLS WWW client authentication",[cn]:"Code Signing",[un]:"E-mail Protection",[ln]:"Time Stamping",[hn]:"OCSP Signing",[_s]:"Signed Data"};class Xu{static serialize(e){return this.serializeObj(e).join("\n")}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,t=0){const r=[];let i=this.pad(t++),n="";const o=e[qu.VALUE];o&&(n=` ${o}`),r.push(`${i}${e[qu.NAME]}:${n}`),i=this.pad(t);for(const s in e){if("symbol"==typeof s)continue;const n=e[s],o=s?`${s}: `:"";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)r.push(`${i}${o}${n}`);else if(n instanceof Date)r.push(`${i}${o}${n.toUTCString()}`);else if(Array.isArray(n))for(const e of n)e[qu.NAME]=s,r.push(...this.serializeObj(e,t));else if(n instanceof qu)n[qu.NAME]=s,r.push(...this.serializeObj(n,t));else if(k.isBufferSource(n))s?(r.push(`${i}${o}`),r.push(...this.serializeBufferSource(n,t+1))):r.push(...this.serializeBufferSource(n,t));else{if(!("toTextObject"in n))throw new TypeError("Cannot serialize data in text format. Unsupported type.");{const e=n.toTextObject();e[qu.NAME]=s,r.push(...this.serializeObj(e,t))}}}return r}static serializeBufferSource(e,t=0){const r=this.pad(t),i=k.toUint8Array(e),n=[];for(let o=0;o<i.length;){const e=[];for(let t=0;t<16&&o<i.length;t++){8===t&&e.push("");const r=i[o++].toString(16).padStart(2,"0");e.push(r)}n.push(`${r}${e.join(" ")}`)}return n}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}}var Gu,Yu;Xu.oidSerializer=Ju,Xu.algorithmSerializer=class{static toTextObject(e){const t=new qu("Algorithm Identifier",{},Ju.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Us:{const r=(new Fu).toWebAlgorithm(e);r&&"namedCurve"in r?t["Named Curve"]=r.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}};class Zu{get rawData(){return zr(this,Gu,"f")||Wr(this,Gu,Kr.serialize(this.asn),"f"),zr(this,Gu,"f")}constructor(...e){Gu.set(this,void 0),k.isBufferSource(e[0])?(this.asn=Kr.parse(e[0],e[1]),Wr(this,Gu,k.toArrayBuffer(e[0]),"f"),this.onInit(this.asn)):(this.asn=e[0],this.onInit(this.asn))}equal(e){return e instanceof Zu&&function(e,t){if(!e||!t)return!1;if(e.byteLength!==t.byteLength)return!1;const r=new Uint8Array(e),i=new Uint8Array(t);for(let n=0;n<e.byteLength;n++)if(r[n]!==i[n])return!1;return!0}(e.rawData,this.rawData)}toString(e="text"){switch(e){case"asn":return Kr.toString(this.rawData);case"text":return Xu.serialize(this.toTextObject());case"hex":return C.ToHex(this.rawData);case"base64":return C.ToBase64(this.rawData);case"base64url":return C.ToBase64Url(this.rawData);default:throw TypeError("Argument 'format' is unsupported value")}}getTextName(){return this.constructor.NAME}toTextObject(){const e=this.toTextObjectEmpty();return e[""]=this.rawData,e}toTextObjectEmpty(e){return new qu(this.getTextName(),{},e)}}Gu=new WeakMap,Zu.NAME="ASN";class Qu extends Zu{constructor(...e){let t;t=k.isBufferSource(e[0])?k.toArrayBuffer(e[0]):Kr.serialize(new Xn({extnID:e[0],critical:e[1],extnValue:new sr(k.toArrayBuffer(e[2]))})),super(t,Xn)}onInit(e){this.type=e.extnID,this.critical=e.critical,this.value=e.extnValue.buffer}toTextObject(){const e=this.toTextObjectWithoutValue();return e[""]=this.value,e}toTextObjectWithoutValue(){const e=this.toTextObjectEmpty(this.critical?"critical":void 0);return e[qu.NAME]===Qu.NAME&&(e[qu.NAME]=Ju.toString(this.type)),e}}class el{static isCryptoKeyPair(e){return e&&e.privateKey&&e.publicKey}static isCryptoKey(e){return e&&e.usages&&e.type&&e.algorithm&&void 0!==e.extractable}constructor(){this.items=new Map,this[Yu]="CryptoProvider","undefined"!=typeof self&&"undefined"!=typeof crypto?this.set(el.DEFAULT,crypto):"undefined"!=typeof global&&global.crypto&&global.crypto.subtle&&this.set(el.DEFAULT,global.crypto)}clear(){this.items.clear()}delete(e){return this.items.delete(e)}forEach(e,t){return this.items.forEach(e,t)}has(e){return this.items.has(e)}get size(){return this.items.size}entries(){return this.items.entries()}keys(){return this.items.keys()}values(){return this.items.values()}[Symbol.iterator](){return this.items[Symbol.iterator]()}get(e=el.DEFAULT){const t=this.items.get(e.toLowerCase());if(!t)throw new Error(`Cannot get Crypto by name '${e}'`);return t}set(e,t){if("string"==typeof e){if(!t)throw new TypeError("Argument 'value' is required");this.items.set(e.toLowerCase(),t)}else this.items.set(el.DEFAULT,e);return this}}Yu=Symbol.toStringTag,el.DEFAULT="default";const tl=new el,rl=/^[0-2](?:\.[1-9][0-9]*)+$/;class il{constructor(e={}){this.items={};for(const t in e)this.register(t,e[t])}get(e){return this.items[e]||null}findId(e){return t=e,new RegExp(rl).test(t)?e:this.get(e);var t}register(e,t){this.items[e]=t,this.items[t]=e}}const nl=new il;function ol(e,t){return`\\${C.ToHex(C.FromUtf8String(t)).toUpperCase()}`}nl.register("CN","2.5.4.3"),nl.register("L","2.5.4.7"),nl.register("ST","2.5.4.8"),nl.register("O","2.5.4.10"),nl.register("OU","2.5.4.11"),nl.register("C","2.5.4.6"),nl.register("DC","0.9.2342.19200300.100.1.25"),nl.register("E","1.2.840.113549.1.9.1"),nl.register("G","2.5.4.42"),nl.register("I","2.5.4.43"),nl.register("SN","2.5.4.4"),nl.register("T","2.5.4.12");class sl{static isASCII(e){for(let t=0;t<e.length;t++){if(e.charCodeAt(t)>255)return!1}return!0}static isPrintableString(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/g.test(e)}constructor(e,t={}){this.extraNames=new il,this.asn=new ni;for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)){const e=t[r];this.extraNames.register(r,e)}"string"==typeof e?this.asn=this.fromString(e):e instanceof ni?this.asn=e:k.isBufferSource(e)?this.asn=Kr.parse(e,ni):this.asn=this.fromJSON(e)}getField(e){const t=this.extraNames.findId(e)||nl.findId(e),r=[];for(const i of this.asn)for(const e of i)e.type===t&&r.push(e.value.toString());return r}getName(e){return this.extraNames.get(e)||nl.get(e)}toString(){return this.asn.map((e=>e.map((e=>`${this.getName(e.type)||e.type}=${e.value.anyValue?`#${C.ToHex(e.value.anyValue)}`:e.value.toString().replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,ol)}`)).join("+"))).join(", ")}toJSON(){var e;const t=[];for(const r of this.asn){const i={};for(const t of r){const r=this.getName(t.type)||t.type;null!==(e=i[r])&&void 0!==e||(i[r]=[]),i[r].push(t.value.anyValue?`#${C.ToHex(t.value.anyValue)}`:t.value.toString())}t.push(i)}return t}fromString(e){const t=new ni,r=/(\d\.[\d.]*\d|[A-Za-z]+)=((?:"")|(?:".*?[^\\]")|(?:[^,+"\\](?=[,+]|$))|(?:[^,+].*?(?:[^\\][,+]))|(?:))([,+])?/g;let i=null,n=",";for(;i=r.exec(`${e},`);){let[,e,r]=i;const o=r[r.length-1];","!==o&&"+"!==o||(r=r.slice(0,r.length-1),i[3]=o);const s=i[3];e=this.getTypeOid(e);const a=this.createAttribute(e,r);"+"===n?t[t.length-1].push(a):t.push(new ri([a])),n=s}return t}fromJSON(e){const t=new ni;for(const r of e){const e=new ri;for(const t in r){const i=this.getTypeOid(t),n=r[t];for(const t of n){const r=this.createAttribute(i,t);e.push(r)}}t.push(e)}return t}getTypeOid(e){if(/[\d.]+/.test(e)||(e=this.getName(e)||""),!e)throw new Error(`Cannot get OID for name type '${e}'`);return e}createAttribute(e,t){const r=new ti({type:e});if("object"==typeof t)for(const i in t)switch(i){case"ia5String":r.value.ia5String=t[i];break;case"utf8String":r.value.utf8String=t[i];break;case"universalString":r.value.universalString=t[i];break;case"bmpString":r.value.bmpString=t[i];break;case"printableString":r.value.printableString=t[i]}else if("#"===t[0])r.value.anyValue=C.FromHex(t.slice(1));else{const i=this.processStringValue(t);e===this.getName("E")||e===this.getName("DC")?r.value.ia5String=i:sl.isPrintableString(i)?r.value.printableString=i:r.value.utf8String=i}return r}processStringValue(e){const t=/"(.*?[^\\])?"/.exec(e);return t&&(e=t[1]),e.replace(/\\0a/gi,"\n").replace(/\\0d/gi,"\r").replace(/\\0g/gi,"\t").replace(/\\(.)/g,"$1")}toArrayBuffer(){return Kr.serialize(this.asn)}async getThumbprint(...e){var t;let r,i="SHA-1";return e.length>=1&&!(null===(t=e[0])||void 0===t?void 0:t.subtle)?(i=e[0]||i,r=e[1]||tl.get()):r=e[0]||tl.get(),await r.subtle.digest(i,this.toArrayBuffer())}}const al="Cannot initialize GeneralName from ASN.1 data.",cl=`${al} Unsupported string format in use.`,ul=`${al} Value doesn't match to GUID regular expression.`,ll=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,hl="1.3.6.1.4.1.311.25.1",pl="1.3.6.1.4.1.311.20.2.3",fl="dns",dl="dn",yl="email",gl="ip",vl="url",ml="guid",wl="upn",bl="id";class Sl extends Zu{constructor(...e){let t;if(2===e.length)switch(e[0]){case dl:{const r=new sl(e[1]).toArrayBuffer(),i=Kr.parse(r,ni);t=new ci({directoryName:i});break}case fl:t=new ci({dNSName:e[1]});break;case yl:t=new ci({rfc822Name:e[1]});break;case ml:{const r=new RegExp(ll,"i").exec(e[1]);if(!r)throw new Error("Cannot parse GUID value. Value doesn't match to regular expression");const i=r.slice(1).map(((e,t)=>t<3?C.ToHex(new Uint8Array(C.FromHex(e)).reverse()):e)).join("");t=new ci({otherName:new si({typeId:hl,value:Kr.serialize(new sr(C.FromHex(i)))})});break}case gl:t=new ci({iPAddress:e[1]});break;case bl:t=new ci({registeredID:e[1]});break;case wl:t=new ci({otherName:new si({typeId:pl,value:Kr.serialize(vr.toASN(e[1]))})});break;case vl:t=new ci({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else t=k.isBufferSource(e[0])?Kr.parse(e[0],ci):e[0];super(t)}onInit(e){if(null!=e.dNSName)this.type=fl,this.value=e.dNSName;else if(null!=e.rfc822Name)this.type=yl,this.value=e.rfc822Name;else if(null!=e.iPAddress)this.type=gl,this.value=e.iPAddress;else if(null!=e.uniformResourceIdentifier)this.type=vl,this.value=e.uniformResourceIdentifier;else if(null!=e.registeredID)this.type=bl,this.value=e.registeredID;else if(null!=e.directoryName)this.type=dl,this.value=new sl(e.directoryName).toString();else{if(null==e.otherName)throw new Error(cl);if(e.otherName.typeId===hl){this.type=ml;const t=Kr.parse(e.otherName.value,sr),r=new RegExp(ll,"i").exec(C.ToHex(t));if(!r)throw new Error(ul);this.value=r.slice(1).map(((e,t)=>t<3?C.ToHex(new Uint8Array(C.FromHex(e)).reverse()):e)).join("-")}else{if(e.otherName.typeId!==pl)throw new Error(cl);this.type=wl,this.value=Kr.parse(e.otherName.value,Qr).toString()}}}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case dl:case fl:case ml:case gl:case bl:case wl:case vl:e=this.type.toUpperCase();break;case yl:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===bl&&(t=Ju.toString(t)),new qu(e,void 0,t)}}class Al extends Zu{constructor(e){let t;if(e instanceof Ni)t=e;else if(Array.isArray(e)){const r=[];for(const t of e)if(t instanceof ci)r.push(t);else{const e=Kr.parse(new Sl(t.type,t.value).rawData,ci);r.push(e)}t=new Ni(r)}else{if(!k.isBufferSource(e))throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");t=Kr.parse(e,Ni)}super(t)}onInit(e){const t=[];for(const r of e){let e=null;try{e=new Sl(r)}catch{continue}t.push(e)}this.items=t}toJSON(){return this.items.map((e=>e.toJSON()))}toTextObject(){const e=super.toTextObjectEmpty();for(const t of this.items){const r=t.toTextObject();let i=e[r[qu.NAME]];Array.isArray(i)||(i=[],e[r[qu.NAME]]=i),i.push(r)}return e}}Al.NAME="GeneralNames";const xl="-{5}",kl="\\n",El="\\n",Bl=`${`${xl}BEGIN (${`[^${kl}]+`}(?=${xl}))${xl}`}${El}(?:((?:${`[^:${kl}]+`}: ${`(?:[^${kl}]+${El}(?: +[^${kl}]+${El})*)`})+))?${El}?(${`(?:[a-zA-Z0-9=+/]+${El})+`})${`${xl}END \\1${xl}`}`;class Nl{static isPem(e){return"string"==typeof e&&new RegExp(Bl,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");const t=new RegExp(Bl,"g"),r=[];let i=null;for(;i=t.exec(e);){const e=i[3].replace(new RegExp(`[${kl}]+`,"g"),""),t={type:i[1],headers:[],rawData:C.FromBase64(e)},n=i[2];if(n){const e=n.split(new RegExp(El,"g"));let r=null;for(const i of e){const[e,n]=i.split(/:(.*)/);if(void 0===n){if(!r)throw new Error("Cannot parse PEM string. Incorrect header value");r.value+=e.trim()}else r&&t.headers.push(r),r={key:e,value:n.trim()}}r&&t.headers.push(r)}r.push(t)}return r}static decode(e){return this.decodeWithHeaders(e).map((e=>e.rawData))}static decodeFirst(e){const t=this.decode(e);if(!t.length)throw new RangeError("PEM string doesn't contain any objects");return t[0]}static encode(e,t){if(Array.isArray(e)){const r=new Array;return t?e.forEach((e=>{if(!k.isBufferSource(e))throw new TypeError("Cannot encode array of BufferSource in PEM format. Not all items of the array are BufferSource");r.push(this.encodeStruct({type:t,rawData:k.toArrayBuffer(e)}))})):e.forEach((e=>{if(!("type"in e))throw new TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");r.push(this.encodeStruct(e))})),r.join("\n")}if(!t)throw new Error("Required argument 'tag' is missed");return this.encodeStruct({type:t,rawData:k.toArrayBuffer(e)})}static encodeStruct(e){var t;const r=e.type.toLocaleUpperCase(),i=[];if(i.push(`-----BEGIN ${r}-----`),null===(t=e.headers)||void 0===t?void 0:t.length){for(const t of e.headers)i.push(`${t.key}: ${t.value}`);i.push("")}const n=C.ToBase64(e.rawData);let o,s=0;const a=Array();for(;s<n.length&&(n.length-s<64?o=n.substring(s):(o=n.substring(s,s+64),s+=64),0!==o.length)&&(a.push(o),!(o.length<64)););return i.push(...a),i.push(`-----END ${r}-----`),i.join("\n")}}Nl.CertificateTag="CERTIFICATE",Nl.CrlTag="CRL",Nl.CertificateRequestTag="CERTIFICATE REQUEST",Nl.PublicKeyTag="PUBLIC KEY",Nl.PrivateKeyTag="PRIVATE KEY";class Tl extends Zu{static isAsnEncoded(e){return k.isBufferSource(e)||"string"==typeof e}static toArrayBuffer(e){if("string"==typeof e){if(Nl.isPem(e))return Nl.decode(e)[0];if(C.isHex(e))return C.FromHex(e);if(C.isBase64(e))return C.FromBase64(e);if(C.isBase64Url(e))return C.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}{const t=k.toUint8Array(e);if(t.length>0&&48===t[0])return k.toArrayBuffer(e);const r=C.ToBinary(e);if(Nl.isPem(r))return Nl.decode(r)[0];if(C.isHex(r))return C.FromHex(r);if(C.isBase64(r))return C.FromBase64(r);if(C.isBase64Url(r))return C.FromBase64Url(r);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}}constructor(...e){Tl.isAsnEncoded(e[0])?super(Tl.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){return"pem"===e?Nl.encode(this.rawData,this.tag):super.toString(e)}}class Il extends Tl{static async create(e,t=tl.get()){if(e instanceof Il)return e;if(el.isCryptoKey(e)){if("public"!==e.type)throw new TypeError("Public key is required");const r=await t.subtle.exportKey("spki",e);return new Il(r)}if(e.publicKey)return e.publicKey;if(k.isBufferSource(e))return new Il(e);throw new TypeError("Unsupported PublicKeyType")}constructor(e){Tl.isAsnEncoded(e)?super(e,zn):super(e),this.tag=Nl.PublicKeyTag}async export(...e){let t,r=["verify"],i={hash:"SHA-256",...this.algorithm};e.length>1?(i=e[0]||i,r=e[1]||r,t=e[2]||tl.get()):t=e[0]||tl.get();let n=this.rawData;const o=Kr.parse(this.rawData,zn);return o.algorithm.algorithm===ua&&(n=function(e,t){return e.algorithm=new Fn({algorithm:sa,parameters:null}),t=Kr.serialize(e),t}(o,n)),t.subtle.importKey("spki",n,i,!0,r)}onInit(e){const t=uc.resolve(pu),r=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case sa:{const t=Kr.parse(e.subjectPublicKey,Pa),i=k.toUint8Array(t.modulus);r.publicExponent=k.toUint8Array(t.publicExponent),r.modulusLength=(i[0]?i:i.slice(1)).byteLength<<3;break}}}async getThumbprint(...e){var t;let r,i="SHA-1";return e.length>=1&&!(null===(t=e[0])||void 0===t?void 0:t.subtle)?(i=e[0]||i,r=e[1]||tl.get()):r=e[0]||tl.get(),await r.subtle.digest(i,this.rawData)}async getKeyIdentifier(...e){let t,r="SHA-1";1===e.length?"string"==typeof e[0]?(r=e[0],t=tl.get()):t=e[0]:2===e.length?(r=e[0],t=e[1]):t=tl.get();const i=Kr.parse(this.rawData,zn);return await t.subtle.digest(r,i.subjectPublicKey)}toTextObject(){const e=this.toTextObjectEmpty(),t=Kr.parse(this.rawData,zn);if(e.Algorithm=Xu.serializeAlgorithm(t.algorithm),t.algorithm.algorithm===Us)e["EC Point"]=t.subjectPublicKey;else e["Raw Data"]=t.subjectPublicKey;return e}}class Ol extends Qu{static async create(e,t=!1,r=tl.get()){if("name"in e&&"serialNumber"in e)return new Ol(e,t);const i=await Il.create(e,r),n=await i.getKeyIdentifier(r);return new Ol(C.ToHex(n),t)}constructor(...e){if(k.isBufferSource(e[0]))super(e[0]);else if("string"==typeof e[0]){const t=new xi({keyIdentifier:new Ai(C.FromHex(e[0]))});super(Si,e[1],Kr.serialize(t))}else{const t=e[0],r=t.name instanceof Al?Kr.parse(t.name.rawData,Ni):t.name,i=new xi({authorityCertIssuer:r,authorityCertSerialNumber:C.FromHex(t.serialNumber)});super(Si,e[1],Kr.serialize(i))}}onInit(e){super.onInit(e);const t=Kr.parse(e.extnValue,xi);t.keyIdentifier&&(this.keyId=C.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?C.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){const e=this.toTextObjectWithoutValue(),t=Kr.parse(this.value,xi);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Al(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}}Ol.NAME="Authority Key Identifier";class Cl extends Qu{constructor(...e){if(k.isBufferSource(e[0])){super(e[0]);const t=Kr.parse(this.value,Ei);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{const t=new Ei({cA:e[0],pathLenConstraint:e[1]});super(ki,e[2],Kr.serialize(t)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){const e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),void 0!==this.pathLength&&(e["Path Length"]=this.pathLength),e}}var jl,_l,Dl;Cl.NAME="Basic Constraints",(_l=jl||(jl={})).serverAuth="1.3.6.1.5.5.7.3.1",_l.clientAuth="1.3.6.1.5.5.7.3.2",_l.codeSigning="1.3.6.1.5.5.7.3.3",_l.emailProtection="1.3.6.1.5.5.7.3.4",_l.timeStamping="1.3.6.1.5.5.7.3.8",_l.ocspSigning="1.3.6.1.5.5.7.3.9";class Rl extends Qu{constructor(...e){if(k.isBufferSource(e[0])){super(e[0]);const t=Kr.parse(this.value,on);this.usages=t.map((e=>e))}else{const t=new on(e[0]);super(nn,e[1],Kr.serialize(t)),this.usages=e[0]}}toTextObject(){const e=this.toTextObjectWithoutValue();return e[""]=this.usages.map((e=>Ju.toString(e))).join(", "),e}}Rl.NAME="Extended Key Usages",function(e){e[e.digitalSignature=1]="digitalSignature",e[e.nonRepudiation=2]="nonRepudiation",e[e.keyEncipherment=4]="keyEncipherment",e[e.dataEncipherment=8]="dataEncipherment",e[e.keyAgreement=16]="keyAgreement",e[e.keyCertSign=32]="keyCertSign",e[e.cRLSign=64]="cRLSign",e[e.encipherOnly=128]="encipherOnly",e[e.decipherOnly=256]="decipherOnly"}(Dl||(Dl={}));class Pl extends Qu{constructor(...e){if(k.isBufferSource(e[0])){super(e[0]);const t=Kr.parse(this.value,Sn);this.usages=t.toNumber()}else{const t=new Sn(e[0]);super(vn,e[1],Kr.serialize(t)),this.usages=e[0]}}toTextObject(){const e=this.toTextObjectWithoutValue(),t=Kr.parse(this.value,Sn);return e[""]=t.toJSON().join(", "),e}}Pl.NAME="Key Usages";class Ul extends Qu{static async create(e,t=!1,r=tl.get()){const i=await Il.create(e,r),n=await i.getKeyIdentifier(r);return new Ul(C.ToHex(n),t)}constructor(...e){if(k.isBufferSource(e[0])){super(e[0]);const t=Kr.parse(this.value,Pn);this.keyId=C.ToHex(t)}else{const t="string"==typeof e[0]?C.FromHex(e[0]):e[0],r=new Pn(t);super(Rn,e[1],Kr.serialize(r)),this.keyId=C.ToHex(t)}}toTextObject(){const e=this.toTextObjectWithoutValue(),t=Kr.parse(this.value,Pn);return e[""]=t,e}}Ul.NAME="Subject Key Identifier";class Ll extends Qu{constructor(...e){k.isBufferSource(e[0])?super(e[0]):super(On,e[1],new Al(e[0]||[]).rawData)}onInit(e){super.onInit(e);const t=Kr.parse(e.extnValue,Cn);this.names=new Al(t)}toTextObject(){const e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(const r in t)e[r]=t[r];return e}}Ll.NAME="Subject Alternative Name";class $l{static register(e,t){this.items.set(e,t)}static create(e){const t=new Qu(e),r=this.items.get(t.type);return r?new r(e):t}}$l.items=new Map;class Vl extends Qu{constructor(...e){var t;if(k.isBufferSource(e[0])){super(e[0]);const t=Kr.parse(this.value,Li);this.policies=t.map((e=>e.policyIdentifier))}else{const r=e[0],i=null!==(t=e[1])&&void 0!==t&&t,n=new Li(r.map((e=>new Ui({policyIdentifier:e}))));super(Ci,i,Kr.serialize(n)),this.policies=r}}toTextObject(){const e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map((e=>new qu("",{},Ju.toString(e)))),e}}Vl.NAME="Certificate Policies",$l.register(Ci,Vl);class Ml extends Qu{constructor(...e){var t;if(k.isBufferSource(e[0]))super(e[0]);else if(Array.isArray(e[0])&&"string"==typeof e[0][0]){const t=e[0].map((e=>new qi({distributionPoint:new Wi({fullName:[new ci({uniformResourceIdentifier:e})]})}))),r=new Ji(t);super(Hi,e[1],Kr.serialize(r))}else{const t=new Ji(e[0]);super(Hi,e[1],Kr.serialize(t))}null!==(t=this.distributionPoints)&&void 0!==t||(this.distributionPoints=[])}onInit(e){super.onInit(e);const t=Kr.parse(e.extnValue,Ji);this.distributionPoints=t}toTextObject(){const e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map((e=>{var t;const r={};return e.distributionPoint&&(r[""]=null===(t=e.distributionPoint.fullName)||void 0===t?void 0:t.map((e=>new Sl(e).toString())).join(", ")),e.reasons&&(r.Reasons=e.reasons.toString()),e.cRLIssuer&&(r["CRL Issuer"]=e.cRLIssuer.map((e=>e.toString())).join(", ")),r})),e}}Ml.NAME="CRL Distribution Points";class Hl extends Qu{constructor(...e){var t,r,i,n;if(k.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof bi){const t=new bi(e[0]);super(mi,e[1],Kr.serialize(t))}else{const t=e[0],r=new bi;Fl(r,t,pi,"ocsp"),Fl(r,t,fi,"caIssuers"),Fl(r,t,di,"timeStamping"),Fl(r,t,yi,"caRepository"),super(mi,e[1],Kr.serialize(r))}null!==(t=this.ocsp)&&void 0!==t||(this.ocsp=[]),null!==(r=this.caIssuers)&&void 0!==r||(this.caIssuers=[]),null!==(i=this.timeStamping)&&void 0!==i||(this.timeStamping=[]),null!==(n=this.caRepository)&&void 0!==n||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[];Kr.parse(e.extnValue,bi).forEach((e=>{switch(e.accessMethod){case pi:this.ocsp.push(new Sl(e.accessLocation));break;case fi:this.caIssuers.push(new Sl(e.accessLocation));break;case di:this.timeStamping.push(new Sl(e.accessLocation));break;case yi:this.caRepository.push(new Sl(e.accessLocation))}}))}toTextObject(){const e=this.toTextObjectWithoutValue();return this.ocsp.length&&Kl(e,"OCSP",this.ocsp),this.caIssuers.length&&Kl(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&Kl(e,"Time Stamping",this.timeStamping),this.caRepository.length&&Kl(e,"CA Repository",this.caRepository),e}}function Kl(e,t,r){if(1===r.length)e[t]=r[0].toTextObject();else{const i=new qu("");r.forEach(((e,t)=>{const r=e.toTextObject(),n=`${r[qu.NAME]} ${t+1}`;let o=i[n];Array.isArray(o)||(o=[],i[n]=o),o.push(r)})),e[t]=i}}function Fl(e,t,r,i){const n=t[i];if(n){(Array.isArray(n)?n:[n]).forEach((t=>{"string"==typeof t&&(t=new Sl("url",t)),e.push(new wi({accessMethod:r,accessLocation:Kr.parse(t.rawData,ci)}))}))}}Hl.NAME="Authority Info Access";class zl extends Qu{constructor(...e){k.isBufferSource(e[0])?super(e[0]):super(yn,e[1],new Al(e[0]||[]).rawData)}onInit(e){super.onInit(e);const t=Kr.parse(e.extnValue,Ni);this.names=new Al(t)}toTextObject(){const e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(const r in t)e[r]=t[r];return e}}zl.NAME="Issuer Alternative Name";class Wl extends Zu{constructor(...e){let t;if(k.isBufferSource(e[0]))t=k.toArrayBuffer(e[0]);else{const r=e[0],i=Array.isArray(e[1])?e[1].map((e=>k.toArrayBuffer(e))):[];t=Kr.serialize(new jn({type:r,values:i}))}super(t,jn)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){const e=this.toTextObjectWithoutValue();return e.Value=this.values.map((e=>new qu("",{"":e}))),e}toTextObjectWithoutValue(){const e=this.toTextObjectEmpty();return e[qu.NAME]===Wl.NAME&&(e[qu.NAME]=Ju.toString(this.type)),e}}Wl.NAME="Attribute";class ql extends Wl{constructor(...e){var t;if(k.isBufferSource(e[0]))super(e[0]);else{const t=new tu({printableString:e[0]});super(Pc,[Kr.serialize(t)])}null!==(t=this.password)&&void 0!==t||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){const e=Kr.parse(this.values[0],tu);this.password=e.toString()}}toTextObject(){const e=this.toTextObjectWithoutValue();return e[qu.VALUE]=this.password,e}}ql.NAME="Challenge Password";class Jl extends Wl{constructor(...e){var t;if(k.isBufferSource(e[0]))super(e[0]);else{const t=e[0],r=new Gn;for(const e of t)r.push(Kr.parse(e.rawData,Xn));super(Uc,[Kr.serialize(r)])}null!==(t=this.items)&&void 0!==t||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){const e=Kr.parse(this.values[0],Gn);this.items=e.map((e=>$l.create(Kr.serialize(e))))}}toTextObject(){const e=this.toTextObjectWithoutValue(),t=this.items.map((e=>e.toTextObject()));for(const r of t)e[r[qu.NAME]]=r;return e}}Jl.NAME="Extensions";class Xl{static register(e,t){this.items.set(e,t)}static create(e){const t=new Wl(e),r=this.items.get(t.type);return r?new r(e):t}}Xl.items=new Map;const Gl="crypto.signatureFormatter";var Yl;let Zl=Yl=class{static createPssParams(e,t){const r=Yl.getHashAlgorithm(e);return r?new Oa({hashAlgorithm:r,maskGenAlgorithm:new Fn({algorithm:ka,parameters:Kr.serialize(r)}),saltLength:t}):null}static getHashAlgorithm(e){const t=uc.resolve(pu);return"string"==typeof e?t.toAsnAlgorithm({name:e}):"object"==typeof e&&e&&"name"in e?t.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if(!("hash"in e))return new Fn({algorithm:sa,parameters:null});{let t;if("string"==typeof e.hash)t=e.hash;else{if(!e.hash||"object"!=typeof e.hash||!("name"in e.hash)||"string"!=typeof e.hash.name)throw new Error("Cannot get hash algorithm name");t=e.hash.name.toUpperCase()}switch(t.toLowerCase()){case"sha-1":return new Fn({algorithm:pa,parameters:null});case"sha-256":return new Fn({algorithm:da,parameters:null});case"sha-384":return new Fn({algorithm:ya,parameters:null});case"sha-512":return new Fn({algorithm:ga,parameters:null})}}break;case"rsa-pss":if("hash"in e){if(!("saltLength"in e)||"number"!=typeof e.saltLength)throw new Error("Cannot get 'saltLength' from 'alg' argument");const t=Yl.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new Fn({algorithm:ua,parameters:Kr.serialize(t)})}return new Fn({algorithm:ua,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case sa:return{name:"RSASSA-PKCS1-v1_5"};case pa:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case da:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case ya:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case ga:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case ua:if(e.parameters){const t=Kr.parse(e.parameters,Oa);return{name:"RSA-PSS",hash:uc.resolve(pu).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}return{name:"RSA-PSS"}}return null}};Zl=Yl=Fr([lc()],Zl),uc.registerSingleton(hu,Zl);let Ql=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new Fn({algorithm:wa});case"sha-256":return new Fn({algorithm:Sa});case"sha-384":return new Fn({algorithm:Aa});case"sha-512":return new Fn({algorithm:xa})}return null}toWebAlgorithm(e){switch(e.algorithm){case wa:return{name:"SHA-1"};case Sa:return{name:"SHA-256"};case Aa:return{name:"SHA-384"};case xa:return{name:"SHA-512"}}return null}};Ql=Fr([lc()],Ql),uc.registerSingleton(hu,Ql);class eh{addPadding(e,t){const r=k.toUint8Array(t),i=new Uint8Array(e);return i.set(r,e-r.length),i.buffer}removePadding(e,t=!1){let r=k.toUint8Array(e);for(let i=0;i<r.length;i++)if(r[i]){r=r.slice(i);break}if(t&&r[0]>127){const e=new Uint8Array(r.length+1);return e.set(r,1),e.buffer}return r.buffer}toAsnSignature(e,t){if("ECDSA"===e.name){const r=e.namedCurve,i=eh.namedCurveSize.get(r)||eh.defaultNamedCurveSize,n=new na,o=k.toUint8Array(t);return n.r=this.removePadding(o.slice(0,i),!0),n.s=this.removePadding(o.slice(i,i+i),!0),Kr.serialize(n)}return null}toWebSignature(e,t){if("ECDSA"===e.name){const r=Kr.parse(t,na),i=e.namedCurve,n=eh.namedCurveSize.get(i)||eh.defaultNamedCurveSize;return function(...e){const t=e.map((e=>e.byteLength)).reduce(((e,t)=>e+t)),r=new Uint8Array(t);let i=0;return e.map((e=>new Uint8Array(e))).forEach((e=>{for(const t of e)r[i++]=t})),r.buffer}(this.addPadding(n,this.removePadding(r.r)),this.addPadding(n,this.removePadding(r.s)))}return null}}eh.namedCurveSize=new Map,eh.defaultNamedCurveSize=32;const th="1.3.101.110",rh="1.3.101.111",ih="1.3.101.112",nh="1.3.101.113";let oh=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=ih;break;case"x25519":t=th;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=ih;break;case"ed448":t=nh}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=th;break;case"x448":t=rh}}return t?new Fn({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case ih:return{name:"Ed25519"};case nh:return{name:"EdDSA",namedCurve:"Ed448"};case th:return{name:"X25519"};case rh:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};var sh,ah,ch,uh,lh,hh,ph,fh,dh,yh,gh,vh,mh,wh,bh,Sh,Ah,xh,kh,Eh,Bh,Nh;oh=Fr([lc()],oh),uc.registerSingleton(hu,oh);sh=new WeakMap,ah=new WeakMap,ch=new WeakMap,uh=new WeakMap,lh=new WeakMap,hh=new WeakMap,ph=new WeakMap,fh=new WeakMap,class extends Tl{get subjectName(){return zr(this,ah,"f")||Wr(this,ah,new sl(this.asn.certificationRequestInfo.subject),"f"),zr(this,ah,"f")}get subject(){return zr(this,ch,"f")||Wr(this,ch,this.subjectName.toString(),"f"),zr(this,ch,"f")}get signatureAlgorithm(){if(!zr(this,uh,"f")){const e=uc.resolve(pu);Wr(this,uh,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return zr(this,uh,"f")}get signature(){return zr(this,lh,"f")||Wr(this,lh,this.asn.signature,"f"),zr(this,lh,"f")}get publicKey(){return zr(this,hh,"f")||Wr(this,hh,new Il(this.asn.certificationRequestInfo.subjectPKInfo),"f"),zr(this,hh,"f")}get attributes(){return zr(this,ph,"f")||Wr(this,ph,this.asn.certificationRequestInfo.attributes.map((e=>Xl.create(Kr.serialize(e)))),"f"),zr(this,ph,"f")}get extensions(){if(!zr(this,fh,"f")){Wr(this,fh,[],"f");const e=this.getAttribute(Uc);e instanceof Jl&&Wr(this,fh,e.items,"f")}return zr(this,fh,"f")}get tbs(){return zr(this,sh,"f")||Wr(this,sh,this.asn.certificationRequestInfoRaw||Kr.serialize(this.asn.certificationRequestInfo),"f"),zr(this,sh,"f")}constructor(e){const t=Tl.isAsnEncoded(e)?[e,lu]:[e];super(t[0],t[1]),sh.set(this,void 0),ah.set(this,void 0),ch.set(this,void 0),uh.set(this,void 0),lh.set(this,void 0),hh.set(this,void 0),ph.set(this,void 0),fh.set(this,void 0),this.tag=Nl.CertificateRequestTag}onInit(e){}getAttribute(e){for(const t of this.attributes)if(t.type===e)return t;return null}getAttributes(e){return this.attributes.filter((t=>t.type===e))}getExtension(e){for(const t of this.extensions)if(t.type===e)return t;return null}getExtensions(e){return this.extensions.filter((t=>t.type===e))}async verify(e=tl.get()){const t={...this.publicKey.algorithm,...this.signatureAlgorithm},r=await this.publicKey.export(t,["verify"],e),i=uc.resolveAll(Gl).reverse();let n=null;for(const o of i)if(n=o.toWebSignature(t,this.signature),n)break;if(!n)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,r,n,this.tbs)}toTextObject(){const e=this.toTextObjectEmpty(),t=Kr.parse(this.rawData,lu),r=t.certificationRequestInfo,i=new qu("",{Version:`${Yn[r.version]} (${r.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){const e=new qu("");for(const t of this.attributes){const r=t.toTextObject();e[r[qu.NAME]]=r}i.Attributes=e}return e.Data=i,e.Signature=new qu("",{Algorithm:Xu.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}}.NAME="PKCS#10 Certificate Request";class Th extends Tl{get publicKey(){return zr(this,Eh,"f")||Wr(this,Eh,new Il(this.asn.tbsCertificate.subjectPublicKeyInfo),"f"),zr(this,Eh,"f")}get serialNumber(){if(!zr(this,yh,"f")){const e=this.asn.tbsCertificate;let t=new Uint8Array(e.serialNumber);t.length>1&&0===t[0]&&t[1]>127&&(t=t.slice(1)),Wr(this,yh,C.ToHex(t),"f")}return zr(this,yh,"f")}get subjectName(){return zr(this,gh,"f")||Wr(this,gh,new sl(this.asn.tbsCertificate.subject),"f"),zr(this,gh,"f")}get subject(){return zr(this,vh,"f")||Wr(this,vh,this.subjectName.toString(),"f"),zr(this,vh,"f")}get issuerName(){return zr(this,mh,"f")||Wr(this,mh,new sl(this.asn.tbsCertificate.issuer),"f"),zr(this,mh,"f")}get issuer(){return zr(this,wh,"f")||Wr(this,wh,this.issuerName.toString(),"f"),zr(this,wh,"f")}get notBefore(){if(!zr(this,bh,"f")){const e=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!e)throw new Error("Cannot get 'notBefore' value");Wr(this,bh,e,"f")}return zr(this,bh,"f")}get notAfter(){if(!zr(this,Sh,"f")){const e=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!e)throw new Error("Cannot get 'notAfter' value");Wr(this,Sh,e,"f")}return zr(this,Sh,"f")}get signatureAlgorithm(){if(!zr(this,Ah,"f")){const e=uc.resolve(pu);Wr(this,Ah,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return zr(this,Ah,"f")}get signature(){return zr(this,xh,"f")||Wr(this,xh,this.asn.signatureValue,"f"),zr(this,xh,"f")}get extensions(){return zr(this,kh,"f")||(Wr(this,kh,[],"f"),this.asn.tbsCertificate.extensions&&Wr(this,kh,this.asn.tbsCertificate.extensions.map((e=>$l.create(Kr.serialize(e)))),"f")),zr(this,kh,"f")}get tbs(){return zr(this,dh,"f")||Wr(this,dh,this.asn.tbsCertificateRaw||Kr.serialize(this.asn.tbsCertificate),"f"),zr(this,dh,"f")}constructor(e){const t=Tl.isAsnEncoded(e)?[e,eo]:[e];super(t[0],t[1]),dh.set(this,void 0),yh.set(this,void 0),gh.set(this,void 0),vh.set(this,void 0),mh.set(this,void 0),wh.set(this,void 0),bh.set(this,void 0),Sh.set(this,void 0),Ah.set(this,void 0),xh.set(this,void 0),kh.set(this,void 0),Eh.set(this,void 0),this.tag=Nl.CertificateTag}onInit(e){}getExtension(e){for(const t of this.extensions)if("string"==typeof e){if(t.type===e)return t}else if(t instanceof e)return t;return null}getExtensions(e){return this.extensions.filter((t=>"string"==typeof e?t.type===e:t instanceof e))}async verify(e={},t=tl.get()){let r,i;const n=e.publicKey;try{if(n)if("publicKey"in n)r={...n.publicKey.algorithm,...this.signatureAlgorithm},i=await n.publicKey.export(r,["verify"],t);else if(n instanceof Il)r={...n.algorithm,...this.signatureAlgorithm},i=await n.export(r,["verify"],t);else if(k.isBufferSource(n)){const e=new Il(n);r={...e.algorithm,...this.signatureAlgorithm},i=await e.export(r,["verify"],t)}else r={...n.algorithm,...this.signatureAlgorithm},i=n;else r={...this.publicKey.algorithm,...this.signatureAlgorithm},i=await this.publicKey.export(r,["verify"],t)}catch{return!1}const o=uc.resolveAll(Gl).reverse();let s=null;for(const c of o)if(s=c.toWebSignature(r,this.signature),s)break;if(!s)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");const a=await t.subtle.verify(this.signatureAlgorithm,i,s,this.tbs);if(e.signatureOnly)return a;{const t=(e.date||new Date).getTime();return a&&this.notBefore.getTime()<t&&t<this.notAfter.getTime()}}async getThumbprint(...e){let t,r="SHA-1";return e[0]&&(e[0].subtle?t=e[0]:(r=e[0]||r,t=e[1])),null!=t||(t=tl.get()),await t.subtle.digest(r,this.rawData)}async isSelfSigned(e=tl.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){const e=this.toTextObjectEmpty(),t=Kr.parse(this.rawData,eo),r=t.tbsCertificate,i=new qu("",{Version:`${Yn[r.version]} (${r.version})`,"Serial Number":r.serialNumber,"Signature Algorithm":Xu.serializeAlgorithm(r.signature),Issuer:this.issuer,Validity:new qu("",{"Not Before":r.validity.notBefore.getTime(),"Not After":r.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(r.issuerUniqueID&&(i["Issuer Unique ID"]=r.issuerUniqueID),r.subjectUniqueID&&(i["Subject Unique ID"]=r.subjectUniqueID),this.extensions.length){const e=new qu("");for(const t of this.extensions){const r=t.toTextObject();e[r[qu.NAME]]=r}i.Extensions=e}return e.Data=i,e.Signature=new qu("",{Algorithm:Xu.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}}dh=new WeakMap,yh=new WeakMap,gh=new WeakMap,vh=new WeakMap,mh=new WeakMap,wh=new WeakMap,bh=new WeakMap,Sh=new WeakMap,Ah=new WeakMap,xh=new WeakMap,kh=new WeakMap,Eh=new WeakMap,Th.NAME="Certificate";class Ih{static async createSelfSigned(e,t=tl.get()){if(!e.keys.privateKey)throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!e.keys.publicKey)throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:e.serialNumber,subject:e.name,issuer:e.name,notBefore:e.notBefore,notAfter:e.notAfter,publicKey:e.keys.publicKey,signingKey:e.keys.privateKey,signingAlgorithm:e.signingAlgorithm,extensions:e.extensions},t)}static async create(e,t=tl.get()){var r;let i;i=e.publicKey instanceof Il?e.publicKey.rawData:"publicKey"in e.publicKey?e.publicKey.publicKey.rawData:k.isBufferSource(e.publicKey)?e.publicKey:await t.subtle.exportKey("spki",e.publicKey);const n=function(e,t=tl.get()){const r=k.toUint8Array(C.FromHex(e||""));let i=r&&r.length&&r.some((e=>e>0))?new Uint8Array(r):void 0;i||(i=t.getRandomValues(new Uint8Array(16)));let n=0;for(;n<i.length-1&&0===i[n];)n++;if(i=i.slice(n),i[0]>127){const e=new Uint8Array(i.length+1);e[0]=0,e.set(i,1),i=e}return i.buffer}(e.serialNumber,t),o=e.notBefore||new Date,s=e.notAfter||new Date(o.getTime()+31536e6),a=new eo({tbsCertificate:new Qn({version:Yn.v3,serialNumber:n,validity:new qn({notBefore:o,notAfter:s}),extensions:new Gn((null===(r=e.extensions)||void 0===r?void 0:r.map((e=>Kr.parse(e.rawData,Xn))))||[]),subjectPublicKeyInfo:Kr.parse(i,zn)})});if(e.subject){const t=e.subject instanceof sl?e.subject:new sl(e.subject);a.tbsCertificate.subject=Kr.parse(t.toArrayBuffer(),ni)}if(e.issuer){const t=e.issuer instanceof sl?e.issuer:new sl(e.issuer);a.tbsCertificate.issuer=Kr.parse(t.toArrayBuffer(),ni)}const c={hash:"SHA-256"},u="signingKey"in e?{...c,...e.signingAlgorithm,...e.signingKey.algorithm}:{...c,...e.signingAlgorithm},l=uc.resolve(pu);a.tbsCertificate.signature=a.signatureAlgorithm=l.toAsnAlgorithm(u);const h=Kr.serialize(a.tbsCertificate),p="signingKey"in e?await t.subtle.sign(u,e.signingKey,h):e.signature,f=uc.resolveAll(Gl).reverse();let d=null;for(const y of f)if(d=y.toAsnSignature(u,p),d)break;if(!d)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return a.signatureValue=d,new Th(Kr.serialize(a))}}function Oh(e){const t=globalThis.process;if("function"==typeof(null==t?void 0:t.getBuiltinModule)){const r=t.getBuiltinModule(e);if(r)return r}if("function"==typeof require)return require(e);throw new Error(`buckyos cert cannot load builtin module ${e} in this runtime`)}function Ch(){const e=globalThis.crypto;if(null==e?void 0:e.subtle)return e;return Oh("node:crypto").webcrypto}(Nh=Bh||(Bh={}))[Nh.unspecified=0]="unspecified",Nh[Nh.keyCompromise=1]="keyCompromise",Nh[Nh.cACompromise=2]="cACompromise",Nh[Nh.affiliationChanged=3]="affiliationChanged",Nh[Nh.superseded=4]="superseded",Nh[Nh.cessationOfOperation=5]="cessationOfOperation",Nh[Nh.certificateHold=6]="certificateHold",Nh[Nh.removeFromCRL=8]="removeFromCRL",Nh[Nh.privilegeWithdrawn=9]="privilegeWithdrawn",Nh[Nh.aACompromise=10]="aACompromise",$l.register(ki,Cl),$l.register(nn,Rl),$l.register(vn,Pl),$l.register(Rn,Ul),$l.register(Si,Ol),$l.register(On,Ll),$l.register(Hi,Ml),$l.register(mi,Hl),$l.register(yn,zl),Xl.register(Pc,ql),Xl.register(Uc,Jl),uc.registerSingleton(Gl,class{toAsnSignature(e,t){return k.toArrayBuffer(t)}toWebSignature(e,t){return k.toArrayBuffer(t)}}),uc.registerSingleton(Gl,eh),eh.namedCurveSize.set("P-256",32),eh.namedCurveSize.set("K-256",32),eh.namedCurveSize.set("P-384",48),eh.namedCurveSize.set("P-521",66);const jh={name:"RSASSA-PKCS1-v1_5",hash:"SHA-256",publicExponent:new Uint8Array([1,0,1]),modulusLength:4096},_h={...jh,modulusLength:2048},Dh=["server","client","authentication","assertion","key-agreement","capability"],Rh=["did-json","did-meta","cert","chain","fullchain","ca","public","csr","meta","private","keyref","verification-method"];function Ph(){const e=new Uint8Array(16);return Ch().getRandomValues(e),e[0]&=127,e[0]|=1,Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join("")}function Uh(e){return new Date(Date.now()+24*e*3600*1e3)}async function Lh(e){const t=new Uint8Array(await Ch().subtle.exportKey("pkcs8",e));return Nl.encode(t,"PRIVATE KEY")}function $h(e){return Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join("")}function Vh(e){const t=e=>e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||46===e||95===e||45===e;let r="";for(const i of function(e){if("undefined"!=typeof TextEncoder)return(new TextEncoder).encode(e);const t=Oh("node:buffer").Buffer;return new Uint8Array(t.from(e,"utf8"))}(e))t(i)?r+=String.fromCharCode(i):r+=`%${i.toString(16).toUpperCase().padStart(2,"0")}`;if(!r||"."===r||".."===r||/[\\/]/.test(r)||r.includes("\0"))throw new Error(`Invalid encoded identity directory name for raw host URI: ${e}`);return r}function Mh(e){const t=e.trim();if(!t)throw new Error("identity DID or hostname is empty");return i.DID.fromStr(function(e){return e.startsWith("did:web:*.")?`did:web:_.${e.slice(10)}`:e.startsWith("*.")?`_.${e.slice(2)}`:e}(t))}function Hh(e){return Mh(e).toRawHostUri()}function Kh(e){return Vh(Hh(e))}function Fh(e){const t=Mh(e);if("web"!==t.method)return null;const r=t.toRawHostName(),i=t.getPathFromId();return i?`https://${r}/${i}/did.json`:`https://${r}/.well-known/did.json`}function zh(e,t){switch(function(e){if(!Dh.includes(e))throw new Error(`Unsupported identity usage: ${e}`)}(e),function(e){if(!Rh.includes(e))throw new Error(`Unsupported identity material: ${e}`)}(t),t){case"did-json":return"did.json";case"did-meta":return"did.meta.json";case"cert":return`${e}.cert.pem`;case"chain":return`${e}.chain.pem`;case"fullchain":return`${e}.fullchain.pem`;case"ca":return`${e}.ca.pem`;case"public":return"server"===e||"client"===e?`${e}.public.pem`:`${e}.public.jwk`;case"csr":return`${e}.csr.pem`;case"meta":return`${e}.meta.json`;case"private":return`${e}.private.pem`;case"keyref":return`${e}.keyref.json`;case"verification-method":return`${e}.verification-method.json`}}function Wh(e){if("string"!=typeof e)return null;const t=e.trim();return t.length>0?t:null}function qh(e,t,r){const i=Oh("node:path");return{cert:i.join(e,zh(r,"cert")),chain:i.join(e,zh(r,"chain")),fullchain:i.join(e,zh(r,"fullchain")),ca:i.join(e,zh(r,"ca")),metadata:i.join(e,zh(r,"meta")),keyref:i.join(t,zh(r,"keyref")),privateKey:i.join(t,zh(r,"private"))}}class Jh{constructor(e,t){const r=Oh("node:path");this.publicRoot=r.resolve(e),this.securityRoot=r.resolve(t)}static fromEnvOrBuckyosRoot(e={}){const t=Oh("node:path"),r=function(){const e=globalThis.process;return(null==e?void 0:e.env)??{}}(),i=Wh(e.buckyosRoot)??Wh(r.BUCKYOS_ROOT)??"/opt/buckyos",n=Wh(e.publicRoot)??Wh(r.BUCKYOS_IDENTITY_ROOT)??t.join(i,"local","identity"),o=Wh(e.securityRoot)??Wh(r.BUCKYOS_SECURITY_ROOT)??t.join(i,"security");return new Jh(n,o)}rawHostUri(e){return Hh(e)}dirName(e){return Kh(e)}publicDir(e){return Oh("node:path").join(this.publicRoot,this.dirName(e))}securityDir(e){return Oh("node:path").join(this.securityRoot,this.dirName(e))}publicFile(e,t,r){return Oh("node:path").join(this.publicDir(e),zh(t,r))}securityFile(e,t,r){return Oh("node:path").join(this.securityDir(e),zh(t,r))}x509Paths(e,t="server"){return qh(this.publicDir(e),this.securityDir(e),t)}identityDirMatch(e){const t=this.rawHostUri(e),r=Vh(t);return{type:t.startsWith("_.")?"wildcard":"exact",rawHostUri:t,dirName:r,publicDir:this.publicDir(e),securityDir:this.securityDir(e),...t.startsWith("_.")?{hostPattern:`*.${t.slice(2)}`}:{host:t}}}findX509Paths(e,t="server"){const r=Oh("node:fs"),i=this.identityDirMatch(e),n=qh(i.publicDir,i.securityDir,t);if(r.existsSync(n.fullchain)||r.existsSync(n.cert))return{match:i,paths:n};const o=Mh(e);if("web"!==o.method)return null;const s=o.toRawHostName().split(".");if(s.length<3)return null;const a=`_.${s.slice(1).join(".")}`,c=Vh(a),u=Oh("node:path"),l=u.join(this.publicRoot,c),h=u.join(this.securityRoot,c),p=qh(l,h,t);return r.existsSync(p.fullchain)||r.existsSync(p.cert)?{match:{type:"wildcard",rawHostUri:a,dirName:c,publicDir:l,securityDir:h,hostPattern:`*.${s.slice(1).join(".")}`},paths:p}:null}}async function Xh(e){const t=Ch();if(e.includes("BEGIN RSA PRIVATE KEY")){const r=function(e){const t=new Uint8Array([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]),r=new Uint8Array([2,1,0]),i=Gh(4,e),n=new Uint8Array(r.length+t.length+i.length);return n.set(r,0),n.set(t,r.length),n.set(i,r.length+t.length),Gh(48,n)}(new Uint8Array(Nl.decode(e)[0]));return t.subtle.importKey("pkcs8",r,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["sign"])}const r=new Uint8Array(Nl.decode(e)[0]);return t.subtle.importKey("pkcs8",r,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["sign"])}function Gh(e,t){let r;r=t.length<128?[e,t.length]:t.length<256?[e,129,t.length]:[e,130,t.length>>8,255&t.length];const i=new Uint8Array(r.length+t.length);return i.set(r,0),i.set(t,r.length),i}function Yh(e){const t=e.extensions.find((e=>e instanceof Cl));if(!(null==t?void 0:t.ca))return"missing basicConstraints CA:TRUE";const r=e.extensions.find((e=>e instanceof Pl));return!r||r.usages&Dl.keyCertSign?void 0:"keyUsage does not allow certificate signing"}async function Zh(e,t="devtest"){const r=Oh("node:fs"),i=Oh("node:path"),n=Ch();tl.set(n),r.mkdirSync(e,{recursive:!0});const o=i.join(e,`${t}_ca_key.pem`),s=i.join(e,`${t}_ca_cert.pem`),a=`C=US, ST=California, L=San Jose, O=${`${t}'s Dev Test Environment`}, OU=Test, CN=${t}`,c=await n.subtle.generateKey(jh,!0,["sign","verify"]),u=await Ih.createSelfSigned({serialNumber:Ph(),name:a,notBefore:new Date,notAfter:Uh(3650),signingAlgorithm:{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},keys:c,extensions:[new Cl(!0,void 0,!0),new Pl(Dl.keyCertSign|Dl.cRLSign|Dl.digitalSignature,!0),await Ul.create(c.publicKey)]});return r.writeFileSync(o,await Lh(c.privateKey)),r.writeFileSync(s,u.toString("pem")),console.log(`CA certificate created: ${s}`),{caCertPath:s,caKeyPath:o}}async function Qh(e,t,r=[],i="server"){const n=Oh("node:fs"),o=Ch();tl.set(o);const{caCertPath:s,caKeyPath:a}=function(e){const t=Oh("node:fs"),r=Oh("node:path"),i=t.readdirSync(e).filter((e=>e.endsWith("_ca_cert.pem")));if(0===i.length)throw new Error(`No CA certificate found matching *_ca_cert.pem pattern in ${e}`);if(i.length>1)throw new Error(`Multiple CA certificates found in ${e}: ${i.join(", ")}`);const n=r.join(e,i[0]),o=r.join(e,i[0].replace("_ca_cert.pem","_ca_key.pem"));if(!t.existsSync(o))throw new Error(`CA key not found: ${o}`);return{caCertPath:n,caKeyPath:o}}(e),c=n.readFileSync(s,"utf8"),u=new Th(c),l=Yh(u);if(l)throw new Error(`Invalid CA certificate at ${s}: ${l}`);const h=await Xh(n.readFileSync(a,"utf8")),p=t[0];if(!p)throw new Error("At least one DNS SAN is required when creating an X.509 certificate");const f=await o.subtle.generateKey(_h,!0,["sign","verify"]),d=new Uint8Array(await o.subtle.exportKey("spki",f.publicKey)),y=await async function(e){const t=await Ch().subtle.digest("SHA-256",e);return`sha256:${$h(new Uint8Array(t))}`}(d),g=[...t.map((e=>({type:"dns",value:e}))),...r.map((e=>({type:"url",value:e})))],v=await Ih.create({serialNumber:Ph(),subject:`CN=${p}`,issuer:u.subjectName,notBefore:new Date,notAfter:Uh(365),signingAlgorithm:{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},publicKey:f.publicKey,signingKey:h,extensions:[new Pl(Dl.digitalSignature|Dl.keyEncipherment,!0),new Rl(["client"===i?jl.clientAuth:jl.serverAuth]),new Ll(g),await Ul.create(f.publicKey),await Ol.create(u)]});return{cert:v,certPem:v.toString("pem"),privateKeyPem:await Lh(f.privateKey),caCertPem:c,publicKeyFingerprint:y}}function ep(e){return`${e.trimEnd()}\n`}function tp(e,t,r){const i=Oh("node:fs"),n=Oh("node:path"),o=n.dirname(e),s=n.join(o,`.${n.basename(e)}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`);try{i.writeFileSync(s,t,void 0===r?void 0:{mode:r});try{const e=i.openSync(s,"r");try{i.fsyncSync(e)}finally{i.closeSync(e)}}catch{}i.renameSync(s,e)}catch(a){try{i.existsSync(s)&&i.unlinkSync(s)}catch{}throw a}}function rp(e){const t=e.toRawHostName();return t.startsWith("_.")?`*.${t.slice(2)}`:t}function ip(e){if("web"!==e.method||e.toRawHostName().startsWith("_."))return;const t=e.toString();return{type:"did-web-domain",did:t,web_origin:`https://${e.toRawHostName()}`,did_document_url:Fh(t)}}async function np(e,t,r,i,n){const o=function(e){const t=e.extensions.find((e=>e instanceof Ll)),r=(null==t?void 0:t.names.toJSON())??[];return{dns:r.filter((e=>"dns"===e.type)).map((e=>e.value)),uri:r.filter((e=>"url"===e.type)).map((e=>e.value))}}(n.cert),s=await async function(e){const t=await e.getThumbprint("SHA-256",Ch());return`sha256:${$h(new Uint8Array(t))}`}(n.cert),a=r.startsWith("_."),c=(new Date).toISOString();return{schema:"buckyos.identity.x509.metadata.v1",did:e.toString(),raw_host_uri:r,dir_name:i,usage:t,match:a?{type:"wildcard",host_pattern:`*.${r.slice(2)}`}:{type:"exact",host:r},certificate:{serial_number:n.cert.serialNumber,issuer:n.cert.issuer,subject:n.cert.subject,not_before:n.cert.notBefore.toISOString(),not_after:n.cert.notAfter.toISOString(),fingerprint_sha256:s,public_key_fingerprint:n.publicKeyFingerprint},san:o,paths:{cert:zh(t,"cert"),chain:zh(t,"chain"),fullchain:zh(t,"fullchain"),ca:zh(t,"ca")},did_binding:ip(e),updated_at:c,generation:`${c.replace(/[-:.]/g,"")}-${s}`}}const op="test test test test test test test test test test test junk",sp=2147483648,ap=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),cp=(1n<<64n)-1n,up=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n],lp=[[0,36,3,41,18],[1,44,10,45,2],[62,6,43,15,61],[28,55,25,21,56],[27,20,39,8,14]];function hp(e,t=""){return o.pbkdf2Sync(n.Buffer.from(e.normalize("NFKD"),"utf8"),n.Buffer.from(`mnemonic${t}`.normalize("NFKD"),"utf8"),2048,64,"sha512")}function pp(e,t){return o.createHmac("sha512",e).update(t).digest()}function fp(e){const t=n.Buffer.alloc(4);return t.writeUInt32BE(e>>>0,0),t}function dp(e){const t=o.createPublicKey(o.createPrivateKey(e)).export({format:"jwk"});if(!t.x)throw new Error("failed to derive Ed25519 public key x");return t.x}function yp(e,t,r){const i=pp(t,n.Buffer.concat([n.Buffer.from([0]),e,fp(r+sp)]));return{key:i.subarray(0,32),chainCode:i.subarray(32)}}function gp(e,t,r){let i=function(e){const t=pp("ed25519 seed",e);return{key:t.subarray(0,32),chainCode:t.subarray(32)}}(hp(e,t));for(const n of[9777,0,r])i=yp(i.key,i.chainCode,n);return n.Buffer.from(i.key)}function vp(e,t,r){const i=function(e){return`-----BEGIN PRIVATE KEY-----\n${n.Buffer.concat([n.Buffer.from("302e020100300506032b657004220420","hex"),e]).toString("base64")}\n-----END PRIVATE KEY-----\n`}(gp(e,t??"",r));return{privateKeyPem:i,publicKeyX:dp(i)}}function mp(e){return vp(op,void 0,e)}function wp(e){const t=e.toString(16).padStart(64,"0");return n.Buffer.from(t,"hex")}function bp(e){return BigInt(`0x${e.toString("hex")}`)}function Sp(e,t){const r=o.createECDH("secp256k1");return r.setPrivateKey(e),r.getPublicKey(void 0,t?"compressed":"uncompressed")}function Ap(e,t,r){const i=pp(t,r>=sp?n.Buffer.concat([n.Buffer.from([0]),e,fp(r)]):n.Buffer.concat([Sp(e,!0),fp(r)])),o=bp(i.subarray(0,32));if(o>=ap)throw new Error(`invalid secp256k1 child tweak at index ${r}`);const s=(o+bp(e))%ap;if(0n===s)throw new Error(`invalid secp256k1 child key at index ${r}`);return{privateKey:wp(s),chainCode:i.subarray(32)}}function xp(e){return`m/44'/60'/0'/0/${e}`}function kp(e,t){if(0===t)return e&cp;const r=BigInt(t);return(e<<r|e>>64n-r)&cp}function Ep(e){for(const t of up){const r=new Array(5),i=new Array(5),n=new Array(25).fill(0n);for(let t=0;t<5;t+=1)r[t]=e[t]^e[t+5]^e[t+10]^e[t+15]^e[t+20];for(let e=0;e<5;e+=1)i[e]=r[(e+4)%5]^kp(r[(e+1)%5],1);for(let t=0;t<5;t+=1)for(let r=0;r<5;r+=1)e[t+5*r]=(e[t+5*r]^i[t])&cp;for(let t=0;t<5;t+=1)for(let r=0;r<5;r+=1)n[r+(2*t+3*r)%5*5]=kp(e[t+5*r],lp[t][r]);for(let t=0;t<5;t+=1)for(let r=0;r<5;r+=1)e[t+5*r]=(n[t+5*r]^~n[(t+1)%5+5*r]&cp&n[(t+2)%5+5*r])&cp;e[0]=(e[0]^t)&cp}}function Bp(e){const t=136,r=new Array(25).fill(0n),i=n.Buffer.concat([e,n.Buffer.from([1]),n.Buffer.alloc((t-(e.length+1)%t)%t)]);i[i.length-1]^=128;for(let n=0;n<i.length;n+=t){for(let e=0;e<t;e+=1)r[Math.floor(e/8)]^=BigInt(i[n+e])<<BigInt(e%8*8);Ep(r)}const o=n.Buffer.alloc(32);for(let n=0;n<o.length;n+=1)o[n]=Number(r[Math.floor(n/8)]>>BigInt(n%8*8)&0xffn);return o}function Np(e){const t=e.toString("hex"),r=Bp(n.Buffer.from(t,"ascii"));let i="0x";for(let n=0;n<t.length;n+=1){const e=t[n],o=r[Math.floor(n/2)]>>4*(1-n%2)&15;i+=/[a-f]/.test(e)&&o>7?e.toUpperCase():e}return i}function Tp(e,t,r){let i=function(e){const t=pp("Bitcoin seed",e),r=t.subarray(0,32),i=bp(r);if(i<=0n||i>=ap)throw new Error("invalid secp256k1 master key");return{privateKey:n.Buffer.from(r),chainCode:t.subarray(32)}}(hp(e,t??""));for(const n of function(e){return[2147483692,2147483708,sp,0,e]}(r))i=Ap(i.privateKey,i.chainCode,n);const o=Sp(i.privateKey,!1),s=Sp(i.privateKey,!0),a=Bp(o.subarray(1)),c=i.privateKey.toString("hex");return{derivationPath:xp(r),privateKey:`0x${c}`,privateKeyHex:c,publicKeyCompressedHex:s.toString("hex"),publicKeyUncompressedHex:o.toString("hex"),address:Np(a.subarray(12))}}function Ip(e){return Tp(op,void 0,e)}const Op={devtest:0,alice:1,bob:2,charlie:3,dave:4,sn_owner:5,devtests:5,"devtest.ood1":100,devtest_ood1:100,"devtest.node1":101,devtest_node1:101,"alice.ood1":102,alice_ood1:102,"bob.ood1":103,bob_ood1:103,"charlie.ood1":104,charlie_ood1:104,"dave.ood1":105,dave_ood1:105,sn:106,sn_server:106,"devtests.ood1":107,devtests_ood1:107,sn_web:107},Cp={alice:1,bob:2,charlie:3,dave:4},jp=Object.fromEntries(Object.entries(Op).map((([e,t])=>[e,mp(t)]))),_p=Object.fromEntries(Object.entries(Cp).map((([e,t])=>[e,Ip(t)]))),Dp=Ip(0);function Rp(e){const t=jp[e];if(!t)throw new Error(`unknown dev test key pair id: ${e}`);return t}const Pp=1743478939,Up=2058838939;function Lp(e){const t=e.split(".");return[Number(t[0])||0,Number(t[1])||0]}function $p(){var e,t,r,i;const n=globalThis,o=null==(t=null==(e=n.Deno)?void 0:e.version)?void 0:t.deno;if(o){const[e,t]=Lp(o);if(e>2||2===e&&t>=2)return;throw new Error(`buckyos provision requires Deno >= 2.2 (node:sqlite), current: ${o}`)}const s=null==(i=null==(r=n.process)?void 0:r.versions)?void 0:i.node;if(s){const[e,t]=Lp(s);if(e>22||22===e&&t>=13)return;throw new Error(`buckyos provision requires Node >= 22.13 (node:sqlite), current: ${s}`)}throw new Error("buckyos provision requires a Node >= 22.13 or Deno >= 2.2 runtime (browser is not supported)")}function Vp(e){$p();const t=globalThis.process;if("function"==typeof(null==t?void 0:t.getBuiltinModule)){const r=t.getBuiltinModule(e);if(r)return r}if("function"==typeof require)return require(e);throw new Error(`buckyos provision cannot load builtin module ${e} in this runtime`)}function Mp(e,t){const r=Vp("node:fs"),i=Vp("node:path");r.mkdirSync(i.dirname(e),{recursive:!0}),r.writeFileSync(e,t),console.log(`# Write file: ${e}`)}function Hp(e,t){Mp(e,JSON.stringify(t,null,2))}function Kp(e){const t=Vp("node:fs");return JSON.parse(t.readFileSync(e,"utf8"))}function Fp(e){if(Array.isArray(e))return e.map(Fp);if(null!==e&&"object"==typeof e){const t={};for(const r of Object.keys(e).sort())t[r]=Fp(e[r]);return t}return e}function zp(e,t){return t||(jp[e]?jp[e]:jp[`${e}.owner`]?jp[`${e}.owner`]:(console.log(`Warning: Key pair for user ${e} not found, using devtest key pair`),Rp("devtest")))}function Wp(e,t,r){return r||Rp(`${e}.${t}`)}function qp(e){const t=Vp("node:path");return new Jh(t.join(e,"local","identity"),t.join(e,"security"))}class Jp{constructor(e){$p(),this.dbPath=e}connect(){const{DatabaseSync:e}=Vp("node:sqlite");return new e(this.dbPath)}initializeDatabase(){const e=this.connect();try{e.exec("CREATE TABLE IF NOT EXISTS activation_codes (code TEXT PRIMARY KEY, used INTEGER);\n CREATE TABLE IF NOT EXISTS users (username TEXT PRIMARY KEY, state TEXT, public_key TEXT, activation_code TEXT, zone_config TEXT, self_cert boolean, user_domain TEXT, sn_ips TEXT);\n CREATE TABLE IF NOT EXISTS user_auth_v2 (username TEXT PRIMARY KEY, password_hash TEXT NOT NULL, password_salt TEXT NOT NULL, password_algo TEXT NOT NULL, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL, last_login_at INTEGER NULL);\n CREATE TABLE IF NOT EXISTS devices (owner TEXT, device_name TEXT, did TEXT PRIMARY KEY, ip TEXT, description TEXT, mini_config_jwt TEXT, created_at INTEGER, updated_at INTEGER);\n CREATE TABLE IF NOT EXISTS user_dns_records (id INTEGER PRIMARY KEY AUTOINCREMENT, owner TEXT, domain TEXT, record_type TEXT, record TEXT, ttl INTEGER, created_at INTEGER, updated_at INTEGER);\n CREATE UNIQUE INDEX IF NOT EXISTS idx_user_domain_record_type ON user_dns_records (owner, domain, record_type);\n CREATE INDEX IF NOT EXISTS user_dns_records_domain_index ON user_dns_records (domain, id);\n CREATE TABLE IF NOT EXISTS user_domain_history (domain TEXT PRIMARY KEY, owner TEXT NOT NULL, created_at INTEGER NOT NULL);\n CREATE TABLE IF NOT EXISTS did_documents (id INTEGER PRIMARY KEY AUTOINCREMENT, obj_id TEXT, owner_user TEXT, obj_name TEXT, did_document TEXT, doc_type TEXT, update_time INTEGER);\n CREATE INDEX IF NOT EXISTS idx_did_documents_owner_obj ON did_documents (owner_user, obj_name, update_time);")}finally{e.close()}}insertActivationCode(e){const t=this.connect();try{t.prepare("INSERT INTO activation_codes (code, used) VALUES (?, 0)").run(e)}finally{t.close()}}registerUserDirectly(e,t,r,i){const n=this.connect();try{n.prepare("INSERT INTO users (username, state, public_key, activation_code, zone_config, user_domain, self_cert, sn_ips) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run(e,"active",t,"DIRECT",r,i??null,1,null)}finally{n.close()}}registerDevice(e,t,r,n,o,s){const a=i.buckyosGetUnixTimestamp(),c=this.connect();try{c.prepare("INSERT INTO devices (owner, device_name, did, ip, description, mini_config_jwt, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run(e,t,r,o,s,n,a,a)}finally{c.close()}}}function Xp(){var e;const t=(null==(e=globalThis.process)?void 0:e.arch)??"";return"x64"===t?"amd64":"arm64"===t?"aarch64":t}function Gp(){var e;const t=(null==(e=globalThis.process)?void 0:e.platform)??"";return"darwin"===t?"apple":"win32"===t?"windows":t}function Yp(e){const t=e.search(/[-+]/),r=(t>=0?e.slice(0,t):e).split(".");if(r.length<1||r.length>4)throw new Error(`invalid version format: ${e}`);3===r.length&&t>=0&&r.push(e.slice(t));const i=e=>{if(void 0===e)return 0n;const t=e.replace(/^[^0-9]*/,"").match(/^\d+/);return t?BigInt(t[0]):0n},n=e=>void 0===e?0n:/^\d+$/.test(e)?BigInt(e):0n,o=i(r[0]);if(o>0xffn)throw new Error(`major version out of range: ${e}`);const s=n(r[1]);if(s>0xffffn)throw new Error(`minor version out of range: ${e}`);const a=n(r[2]);if(a>0xffffn)throw new Error(`patch version out of range: ${e}`);const c=i(r[3]);if(c>0xffffffn)throw new Error(`build number out of range: ${e}`);return o<<56n|s<<40n|a<<24n|c}function Zp(e){const t={...e},r=(e,r)=>{e in t&&r(t[e])&&delete t[e]};return r("did",(e=>null==e)),r("name",(e=>""===e)),r("author",(e=>""===e)),r("owner",(e=>null==e||"did:undefined:undefined"===e)),r("copyright",(e=>null==e)),r("tags",(e=>Array.isArray(e)&&0===e.length)),r("categories",(e=>Array.isArray(e)&&0===e.length)),r("base_on",(e=>null==e)),r("directory",(e=>e&&"object"==typeof e&&0===Object.keys(e).length)),r("references",(e=>e&&"object"==typeof e&&0===Object.keys(e).length)),r("exp",(e=>0===e)),r("size",(e=>0===e)),r("content",(e=>""===e)),r("version_tag",(e=>null==e)),r("deps",(e=>e&&"object"==typeof e&&0===Object.keys(e).length)),t}function Qp(e){const t=Zp(e),[r]=i.buildNamedObjectByJson("pkg",t);return r.toString()}class ef{constructor(e){$p(),this.dbPath=e}connect(){const{DatabaseSync:e}=Vp("node:sqlite");return new e(this.dbPath)}initializeDatabase(){const e=this.connect();try{e.exec("CREATE TABLE IF NOT EXISTS pkg_metas (\n metaobjid TEXT PRIMARY KEY,\n pkg_meta TEXT NOT NULL,\n author TEXT NOT NULL,\n author_pk TEXT NOT NULL,\n update_time INTEGER NOT NULL\n )"),e.exec("CREATE TABLE IF NOT EXISTS pkg_versions (\n pkg_name TEXT NOT NULL,\n author TEXT ,\n version TEXT NOT NULL,\n version_int INTEGER NOT NULL,\n metaobjid TEXT NOT NULL,\n tag TEXT,\n update_time INTEGER NOT NULL,\n PRIMARY KEY (pkg_name, version)\n )"),e.exec("CREATE TABLE IF NOT EXISTS author_info (\n author_name TEXT PRIMARY KEY,\n author_owner_config TEXT,\n author_zone_config TEXT\n )"),e.exec("CREATE INDEX IF NOT EXISTS idx_pkg_versions_pkgname ON pkg_versions (pkg_name)"),e.exec("CREATE INDEX IF NOT EXISTS idx_pkg_metas_author ON pkg_metas (author)"),e.exec("CREATE INDEX IF NOT EXISTS idx_pkg_versions_version_int ON pkg_versions (pkg_name, version_int)")}finally{e.close()}}addPkgMetaBatch(e){const t=this.connect();try{const n=i.buckyosGetUnixTimestamp();t.exec("BEGIN");try{for(const[r,i]of Object.entries(e)){t.prepare("INSERT OR REPLACE INTO pkg_metas (metaobjid, pkg_meta, author, author_pk, update_time) VALUES (?, ?, ?, ?, ?)").run(r,i.metaJwt,i.author,i.authorPk,n);const e=Yp(i.version);t.prepare("SELECT 1 FROM pkg_versions WHERE pkg_name = ? AND author = ? AND version = ?").get(i.pkgName,i.author,i.version)?t.prepare("UPDATE pkg_versions SET metaobjid = ?, tag = ?, update_time = ? WHERE pkg_name = ? AND author = ? AND version = ?").run(r,i.tag??null,n,i.pkgName,i.author,i.version):t.prepare("INSERT INTO pkg_versions (pkg_name, author, version, version_int, metaobjid, tag, update_time) VALUES (?, ?, ?, ?, ?, ?, ?)").run(i.pkgName,i.author,i.version,e,r,i.tag??null,n)}t.exec("COMMIT")}catch(r){throw t.exec("ROLLBACK"),r}}finally{t.close()}}}const tf=[{uniqueId:"verify-hub",showName:"Verify Hub",description:"Verify Hub",selectorType:"random"},{uniqueId:"scheduler",showName:"Scheduler",description:"Scheduler",selectorType:"single"},{uniqueId:"smb-service",showName:"Samba Service",description:"Samba Service",selectorType:"random"},{uniqueId:"msg-center",showName:"Message Center",description:"Message Center",selectorType:"single"},{uniqueId:"opendan",showName:"OpenDAN Runtime",description:"OpenDAN Runtime",selectorType:"single"},{uniqueId:"workflow",showName:"Workflow Service",description:"Workflow Service",selectorType:"single"}],rf="0.7.0";function nf(e){const t=e.split("_");return 2===t.length?i.DID.fromStr(`did:bns:${t[1]}.${t[0]}`):i.DID.fromStr(`did:bns:${e}`)}exports.NODE_IDENTITY_SCHEMA_V2=i.NODE_IDENTITY_SCHEMA_V2,exports.DEVICE_DOC_JWT_FILE_NAME=s,exports.DEVICE_MINI_DOC_JWT_FILE_NAME=a,exports.DEV_TEST_EVM_ACCOUNTS=_p,exports.DEV_TEST_EVM_SEED_SENDER=Dp,exports.DEV_TEST_EVM_SEED_SENDER_INDEX=0,exports.DEV_TEST_EVM_USER_INDEXES=Cp,exports.DEV_TEST_KEYS=jp,exports.DEV_TEST_KEY_INDEXES=Op,exports.DEV_TEST_MNEMONIC=op,exports.DevSnDb=Jp,exports.IDENTITY_MATERIALS=Rh,exports.IDENTITY_USAGES=Dh,exports.IdentityRoots=Jh,exports.KERNEL_SERVICE_DOC_VERSION=rf,exports.MetaIndexDb=ef,exports.NODE_GATEWAY_PARAMS_FILE_NAME=c,exports.PROVISION_BASE_TIME=Pp,exports.PROVISION_DEFAULT_EXP=Up,exports.assertProvisionRuntime=$p,exports.bindDeviceDocumentDid=g,exports.buildDeviceDid=y,exports.buildDidDocs=function(e,t){$p();const r=Vp("node:path"),n=(null==t?void 0:t.version)??rf,o=(null==t?void 0:t.now)??i.buckyosGetUnixTimestamp(),s=[];for(const i of tf){const t=nf(i.uniqueId),a=Fp({name:i.uniqueId,show_name:i.showName,version:n,author:"did:bns:buckyos",owner:"did:bns:buckyos",create_time:o,last_update_time:o,description:{detail:{en:i.description}},categories:["service"],selector_type:i.selectorType,install_config_tips:{data_mount_point:[],local_cache_mount_point:[],rdb_instances:{},service_ports:{}},pkg_list:{}}),c=r.join(e,`${t.toRawHostName()}.doc.json`);Hp(c,a),s.push(c)}return s},exports.calcPkgMetaObjId=Qp,exports.createCa=Zh,exports.createCertFromCa=async function(e,t,r,i){const n=Oh("node:fs"),o=Oh("node:path"),s=i&&i.length>0?i:[t],a=s[0].replace(/\*/g,"wildcard").replace(/\./g,"_");n.mkdirSync(r,{recursive:!0});const c=o.join(r,`${a}.crt`),u=o.join(r,`${a}.key`),l=await Qh(e,s);return n.writeFileSync(u,l.privateKeyPem),n.writeFileSync(c,l.certPem),console.log(`Certificate created: ${c}`),{certPath:c,keyPath:u}},exports.createIdentityCertFromCa=async function(e,t,r,i={}){const n=Oh("node:fs"),o=function(e){return e instanceof Jh?e:Jh.fromEnvOrBuckyosRoot(e)}(r),s=i.usage??"server",a=Mh(t),c=a.toRawHostUri(),u=Vh(c),l=o.publicDir(a.toString()),h=o.securityDir(a.toString()),p=qh(l,h,s),f=i.hostnames&&i.hostnames.length>0?i.hostnames:[rp(a)],d=i.uriSans??[a.toString()];n.mkdirSync(l,{recursive:!0,mode:493}),n.mkdirSync(h,{recursive:!0,mode:448});const y=await Qh(e,f,d,s),g=ep(y.certPem),v=ep(y.caCertPem),m=v,w=`${g}${m}`;var b,S,A;return tp(p.privateKey,y.privateKeyPem,384),tp(p.cert,g,420),tp(p.chain,m,420),tp(p.fullchain,w,420),tp(p.ca,v,420),b=p.metadata,S=await np(a,s,c,u,y),A=420,tp(b,`${JSON.stringify(S,null,2)}\n`,A),console.log(`Identity certificate created: ${p.fullchain}`),{did:a.toString(),rawHostUri:c,dirName:u,paths:p,certPath:p.cert,chainPath:p.chain,fullchainPath:p.fullchain,caPath:p.ca,keyPath:p.privateKey,metadataPath:p.metadata}},exports.createNodeConfigs=async function(e){$p();const t=Vp("node:path"),r=e.envDir,n=Kp(t.join(r,"user_config.json")).name;if("string"!=typeof n||!n)throw new Error("user_config.json missing name field");const o=Kp(t.join(r,"zone_config.json")),s=i.DID.fromStr(o.id),a=zp(n,e.ownerKeyPair),c=Wp(n,e.deviceName,e.deviceKeyPair),u=t.join(r,e.deviceName),l=new i.DID("bns",n),h=y(e.deviceName,s),f=v(e.deviceName,i.createJwkByX(c.publicKeyX),h,e.now);f.support_container=!0,delete f.support_container,void 0!==e.netId&&(f.net_id=e.netId),f.owner=l.toString(),f.zone_did=s.toString(),console.log(`input net_id: ${e.netId}, device_config.net_id: ${f.net_id}`);const d=await i.encodeDeviceDocument(f,a.privateKeyPem);console.log(`${e.deviceName} device jwt: ${d}`);const g=i.newDeviceMiniDocumentByDeviceDocument(f),m=await i.deviceMiniDocumentToJwt(g,a.privateKeyPem);Mp(t.join(u,"device_mini_config.jwt"),m);const w=p({zoneDid:s,ownerDid:l,ownerPublicKey:i.createJwkByX(a.publicKeyX),deviceName:e.deviceName,deviceDid:h,zoneIat:Pp});if(b(u,qp(u),w,f,d,m,c.privateKeyPem),e.deviceName.startsWith("ood")){const e=Fp({admin_password_hash:"o8XyToejrbCYou84h/VkF4Tht0BeQQbuX3XKG+8+GQ4=",device_private_key:c.privateKeyPem,device_public_key:i.createJwkByX(c.publicKeyX),ood_jwt:d,friend_passcode:"sdfsdfsdf",gateway_type:"PortForward",guest_access:!0,private_key:a.privateKeyPem,public_key:i.createJwkByX(a.publicKeyX),user_name:n,zone_name:s.toHostName(),BUCKYOS_ROOT:"/opt/buckyos"});Hp(t.join(u,"start_config.json"),e)}return console.log(`Successfully created node configuration: ${n}.${e.deviceName}`),i.encodeDeviceDocument(f,c.privateKeyPem)},exports.createSnConfigs=async function(e){$p();const t=Vp("node:path"),r=t.join(e.outputDir,"sn_server"),n=Rp("sn_owner"),o=Rp("sn_server"),s=Up;Mp(t.join(r,".buckycli","user_private_key.pem"),n.privateKeyPem);const a=i.newOwnerDocument({did:new i.DID("bns","sn"),name:"root",displayName:"sn admin",publicKeyJwk:i.createJwkByX(n.publicKeyX)});Hp(t.join(r,".buckycli","user_config.json"),i.ownerDocumentToOrderedJson(a)),console.log("- Created owner config for sn admin.");const c=i.newDeviceMiniDocument({name:"sn",x:o.publicKeyX,exp:s}),u=await i.deviceMiniDocumentToJwt(c,n.privateKeyPem),l=i.newDeviceDocumentByMiniDocument(u,c,"did:web:sn.devtests.org","did:bns:sn");l.net_id="wan",Hp(t.join(r,"sn_device_config.json"),i.deviceDocumentToOrderedJson(l)),Mp(t.join(r,"sn_private_key.pem"),o.privateKeyPem),console.log("- Created sn device config & private key.");const h=i.newZoneBootDocument({oods:["sn"],exp:s}),p=Fp({params:{sn_boot_jwt:await i.encodeZoneBootDocument(h,n.privateKeyPem),sn_owner_pk:n.publicKeyX,sn_device_jwt:u,sn_host:e.snBaseHost,sn_ip:e.snIp,sn_cer:"fullchain.cert",sn_pem:"fullchain.pem",web3_cer:"fullchain.cert",web3_pem:"fullchain.pem"}});Hp(t.join(r,"params.json"),p),console.log("- Created params.json.");const f=new Jp(t.join(r,"sn_db.sqlite3"));f.initializeDatabase();for(let i=0;i<9;i++){const e=`sndevtest${i}`;console.log(`insert activation code: ${e}`),f.insertActivationCode(e)}console.log("- Created SN database."),console.log("Successfully created SN configuration")},exports.createUserEnv=async function(e){$p();const t=Vp("node:path"),r=e.rtcpPort??2980,n=e.outputDir,o=Up,s=zp(e.username,e.ownerKeyPair),a=new i.DID("bns",e.username);let c,u=new i.DID("web",e.hostname);if(e.snBaseHost&&e.snBaseHost.includes(".")){const t=`web3.${e.snBaseHost}`;u=i.DID.fromHostNameByBridge(e.hostname,"bns",t),c=`sn.${e.snBaseHost}`}Mp(t.join(n,"user_private_key.pem"),s.privateKeyPem);const l=i.createJwkByX(s.publicKeyX),h=i.newOwnerDocument({did:a,name:e.username,displayName:e.username,publicKeyJwk:l});Hp(t.join(n,"user_config.json"),i.ownerDocumentToOrderedJson(h)),console.log(`Created owner config for ${e.username}`);const p=i.parseOODDescription(e.oodName),f=Wp(e.username,p.name,e.deviceKeyPair);let d,g=c;p.netId&&(p.netId.startsWith("wan")&&(g=void 0),p.netId.startsWith("wan_dyn")&&c&&(d=`https://${c}/kapi/sn`));const m=i.oodDescriptionToString(p),w=i.newZoneBootDocument({oods:[m],sn:g,exp:o}),b=u.toRawHostName();Hp(t.join(n,`${b}.zone.json`),w),w.id=u.toString();const S=i.newZoneDocument({id:u,ownerDid:a,publicKeyJwk:l}),A=await i.encodeZoneBootDocument(w,s.privateKeyPem);S.boot_jwt=A,S.id=w.id,S.oods=[...w.oods],void 0!==w.sn?S.sn=w.sn:delete S.sn,S.exp=w.exp,S.iat=w.exp-i.DEFAULT_EXPIRE_TIME,S.version_seq=0,S.owner=w.owner??i.DID.undefined().toString(),void 0!==w.owner_key&&(S.verificationMethod[0].publicKeyJwk=w.owner_key),Hp(t.join(n,"zone_config.json"),i.zoneDocumentToOrderedJson(S));const x=s.publicKeyX;console.log(`=> ${b} TXT Record(${A.length+6}): BOOT=${A};`),console.log(`=> ${b} TXT Record(${x.length+5}): PKX=${x};`);const k=2980===r?void 0:r,E=i.newDeviceMiniDocument({name:p.name,x:f.publicKeyX,rtcpPort:k,exp:o}),B=await i.deviceMiniDocumentToJwt(E,s.privateKeyPem);console.log(`=> ${b} TXT Record(${B.length+5}): DEV=${B};`);const N=y(p.name,u),T=v(p.name,i.createJwkByX(f.publicKeyX),N);T.support_container=!0,void 0!==p.netId&&(T.net_id=p.netId),T.owner=a.toString(),T.zone_did=u.toString(),void 0!==d&&(T.ddns_sn_url=d),console.log(`${p.name} device config: ${JSON.stringify(i.deviceDocumentToOrderedJson(T),null,2)}`);const I={boot_config_jwt:A,device_mini_doc_jwt:B,pkx:x};return Hp(t.join(n,"zone_txt_record.json"),I),console.log(`Successfully created user environment configuration: ${e.username}`),I},exports.decodeDeviceDocumentWithoutVerify=S,exports.deriveDevTestEvmAccount=Ip,exports.deriveDevTestEvmAccountFromMnemonic=Tp,exports.deriveDevTestKeyPair=mp,exports.deriveDevTestKeyPairFromMnemonic=vp,exports.devTestKeccak256=Bp,exports.deviceIdentityPathsForRoots=d,exports.didWebDocumentUrl=Fh,exports.encodeIdentityDirName=Vh,exports.ensureCa=async function(e,t="devtest"){const r=Oh("node:fs"),i=Oh("node:path"),n=i.join(e,`${t}_ca_cert.pem`),o=i.join(e,`${t}_ca_key.pem`);if(r.existsSync(n)&&r.existsSync(o)){const i=function(e){try{return Yh(new Th(e))}catch(t){return t instanceof Error?`cannot parse CA certificate: ${t.message}`:"cannot parse CA certificate"}}(r.readFileSync(n,"utf8"));return i?(console.log(`Existing CA at ${n} is invalid (${i}); regenerating`),Zh(e,t)):(console.log(`Use existing CA at: ${n}`),{caCertPath:n,caKeyPath:o})}return Zh(e,t)},exports.getDevTestEvmAccountByIndex=function(e){return Ip(e)},exports.getDevTestEvmAccountByUsername=function(e){const t=_p[e];if(!t)throw new Error(`no deterministic EVM account for seed user ${e}; register it in DEV_TEST_EVM_USER_INDEXES`);return t},exports.getDevTestKeyPairById=Rp,exports.getDevTestKeyPairByIndex=function(e){return mp(e)},exports.identityDirName=Kh,exports.identityFileName=zh,exports.identityRawHostUri=Hh,exports.loadDeviceDocJwtForRoots=m,exports.loadDeviceMiniDocJwtForRoots=function(e,t){return u("node:fs").readFileSync(d(e,t).deviceMiniDocJwt,"utf8")},exports.loadLocalDeviceDocumentForRoots=async function(e,t,r){const n=m(e,t.device_did),o=r?await i.verifyJwtEdDSA(n,t.owner_public_key):S(n);if(o.id!==t.device_did)throw new Error(`device_doc.jwt id ${o.id} does not match node_identity device_did ${t.device_did}`);return[n,o]},exports.loadLocalNodeIdentityConfig=f,exports.newDeviceDocumentByJwkWithDid=v,exports.newLocalNodeIdentityConfig=p,exports.nodeTestIdentityRoots=qp,exports.normalizePackageMetaForObjId=Zp,exports.registerDeviceToSn=async function(e,t,r,n){$p();const o=Vp("node:path"),s=Vp("node:fs"),a=Vp("node:os"),c=o.join(e,t,r),u=o.join(c,"node_identity.json");if(!s.existsSync(u))throw new Error(`Device config not found: ${u}`);const l=f(u),h=i.DID.fromStr(l.owner_did).id,p=d(qp(c),l.device_did),y=s.readFileSync(p.deviceDocJwt,"utf8"),g=s.readFileSync(p.deviceMiniDocJwt,"utf8"),v=await i.verifyJwtEdDSA(y,l.owner_public_key),m=v.id;let w;try{w=i.parseOODDescription(r)}catch{w={name:r,nodeType:"Device"}}try{const n=Kp(o.join(e,t,"zone_config.json")).oods.map(i.parseOODDescription).find((e=>e.name===r));n&&(w=n)}catch{}const b=function(){const e=[],t=Vp("node:os").networkInterfaces();for(const r of Object.values(t))for(const t of r??[])t.internal||"IPv6"===t.family&&t.address.startsWith("fe80")||e.includes(t.address)||e.push(t.address);return e}(),S={...v};w.ip&&(S.ips=[w.ip]),void 0!==w.netId&&(S.net_id=w.netId);const A={...S,arch:Xp(),os:Gp(),update_time:i.buckyosGetUnixTimestamp(),state:"Ready",sys_hostname:a.hostname(),base_os_info:`${a.type()} ${a.release()}`,all_ip:b,cpu_num:a.cpus().length,total_mem:a.totalmem(),mem_usage:a.totalmem()-a.freemem()};let x="127.0.0.1";b.length>0&&(x=b[0]),w.ip&&(x=w.ip),new Jp(n).registerDevice(h,r,m,g,x,JSON.stringify(A,null,2)),console.log(`Successfully registered device ${h}.${r} (DID: ${m}) to SN database at ${n}`)},exports.registerUserToSn=async function(e,t,r){$p();const n=Vp("node:path"),o=Kp(n.join(e,t,"user_config.json")).name;if("string"!=typeof o||!o)throw new Error("user_config.json missing name field");const s=Kp(n.join(e,t,"zone_config.json")),a=i.DID.fromStr(s.id);let c;"bns"!==a.method&&(c=a.toHostName());const u=Kp(n.join(e,t,"zone_txt_record.json")),l=new Jp(r),h=JSON.stringify(Fp({kty:"OKP",crv:"Ed25519",x:u.pkx}));l.registerUserDirectly(o,h,u.boot_config_jwt,c),console.log(`Successfully registered user ${o}@${t} to SN database at ${r}`)},exports.saveLocalDeviceIdentityForRoots=b,exports.saveNodeGatewayParams=w,exports.setPkgMeta=async function(e,t){$p();const r=Vp("node:fs");if(!r.existsSync(e))throw new Error(`meta_path ${e} does not exist`);if(!r.existsSync(t))throw new Error(`db_path ${t} does not exist`);const n=r.readFileSync(e,"utf8"),o=n.trimStart().startsWith("{")?JSON.parse(n):i.decodeJwtClaimWithoutVerify(n.trim()),s=Qp(o),a=new ef(t);return a.initializeDatabase(),a.addPkgMetaBatch({[s]:{metaJwt:n,pkgName:o.name,version:o.version,tag:o.version_tag??void 0,author:o.author,authorPk:""}}),s},exports.uniqueNameToDid=nf,exports.versionToInt=Yp;
|
|
91
|
+
const pu="crypto.algorithm";const hu="crypto.algorithmProvider";var du;uc.registerSingleton(hu,class{getAlgorithms(){return uc.resolveAll(pu)}toAsnAlgorithm(e){for(const t of this.getAlgorithms()){const r=t.toAsnAlgorithm(e);if(r)return r}if(/^[0-9.]+$/.test(e.name)){const t=new Fn({algorithm:e.name});if("parameters"in e){const r=e;t.parameters=r.parameters}return t}throw new Error("Cannot convert WebCrypto algorithm to ASN.1 algorithm")}toWebAlgorithm(e){for(const t of this.getAlgorithms()){const r=t.toWebAlgorithm(e);if(r)return r}return{name:e.algorithm,parameters:e.parameters}}});const fu="1.3.36.3.3.2.8.1.1",yu=`${fu}.1`,gu=`${fu}.2`,mu=`${fu}.3`,vu=`${fu}.4`,wu=`${fu}.5`,bu=`${fu}.6`,Su=`${fu}.7`,Au=`${fu}.8`,Eu=`${fu}.9`,ku=`${fu}.10`,xu=`${fu}.11`,_u=`${fu}.12`,Nu=`${fu}.13`,Iu=`${fu}.14`,Tu="brainpoolP160r1",Bu="brainpoolP160t1",Ou="brainpoolP192r1",Cu="brainpoolP192t1",Du="brainpoolP224r1",ju="brainpoolP224t1",Pu="brainpoolP256r1",Ru="brainpoolP256t1",Uu="brainpoolP320r1",$u="brainpoolP320t1",Mu="brainpoolP384r1",Lu="brainpoolP384t1",Vu="brainpoolP512r1",Hu="brainpoolP512t1",Ku="ECDSA";let Fu=du=class{toAsnAlgorithm(e){if(e.name.toLowerCase()===Ku.toLowerCase())if("hash"in e){switch(("string"==typeof e.hash?e.hash:e.hash.name).toLowerCase()){case"sha-1":return Js;case"sha-256":return qs;case"sha-384":return Gs;case"sha-512":return Xs}}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Ks;break;case"K-256":t=du.SECP256K1;break;case"P-384":t=Fs;break;case"P-521":t=zs;break;case Tu:t=yu;break;case Bu:t=gu;break;case Ou:t=mu;break;case Cu:t=vu;break;case Du:t=wu;break;case ju:t=bu;break;case Pu:t=Su;break;case Ru:t=Au;break;case Uu:t=Eu;break;case $u:t=ku;break;case Mu:t=xu;break;case Lu:t=_u;break;case Vu:t=Nu;break;case Hu:t=Iu}if(t)return new Fn({algorithm:Us,parameters:Kr.serialize(new ra({namedCurve:t}))})}return null}toWebAlgorithm(e){switch(e.algorithm){case $s:return{name:Ku,hash:{name:"SHA-1"}};case Ls:return{name:Ku,hash:{name:"SHA-256"}};case Vs:return{name:Ku,hash:{name:"SHA-384"}};case Hs:return{name:Ku,hash:{name:"SHA-512"}};case Us:if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(Kr.parse(e.parameters,ra).namedCurve){case Ks:return{name:Ku,namedCurve:"P-256"};case du.SECP256K1:return{name:Ku,namedCurve:"K-256"};case Fs:return{name:Ku,namedCurve:"P-384"};case zs:return{name:Ku,namedCurve:"P-521"};case yu:return{name:Ku,namedCurve:Tu};case gu:return{name:Ku,namedCurve:Bu};case mu:return{name:Ku,namedCurve:Ou};case vu:return{name:Ku,namedCurve:Cu};case wu:return{name:Ku,namedCurve:Du};case bu:return{name:Ku,namedCurve:ju};case Su:return{name:Ku,namedCurve:Pu};case Au:return{name:Ku,namedCurve:Ru};case Eu:return{name:Ku,namedCurve:Uu};case ku:return{name:Ku,namedCurve:$u};case xu:return{name:Ku,namedCurve:Mu};case _u:return{name:Ku,namedCurve:Lu};case Nu:return{name:Ku,namedCurve:Vu};case Iu:return{name:Ku,namedCurve:Hu}}}return null}};Fu.SECP256K1="1.3.132.0.10",Fu=du=Fr([lc()],Fu),uc.registerSingleton(pu,Fu);const zu=Symbol("name"),Wu=Symbol("value");class Ju{constructor(e,t={},r=""){this[zu]=e,this[Wu]=r;for(const i in t)this[i]=t[i]}}Ju.NAME=zu,Ju.VALUE=Wu;class qu{static toString(e){const t=this.items[e];return t||e}}qu.items={[wa]:"sha1",[ba]:"sha224",[Sa]:"sha256",[Aa]:"sha384",[Ea]:"sha512",[sa]:"rsaEncryption",[ha]:"sha1WithRSAEncryption",[da]:"sha224WithRSAEncryption",[fa]:"sha256WithRSAEncryption",[ya]:"sha384WithRSAEncryption",[ga]:"sha512WithRSAEncryption",[Us]:"ecPublicKey",[$s]:"ecdsaWithSHA1",[Ms]:"ecdsaWithSHA224",[Ls]:"ecdsaWithSHA256",[Vs]:"ecdsaWithSHA384",[Hs]:"ecdsaWithSHA512",[sn]:"TLS WWW server authentication",[an]:"TLS WWW client authentication",[cn]:"Code Signing",[un]:"E-mail Protection",[ln]:"Time Stamping",[pn]:"OCSP Signing",[Ds]:"Signed Data"};class Gu{static serialize(e){return this.serializeObj(e).join("\n")}static pad(e=0){return"".padStart(2*e," ")}static serializeObj(e,t=0){const r=[];let i=this.pad(t++),n="";const o=e[Ju.VALUE];o&&(n=` ${o}`),r.push(`${i}${e[Ju.NAME]}:${n}`),i=this.pad(t);for(const s in e){if("symbol"==typeof s)continue;const n=e[s],o=s?`${s}: `:"";if("string"==typeof n||"number"==typeof n||"boolean"==typeof n)r.push(`${i}${o}${n}`);else if(n instanceof Date)r.push(`${i}${o}${n.toUTCString()}`);else if(Array.isArray(n))for(const e of n)e[Ju.NAME]=s,r.push(...this.serializeObj(e,t));else if(n instanceof Ju)n[Ju.NAME]=s,r.push(...this.serializeObj(n,t));else if(k.isBufferSource(n))s?(r.push(`${i}${o}`),r.push(...this.serializeBufferSource(n,t+1))):r.push(...this.serializeBufferSource(n,t));else{if(!("toTextObject"in n))throw new TypeError("Cannot serialize data in text format. Unsupported type.");{const e=n.toTextObject();e[Ju.NAME]=s,r.push(...this.serializeObj(e,t))}}}return r}static serializeBufferSource(e,t=0){const r=this.pad(t),i=k.toUint8Array(e),n=[];for(let o=0;o<i.length;){const e=[];for(let t=0;t<16&&o<i.length;t++){8===t&&e.push("");const r=i[o++].toString(16).padStart(2,"0");e.push(r)}n.push(`${r}${e.join(" ")}`)}return n}static serializeAlgorithm(e){return this.algorithmSerializer.toTextObject(e)}}var Xu,Yu;Gu.oidSerializer=qu,Gu.algorithmSerializer=class{static toTextObject(e){const t=new Ju("Algorithm Identifier",{},qu.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case Us:{const r=(new Fu).toWebAlgorithm(e);r&&"namedCurve"in r?t["Named Curve"]=r.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}};class Zu{get rawData(){return zr(this,Xu,"f")||Wr(this,Xu,Kr.serialize(this.asn),"f"),zr(this,Xu,"f")}constructor(...e){Xu.set(this,void 0),k.isBufferSource(e[0])?(this.asn=Kr.parse(e[0],e[1]),Wr(this,Xu,k.toArrayBuffer(e[0]),"f"),this.onInit(this.asn)):(this.asn=e[0],this.onInit(this.asn))}equal(e){return e instanceof Zu&&function(e,t){if(!e||!t)return!1;if(e.byteLength!==t.byteLength)return!1;const r=new Uint8Array(e),i=new Uint8Array(t);for(let n=0;n<e.byteLength;n++)if(r[n]!==i[n])return!1;return!0}(e.rawData,this.rawData)}toString(e="text"){switch(e){case"asn":return Kr.toString(this.rawData);case"text":return Gu.serialize(this.toTextObject());case"hex":return O.ToHex(this.rawData);case"base64":return O.ToBase64(this.rawData);case"base64url":return O.ToBase64Url(this.rawData);default:throw TypeError("Argument 'format' is unsupported value")}}getTextName(){return this.constructor.NAME}toTextObject(){const e=this.toTextObjectEmpty();return e[""]=this.rawData,e}toTextObjectEmpty(e){return new Ju(this.getTextName(),{},e)}}Xu=new WeakMap,Zu.NAME="ASN";class Qu extends Zu{constructor(...e){let t;t=k.isBufferSource(e[0])?k.toArrayBuffer(e[0]):Kr.serialize(new Gn({extnID:e[0],critical:e[1],extnValue:new sr(k.toArrayBuffer(e[2]))})),super(t,Gn)}onInit(e){this.type=e.extnID,this.critical=e.critical,this.value=e.extnValue.buffer}toTextObject(){const e=this.toTextObjectWithoutValue();return e[""]=this.value,e}toTextObjectWithoutValue(){const e=this.toTextObjectEmpty(this.critical?"critical":void 0);return e[Ju.NAME]===Qu.NAME&&(e[Ju.NAME]=qu.toString(this.type)),e}}class el{static isCryptoKeyPair(e){return e&&e.privateKey&&e.publicKey}static isCryptoKey(e){return e&&e.usages&&e.type&&e.algorithm&&void 0!==e.extractable}constructor(){this.items=new Map,this[Yu]="CryptoProvider","undefined"!=typeof self&&"undefined"!=typeof crypto?this.set(el.DEFAULT,crypto):"undefined"!=typeof global&&global.crypto&&global.crypto.subtle&&this.set(el.DEFAULT,global.crypto)}clear(){this.items.clear()}delete(e){return this.items.delete(e)}forEach(e,t){return this.items.forEach(e,t)}has(e){return this.items.has(e)}get size(){return this.items.size}entries(){return this.items.entries()}keys(){return this.items.keys()}values(){return this.items.values()}[Symbol.iterator](){return this.items[Symbol.iterator]()}get(e=el.DEFAULT){const t=this.items.get(e.toLowerCase());if(!t)throw new Error(`Cannot get Crypto by name '${e}'`);return t}set(e,t){if("string"==typeof e){if(!t)throw new TypeError("Argument 'value' is required");this.items.set(e.toLowerCase(),t)}else this.items.set(el.DEFAULT,e);return this}}Yu=Symbol.toStringTag,el.DEFAULT="default";const tl=new el,rl=/^[0-2](?:\.[1-9][0-9]*)+$/;class il{constructor(e={}){this.items={};for(const t in e)this.register(t,e[t])}get(e){return this.items[e]||null}findId(e){return t=e,new RegExp(rl).test(t)?e:this.get(e);var t}register(e,t){this.items[e]=t,this.items[t]=e}}const nl=new il;function ol(e,t){return`\\${O.ToHex(O.FromUtf8String(t)).toUpperCase()}`}nl.register("CN","2.5.4.3"),nl.register("L","2.5.4.7"),nl.register("ST","2.5.4.8"),nl.register("O","2.5.4.10"),nl.register("OU","2.5.4.11"),nl.register("C","2.5.4.6"),nl.register("DC","0.9.2342.19200300.100.1.25"),nl.register("E","1.2.840.113549.1.9.1"),nl.register("G","2.5.4.42"),nl.register("I","2.5.4.43"),nl.register("SN","2.5.4.4"),nl.register("T","2.5.4.12");class sl{static isASCII(e){for(let t=0;t<e.length;t++){if(e.charCodeAt(t)>255)return!1}return!0}static isPrintableString(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/g.test(e)}constructor(e,t={}){this.extraNames=new il,this.asn=new ni;for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)){const e=t[r];this.extraNames.register(r,e)}"string"==typeof e?this.asn=this.fromString(e):e instanceof ni?this.asn=e:k.isBufferSource(e)?this.asn=Kr.parse(e,ni):this.asn=this.fromJSON(e)}getField(e){const t=this.extraNames.findId(e)||nl.findId(e),r=[];for(const i of this.asn)for(const e of i)e.type===t&&r.push(e.value.toString());return r}getName(e){return this.extraNames.get(e)||nl.get(e)}toString(){return this.asn.map((e=>e.map((e=>`${this.getName(e.type)||e.type}=${e.value.anyValue?`#${O.ToHex(e.value.anyValue)}`:e.value.toString().replace(/([,+"\\<>;])/g,"\\$1").replace(/^([ #])/,"\\$1").replace(/([ ]$)/,"\\$1").replace(/([\r\n\t])/,ol)}`)).join("+"))).join(", ")}toJSON(){var e;const t=[];for(const r of this.asn){const i={};for(const t of r){const r=this.getName(t.type)||t.type;null!==(e=i[r])&&void 0!==e||(i[r]=[]),i[r].push(t.value.anyValue?`#${O.ToHex(t.value.anyValue)}`:t.value.toString())}t.push(i)}return t}fromString(e){const t=new ni,r=/(\d\.[\d.]*\d|[A-Za-z]+)=((?:"")|(?:".*?[^\\]")|(?:[^,+"\\](?=[,+]|$))|(?:[^,+].*?(?:[^\\][,+]))|(?:))([,+])?/g;let i=null,n=",";for(;i=r.exec(`${e},`);){let[,e,r]=i;const o=r[r.length-1];","!==o&&"+"!==o||(r=r.slice(0,r.length-1),i[3]=o);const s=i[3];e=this.getTypeOid(e);const a=this.createAttribute(e,r);"+"===n?t[t.length-1].push(a):t.push(new ri([a])),n=s}return t}fromJSON(e){const t=new ni;for(const r of e){const e=new ri;for(const t in r){const i=this.getTypeOid(t),n=r[t];for(const t of n){const r=this.createAttribute(i,t);e.push(r)}}t.push(e)}return t}getTypeOid(e){if(/[\d.]+/.test(e)||(e=this.getName(e)||""),!e)throw new Error(`Cannot get OID for name type '${e}'`);return e}createAttribute(e,t){const r=new ti({type:e});if("object"==typeof t)for(const i in t)switch(i){case"ia5String":r.value.ia5String=t[i];break;case"utf8String":r.value.utf8String=t[i];break;case"universalString":r.value.universalString=t[i];break;case"bmpString":r.value.bmpString=t[i];break;case"printableString":r.value.printableString=t[i]}else if("#"===t[0])r.value.anyValue=O.FromHex(t.slice(1));else{const i=this.processStringValue(t);e===this.getName("E")||e===this.getName("DC")?r.value.ia5String=i:sl.isPrintableString(i)?r.value.printableString=i:r.value.utf8String=i}return r}processStringValue(e){const t=/"(.*?[^\\])?"/.exec(e);return t&&(e=t[1]),e.replace(/\\0a/gi,"\n").replace(/\\0d/gi,"\r").replace(/\\0g/gi,"\t").replace(/\\(.)/g,"$1")}toArrayBuffer(){return Kr.serialize(this.asn)}async getThumbprint(...e){var t;let r,i="SHA-1";return e.length>=1&&!(null===(t=e[0])||void 0===t?void 0:t.subtle)?(i=e[0]||i,r=e[1]||tl.get()):r=e[0]||tl.get(),await r.subtle.digest(i,this.toArrayBuffer())}}const al="Cannot initialize GeneralName from ASN.1 data.",cl=`${al} Unsupported string format in use.`,ul=`${al} Value doesn't match to GUID regular expression.`,ll=/^([0-9a-f]{8})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{4})-?([0-9a-f]{12})$/i,pl="1.3.6.1.4.1.311.25.1",hl="1.3.6.1.4.1.311.20.2.3",dl="dns",fl="dn",yl="email",gl="ip",ml="url",vl="guid",wl="upn",bl="id";class Sl extends Zu{constructor(...e){let t;if(2===e.length)switch(e[0]){case fl:{const r=new sl(e[1]).toArrayBuffer(),i=Kr.parse(r,ni);t=new ci({directoryName:i});break}case dl:t=new ci({dNSName:e[1]});break;case yl:t=new ci({rfc822Name:e[1]});break;case vl:{const r=new RegExp(ll,"i").exec(e[1]);if(!r)throw new Error("Cannot parse GUID value. Value doesn't match to regular expression");const i=r.slice(1).map(((e,t)=>t<3?O.ToHex(new Uint8Array(O.FromHex(e)).reverse()):e)).join("");t=new ci({otherName:new si({typeId:pl,value:Kr.serialize(new sr(O.FromHex(i)))})});break}case gl:t=new ci({iPAddress:e[1]});break;case bl:t=new ci({registeredID:e[1]});break;case wl:t=new ci({otherName:new si({typeId:hl,value:Kr.serialize(mr.toASN(e[1]))})});break;case ml:t=new ci({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else t=k.isBufferSource(e[0])?Kr.parse(e[0],ci):e[0];super(t)}onInit(e){if(null!=e.dNSName)this.type=dl,this.value=e.dNSName;else if(null!=e.rfc822Name)this.type=yl,this.value=e.rfc822Name;else if(null!=e.iPAddress)this.type=gl,this.value=e.iPAddress;else if(null!=e.uniformResourceIdentifier)this.type=ml,this.value=e.uniformResourceIdentifier;else if(null!=e.registeredID)this.type=bl,this.value=e.registeredID;else if(null!=e.directoryName)this.type=fl,this.value=new sl(e.directoryName).toString();else{if(null==e.otherName)throw new Error(cl);if(e.otherName.typeId===pl){this.type=vl;const t=Kr.parse(e.otherName.value,sr),r=new RegExp(ll,"i").exec(O.ToHex(t));if(!r)throw new Error(ul);this.value=r.slice(1).map(((e,t)=>t<3?O.ToHex(new Uint8Array(O.FromHex(e)).reverse()):e)).join("-")}else{if(e.otherName.typeId!==hl)throw new Error(cl);this.type=wl,this.value=Kr.parse(e.otherName.value,Qr).toString()}}}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case fl:case dl:case vl:case gl:case bl:case wl:case ml:e=this.type.toUpperCase();break;case yl:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===bl&&(t=qu.toString(t)),new Ju(e,void 0,t)}}class Al extends Zu{constructor(e){let t;if(e instanceof Ni)t=e;else if(Array.isArray(e)){const r=[];for(const t of e)if(t instanceof ci)r.push(t);else{const e=Kr.parse(new Sl(t.type,t.value).rawData,ci);r.push(e)}t=new Ni(r)}else{if(!k.isBufferSource(e))throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");t=Kr.parse(e,Ni)}super(t)}onInit(e){const t=[];for(const r of e){let e=null;try{e=new Sl(r)}catch{continue}t.push(e)}this.items=t}toJSON(){return this.items.map((e=>e.toJSON()))}toTextObject(){const e=super.toTextObjectEmpty();for(const t of this.items){const r=t.toTextObject();let i=e[r[Ju.NAME]];Array.isArray(i)||(i=[],e[r[Ju.NAME]]=i),i.push(r)}return e}}Al.NAME="GeneralNames";const El="-{5}",kl="\\n",xl="\\n",_l=`${`${El}BEGIN (${`[^${kl}]+`}(?=${El}))${El}`}${xl}(?:((?:${`[^:${kl}]+`}: ${`(?:[^${kl}]+${xl}(?: +[^${kl}]+${xl})*)`})+))?${xl}?(${`(?:[a-zA-Z0-9=+/]+${xl})+`})${`${El}END \\1${El}`}`;class Nl{static isPem(e){return"string"==typeof e&&new RegExp(_l,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");const t=new RegExp(_l,"g"),r=[];let i=null;for(;i=t.exec(e);){const e=i[3].replace(new RegExp(`[${kl}]+`,"g"),""),t={type:i[1],headers:[],rawData:O.FromBase64(e)},n=i[2];if(n){const e=n.split(new RegExp(xl,"g"));let r=null;for(const i of e){const[e,n]=i.split(/:(.*)/);if(void 0===n){if(!r)throw new Error("Cannot parse PEM string. Incorrect header value");r.value+=e.trim()}else r&&t.headers.push(r),r={key:e,value:n.trim()}}r&&t.headers.push(r)}r.push(t)}return r}static decode(e){return this.decodeWithHeaders(e).map((e=>e.rawData))}static decodeFirst(e){const t=this.decode(e);if(!t.length)throw new RangeError("PEM string doesn't contain any objects");return t[0]}static encode(e,t){if(Array.isArray(e)){const r=new Array;return t?e.forEach((e=>{if(!k.isBufferSource(e))throw new TypeError("Cannot encode array of BufferSource in PEM format. Not all items of the array are BufferSource");r.push(this.encodeStruct({type:t,rawData:k.toArrayBuffer(e)}))})):e.forEach((e=>{if(!("type"in e))throw new TypeError("Cannot encode array of PemStruct in PEM format. Not all items of the array are PemStrut");r.push(this.encodeStruct(e))})),r.join("\n")}if(!t)throw new Error("Required argument 'tag' is missed");return this.encodeStruct({type:t,rawData:k.toArrayBuffer(e)})}static encodeStruct(e){var t;const r=e.type.toLocaleUpperCase(),i=[];if(i.push(`-----BEGIN ${r}-----`),null===(t=e.headers)||void 0===t?void 0:t.length){for(const t of e.headers)i.push(`${t.key}: ${t.value}`);i.push("")}const n=O.ToBase64(e.rawData);let o,s=0;const a=Array();for(;s<n.length&&(n.length-s<64?o=n.substring(s):(o=n.substring(s,s+64),s+=64),0!==o.length)&&(a.push(o),!(o.length<64)););return i.push(...a),i.push(`-----END ${r}-----`),i.join("\n")}}Nl.CertificateTag="CERTIFICATE",Nl.CrlTag="CRL",Nl.CertificateRequestTag="CERTIFICATE REQUEST",Nl.PublicKeyTag="PUBLIC KEY",Nl.PrivateKeyTag="PRIVATE KEY";class Il extends Zu{static isAsnEncoded(e){return k.isBufferSource(e)||"string"==typeof e}static toArrayBuffer(e){if("string"==typeof e){if(Nl.isPem(e))return Nl.decode(e)[0];if(O.isHex(e))return O.FromHex(e);if(O.isBase64(e))return O.FromBase64(e);if(O.isBase64Url(e))return O.FromBase64Url(e);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}{const t=k.toUint8Array(e);if(t.length>0&&48===t[0])return k.toArrayBuffer(e);const r=O.ToBinary(e);if(Nl.isPem(r))return Nl.decode(r)[0];if(O.isHex(r))return O.FromHex(r);if(O.isBase64(r))return O.FromBase64(r);if(O.isBase64Url(r))return O.FromBase64Url(r);throw new TypeError("Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url")}}constructor(...e){Il.isAsnEncoded(e[0])?super(Il.toArrayBuffer(e[0]),e[1]):super(e[0])}toString(e="pem"){return"pem"===e?Nl.encode(this.rawData,this.tag):super.toString(e)}}class Tl extends Il{static async create(e,t=tl.get()){if(e instanceof Tl)return e;if(el.isCryptoKey(e)){if("public"!==e.type)throw new TypeError("Public key is required");const r=await t.subtle.exportKey("spki",e);return new Tl(r)}if(e.publicKey)return e.publicKey;if(k.isBufferSource(e))return new Tl(e);throw new TypeError("Unsupported PublicKeyType")}constructor(e){Il.isAsnEncoded(e)?super(e,zn):super(e),this.tag=Nl.PublicKeyTag}async export(...e){let t,r=["verify"],i={hash:"SHA-256",...this.algorithm};e.length>1?(i=e[0]||i,r=e[1]||r,t=e[2]||tl.get()):t=e[0]||tl.get();let n=this.rawData;const o=Kr.parse(this.rawData,zn);return o.algorithm.algorithm===ua&&(n=function(e,t){return e.algorithm=new Fn({algorithm:sa,parameters:null}),t=Kr.serialize(e),t}(o,n)),t.subtle.importKey("spki",n,i,!0,r)}onInit(e){const t=uc.resolve(hu),r=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case sa:{const t=Kr.parse(e.subjectPublicKey,Ra),i=k.toUint8Array(t.modulus);r.publicExponent=k.toUint8Array(t.publicExponent),r.modulusLength=(i[0]?i:i.slice(1)).byteLength<<3;break}}}async getThumbprint(...e){var t;let r,i="SHA-1";return e.length>=1&&!(null===(t=e[0])||void 0===t?void 0:t.subtle)?(i=e[0]||i,r=e[1]||tl.get()):r=e[0]||tl.get(),await r.subtle.digest(i,this.rawData)}async getKeyIdentifier(...e){let t,r="SHA-1";1===e.length?"string"==typeof e[0]?(r=e[0],t=tl.get()):t=e[0]:2===e.length?(r=e[0],t=e[1]):t=tl.get();const i=Kr.parse(this.rawData,zn);return await t.subtle.digest(r,i.subjectPublicKey)}toTextObject(){const e=this.toTextObjectEmpty(),t=Kr.parse(this.rawData,zn);if(e.Algorithm=Gu.serializeAlgorithm(t.algorithm),t.algorithm.algorithm===Us)e["EC Point"]=t.subjectPublicKey;else e["Raw Data"]=t.subjectPublicKey;return e}}class Bl extends Qu{static async create(e,t=!1,r=tl.get()){if("name"in e&&"serialNumber"in e)return new Bl(e,t);const i=await Tl.create(e,r),n=await i.getKeyIdentifier(r);return new Bl(O.ToHex(n),t)}constructor(...e){if(k.isBufferSource(e[0]))super(e[0]);else if("string"==typeof e[0]){const t=new Ei({keyIdentifier:new Ai(O.FromHex(e[0]))});super(Si,e[1],Kr.serialize(t))}else{const t=e[0],r=t.name instanceof Al?Kr.parse(t.name.rawData,Ni):t.name,i=new Ei({authorityCertIssuer:r,authorityCertSerialNumber:O.FromHex(t.serialNumber)});super(Si,e[1],Kr.serialize(i))}}onInit(e){super.onInit(e);const t=Kr.parse(e.extnValue,Ei);t.keyIdentifier&&(this.keyId=O.ToHex(t.keyIdentifier)),(t.authorityCertIssuer||t.authorityCertSerialNumber)&&(this.certId={name:t.authorityCertIssuer||[],serialNumber:t.authorityCertSerialNumber?O.ToHex(t.authorityCertSerialNumber):""})}toTextObject(){const e=this.toTextObjectWithoutValue(),t=Kr.parse(this.value,Ei);return t.authorityCertIssuer&&(e["Authority Issuer"]=new Al(t.authorityCertIssuer).toTextObject()),t.authorityCertSerialNumber&&(e["Authority Serial Number"]=t.authorityCertSerialNumber),t.keyIdentifier&&(e[""]=t.keyIdentifier),e}}Bl.NAME="Authority Key Identifier";class Ol extends Qu{constructor(...e){if(k.isBufferSource(e[0])){super(e[0]);const t=Kr.parse(this.value,xi);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{const t=new xi({cA:e[0],pathLenConstraint:e[1]});super(ki,e[2],Kr.serialize(t)),this.ca=e[0],this.pathLength=e[1]}}toTextObject(){const e=this.toTextObjectWithoutValue();return this.ca&&(e.CA=this.ca),void 0!==this.pathLength&&(e["Path Length"]=this.pathLength),e}}var Cl,Dl,jl;Ol.NAME="Basic Constraints",(Dl=Cl||(Cl={})).serverAuth="1.3.6.1.5.5.7.3.1",Dl.clientAuth="1.3.6.1.5.5.7.3.2",Dl.codeSigning="1.3.6.1.5.5.7.3.3",Dl.emailProtection="1.3.6.1.5.5.7.3.4",Dl.timeStamping="1.3.6.1.5.5.7.3.8",Dl.ocspSigning="1.3.6.1.5.5.7.3.9";class Pl extends Qu{constructor(...e){if(k.isBufferSource(e[0])){super(e[0]);const t=Kr.parse(this.value,on);this.usages=t.map((e=>e))}else{const t=new on(e[0]);super(nn,e[1],Kr.serialize(t)),this.usages=e[0]}}toTextObject(){const e=this.toTextObjectWithoutValue();return e[""]=this.usages.map((e=>qu.toString(e))).join(", "),e}}Pl.NAME="Extended Key Usages",function(e){e[e.digitalSignature=1]="digitalSignature",e[e.nonRepudiation=2]="nonRepudiation",e[e.keyEncipherment=4]="keyEncipherment",e[e.dataEncipherment=8]="dataEncipherment",e[e.keyAgreement=16]="keyAgreement",e[e.keyCertSign=32]="keyCertSign",e[e.cRLSign=64]="cRLSign",e[e.encipherOnly=128]="encipherOnly",e[e.decipherOnly=256]="decipherOnly"}(jl||(jl={}));class Rl extends Qu{constructor(...e){if(k.isBufferSource(e[0])){super(e[0]);const t=Kr.parse(this.value,Sn);this.usages=t.toNumber()}else{const t=new Sn(e[0]);super(mn,e[1],Kr.serialize(t)),this.usages=e[0]}}toTextObject(){const e=this.toTextObjectWithoutValue(),t=Kr.parse(this.value,Sn);return e[""]=t.toJSON().join(", "),e}}Rl.NAME="Key Usages";class Ul extends Qu{static async create(e,t=!1,r=tl.get()){const i=await Tl.create(e,r),n=await i.getKeyIdentifier(r);return new Ul(O.ToHex(n),t)}constructor(...e){if(k.isBufferSource(e[0])){super(e[0]);const t=Kr.parse(this.value,Rn);this.keyId=O.ToHex(t)}else{const t="string"==typeof e[0]?O.FromHex(e[0]):e[0],r=new Rn(t);super(Pn,e[1],Kr.serialize(r)),this.keyId=O.ToHex(t)}}toTextObject(){const e=this.toTextObjectWithoutValue(),t=Kr.parse(this.value,Rn);return e[""]=t,e}}Ul.NAME="Subject Key Identifier";class $l extends Qu{constructor(...e){k.isBufferSource(e[0])?super(e[0]):super(Bn,e[1],new Al(e[0]||[]).rawData)}onInit(e){super.onInit(e);const t=Kr.parse(e.extnValue,On);this.names=new Al(t)}toTextObject(){const e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(const r in t)e[r]=t[r];return e}}$l.NAME="Subject Alternative Name";class Ml{static register(e,t){this.items.set(e,t)}static create(e){const t=new Qu(e),r=this.items.get(t.type);return r?new r(e):t}}Ml.items=new Map;class Ll extends Qu{constructor(...e){var t;if(k.isBufferSource(e[0])){super(e[0]);const t=Kr.parse(this.value,$i);this.policies=t.map((e=>e.policyIdentifier))}else{const r=e[0],i=null!==(t=e[1])&&void 0!==t&&t,n=new $i(r.map((e=>new Ui({policyIdentifier:e}))));super(Oi,i,Kr.serialize(n)),this.policies=r}}toTextObject(){const e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map((e=>new Ju("",{},qu.toString(e)))),e}}Ll.NAME="Certificate Policies",Ml.register(Oi,Ll);class Vl extends Qu{constructor(...e){var t;if(k.isBufferSource(e[0]))super(e[0]);else if(Array.isArray(e[0])&&"string"==typeof e[0][0]){const t=e[0].map((e=>new Ji({distributionPoint:new Wi({fullName:[new ci({uniformResourceIdentifier:e})]})}))),r=new qi(t);super(Hi,e[1],Kr.serialize(r))}else{const t=new qi(e[0]);super(Hi,e[1],Kr.serialize(t))}null!==(t=this.distributionPoints)&&void 0!==t||(this.distributionPoints=[])}onInit(e){super.onInit(e);const t=Kr.parse(e.extnValue,qi);this.distributionPoints=t}toTextObject(){const e=this.toTextObjectWithoutValue();return e["Distribution Point"]=this.distributionPoints.map((e=>{var t;const r={};return e.distributionPoint&&(r[""]=null===(t=e.distributionPoint.fullName)||void 0===t?void 0:t.map((e=>new Sl(e).toString())).join(", ")),e.reasons&&(r.Reasons=e.reasons.toString()),e.cRLIssuer&&(r["CRL Issuer"]=e.cRLIssuer.map((e=>e.toString())).join(", ")),r})),e}}Vl.NAME="CRL Distribution Points";class Hl extends Qu{constructor(...e){var t,r,i,n;if(k.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof bi){const t=new bi(e[0]);super(vi,e[1],Kr.serialize(t))}else{const t=e[0],r=new bi;Fl(r,t,hi,"ocsp"),Fl(r,t,di,"caIssuers"),Fl(r,t,fi,"timeStamping"),Fl(r,t,yi,"caRepository"),super(vi,e[1],Kr.serialize(r))}null!==(t=this.ocsp)&&void 0!==t||(this.ocsp=[]),null!==(r=this.caIssuers)&&void 0!==r||(this.caIssuers=[]),null!==(i=this.timeStamping)&&void 0!==i||(this.timeStamping=[]),null!==(n=this.caRepository)&&void 0!==n||(this.caRepository=[])}onInit(e){super.onInit(e),this.ocsp=[],this.caIssuers=[],this.timeStamping=[],this.caRepository=[];Kr.parse(e.extnValue,bi).forEach((e=>{switch(e.accessMethod){case hi:this.ocsp.push(new Sl(e.accessLocation));break;case di:this.caIssuers.push(new Sl(e.accessLocation));break;case fi:this.timeStamping.push(new Sl(e.accessLocation));break;case yi:this.caRepository.push(new Sl(e.accessLocation))}}))}toTextObject(){const e=this.toTextObjectWithoutValue();return this.ocsp.length&&Kl(e,"OCSP",this.ocsp),this.caIssuers.length&&Kl(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&Kl(e,"Time Stamping",this.timeStamping),this.caRepository.length&&Kl(e,"CA Repository",this.caRepository),e}}function Kl(e,t,r){if(1===r.length)e[t]=r[0].toTextObject();else{const i=new Ju("");r.forEach(((e,t)=>{const r=e.toTextObject(),n=`${r[Ju.NAME]} ${t+1}`;let o=i[n];Array.isArray(o)||(o=[],i[n]=o),o.push(r)})),e[t]=i}}function Fl(e,t,r,i){const n=t[i];if(n){(Array.isArray(n)?n:[n]).forEach((t=>{"string"==typeof t&&(t=new Sl("url",t)),e.push(new wi({accessMethod:r,accessLocation:Kr.parse(t.rawData,ci)}))}))}}Hl.NAME="Authority Info Access";class zl extends Qu{constructor(...e){k.isBufferSource(e[0])?super(e[0]):super(yn,e[1],new Al(e[0]||[]).rawData)}onInit(e){super.onInit(e);const t=Kr.parse(e.extnValue,Ni);this.names=new Al(t)}toTextObject(){const e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(const r in t)e[r]=t[r];return e}}zl.NAME="Issuer Alternative Name";class Wl extends Zu{constructor(...e){let t;if(k.isBufferSource(e[0]))t=k.toArrayBuffer(e[0]);else{const r=e[0],i=Array.isArray(e[1])?e[1].map((e=>k.toArrayBuffer(e))):[];t=Kr.serialize(new Cn({type:r,values:i}))}super(t,Cn)}onInit(e){this.type=e.type,this.values=e.values}toTextObject(){const e=this.toTextObjectWithoutValue();return e.Value=this.values.map((e=>new Ju("",{"":e}))),e}toTextObjectWithoutValue(){const e=this.toTextObjectEmpty();return e[Ju.NAME]===Wl.NAME&&(e[Ju.NAME]=qu.toString(this.type)),e}}Wl.NAME="Attribute";class Jl extends Wl{constructor(...e){var t;if(k.isBufferSource(e[0]))super(e[0]);else{const t=new tu({printableString:e[0]});super(Rc,[Kr.serialize(t)])}null!==(t=this.password)&&void 0!==t||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){const e=Kr.parse(this.values[0],tu);this.password=e.toString()}}toTextObject(){const e=this.toTextObjectWithoutValue();return e[Ju.VALUE]=this.password,e}}Jl.NAME="Challenge Password";class ql extends Wl{constructor(...e){var t;if(k.isBufferSource(e[0]))super(e[0]);else{const t=e[0],r=new Xn;for(const e of t)r.push(Kr.parse(e.rawData,Gn));super(Uc,[Kr.serialize(r)])}null!==(t=this.items)&&void 0!==t||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){const e=Kr.parse(this.values[0],Xn);this.items=e.map((e=>Ml.create(Kr.serialize(e))))}}toTextObject(){const e=this.toTextObjectWithoutValue(),t=this.items.map((e=>e.toTextObject()));for(const r of t)e[r[Ju.NAME]]=r;return e}}ql.NAME="Extensions";class Gl{static register(e,t){this.items.set(e,t)}static create(e){const t=new Wl(e),r=this.items.get(t.type);return r?new r(e):t}}Gl.items=new Map;const Xl="crypto.signatureFormatter";var Yl;let Zl=Yl=class{static createPssParams(e,t){const r=Yl.getHashAlgorithm(e);return r?new Ba({hashAlgorithm:r,maskGenAlgorithm:new Fn({algorithm:ka,parameters:Kr.serialize(r)}),saltLength:t}):null}static getHashAlgorithm(e){const t=uc.resolve(hu);return"string"==typeof e?t.toAsnAlgorithm({name:e}):"object"==typeof e&&e&&"name"in e?t.toAsnAlgorithm(e):null}toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"rsassa-pkcs1-v1_5":if(!("hash"in e))return new Fn({algorithm:sa,parameters:null});{let t;if("string"==typeof e.hash)t=e.hash;else{if(!e.hash||"object"!=typeof e.hash||!("name"in e.hash)||"string"!=typeof e.hash.name)throw new Error("Cannot get hash algorithm name");t=e.hash.name.toUpperCase()}switch(t.toLowerCase()){case"sha-1":return new Fn({algorithm:ha,parameters:null});case"sha-256":return new Fn({algorithm:fa,parameters:null});case"sha-384":return new Fn({algorithm:ya,parameters:null});case"sha-512":return new Fn({algorithm:ga,parameters:null})}}break;case"rsa-pss":if("hash"in e){if(!("saltLength"in e)||"number"!=typeof e.saltLength)throw new Error("Cannot get 'saltLength' from 'alg' argument");const t=Yl.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new Fn({algorithm:ua,parameters:Kr.serialize(t)})}return new Fn({algorithm:ua,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case sa:return{name:"RSASSA-PKCS1-v1_5"};case ha:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case fa:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case ya:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case ga:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case ua:if(e.parameters){const t=Kr.parse(e.parameters,Ba);return{name:"RSA-PSS",hash:uc.resolve(hu).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}return{name:"RSA-PSS"}}return null}};Zl=Yl=Fr([lc()],Zl),uc.registerSingleton(pu,Zl);let Ql=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new Fn({algorithm:wa});case"sha-256":return new Fn({algorithm:Sa});case"sha-384":return new Fn({algorithm:Aa});case"sha-512":return new Fn({algorithm:Ea})}return null}toWebAlgorithm(e){switch(e.algorithm){case wa:return{name:"SHA-1"};case Sa:return{name:"SHA-256"};case Aa:return{name:"SHA-384"};case Ea:return{name:"SHA-512"}}return null}};Ql=Fr([lc()],Ql),uc.registerSingleton(pu,Ql);class ep{addPadding(e,t){const r=k.toUint8Array(t),i=new Uint8Array(e);return i.set(r,e-r.length),i.buffer}removePadding(e,t=!1){let r=k.toUint8Array(e);for(let i=0;i<r.length;i++)if(r[i]){r=r.slice(i);break}if(t&&r[0]>127){const e=new Uint8Array(r.length+1);return e.set(r,1),e.buffer}return r.buffer}toAsnSignature(e,t){if("ECDSA"===e.name){const r=e.namedCurve,i=ep.namedCurveSize.get(r)||ep.defaultNamedCurveSize,n=new na,o=k.toUint8Array(t);return n.r=this.removePadding(o.slice(0,i),!0),n.s=this.removePadding(o.slice(i,i+i),!0),Kr.serialize(n)}return null}toWebSignature(e,t){if("ECDSA"===e.name){const r=Kr.parse(t,na),i=e.namedCurve,n=ep.namedCurveSize.get(i)||ep.defaultNamedCurveSize;return function(...e){const t=e.map((e=>e.byteLength)).reduce(((e,t)=>e+t)),r=new Uint8Array(t);let i=0;return e.map((e=>new Uint8Array(e))).forEach((e=>{for(const t of e)r[i++]=t})),r.buffer}(this.addPadding(n,this.removePadding(r.r)),this.addPadding(n,this.removePadding(r.s)))}return null}}ep.namedCurveSize=new Map,ep.defaultNamedCurveSize=32;const tp="1.3.101.110",rp="1.3.101.111",ip="1.3.101.112",np="1.3.101.113";let op=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=ip;break;case"x25519":t=tp;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=ip;break;case"ed448":t=np}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=tp;break;case"x448":t=rp}}return t?new Fn({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case ip:return{name:"Ed25519"};case np:return{name:"EdDSA",namedCurve:"Ed448"};case tp:return{name:"X25519"};case rp:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};var sp,ap,cp,up,lp,pp,hp,dp,fp,yp,gp,mp,vp,wp,bp,Sp,Ap,Ep,kp,xp,_p,Np;op=Fr([lc()],op),uc.registerSingleton(pu,op);sp=new WeakMap,ap=new WeakMap,cp=new WeakMap,up=new WeakMap,lp=new WeakMap,pp=new WeakMap,hp=new WeakMap,dp=new WeakMap,class extends Il{get subjectName(){return zr(this,ap,"f")||Wr(this,ap,new sl(this.asn.certificationRequestInfo.subject),"f"),zr(this,ap,"f")}get subject(){return zr(this,cp,"f")||Wr(this,cp,this.subjectName.toString(),"f"),zr(this,cp,"f")}get signatureAlgorithm(){if(!zr(this,up,"f")){const e=uc.resolve(hu);Wr(this,up,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return zr(this,up,"f")}get signature(){return zr(this,lp,"f")||Wr(this,lp,this.asn.signature,"f"),zr(this,lp,"f")}get publicKey(){return zr(this,pp,"f")||Wr(this,pp,new Tl(this.asn.certificationRequestInfo.subjectPKInfo),"f"),zr(this,pp,"f")}get attributes(){return zr(this,hp,"f")||Wr(this,hp,this.asn.certificationRequestInfo.attributes.map((e=>Gl.create(Kr.serialize(e)))),"f"),zr(this,hp,"f")}get extensions(){if(!zr(this,dp,"f")){Wr(this,dp,[],"f");const e=this.getAttribute(Uc);e instanceof ql&&Wr(this,dp,e.items,"f")}return zr(this,dp,"f")}get tbs(){return zr(this,sp,"f")||Wr(this,sp,this.asn.certificationRequestInfoRaw||Kr.serialize(this.asn.certificationRequestInfo),"f"),zr(this,sp,"f")}constructor(e){const t=Il.isAsnEncoded(e)?[e,lu]:[e];super(t[0],t[1]),sp.set(this,void 0),ap.set(this,void 0),cp.set(this,void 0),up.set(this,void 0),lp.set(this,void 0),pp.set(this,void 0),hp.set(this,void 0),dp.set(this,void 0),this.tag=Nl.CertificateRequestTag}onInit(e){}getAttribute(e){for(const t of this.attributes)if(t.type===e)return t;return null}getAttributes(e){return this.attributes.filter((t=>t.type===e))}getExtension(e){for(const t of this.extensions)if(t.type===e)return t;return null}getExtensions(e){return this.extensions.filter((t=>t.type===e))}async verify(e=tl.get()){const t={...this.publicKey.algorithm,...this.signatureAlgorithm},r=await this.publicKey.export(t,["verify"],e),i=uc.resolveAll(Xl).reverse();let n=null;for(const o of i)if(n=o.toWebSignature(t,this.signature),n)break;if(!n)throw Error("Cannot convert WebCrypto signature value to ASN.1 format");return await e.subtle.verify(this.signatureAlgorithm,r,n,this.tbs)}toTextObject(){const e=this.toTextObjectEmpty(),t=Kr.parse(this.rawData,lu),r=t.certificationRequestInfo,i=new Ju("",{Version:`${Yn[r.version]} (${r.version})`,Subject:this.subject,"Subject Public Key Info":this.publicKey});if(this.attributes.length){const e=new Ju("");for(const t of this.attributes){const r=t.toTextObject();e[r[Ju.NAME]]=r}i.Attributes=e}return e.Data=i,e.Signature=new Ju("",{Algorithm:Gu.serializeAlgorithm(t.signatureAlgorithm),"":t.signature}),e}}.NAME="PKCS#10 Certificate Request";class Ip extends Il{get publicKey(){return zr(this,xp,"f")||Wr(this,xp,new Tl(this.asn.tbsCertificate.subjectPublicKeyInfo),"f"),zr(this,xp,"f")}get serialNumber(){if(!zr(this,yp,"f")){const e=this.asn.tbsCertificate;let t=new Uint8Array(e.serialNumber);t.length>1&&0===t[0]&&t[1]>127&&(t=t.slice(1)),Wr(this,yp,O.ToHex(t),"f")}return zr(this,yp,"f")}get subjectName(){return zr(this,gp,"f")||Wr(this,gp,new sl(this.asn.tbsCertificate.subject),"f"),zr(this,gp,"f")}get subject(){return zr(this,mp,"f")||Wr(this,mp,this.subjectName.toString(),"f"),zr(this,mp,"f")}get issuerName(){return zr(this,vp,"f")||Wr(this,vp,new sl(this.asn.tbsCertificate.issuer),"f"),zr(this,vp,"f")}get issuer(){return zr(this,wp,"f")||Wr(this,wp,this.issuerName.toString(),"f"),zr(this,wp,"f")}get notBefore(){if(!zr(this,bp,"f")){const e=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!e)throw new Error("Cannot get 'notBefore' value");Wr(this,bp,e,"f")}return zr(this,bp,"f")}get notAfter(){if(!zr(this,Sp,"f")){const e=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!e)throw new Error("Cannot get 'notAfter' value");Wr(this,Sp,e,"f")}return zr(this,Sp,"f")}get signatureAlgorithm(){if(!zr(this,Ap,"f")){const e=uc.resolve(hu);Wr(this,Ap,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return zr(this,Ap,"f")}get signature(){return zr(this,Ep,"f")||Wr(this,Ep,this.asn.signatureValue,"f"),zr(this,Ep,"f")}get extensions(){return zr(this,kp,"f")||(Wr(this,kp,[],"f"),this.asn.tbsCertificate.extensions&&Wr(this,kp,this.asn.tbsCertificate.extensions.map((e=>Ml.create(Kr.serialize(e)))),"f")),zr(this,kp,"f")}get tbs(){return zr(this,fp,"f")||Wr(this,fp,this.asn.tbsCertificateRaw||Kr.serialize(this.asn.tbsCertificate),"f"),zr(this,fp,"f")}constructor(e){const t=Il.isAsnEncoded(e)?[e,eo]:[e];super(t[0],t[1]),fp.set(this,void 0),yp.set(this,void 0),gp.set(this,void 0),mp.set(this,void 0),vp.set(this,void 0),wp.set(this,void 0),bp.set(this,void 0),Sp.set(this,void 0),Ap.set(this,void 0),Ep.set(this,void 0),kp.set(this,void 0),xp.set(this,void 0),this.tag=Nl.CertificateTag}onInit(e){}getExtension(e){for(const t of this.extensions)if("string"==typeof e){if(t.type===e)return t}else if(t instanceof e)return t;return null}getExtensions(e){return this.extensions.filter((t=>"string"==typeof e?t.type===e:t instanceof e))}async verify(e={},t=tl.get()){let r,i;const n=e.publicKey;try{if(n)if("publicKey"in n)r={...n.publicKey.algorithm,...this.signatureAlgorithm},i=await n.publicKey.export(r,["verify"],t);else if(n instanceof Tl)r={...n.algorithm,...this.signatureAlgorithm},i=await n.export(r,["verify"],t);else if(k.isBufferSource(n)){const e=new Tl(n);r={...e.algorithm,...this.signatureAlgorithm},i=await e.export(r,["verify"],t)}else r={...n.algorithm,...this.signatureAlgorithm},i=n;else r={...this.publicKey.algorithm,...this.signatureAlgorithm},i=await this.publicKey.export(r,["verify"],t)}catch{return!1}const o=uc.resolveAll(Xl).reverse();let s=null;for(const c of o)if(s=c.toWebSignature(r,this.signature),s)break;if(!s)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");const a=await t.subtle.verify(this.signatureAlgorithm,i,s,this.tbs);if(e.signatureOnly)return a;{const t=(e.date||new Date).getTime();return a&&this.notBefore.getTime()<t&&t<this.notAfter.getTime()}}async getThumbprint(...e){let t,r="SHA-1";return e[0]&&(e[0].subtle?t=e[0]:(r=e[0]||r,t=e[1])),null!=t||(t=tl.get()),await t.subtle.digest(r,this.rawData)}async isSelfSigned(e=tl.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){const e=this.toTextObjectEmpty(),t=Kr.parse(this.rawData,eo),r=t.tbsCertificate,i=new Ju("",{Version:`${Yn[r.version]} (${r.version})`,"Serial Number":r.serialNumber,"Signature Algorithm":Gu.serializeAlgorithm(r.signature),Issuer:this.issuer,Validity:new Ju("",{"Not Before":r.validity.notBefore.getTime(),"Not After":r.validity.notAfter.getTime()}),Subject:this.subject,"Subject Public Key Info":this.publicKey});if(r.issuerUniqueID&&(i["Issuer Unique ID"]=r.issuerUniqueID),r.subjectUniqueID&&(i["Subject Unique ID"]=r.subjectUniqueID),this.extensions.length){const e=new Ju("");for(const t of this.extensions){const r=t.toTextObject();e[r[Ju.NAME]]=r}i.Extensions=e}return e.Data=i,e.Signature=new Ju("",{Algorithm:Gu.serializeAlgorithm(t.signatureAlgorithm),"":t.signatureValue}),e}}fp=new WeakMap,yp=new WeakMap,gp=new WeakMap,mp=new WeakMap,vp=new WeakMap,wp=new WeakMap,bp=new WeakMap,Sp=new WeakMap,Ap=new WeakMap,Ep=new WeakMap,kp=new WeakMap,xp=new WeakMap,Ip.NAME="Certificate";class Tp{static async createSelfSigned(e,t=tl.get()){if(!e.keys.privateKey)throw new Error("Bad field 'keys' in 'params' argument. 'privateKey' is empty");if(!e.keys.publicKey)throw new Error("Bad field 'keys' in 'params' argument. 'publicKey' is empty");return this.create({serialNumber:e.serialNumber,subject:e.name,issuer:e.name,notBefore:e.notBefore,notAfter:e.notAfter,publicKey:e.keys.publicKey,signingKey:e.keys.privateKey,signingAlgorithm:e.signingAlgorithm,extensions:e.extensions},t)}static async create(e,t=tl.get()){var r;let i;i=e.publicKey instanceof Tl?e.publicKey.rawData:"publicKey"in e.publicKey?e.publicKey.publicKey.rawData:k.isBufferSource(e.publicKey)?e.publicKey:await t.subtle.exportKey("spki",e.publicKey);const n=function(e,t=tl.get()){const r=k.toUint8Array(O.FromHex(e||""));let i=r&&r.length&&r.some((e=>e>0))?new Uint8Array(r):void 0;i||(i=t.getRandomValues(new Uint8Array(16)));let n=0;for(;n<i.length-1&&0===i[n];)n++;if(i=i.slice(n),i[0]>127){const e=new Uint8Array(i.length+1);e[0]=0,e.set(i,1),i=e}return i.buffer}(e.serialNumber,t),o=e.notBefore||new Date,s=e.notAfter||new Date(o.getTime()+31536e6),a=new eo({tbsCertificate:new Qn({version:Yn.v3,serialNumber:n,validity:new Jn({notBefore:o,notAfter:s}),extensions:new Xn((null===(r=e.extensions)||void 0===r?void 0:r.map((e=>Kr.parse(e.rawData,Gn))))||[]),subjectPublicKeyInfo:Kr.parse(i,zn)})});if(e.subject){const t=e.subject instanceof sl?e.subject:new sl(e.subject);a.tbsCertificate.subject=Kr.parse(t.toArrayBuffer(),ni)}if(e.issuer){const t=e.issuer instanceof sl?e.issuer:new sl(e.issuer);a.tbsCertificate.issuer=Kr.parse(t.toArrayBuffer(),ni)}const c={hash:"SHA-256"},u="signingKey"in e?{...c,...e.signingAlgorithm,...e.signingKey.algorithm}:{...c,...e.signingAlgorithm},l=uc.resolve(hu);a.tbsCertificate.signature=a.signatureAlgorithm=l.toAsnAlgorithm(u);const p=Kr.serialize(a.tbsCertificate),h="signingKey"in e?await t.subtle.sign(u,e.signingKey,p):e.signature,d=uc.resolveAll(Xl).reverse();let f=null;for(const y of d)if(f=y.toAsnSignature(u,h),f)break;if(!f)throw Error("Cannot convert ASN.1 signature value to WebCrypto format");return a.signatureValue=f,new Ip(Kr.serialize(a))}}function Bp(e){const t=globalThis.process;if("function"==typeof(null==t?void 0:t.getBuiltinModule)){const r=t.getBuiltinModule(e);if(r)return r}if("function"==typeof require)return require(e);throw new Error(`buckyos cert cannot load builtin module ${e} in this runtime`)}function Op(){const e=globalThis.crypto;if(null==e?void 0:e.subtle)return e;return Bp("node:crypto").webcrypto}(Np=_p||(_p={}))[Np.unspecified=0]="unspecified",Np[Np.keyCompromise=1]="keyCompromise",Np[Np.cACompromise=2]="cACompromise",Np[Np.affiliationChanged=3]="affiliationChanged",Np[Np.superseded=4]="superseded",Np[Np.cessationOfOperation=5]="cessationOfOperation",Np[Np.certificateHold=6]="certificateHold",Np[Np.removeFromCRL=8]="removeFromCRL",Np[Np.privilegeWithdrawn=9]="privilegeWithdrawn",Np[Np.aACompromise=10]="aACompromise",Ml.register(ki,Ol),Ml.register(nn,Pl),Ml.register(mn,Rl),Ml.register(Pn,Ul),Ml.register(Si,Bl),Ml.register(Bn,$l),Ml.register(Hi,Vl),Ml.register(vi,Hl),Ml.register(yn,zl),Gl.register(Rc,Jl),Gl.register(Uc,ql),uc.registerSingleton(Xl,class{toAsnSignature(e,t){return k.toArrayBuffer(t)}toWebSignature(e,t){return k.toArrayBuffer(t)}}),uc.registerSingleton(Xl,ep),ep.namedCurveSize.set("P-256",32),ep.namedCurveSize.set("K-256",32),ep.namedCurveSize.set("P-384",48),ep.namedCurveSize.set("P-521",66);const Cp={name:"RSASSA-PKCS1-v1_5",hash:"SHA-256",publicExponent:new Uint8Array([1,0,1]),modulusLength:4096},Dp={...Cp,modulusLength:2048},jp=["server","client","authentication","assertion","key-agreement","capability"],Pp=["did-json","did-meta","cert","chain","fullchain","ca","public","csr","meta","private","keyref","verification-method"];function Rp(){const e=new Uint8Array(16);return Op().getRandomValues(e),e[0]&=127,e[0]|=1,Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join("")}function Up(e){return new Date(Date.now()+24*e*3600*1e3)}async function $p(e){const t=new Uint8Array(await Op().subtle.exportKey("pkcs8",e));return Nl.encode(t,"PRIVATE KEY")}function Mp(e){return Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join("")}function Lp(e){const t=e=>e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||46===e||95===e||45===e;let r="";for(const i of function(e){if("undefined"!=typeof TextEncoder)return(new TextEncoder).encode(e);const t=Bp("node:buffer").Buffer;return new Uint8Array(t.from(e,"utf8"))}(e))t(i)?r+=String.fromCharCode(i):r+=`%${i.toString(16).toUpperCase().padStart(2,"0")}`;if(!r||"."===r||".."===r||/[\\/]/.test(r)||r.includes("\0"))throw new Error(`Invalid encoded identity directory name for raw host URI: ${e}`);return r}function Vp(e){const t=e.trim();if(!t)throw new Error("identity DID or hostname is empty");return i.DID.fromStr(function(e){return e.startsWith("did:web:*.")?`did:web:_.${e.slice(10)}`:e.startsWith("*.")?`_.${e.slice(2)}`:e}(t))}function Hp(e){return Vp(e).toRawHostUri()}function Kp(e){return Lp(Hp(e))}function Fp(e){const t=Vp(e);if("web"!==t.method)return null;const r=t.toRawHostName(),i=t.getPathFromId();return i?`https://${r}/${i}/did.json`:`https://${r}/.well-known/did.json`}function zp(e,t){switch(function(e){if(!jp.includes(e))throw new Error(`Unsupported identity usage: ${e}`)}(e),function(e){if(!Pp.includes(e))throw new Error(`Unsupported identity material: ${e}`)}(t),t){case"did-json":return"did.json";case"did-meta":return"did.meta.json";case"cert":return`${e}.cert.pem`;case"chain":return`${e}.chain.pem`;case"fullchain":return`${e}.fullchain.pem`;case"ca":return`${e}.ca.pem`;case"public":return"server"===e||"client"===e?`${e}.public.pem`:`${e}.public.jwk`;case"csr":return`${e}.csr.pem`;case"meta":return`${e}.meta.json`;case"private":return`${e}.private.pem`;case"keyref":return`${e}.keyref.json`;case"verification-method":return`${e}.verification-method.json`}}function Wp(e){if("string"!=typeof e)return null;const t=e.trim();return t.length>0?t:null}function Jp(e,t,r){const i=Bp("node:path");return{cert:i.join(e,zp(r,"cert")),chain:i.join(e,zp(r,"chain")),fullchain:i.join(e,zp(r,"fullchain")),ca:i.join(e,zp(r,"ca")),metadata:i.join(e,zp(r,"meta")),keyref:i.join(t,zp(r,"keyref")),privateKey:i.join(t,zp(r,"private"))}}class qp{constructor(e,t){const r=Bp("node:path");this.publicRoot=r.resolve(e),this.securityRoot=r.resolve(t)}static fromEnvOrBuckyosRoot(e={}){const t=Bp("node:path"),r=function(){const e=globalThis.process;return(null==e?void 0:e.env)??{}}(),i=Wp(e.buckyosRoot)??Wp(r.BUCKYOS_ROOT)??"/opt/buckyos",n=Wp(e.publicRoot)??Wp(r.BUCKYOS_IDENTITY_ROOT)??t.join(i,"local","identity"),o=Wp(e.securityRoot)??Wp(r.BUCKYOS_SECURITY_ROOT)??t.join(i,"security");return new qp(n,o)}rawHostUri(e){return Hp(e)}dirName(e){return Kp(e)}publicDir(e){return Bp("node:path").join(this.publicRoot,this.dirName(e))}securityDir(e){return Bp("node:path").join(this.securityRoot,this.dirName(e))}publicFile(e,t,r){return Bp("node:path").join(this.publicDir(e),zp(t,r))}securityFile(e,t,r){return Bp("node:path").join(this.securityDir(e),zp(t,r))}x509Paths(e,t="server"){return Jp(this.publicDir(e),this.securityDir(e),t)}identityDirMatch(e){const t=this.rawHostUri(e),r=Lp(t);return{type:t.startsWith("_.")?"wildcard":"exact",rawHostUri:t,dirName:r,publicDir:this.publicDir(e),securityDir:this.securityDir(e),...t.startsWith("_.")?{hostPattern:`*.${t.slice(2)}`}:{host:t}}}findX509Paths(e,t="server"){const r=Bp("node:fs"),i=this.identityDirMatch(e),n=Jp(i.publicDir,i.securityDir,t);if(r.existsSync(n.fullchain)||r.existsSync(n.cert))return{match:i,paths:n};const o=Vp(e);if("web"!==o.method)return null;const s=o.toRawHostName().split(".");if(s.length<3)return null;const a=`_.${s.slice(1).join(".")}`,c=Lp(a),u=Bp("node:path"),l=u.join(this.publicRoot,c),p=u.join(this.securityRoot,c),h=Jp(l,p,t);return r.existsSync(h.fullchain)||r.existsSync(h.cert)?{match:{type:"wildcard",rawHostUri:a,dirName:c,publicDir:l,securityDir:p,hostPattern:`*.${s.slice(1).join(".")}`},paths:h}:null}}async function Gp(e){const t=Op();if(e.includes("BEGIN RSA PRIVATE KEY")){const r=function(e){const t=new Uint8Array([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]),r=new Uint8Array([2,1,0]),i=Xp(4,e),n=new Uint8Array(r.length+t.length+i.length);return n.set(r,0),n.set(t,r.length),n.set(i,r.length+t.length),Xp(48,n)}(new Uint8Array(Nl.decode(e)[0]));return t.subtle.importKey("pkcs8",r,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["sign"])}const r=new Uint8Array(Nl.decode(e)[0]);return t.subtle.importKey("pkcs8",r,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["sign"])}function Xp(e,t){let r;r=t.length<128?[e,t.length]:t.length<256?[e,129,t.length]:[e,130,t.length>>8,255&t.length];const i=new Uint8Array(r.length+t.length);return i.set(r,0),i.set(t,r.length),i}function Yp(e){const t=e.extensions.find((e=>e instanceof Ol));if(!(null==t?void 0:t.ca))return"missing basicConstraints CA:TRUE";const r=e.extensions.find((e=>e instanceof Rl));return!r||r.usages&jl.keyCertSign?void 0:"keyUsage does not allow certificate signing"}async function Zp(e,t="devtest"){const r=Bp("node:fs"),i=Bp("node:path"),n=Op();tl.set(n),r.mkdirSync(e,{recursive:!0});const o=i.join(e,`${t}_ca_key.pem`),s=i.join(e,`${t}_ca_cert.pem`),a=`C=US, ST=California, L=San Jose, O=${`${t}'s Dev Test Environment`}, OU=Test, CN=${t}`,c=await n.subtle.generateKey(Cp,!0,["sign","verify"]),u=await Tp.createSelfSigned({serialNumber:Rp(),name:a,notBefore:new Date,notAfter:Up(3650),signingAlgorithm:{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},keys:c,extensions:[new Ol(!0,void 0,!0),new Rl(jl.keyCertSign|jl.cRLSign|jl.digitalSignature,!0),await Ul.create(c.publicKey)]});return r.writeFileSync(o,await $p(c.privateKey)),r.writeFileSync(s,u.toString("pem")),console.log(`CA certificate created: ${s}`),{caCertPath:s,caKeyPath:o}}async function Qp(e,t,r=[],i="server"){const n=Bp("node:fs"),o=Op();tl.set(o);const{caCertPath:s,caKeyPath:a}=function(e){const t=Bp("node:fs"),r=Bp("node:path"),i=t.readdirSync(e).filter((e=>e.endsWith("_ca_cert.pem")));if(0===i.length)throw new Error(`No CA certificate found matching *_ca_cert.pem pattern in ${e}`);if(i.length>1)throw new Error(`Multiple CA certificates found in ${e}: ${i.join(", ")}`);const n=r.join(e,i[0]),o=r.join(e,i[0].replace("_ca_cert.pem","_ca_key.pem"));if(!t.existsSync(o))throw new Error(`CA key not found: ${o}`);return{caCertPath:n,caKeyPath:o}}(e),c=n.readFileSync(s,"utf8"),u=new Ip(c),l=Yp(u);if(l)throw new Error(`Invalid CA certificate at ${s}: ${l}`);const p=await Gp(n.readFileSync(a,"utf8")),h=t[0];if(!h)throw new Error("At least one DNS SAN is required when creating an X.509 certificate");const d=await o.subtle.generateKey(Dp,!0,["sign","verify"]),f=new Uint8Array(await o.subtle.exportKey("spki",d.publicKey)),y=await async function(e){const t=await Op().subtle.digest("SHA-256",e);return`sha256:${Mp(new Uint8Array(t))}`}(f),g=[...t.map((e=>({type:"dns",value:e}))),...r.map((e=>({type:"url",value:e})))],m=await Tp.create({serialNumber:Rp(),subject:`CN=${h}`,issuer:u.subjectName,notBefore:new Date,notAfter:Up(365),signingAlgorithm:{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},publicKey:d.publicKey,signingKey:p,extensions:[new Rl(jl.digitalSignature|jl.keyEncipherment,!0),new Pl(["client"===i?Cl.clientAuth:Cl.serverAuth]),new $l(g),await Ul.create(d.publicKey),await Bl.create(u)]});return{cert:m,certPem:m.toString("pem"),privateKeyPem:await $p(d.privateKey),caCertPem:c,publicKeyFingerprint:y}}function eh(e){return`${e.trimEnd()}\n`}function th(e,t,r){const i=Bp("node:fs"),n=Bp("node:path"),o=n.dirname(e),s=n.join(o,`.${n.basename(e)}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`);try{i.writeFileSync(s,t,void 0===r?void 0:{mode:r});try{const e=i.openSync(s,"r");try{i.fsyncSync(e)}finally{i.closeSync(e)}}catch{}i.renameSync(s,e)}catch(a){try{i.existsSync(s)&&i.unlinkSync(s)}catch{}throw a}}function rh(e){const t=e.toRawHostName();return t.startsWith("_.")?`*.${t.slice(2)}`:t}function ih(e){if("web"!==e.method||e.toRawHostName().startsWith("_."))return;const t=e.toString();return{type:"did-web-domain",did:t,web_origin:`https://${e.toRawHostName()}`,did_document_url:Fp(t)}}async function nh(e,t,r,i,n){const o=function(e){const t=e.extensions.find((e=>e instanceof $l)),r=(null==t?void 0:t.names.toJSON())??[];return{dns:r.filter((e=>"dns"===e.type)).map((e=>e.value)),uri:r.filter((e=>"url"===e.type)).map((e=>e.value))}}(n.cert),s=await async function(e){const t=await e.getThumbprint("SHA-256",Op());return`sha256:${Mp(new Uint8Array(t))}`}(n.cert),a=r.startsWith("_."),c=(new Date).toISOString();return{schema:"buckyos.identity.x509.metadata.v1",did:e.toString(),raw_host_uri:r,dir_name:i,usage:t,match:a?{type:"wildcard",host_pattern:`*.${r.slice(2)}`}:{type:"exact",host:r},certificate:{serial_number:n.cert.serialNumber,issuer:n.cert.issuer,subject:n.cert.subject,not_before:n.cert.notBefore.toISOString(),not_after:n.cert.notAfter.toISOString(),fingerprint_sha256:s,public_key_fingerprint:n.publicKeyFingerprint},san:o,paths:{cert:zp(t,"cert"),chain:zp(t,"chain"),fullchain:zp(t,"fullchain"),ca:zp(t,"ca")},did_binding:ih(e),updated_at:c,generation:`${c.replace(/[-:.]/g,"")}-${s}`}}const oh="test test test test test test test test test test test junk",sh=2147483648,ah=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ch=(1n<<64n)-1n,uh=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n],lh=[[0,36,3,41,18],[1,44,10,45,2],[62,6,43,15,61],[28,55,25,21,56],[27,20,39,8,14]];function ph(e,t=""){return o.pbkdf2Sync(n.Buffer.from(e.normalize("NFKD"),"utf8"),n.Buffer.from(`mnemonic${t}`.normalize("NFKD"),"utf8"),2048,64,"sha512")}function hh(e,t){return o.createHmac("sha512",e).update(t).digest()}function dh(e){const t=n.Buffer.alloc(4);return t.writeUInt32BE(e>>>0,0),t}function fh(e){const t=o.createPublicKey(o.createPrivateKey(e)).export({format:"jwk"});if(!t.x)throw new Error("failed to derive Ed25519 public key x");return t.x}function yh(e,t,r){const i=hh(t,n.Buffer.concat([n.Buffer.from([0]),e,dh(r+sh)]));return{key:i.subarray(0,32),chainCode:i.subarray(32)}}function gh(e,t,r){let i=function(e){const t=hh("ed25519 seed",e);return{key:t.subarray(0,32),chainCode:t.subarray(32)}}(ph(e,t));for(const n of[9777,0,r])i=yh(i.key,i.chainCode,n);return n.Buffer.from(i.key)}function mh(e,t,r){const i=function(e){return`-----BEGIN PRIVATE KEY-----\n${n.Buffer.concat([n.Buffer.from("302e020100300506032b657004220420","hex"),e]).toString("base64")}\n-----END PRIVATE KEY-----\n`}(gh(e,t??"",r));return{privateKeyPem:i,publicKeyX:fh(i)}}function vh(e){return mh(oh,void 0,e)}function wh(e){const t=e.toString(16).padStart(64,"0");return n.Buffer.from(t,"hex")}function bh(e){return BigInt(`0x${e.toString("hex")}`)}function Sh(e,t){const r=o.createECDH("secp256k1");return r.setPrivateKey(e),r.getPublicKey(void 0,t?"compressed":"uncompressed")}function Ah(e,t,r){const i=hh(t,r>=sh?n.Buffer.concat([n.Buffer.from([0]),e,dh(r)]):n.Buffer.concat([Sh(e,!0),dh(r)])),o=bh(i.subarray(0,32));if(o>=ah)throw new Error(`invalid secp256k1 child tweak at index ${r}`);const s=(o+bh(e))%ah;if(0n===s)throw new Error(`invalid secp256k1 child key at index ${r}`);return{privateKey:wh(s),chainCode:i.subarray(32)}}function Eh(e){return`m/44'/60'/0'/0/${e}`}function kh(e,t){if(0===t)return e&ch;const r=BigInt(t);return(e<<r|e>>64n-r)&ch}function xh(e){for(const t of uh){const r=new Array(5),i=new Array(5),n=new Array(25).fill(0n);for(let t=0;t<5;t+=1)r[t]=e[t]^e[t+5]^e[t+10]^e[t+15]^e[t+20];for(let e=0;e<5;e+=1)i[e]=r[(e+4)%5]^kh(r[(e+1)%5],1);for(let t=0;t<5;t+=1)for(let r=0;r<5;r+=1)e[t+5*r]=(e[t+5*r]^i[t])&ch;for(let t=0;t<5;t+=1)for(let r=0;r<5;r+=1)n[r+(2*t+3*r)%5*5]=kh(e[t+5*r],lh[t][r]);for(let t=0;t<5;t+=1)for(let r=0;r<5;r+=1)e[t+5*r]=(n[t+5*r]^~n[(t+1)%5+5*r]&ch&n[(t+2)%5+5*r])&ch;e[0]=(e[0]^t)&ch}}function _h(e){const t=136,r=new Array(25).fill(0n),i=n.Buffer.concat([e,n.Buffer.from([1]),n.Buffer.alloc((t-(e.length+1)%t)%t)]);i[i.length-1]^=128;for(let n=0;n<i.length;n+=t){for(let e=0;e<t;e+=1)r[Math.floor(e/8)]^=BigInt(i[n+e])<<BigInt(e%8*8);xh(r)}const o=n.Buffer.alloc(32);for(let n=0;n<o.length;n+=1)o[n]=Number(r[Math.floor(n/8)]>>BigInt(n%8*8)&0xffn);return o}function Nh(e){const t=e.toString("hex"),r=_h(n.Buffer.from(t,"ascii"));let i="0x";for(let n=0;n<t.length;n+=1){const e=t[n],o=r[Math.floor(n/2)]>>4*(1-n%2)&15;i+=/[a-f]/.test(e)&&o>7?e.toUpperCase():e}return i}function Ih(e,t,r){let i=function(e){const t=hh("Bitcoin seed",e),r=t.subarray(0,32),i=bh(r);if(i<=0n||i>=ah)throw new Error("invalid secp256k1 master key");return{privateKey:n.Buffer.from(r),chainCode:t.subarray(32)}}(ph(e,t??""));for(const n of function(e){return[2147483692,2147483708,sh,0,e]}(r))i=Ah(i.privateKey,i.chainCode,n);const o=Sh(i.privateKey,!1),s=Sh(i.privateKey,!0),a=_h(o.subarray(1)),c=i.privateKey.toString("hex");return{derivationPath:Eh(r),privateKey:`0x${c}`,privateKeyHex:c,publicKeyCompressedHex:s.toString("hex"),publicKeyUncompressedHex:o.toString("hex"),address:Nh(a.subarray(12))}}function Th(e){return Ih(oh,void 0,e)}const Bh={devtest:0,alice:1,bob:2,charlie:3,dave:4,sn_owner:5,devtests:5,"devtest.ood1":100,devtest_ood1:100,"devtest.node1":101,devtest_node1:101,"alice.ood1":102,alice_ood1:102,"bob.ood1":103,bob_ood1:103,"charlie.ood1":104,charlie_ood1:104,"dave.ood1":105,dave_ood1:105,sn:106,sn_server:106,"devtests.ood1":107,devtests_ood1:107,sn_web:107},Oh={alice:1,bob:2,charlie:3,dave:4},Ch=Object.fromEntries(Object.entries(Bh).map((([e,t])=>[e,vh(t)]))),Dh=Object.fromEntries(Object.entries(Oh).map((([e,t])=>[e,Th(t)]))),jh=Th(0);function Ph(e){const t=Ch[e];if(!t)throw new Error(`unknown dev test key pair id: ${e}`);return t}const Rh="ood1",Uh="wan",$h=i.DEFAULT_EXPIRE_TIME,Mh="provision_activation.lock",Lh="zone_dns_records.json",Vh="zone_document.jwt";class Hh extends Error{constructor(e,t,r={}){super(t),this.name="ActivationError",this.code=e,this.details=r}}function Kh(e){const t=globalThis.process;if("function"==typeof(null==t?void 0:t.getBuiltinModule)){const r=t.getBuiltinModule(e);if(r)return r}if("function"==typeof require)return require(e);throw new Hh("RUNTIME_UNSUPPORTED",`buckyos provision cannot load builtin module ${e} in this runtime (Node >= 22.13 or Deno >= 2.2 is required)`)}function Fh(){var e;return"win32"===(null==(e=globalThis.process)?void 0:e.platform)}function zh(e,t){const r=Kh("node:path");return r.relative(e,t).split(r.sep).join("/")}function Wh(e){return Kh("node:crypto").createHash("sha256").update(e,"utf8").digest("hex")}function Jh(){return Kh("node:crypto").randomBytes(6).toString("hex")}function qh(e){const t=Kh("node:fs");try{return t.lstatSync(e)}catch(r){const e=r.code;if("ENOENT"===e||"ENOTDIR"===e)return null;throw r}}function Gh(e){const t=Kh("node:fs");try{return t.statSync(e)}catch(r){if("ENOENT"===r.code||"ENOTDIR"===r.code)return null;throw r}}function Xh(e){var t;return!0===(null==(t=Gh(e))?void 0:t.isDirectory())}function Yh(e){var t;return!0===(null==(t=Gh(e))?void 0:t.isFile())}function Zh(e){const t=Kh("node:fs"),r=JSON.parse(t.readFileSync(e,"utf8"));if(!r||"object"!=typeof r||Array.isArray(r))throw new Error(`${e} is not a JSON object`);return r}function Qh(e){return JSON.stringify(e,null,2)}function ed(e,t,r,i){const n=Kh("node:fs"),o=Kh("node:path"),s=o.dirname(e);if(n.mkdirSync(s,{recursive:!0,mode:i}),Fh()||n.chmodSync(s,i),qh(e))throw new Error(`refusing to overwrite existing file: ${e}`);const a=o.join(s,`.${o.basename(e)}.provision-${Jh()}`);try{n.writeFileSync(a,t,{mode:r,flag:"wx"}),Fh()||n.chmodSync(a,r),n.renameSync(a,e)}finally{qh(a)&&n.rmSync(a,{force:!0})}}function td(e){const t=function(e){return e.trim().toLowerCase().replace(/\.$/,"")}(String(e??""));if(0===t.length||t.length>253||!t.includes(".")||t.split(".").some((e=>0===e.length||e.length>63||e.startsWith("-")||e.endsWith("-")||!/^[a-z0-9-]+$/.test(e))))throw new Hh("INVALID_ARGUMENT",`invalid did:web domain: ${e}`,{field:"domain"});return t}function rd(e){const t=String(e??"").trim().toLowerCase();if(0===t.length||t.length>63||!/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(t))throw new Hh("INVALID_ARGUMENT","owner name must be a lowercase DNS label (letters, digits, and hyphens)",{field:"owner_name"});return t}function id(e){const t=e??2980;if(!Number.isInteger(t)||t<1||t>65535)throw new Hh("INVALID_ARGUMENT",`invalid RTCP port: ${String(e)}`,{field:"rtcp_port"});return t}function nd(e){const t=(null==e?void 0:e.trim())||void 0;if(void 0===t)return;if(0===Kh("node:net").isIP(t))throw new Hh("INVALID_ARGUMENT",`invalid public IP address: ${t}`,{field:"public_ip"});return t}function od(e){if("string"!=typeof e||e.length<8)throw new Hh("INVALID_ARGUMENT","administrator password must contain at least 8 characters",{field:"admin_password"});return e}function sd(e,t){return i.hashPassword(e,t,null)}function ad(e,t){const r=[];if(t){const i=Kh("node:net");r.push({type:6===i.isIP(t)?"AAAA":"A",name:e,value:t})}return r}function cd(){const e=Kh("node:crypto"),{privateKey:t,publicKey:r}=e.generateKeyPairSync("ed25519"),i=r.export({format:"jwk"});if("string"!=typeof i.x||0===i.x.length)throw new Hh("KEY_GENERATION_FAILED","generated Ed25519 public key has no x coordinate");return{privateKeyPem:t.export({format:"pem",type:"pkcs8"}).toString(),publicKeyX:i.x}}function ud(e){const t=Kh("node:path");if("string"!=typeof e.rootDir||0===e.rootDir.trim().length)throw new Hh("INVALID_ARGUMENT","target root is required",{field:"root"});if("string"!=typeof e.ownerKeyBackupPath||0===e.ownerKeyBackupPath.trim().length)throw new Hh("INVALID_ARGUMENT","owner key backup path is required",{field:"owner_key_backup"});const r=td(e.domain),n=new i.DID("web",r);return{rootDir:t.resolve(e.rootDir),domain:r,ownerName:rd(e.ownerName),ownerKeyBackupPath:t.resolve(e.ownerKeyBackupPath),rtcpPort:id(e.rtcpPort),guestAccess:e.guestAccess??!1,publicIp:nd(e.publicIp),ownerDid:n,zoneDid:n,deviceDid:y(Rh,n)}}function ld(e){const t=Kh("node:path");return new qp(t.join(e,"local","identity"),t.join(e,"security"))}function pd(e,t,r){const i=Kh("node:path"),n=i.join(e,"etc"),o=f(ld(e),r);return{etcDir:n,lockPath:i.join(n,Mh),nodeIdentityPath:i.join(n,"node_identity.json"),startConfigPath:i.join(n,"start_config.json"),zoneDocumentJwtPath:i.join(n,Vh),gatewayParamsPath:i.join(n,"node_gateway_params.json"),dnsRecordsPath:i.join(n,Lh),zoneBootOverridePath:i.join(n,`${t.toRawHostName()}.zone.json`),didJsonPath:o.didJson,deviceDocJwtPath:o.deviceDocJwt,deviceMiniDocJwtPath:o.deviceMiniDocJwt,devicePrivateKeyPath:o.authenticationPrivateKey,publicDir:o.publicDir,securityDir:o.securityDir}}function hd(e,t){const r=(t,r,i,n)=>({path:zh(e,t),role:r,required:i,secret:n,absolutePath:t,mode:n?384:420,dirMode:n?448:493});return[r(t.devicePrivateKeyPath,"device_private_key",!0,!0),r(t.didJsonPath,"device_document",!0,!1),r(t.deviceDocJwtPath,"device_document_jwt",!0,!1),r(t.deviceMiniDocJwtPath,"device_mini_document_jwt",!0,!1),r(t.zoneBootOverridePath,"zone_boot_override",!0,!1),r(t.zoneDocumentJwtPath,"zone_document_jwt",!0,!1),r(t.dnsRecordsPath,"dns_records",!1,!1),r(t.startConfigPath,"start_config",!0,!1),r(t.gatewayParamsPath,"gateway_params",!0,!1),r(t.nodeIdentityPath,"node_identity",!0,!1)]}function dd(e){return{path:e.path,role:e.role,required:e.required,secret:e.secret}}function fd(e){if(!qh(e))return null;const t={path:e,schemaVersion:null,traceId:null,startedAt:null,domain:null,stage:null,committedFiles:[],ownerKeyBackupPath:null,corrupt:!1};try{const r=Zh(e),i=r.stage;return{...t,schemaVersion:"number"==typeof r.schema_version?r.schema_version:null,traceId:"string"==typeof r.trace_id?r.trace_id:null,startedAt:"number"==typeof r.started_at?r.started_at:null,domain:"string"==typeof r.domain?r.domain:null,stage:"locked"===i||"backup_saved"===i||"committing"===i||"committed"===i?i:null,committedFiles:Array.isArray(r.committed)?r.committed.filter((e=>"string"==typeof e)):[],ownerKeyBackupPath:"string"==typeof r.owner_key_backup?r.owner_key_backup:null}}catch{return{...t,corrupt:!0}}}function yd(e,t){const r=Kh("node:fs"),i=Kh("node:path"),n=i.join(i.dirname(e),`.${Mh}.${Jh()}`);try{r.writeFileSync(n,Qh(t),{mode:384,flag:"wx"}),r.renameSync(n,e)}finally{qh(n)&&r.rmSync(n,{force:!0})}}function gd(e){const t=Kh("node:fs");return Xh(e)?t.readdirSync(e,{withFileTypes:!0}).filter((e=>e.isDirectory())).map((e=>e.name)).sort():[]}function md(e){try{return i.getXFromJwk(e)}catch{return null}}async function vd(e){const t=Kh("node:path"),r=t.resolve(String(e??"")),n=i.buckyosGetUnixTimestamp(),o=[],s=[],a=e=>({rootDir:r,state:e,startupRequired:"configured"===e,observedAt:n,zoneDid:null,ownerDid:null,deviceDid:null,deviceName:null,accessHostname:null,files:[],problems:o,warnings:s,lock:null});if(!Xh(r))return o.push({code:"ROOT_MISSING",message:`BUCKYOS_ROOT does not exist: ${r}`}),a("not_installed");const c=["bin","etc"].filter((e=>!Xh(t.join(r,e))));if(c.length>0){for(const e of c)o.push({code:"INSTALL_INCOMPLETE",message:`installed BuckyOS directory is missing: ${t.join(r,e)}`});return a("not_installed")}const u=t.join(r,"etc"),l=fd(t.join(u,Mh)),p=function(e,t){if(!Yh(e))return{nodeIdentity:null,zoneDid:null,deviceDid:null};try{const r=Zh(e);if(r.schema!==i.NODE_IDENTITY_SCHEMA_V2)return t.push({code:"NODE_IDENTITY_SCHEMA",message:`etc/node_identity.json schema '${String(r.schema)}' is not ${i.NODE_IDENTITY_SCHEMA_V2}`}),{nodeIdentity:r,zoneDid:null,deviceDid:null};return{nodeIdentity:r,zoneDid:i.DID.fromStr(String(r.zone_did)),deviceDid:i.DID.fromStr(String(r.device_did))}}catch(r){return t.push({code:"NODE_IDENTITY_UNREADABLE",message:`etc/node_identity.json cannot be parsed: ${r instanceof Error?r.message:String(r)}`}),{nodeIdentity:null,zoneDid:null,deviceDid:null}}}(t.join(u,"node_identity.json"),o);let h=p.zoneDid,d=p.deviceDid;const g=gd(t.join(r,"local","identity")),m=gd(t.join(r,"security")),v=function(e,t){const r=Kh("node:fs");return Xh(e)?r.readdirSync(e,{withFileTypes:!0}).filter((e=>e.isFile()&&t(e.name))).map((e=>e.name)).sort():[]}(u,(e=>e.endsWith(".zone.json")));if(!h&&v.length>0){const e=v[0].slice(0,-10);e.endsWith(".did")||(h=new i.DID("web",e))}!d&&h&&(d=y(Rh,h));const w=[...g,...m].filter((e=>!d||e!==t.basename(f(ld(r),d).publicDir))),b=[];let S=null;if(h&&d){S=pd(r,h,d);for(const e of hd(r,S))b.push({...dd(e),present:Yh(e.absolutePath)})}else{for(const[e,r,i]of[["node_identity.json","node_identity",!0],["start_config.json","start_config",!0],[Vh,"zone_document_jwt",!0],["node_gateway_params.json","gateway_params",!0],[Lh,"dns_records",!1]])b.push({path:`etc/${e}`,role:r,required:i,secret:!1,present:Yh(t.join(u,e))});for(const e of v)b.push({path:`etc/${e}`,role:"zone_boot_override",required:!0,secret:!1,present:!0})}const A=b.find((e=>"gateway_params"===e.role)),E=!0===(null==A?void 0:A.present)&&function(e){try{const t=Zh(e).params;return!!t&&"object"==typeof t&&"did:bns:unactivated.local"===t.device_did}catch{return!1}}(t.join(u,"node_gateway_params.json"));A&&E&&(A.present=!1);const k=b.filter((e=>e.present&&"dns_records"!==e.role)),x=b.filter((e=>e.required&&!e.present)),_=a("unactivated");_.files=b,_.lock=l,_.zoneDid=(null==h?void 0:h.toString())??null,_.deviceDid=(null==d?void 0:d.toString())??null,_.deviceName=p.nodeIdentity?String(p.nodeIdentity.device_name):d?Rh:null,_.ownerDid=p.nodeIdentity?String(p.nodeIdentity.owner_did):null,l&&s.push(l.corrupt?`activation lock ${l.path} exists but cannot be parsed`:`activation lock ${l.path} exists (stage=${l.stage??"unknown"}, committed=${l.committedFiles.length})`);for(const i of w)s.push(`unexpected identity directory: ${i}`);if(0===k.length&&0===w.length&&!l&&0===o.length)return _.state="unactivated",_;if(x.length>0||!S||w.length>0&&0===k.length){for(const e of x)o.push({code:"FILE_MISSING",message:`${e.path} is missing`});return _.state="partial",_}const N=await async function(e,t,r,n){var o,s,a;const c=Kh("node:fs"),u=r.nodeIdentity;if(!u||!r.zoneDid||!r.deviceDid)return{ownerDid:null,accessHostname:null};const l=(e,t)=>n.push({code:e,message:t}),p=r.zoneDid,h=r.deviceDid,d=String(u.owner_did),f=u.owner_public_key;"web"!==p.method&&l("IDENTITY_NOT_DID_WEB",`zone DID ${p.toString()} is not a did:web identity`),d!==p.toString()&&l("OWNER_ZONE_MISMATCH",`owner DID ${d} differs from zone DID ${p.toString()}`);const g=y(String(u.device_name),p).toString();if(h.toString()!==g&&l("DEVICE_DID_MISMATCH",`device DID ${h.toString()} is not ${g}`),!f||"object"!=typeof f||"string"!=typeof f.x)return l("OWNER_KEY_MISSING","etc/node_identity.json owner_public_key is not an Ed25519 JWK"),{ownerDid:d,accessHostname:null};let m=null;try{m=Zh(t.startConfigPath)}catch(O){l("START_CONFIG_UNREADABLE",`etc/start_config.json cannot be parsed: ${O instanceof Error?O.message:String(O)}`)}let v=null;const w={};if(m){for(const t of["user_name","zone_name","access_hostname","admin_password_hash"])"string"==typeof m[t]&&0!==m[t].length||l("START_CONFIG_FIELD",`etc/start_config.json is missing ${t}`);for(const t of["boot_config_jwt","device_doc_jwt","device_mini_doc_jwt","zone_document_jwt","ood_jwt"])"string"==typeof m[t]&&m[t].length>0?w[t]=m[t]:l("START_CONFIG_FIELD",`etc/start_config.json is missing ${t}`);m.zone_name!==p.toString()&&l("START_CONFIG_ZONE",`etc/start_config.json zone_name is not ${p.toString()}`),"string"==typeof m.access_hostname&&(v=m.access_hostname,v!==p.toRawHostName()&&l("START_CONFIG_HOSTNAME",`etc/start_config.json access_hostname is not ${p.toRawHostName()}`));const e=m.owner_document;if(e&&"object"==typeof e){e.id!==d&&l("START_CONFIG_OWNER",`owner_document id ${String(e.id)} is not ${d}`);const t=Array.isArray(e.verificationMethod)?e.verificationMethod.find((e=>e&&"#main_key"===e.id)):void 0;t&&md(t.publicKeyJwk)===f.x||l("START_CONFIG_OWNER_KEY","owner_document #main_key differs from node_identity owner_public_key")}else l("START_CONFIG_OWNER","etc/start_config.json is missing owner_document");w.ood_jwt&&w.device_doc_jwt&&w.ood_jwt!==w.device_doc_jwt&&l("START_CONFIG_OOD_JWT","etc/start_config.json ood_jwt differs from device_doc_jwt");for(const[t,r]of[["private_key",!0],["device_private_key",!0],["sn_access_token",!0],["bns_evm_private_key",!0]])r&&t in m&&l("START_CONFIG_SECRET",`etc/start_config.json must not contain ${t}`)}const b=(e,t)=>{try{return String(c.readFileSync(e,"utf8"))}catch(O){return l("FILE_UNREADABLE",`${t} cannot be read: ${O instanceof Error?O.message:String(O)}`),null}},S=(null==(o=b(t.zoneDocumentJwtPath,"etc/zone_document.jwt"))?void 0:o.trim())??null,A=(null==(s=b(t.deviceDocJwtPath,zh(e,t.deviceDocJwtPath)))?void 0:s.trim())??null,E=(null==(a=b(t.deviceMiniDocJwtPath,zh(e,t.deviceMiniDocJwtPath)))?void 0:a.trim())??null;S&&w.zone_document_jwt&&S!==w.zone_document_jwt&&l("ZONE_DOCUMENT_MISMATCH","etc/zone_document.jwt differs from start_config zone_document_jwt"),A&&w.device_doc_jwt&&A!==w.device_doc_jwt&&l("DEVICE_DOCUMENT_MISMATCH","device_doc.jwt differs from start_config device_doc_jwt"),E&&w.device_mini_doc_jwt&&E!==w.device_mini_doc_jwt&&l("DEVICE_MINI_DOCUMENT_MISMATCH","device_mini_doc.jwt differs from start_config device_mini_doc_jwt");const k=async(e,t)=>{if(!e)return null;try{return await i.verifyJwtEdDSA(e,f)}catch(O){return l("JWT_SIGNATURE",`${t} is not signed by the owner key: ${O instanceof Error?O.message:String(O)}`),null}},x=await k(w.boot_config_jwt??null,"boot_config_jwt"),_=await k(A??w.device_doc_jwt??null,"device_doc.jwt"),N=await k(E??w.device_mini_doc_jwt??null,"device_mini_doc.jwt"),I=await k(S??w.zone_document_jwt??null,"zone_document.jwt"),T=i.buckyosGetUnixTimestamp();if(x){x.id!==p.toString()&&l("BOOT_DOCUMENT","boot document id differs from zone DID"),Array.isArray(x.oods)&&0!==x.oods.length||l("BOOT_DOCUMENT","boot document has no oods"),"sn"in x&&l("BOOT_DOCUMENT","boot document must not reference an SN in offline mode"),("number"!=typeof x.exp||x.exp<=T)&&l("BOOT_DOCUMENT","boot document has expired");try{const r=Zh(t.zoneBootOverridePath);JSON.stringify(r)!==JSON.stringify(x)&&l("BOOT_OVERRIDE_MISMATCH",`${zh(e,t.zoneBootOverridePath)} differs from boot_config_jwt`)}catch(O){l("BOOT_OVERRIDE_UNREADABLE",`local boot override cannot be parsed: ${O instanceof Error?O.message:String(O)}`)}}let B=null;if(_){_.id!==h.toString()&&l("DEVICE_DOCUMENT","device document id differs from node_identity device_did"),_.owner!==d&&l("DEVICE_DOCUMENT","device document owner differs from owner DID"),_.zone_did!==p.toString()&&l("DEVICE_DOCUMENT","device document zone_did differs from zone DID"),("number"!=typeof _.exp||_.exp<=T)&&l("DEVICE_DOCUMENT","device document has expired");const r=Array.isArray(_.verificationMethod)?_.verificationMethod.find((e=>e&&"#main_key"===e.id)):void 0;B=r?md(r.publicKeyJwk):null,B||l("DEVICE_DOCUMENT","device document has no #main_key");try{Zh(t.didJsonPath).id!==h.toString()&&l("DEVICE_DID_JSON",`${zh(e,t.didJsonPath)} id differs from node_identity device_did`)}catch(O){l("DEVICE_DID_JSON",`device did.json cannot be parsed: ${O instanceof Error?O.message:String(O)}`)}}if(N&&B&&N.x!==B&&l("DEVICE_MINI_DOCUMENT","device mini document key differs from device document key"),I&&(I.id!==p.toString()&&l("ZONE_DOCUMENT","zone document id differs from zone DID"),I.owner!==d&&l("ZONE_DOCUMENT","zone document owner differs from owner DID"),w.boot_config_jwt&&I.boot_jwt!==w.boot_config_jwt&&l("ZONE_DOCUMENT","zone document boot_jwt differs from start_config boot_config_jwt"),"sn"in I&&l("ZONE_DOCUMENT","zone document must not reference an SN in offline mode")),B){try{const e=String(c.readFileSync(t.devicePrivateKeyPath,"utf8"));await i.getPublicKeyXFromPrivatePem(e)!==B&&l("DEVICE_PRIVATE_KEY","device private key does not match the device document key")}catch(O){l("DEVICE_PRIVATE_KEY",`device private key cannot be loaded: ${O instanceof Error?O.message:String(O)}`)}if(!Fh()){const e=qh(t.devicePrivateKeyPath);e&&63&e.mode&&l("DEVICE_PRIVATE_KEY_MODE","device private key is readable by other users")}}return{ownerDid:d,accessHostname:v}}(r,S,p,o);return _.ownerDid=N.ownerDid??_.ownerDid,_.accessHostname=N.accessHostname??(h?h.toRawHostName():null),l&&"committed"!==l.stage&&o.push({code:"ACTIVATION_INTERRUPTED",message:`activation lock is still at stage ${l.stage??"unknown"}; the commit did not finish cleanly`}),_.state=0===o.length?"configured":"invalid",_.startupRequired="configured"===_.state,_}async function wd(e){const t=ud(e),r=await vd(t.rootDir),i=[],n=function(e){if(e.lock)return{code:"ACTIVATION_IN_PROGRESS",message:`activation lock exists: ${e.lock.path} (stage=${e.lock.stage??"unknown"})`};switch(e.state){case"unactivated":return null;case"not_installed":return{code:"TARGET_NOT_INSTALLED",message:`BuckyOS is not installed at ${e.rootDir}`};case"configured":return{code:"TARGET_ALREADY_ACTIVATED",message:`BuckyOS is already activated at ${e.rootDir}`};case"invalid":return{code:"TARGET_ALREADY_ACTIVATED",message:`BuckyOS activation material exists but is invalid at ${e.rootDir}; it is not overwritten`};case"partial":return{code:"TARGET_PARTIALLY_ACTIVATED",message:`BuckyOS is partially activated at ${e.rootDir}; remove the partial material or reinstall`}}}(r);n&&i.push(n);const o=function(e,t){const r=Kh("node:path").dirname(e),i=Xh(r),n=null!==qh(e);return i||t.push({code:"OWNER_KEY_BACKUP_DIRECTORY_MISSING",message:`owner key backup directory does not exist: ${r}`}),n&&t.push({code:"OWNER_KEY_BACKUP_EXISTS",message:`owner key backup already exists: ${e}`}),{path:e,directoryExists:i,exists:n}}(t.ownerKeyBackupPath,i),s=pd(t.rootDir,t.zoneDid,t.deviceDid);return{ready:0===i.length,rootDir:t.rootDir,state:r.state,domain:t.domain,ownerName:t.ownerName,ownerDid:t.ownerDid.toString(),zoneDid:t.zoneDid.toString(),deviceDid:t.deviceDid.toString(),deviceName:Rh,accessHostname:t.domain,rtcpPort:t.rtcpPort,guestAccess:t.guestAccess,publicIp:t.publicIp??null,dnsRecords:ad(t.domain,t.publicIp),ownerKeyBackup:o,plannedFiles:hd(t.rootDir,s).map(dd),problems:i,status:r}}function bd(e){const t=e.problems[0];return new Hh(1===e.problems.length?t.code:"ACTIVATION_PRECHECK_FAILED",1===e.problems.length?t.message:`activation precheck failed: ${e.problems.map((e=>e.message)).join("; ")}`,{state:e.state,problems:e.problems})}function Sd(e,t,r,i){switch(e.role){case"device_private_key":return r.privateKeyPem;case"device_document":return Qh(t.deviceDocument);case"device_document_jwt":return t.deviceDocJwt;case"device_mini_document_jwt":return t.deviceMiniDocJwt;case"zone_boot_override":return Qh(t.bootDocument);case"zone_document_jwt":return t.zoneDocumentJwt;case"dns_records":return Qh({hostname:i,records:t.dnsRecords});case"start_config":return Qh(t.startConfig);case"gateway_params":return Qh(t.gatewayParams);case"node_identity":return Qh(t.nodeIdentity)}}function Ad(e,t,r){return["inspect the target with: buckyos provision status --root <root>",r.length>0?`the following files were committed and are left in place: ${r.join(", ")}`:"no activation file was committed to the target root",`the owner private key backup was saved at ${t}; keep it or delete it before retrying (the backup path must not exist)`,`remove the committed files and the lock file ${e} (or reinstall BuckyOS), then run provision check again`,"the generated identity is not deleted or regenerated automatically"]}const Ed=1743478939,kd=2058838939;function xd(e){const t=e.split(".");return[Number(t[0])||0,Number(t[1])||0]}function _d(){var e,t,r,i;const n=globalThis,o=null==(t=null==(e=n.Deno)?void 0:e.version)?void 0:t.deno;if(o){const[e,t]=xd(o);if(e>2||2===e&&t>=2)return;throw new Error(`buckyos provision requires Deno >= 2.2 (node:sqlite), current: ${o}`)}const s=null==(i=null==(r=n.process)?void 0:r.versions)?void 0:i.node;if(s){const[e,t]=xd(s);if(e>22||22===e&&t>=13)return;throw new Error(`buckyos provision requires Node >= 22.13 (node:sqlite), current: ${s}`)}throw new Error("buckyos provision requires a Node >= 22.13 or Deno >= 2.2 runtime (browser is not supported)")}function Nd(e){_d();const t=globalThis.process;if("function"==typeof(null==t?void 0:t.getBuiltinModule)){const r=t.getBuiltinModule(e);if(r)return r}if("function"==typeof require)return require(e);throw new Error(`buckyos provision cannot load builtin module ${e} in this runtime`)}function Id(e,t){const r=Nd("node:fs"),i=Nd("node:path");r.mkdirSync(i.dirname(e),{recursive:!0}),r.writeFileSync(e,t),console.log(`# Write file: ${e}`)}function Td(e,t){Id(e,JSON.stringify(t,null,2))}function Bd(e){const t=Nd("node:fs");return JSON.parse(t.readFileSync(e,"utf8"))}function Od(e){if(Array.isArray(e))return e.map(Od);if(null!==e&&"object"==typeof e){const t={};for(const r of Object.keys(e).sort())t[r]=Od(e[r]);return t}return e}function Cd(e,t){return t||(Ch[e]?Ch[e]:Ch[`${e}.owner`]?Ch[`${e}.owner`]:(console.log(`Warning: Key pair for user ${e} not found, using devtest key pair`),Ph("devtest")))}function Dd(e,t,r){return r||Ph(`${e}.${t}`)}function jd(e){const t=Nd("node:path");return new qp(t.join(e,"local","identity"),t.join(e,"security"))}class Pd{constructor(e){_d(),this.dbPath=e}connect(){const{DatabaseSync:e}=Nd("node:sqlite");return new e(this.dbPath)}initializeDatabase(){const e=this.connect();try{e.exec("CREATE TABLE IF NOT EXISTS activation_codes (code TEXT PRIMARY KEY, used INTEGER);\n CREATE TABLE IF NOT EXISTS users (username TEXT PRIMARY KEY, state TEXT, public_key TEXT, activation_code TEXT, zone_config TEXT, self_cert boolean, user_domain TEXT, sn_ips TEXT);\n CREATE TABLE IF NOT EXISTS user_auth_v2 (username TEXT PRIMARY KEY, password_hash TEXT NOT NULL, password_salt TEXT NOT NULL, password_algo TEXT NOT NULL, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL, last_login_at INTEGER NULL);\n CREATE TABLE IF NOT EXISTS devices (owner TEXT, device_name TEXT, did TEXT PRIMARY KEY, ip TEXT, description TEXT, mini_config_jwt TEXT, created_at INTEGER, updated_at INTEGER);\n CREATE TABLE IF NOT EXISTS user_dns_records (id INTEGER PRIMARY KEY AUTOINCREMENT, owner TEXT, domain TEXT, record_type TEXT, record TEXT, ttl INTEGER, created_at INTEGER, updated_at INTEGER);\n CREATE UNIQUE INDEX IF NOT EXISTS idx_user_domain_record_type ON user_dns_records (owner, domain, record_type);\n CREATE INDEX IF NOT EXISTS user_dns_records_domain_index ON user_dns_records (domain, id);\n CREATE TABLE IF NOT EXISTS user_domain_history (domain TEXT PRIMARY KEY, owner TEXT NOT NULL, created_at INTEGER NOT NULL);\n CREATE TABLE IF NOT EXISTS did_documents (id INTEGER PRIMARY KEY AUTOINCREMENT, obj_id TEXT, owner_user TEXT, obj_name TEXT, did_document TEXT, doc_type TEXT, update_time INTEGER);\n CREATE INDEX IF NOT EXISTS idx_did_documents_owner_obj ON did_documents (owner_user, obj_name, update_time);")}finally{e.close()}}insertActivationCode(e){const t=this.connect();try{t.prepare("INSERT INTO activation_codes (code, used) VALUES (?, 0)").run(e)}finally{t.close()}}registerUserDirectly(e,t,r,i){const n=this.connect();try{n.prepare("INSERT INTO users (username, state, public_key, activation_code, zone_config, user_domain, self_cert, sn_ips) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run(e,"active",t,"DIRECT",r,i??null,1,null)}finally{n.close()}}registerDevice(e,t,r,n,o,s){const a=i.buckyosGetUnixTimestamp(),c=this.connect();try{c.prepare("INSERT INTO devices (owner, device_name, did, ip, description, mini_config_jwt, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run(e,t,r,o,s,n,a,a)}finally{c.close()}}}function Rd(){var e;const t=(null==(e=globalThis.process)?void 0:e.arch)??"";return"x64"===t?"amd64":"arm64"===t?"aarch64":t}function Ud(){var e;const t=(null==(e=globalThis.process)?void 0:e.platform)??"";return"darwin"===t?"apple":"win32"===t?"windows":t}function $d(e){const t=e.search(/[-+]/),r=(t>=0?e.slice(0,t):e).split(".");if(r.length<1||r.length>4)throw new Error(`invalid version format: ${e}`);3===r.length&&t>=0&&r.push(e.slice(t));const i=e=>{if(void 0===e)return 0n;const t=e.replace(/^[^0-9]*/,"").match(/^\d+/);return t?BigInt(t[0]):0n},n=e=>void 0===e?0n:/^\d+$/.test(e)?BigInt(e):0n,o=i(r[0]);if(o>0xffn)throw new Error(`major version out of range: ${e}`);const s=n(r[1]);if(s>0xffffn)throw new Error(`minor version out of range: ${e}`);const a=n(r[2]);if(a>0xffffn)throw new Error(`patch version out of range: ${e}`);const c=i(r[3]);if(c>0xffffffn)throw new Error(`build number out of range: ${e}`);return o<<56n|s<<40n|a<<24n|c}function Md(e){const t={...e},r=(e,r)=>{e in t&&r(t[e])&&delete t[e]};return r("did",(e=>null==e)),r("name",(e=>""===e)),r("author",(e=>""===e)),r("owner",(e=>null==e||"did:undefined:undefined"===e)),r("copyright",(e=>null==e)),r("tags",(e=>Array.isArray(e)&&0===e.length)),r("categories",(e=>Array.isArray(e)&&0===e.length)),r("base_on",(e=>null==e)),r("directory",(e=>e&&"object"==typeof e&&0===Object.keys(e).length)),r("references",(e=>e&&"object"==typeof e&&0===Object.keys(e).length)),r("exp",(e=>0===e)),r("size",(e=>0===e)),r("content",(e=>""===e)),r("version_tag",(e=>null==e)),r("deps",(e=>e&&"object"==typeof e&&0===Object.keys(e).length)),t}function Ld(e){const t=Md(e),[r]=i.buildNamedObjectByJson("pkg",t);return r.toString()}class Vd{constructor(e){_d(),this.dbPath=e}connect(){const{DatabaseSync:e}=Nd("node:sqlite");return new e(this.dbPath)}initializeDatabase(){const e=this.connect();try{e.exec("CREATE TABLE IF NOT EXISTS pkg_metas (\n metaobjid TEXT PRIMARY KEY,\n pkg_meta TEXT NOT NULL,\n author TEXT NOT NULL,\n author_pk TEXT NOT NULL,\n update_time INTEGER NOT NULL\n )"),e.exec("CREATE TABLE IF NOT EXISTS pkg_versions (\n pkg_name TEXT NOT NULL,\n author TEXT ,\n version TEXT NOT NULL,\n version_int INTEGER NOT NULL,\n metaobjid TEXT NOT NULL,\n tag TEXT,\n update_time INTEGER NOT NULL,\n PRIMARY KEY (pkg_name, version)\n )"),e.exec("CREATE TABLE IF NOT EXISTS author_info (\n author_name TEXT PRIMARY KEY,\n author_owner_config TEXT,\n author_zone_config TEXT\n )"),e.exec("CREATE INDEX IF NOT EXISTS idx_pkg_versions_pkgname ON pkg_versions (pkg_name)"),e.exec("CREATE INDEX IF NOT EXISTS idx_pkg_metas_author ON pkg_metas (author)"),e.exec("CREATE INDEX IF NOT EXISTS idx_pkg_versions_version_int ON pkg_versions (pkg_name, version_int)")}finally{e.close()}}addPkgMetaBatch(e){const t=this.connect();try{const n=i.buckyosGetUnixTimestamp();t.exec("BEGIN");try{for(const[r,i]of Object.entries(e)){t.prepare("INSERT OR REPLACE INTO pkg_metas (metaobjid, pkg_meta, author, author_pk, update_time) VALUES (?, ?, ?, ?, ?)").run(r,i.metaJwt,i.author,i.authorPk,n);const e=$d(i.version);t.prepare("SELECT 1 FROM pkg_versions WHERE pkg_name = ? AND author = ? AND version = ?").get(i.pkgName,i.author,i.version)?t.prepare("UPDATE pkg_versions SET metaobjid = ?, tag = ?, update_time = ? WHERE pkg_name = ? AND author = ? AND version = ?").run(r,i.tag??null,n,i.pkgName,i.author,i.version):t.prepare("INSERT INTO pkg_versions (pkg_name, author, version, version_int, metaobjid, tag, update_time) VALUES (?, ?, ?, ?, ?, ?, ?)").run(i.pkgName,i.author,i.version,e,r,i.tag??null,n)}t.exec("COMMIT")}catch(r){throw t.exec("ROLLBACK"),r}}finally{t.close()}}}const Hd=[{uniqueId:"verify-hub",showName:"Verify Hub",description:"Verify Hub",selectorType:"random"},{uniqueId:"scheduler",showName:"Scheduler",description:"Scheduler",selectorType:"single"},{uniqueId:"smb-service",showName:"Samba Service",description:"Samba Service",selectorType:"random"},{uniqueId:"msg-center",showName:"Message Center",description:"Message Center",selectorType:"single"},{uniqueId:"opendan",showName:"OpenDAN Runtime",description:"OpenDAN Runtime",selectorType:"single"},{uniqueId:"workflow",showName:"Workflow Service",description:"Workflow Service",selectorType:"single"}],Kd="0.7.0";function Fd(e){const t=e.split("_");return 2===t.length?i.DID.fromStr(`did:bns:${t[1]}.${t[0]}`):i.DID.fromStr(`did:bns:${e}`)}exports.NODE_IDENTITY_SCHEMA_V2=i.NODE_IDENTITY_SCHEMA_V2,exports.ACTIVATION_DEFAULT_RTCP_PORT=2980,exports.ACTIVATION_DEVICE_NAME=Rh,exports.ACTIVATION_DOCUMENT_VALIDITY_SECONDS=$h,exports.ACTIVATION_LOCK_FILE_NAME=Mh,exports.ACTIVATION_MIN_PASSWORD_LENGTH=8,exports.ACTIVATION_NET_ID=Uh,exports.ActivationError=Hh,exports.DEVICE_DOC_JWT_FILE_NAME=s,exports.DEVICE_MINI_DOC_JWT_FILE_NAME=a,exports.DEV_TEST_EVM_ACCOUNTS=Dh,exports.DEV_TEST_EVM_SEED_SENDER=jh,exports.DEV_TEST_EVM_SEED_SENDER_INDEX=0,exports.DEV_TEST_EVM_USER_INDEXES=Oh,exports.DEV_TEST_KEYS=Ch,exports.DEV_TEST_KEY_INDEXES=Bh,exports.DEV_TEST_MNEMONIC=oh,exports.DevSnDb=Pd,exports.IDENTITY_MATERIALS=Pp,exports.IDENTITY_USAGES=jp,exports.IdentityRoots=qp,exports.KERNEL_SERVICE_DOC_VERSION=Kd,exports.MetaIndexDb=Vd,exports.NODE_GATEWAY_PARAMS_FILE_NAME=c,exports.PROVISION_BASE_TIME=Ed,exports.PROVISION_DEFAULT_EXP=kd,exports.ZONE_DNS_RECORDS_FILE_NAME=Lh,exports.ZONE_DOCUMENT_JWT_FILE_NAME=Vh,exports.activateOfflineZone=async function(e){const t=Kh("node:fs"),r=ud(e),n=od(e.adminPassword),o=await wd(e);if(!o.ready)throw bd(o);const s=e.ownerKeyPair??cd(),a=e.deviceKeyPair??cd(),c=await async function(e,t,r,n){const o=i.buckyosGetUnixTimestamp(),s=o+$h,a=i.createJwkByX(r.publicKeyX),c=i.createJwkByX(n.publicKeyX),u=e.ownerDid.toString(),l=e.zoneDid.toString(),p=e.deviceDid.toString(),d=i.newOwnerDocument({did:e.ownerDid,name:e.ownerName,displayName:e.ownerName,publicKeyJwk:a,now:o});d.exp=s,i.ownerDocumentSetDefaultZoneDid(d,e.zoneDid);const f=i.ownerDocumentToOrderedJson(d),y=i.oodDescriptionToString(i.parseOODDescription(`${Rh}@${Uh}`)),g=await i.encodeZoneBootDocument(i.newZoneBootDocument({id:e.zoneDid,oods:[y],exp:s}),r.privateKeyPem),v=i.decodeJwtClaimWithoutVerify(g),w=m(Rh,c,e.deviceDid,o);delete w.support_container,w.owner=u,w.zone_did=l,w.net_id=Uh,w.rtcp_port=e.rtcpPort,w.iat=o,w.exp=s,w.version_seq=0;const b=i.deviceDocumentToOrderedJson(w),S=await i.encodeDeviceDocument(w,r.privateKeyPem),A=i.newDeviceMiniDocumentByDeviceDocument(w);A.iat=o;const E=await i.deviceMiniDocumentToJwt(A,r.privateKeyPem),k=i.newZoneDocument({id:e.zoneDid,ownerDid:e.ownerDid,publicKeyJwk:a,now:o});k.hostname=e.domain,k.owner=u,k.oods=[y],k.boot_jwt=g,k.devices={[Rh]:b},k.mini_device_jwts={[Rh]:E},k.iat=o,k.exp=s,k.version_seq=0,delete k.sn;const x=await i.encodeZoneDocument(k,r.privateKeyPem);if((new TextEncoder).encode(x).length>=4096)throw new Hh("ZONE_DOCUMENT_TOO_LARGE","zone document JWT exceeds the 4096 byte inline limit");return{documentIat:o,documentExp:s,ownerDocument:f,bootDocument:v,bootJwt:g,deviceDocument:b,deviceDocJwt:S,deviceMiniDocJwt:E,zoneDocumentJwt:x,nodeIdentity:h({zoneDid:e.zoneDid,ownerDid:e.ownerDid,ownerPublicKey:a,deviceName:Rh,deviceDid:e.deviceDid,zoneIat:o}),startConfig:{user_name:e.ownerName,owner_document:f,zone_name:l,access_hostname:e.domain,zone_document_jwt:x,boot_config_jwt:g,device_doc_jwt:S,device_mini_doc_jwt:E,ood_jwt:S,admin_password_hash:sd(e.ownerName,t),guest_access:e.guestAccess,friend_passcode:"",enabled_features:{},ai_provider_config:{},jarvis_msg_tunnel_config:{}},gatewayParams:{params:{device_did:p}},dnsRecords:ad(e.domain,e.publicIp)}}(r,n,s,a),u=pd(r.rootDir,r.zoneDid,r.deviceDid),l=hd(r.rootDir,u),p=[],d={schema_version:1,trace_id:e.traceId??null,started_at:i.buckyosGetUnixTimestamp(),domain:r.domain,owner_key_backup:r.ownerKeyBackupPath,stage:"locked",committed:[]};!function(e,t){const r=Kh("node:fs");try{r.writeFileSync(e,Qh(t),{mode:384,flag:"wx"})}catch(i){if("EEXIST"===i.code)throw new Hh("ACTIVATION_IN_PROGRESS",`another activation holds the lock ${e}; inspect it with provision status`,{lock_file:e,lock:fd(e)});throw i}}(u.lockPath,d);const f=()=>{try{t.rmSync(u.lockPath,{force:!0})}catch{}};let y;try{y=await wd(e)}catch(b){throw f(),b}const g=y.problems.filter((e=>"ACTIVATION_IN_PROGRESS"!==e.code));if(g.length>0)throw f(),bd({...y,problems:g});for(const i of l)if(qh(i.absolutePath))throw f(),new Hh("TARGET_PARTIALLY_ACTIVATED",`activation file already exists: ${i.path}`,{state:"partial",problems:[{code:"FILE_EXISTS",message:`${i.path} already exists`}]});try{!function(e,t){const r=Kh("node:fs");r.writeFileSync(e,t,{mode:384,flag:"wx"}),Fh()||r.chmodSync(e,384)}(r.ownerKeyBackupPath,s.privateKeyPem)}catch(b){f();const e=b.code;throw new Hh("EEXIST"===e?"OWNER_KEY_BACKUP_EXISTS":"OWNER_KEY_BACKUP_FAILED",`owner key backup could not be saved: ${b instanceof Error?b.message:String(b)}`,{owner_key_backup:{path:r.ownerKeyBackupPath,saved:!1},committed_files:[]})}d.stage="backup_saved";const v=[],w=(e,t)=>{throw new Hh("ACTIVATION_COMMIT_FAILED",`activation commit failed at ${t}: ${e instanceof Error?e.message:String(e)}`,{stage:t,owner_key_backup:{path:r.ownerKeyBackupPath,saved:!0},committed_files:v,lock_file:u.lockPath,recovery:Ad(u.lockPath,r.ownerKeyBackupPath,v.map((e=>e.path)))})};try{yd(u.lockPath,d)}catch(b){w(b,"lock:backup_saved")}d.stage="committing";for(const i of l){const e=Sd(i,c,a,r.domain);try{ed(i.absolutePath,e,i.mode,i.dirMode)}catch(b){w(b,i.path)}v.push({...dd(i),sha256:i.secret?null:Wh(e)}),d.committed=v.map((e=>e.path));try{yd(u.lockPath,d)}catch(b){w(b,`lock:${i.path}`)}}d.stage="committed";try{yd(u.lockPath,d),t.rmSync(u.lockPath,{force:!0})}catch(b){p.push(`activation completed but the lock ${u.lockPath} could not be removed: ${b instanceof Error?b.message:String(b)}`)}return{rootDir:r.rootDir,state:"configured",startupRequired:!0,domain:r.domain,ownerName:r.ownerName,ownerDid:r.ownerDid.toString(),zoneDid:r.zoneDid.toString(),deviceDid:r.deviceDid.toString(),deviceName:Rh,accessHostname:r.domain,rtcpPort:r.rtcpPort,guestAccess:r.guestAccess,publicIp:r.publicIp??null,documentIat:c.documentIat,documentExp:c.documentExp,ownerKeyBackup:{path:r.ownerKeyBackupPath,saved:!0},dnsRecords:c.dnsRecords,committedFiles:v,warnings:p}},exports.assertProvisionRuntime=_d,exports.bindDeviceDocumentDid=g,exports.buildActivationDnsRecords=ad,exports.buildDeviceDid=y,exports.buildDidDocs=function(e,t){_d();const r=Nd("node:path"),n=(null==t?void 0:t.version)??Kd,o=(null==t?void 0:t.now)??i.buckyosGetUnixTimestamp(),s=[];for(const i of Hd){const t=Fd(i.uniqueId),a=Od({name:i.uniqueId,show_name:i.showName,version:n,author:"did:bns:buckyos",owner:"did:bns:buckyos",create_time:o,last_update_time:o,description:{detail:{en:i.description}},categories:["service"],selector_type:i.selectorType,install_config_tips:{data_mount_point:[],local_cache_mount_point:[],rdb_instances:{},service_ports:{}},pkg_list:{}}),c=r.join(e,`${t.toRawHostName()}.doc.json`);Td(c,a),s.push(c)}return s},exports.calcPkgMetaObjId=Ld,exports.checkOfflineActivation=wd,exports.createCa=Zp,exports.createCertFromCa=async function(e,t,r,i){const n=Bp("node:fs"),o=Bp("node:path"),s=i&&i.length>0?i:[t],a=s[0].replace(/\*/g,"wildcard").replace(/\./g,"_");n.mkdirSync(r,{recursive:!0});const c=o.join(r,`${a}.crt`),u=o.join(r,`${a}.key`),l=await Qp(e,s);return n.writeFileSync(u,l.privateKeyPem),n.writeFileSync(c,l.certPem),console.log(`Certificate created: ${c}`),{certPath:c,keyPath:u}},exports.createIdentityCertFromCa=async function(e,t,r,i={}){const n=Bp("node:fs"),o=function(e){return e instanceof qp?e:qp.fromEnvOrBuckyosRoot(e)}(r),s=i.usage??"server",a=Vp(t),c=a.toRawHostUri(),u=Lp(c),l=o.publicDir(a.toString()),p=o.securityDir(a.toString()),h=Jp(l,p,s),d=i.hostnames&&i.hostnames.length>0?i.hostnames:[rh(a)],f=i.uriSans??[a.toString()];n.mkdirSync(l,{recursive:!0,mode:493}),n.mkdirSync(p,{recursive:!0,mode:448});const y=await Qp(e,d,f,s),g=eh(y.certPem),m=eh(y.caCertPem),v=m,w=`${g}${v}`;var b,S,A;return th(h.privateKey,y.privateKeyPem,384),th(h.cert,g,420),th(h.chain,v,420),th(h.fullchain,w,420),th(h.ca,m,420),b=h.metadata,S=await nh(a,s,c,u,y),A=420,th(b,`${JSON.stringify(S,null,2)}\n`,A),console.log(`Identity certificate created: ${h.fullchain}`),{did:a.toString(),rawHostUri:c,dirName:u,paths:h,certPath:h.cert,chainPath:h.chain,fullchainPath:h.fullchain,caPath:h.ca,keyPath:h.privateKey,metadataPath:h.metadata}},exports.createNodeConfigs=async function(e){_d();const t=Nd("node:path"),r=e.envDir,n=Bd(t.join(r,"user_config.json")).name;if("string"!=typeof n||!n)throw new Error("user_config.json missing name field");const o=Bd(t.join(r,"zone_config.json")),s=i.DID.fromStr(o.id),a=Cd(n,e.ownerKeyPair),c=Dd(n,e.deviceName,e.deviceKeyPair),u=t.join(r,e.deviceName),l=new i.DID("bns",n),p=y(e.deviceName,s),d=m(e.deviceName,i.createJwkByX(c.publicKeyX),p,e.now);d.support_container=!0,delete d.support_container,void 0!==e.netId&&(d.net_id=e.netId),d.owner=l.toString(),d.zone_did=s.toString(),console.log(`input net_id: ${e.netId}, device_config.net_id: ${d.net_id}`);const f=await i.encodeDeviceDocument(d,a.privateKeyPem);console.log(`${e.deviceName} device jwt: ${f}`);const g=i.newDeviceMiniDocumentByDeviceDocument(d),v=await i.deviceMiniDocumentToJwt(g,a.privateKeyPem);Id(t.join(u,"device_mini_config.jwt"),v);const w=h({zoneDid:s,ownerDid:l,ownerPublicKey:i.createJwkByX(a.publicKeyX),deviceName:e.deviceName,deviceDid:p,zoneIat:Ed});if(b(u,jd(u),w,d,f,v,c.privateKeyPem),e.deviceName.startsWith("ood")){const e=Od({admin_password_hash:"o8XyToejrbCYou84h/VkF4Tht0BeQQbuX3XKG+8+GQ4=",device_private_key:c.privateKeyPem,device_public_key:i.createJwkByX(c.publicKeyX),ood_jwt:f,friend_passcode:"sdfsdfsdf",gateway_type:"PortForward",guest_access:!0,private_key:a.privateKeyPem,public_key:i.createJwkByX(a.publicKeyX),user_name:n,zone_name:s.toHostName(),BUCKYOS_ROOT:"/opt/buckyos"});Td(t.join(u,"start_config.json"),e)}return console.log(`Successfully created node configuration: ${n}.${e.deviceName}`),i.encodeDeviceDocument(d,c.privateKeyPem)},exports.createSnConfigs=async function(e){_d();const t=Nd("node:path"),r=t.join(e.outputDir,"sn_server"),n=Ph("sn_owner"),o=Ph("sn_server"),s=kd;Id(t.join(r,".buckycli","user_private_key.pem"),n.privateKeyPem);const a=i.newOwnerDocument({did:new i.DID("bns","sn"),name:"root",displayName:"sn admin",publicKeyJwk:i.createJwkByX(n.publicKeyX)});Td(t.join(r,".buckycli","user_config.json"),i.ownerDocumentToOrderedJson(a)),console.log("- Created owner config for sn admin.");const c=i.newDeviceMiniDocument({name:"sn",x:o.publicKeyX,exp:s}),u=await i.deviceMiniDocumentToJwt(c,n.privateKeyPem),l=i.newDeviceDocumentByMiniDocument(u,c,"did:web:sn.devtests.org","did:bns:sn");l.net_id="wan",Td(t.join(r,"sn_device_config.json"),i.deviceDocumentToOrderedJson(l)),Id(t.join(r,"sn_private_key.pem"),o.privateKeyPem),console.log("- Created sn device config & private key.");const p=i.newZoneBootDocument({oods:["sn"],exp:s}),h=Od({params:{sn_boot_jwt:await i.encodeZoneBootDocument(p,n.privateKeyPem),sn_owner_pk:n.publicKeyX,sn_device_jwt:u,sn_host:e.snBaseHost,sn_ip:e.snIp,sn_cer:"fullchain.cert",sn_pem:"fullchain.pem",web3_cer:"fullchain.cert",web3_pem:"fullchain.pem"}});Td(t.join(r,"params.json"),h),console.log("- Created params.json.");const d=new Pd(t.join(r,"sn_db.sqlite3"));d.initializeDatabase();for(let i=0;i<9;i++){const e=`sndevtest${i}`;console.log(`insert activation code: ${e}`),d.insertActivationCode(e)}console.log("- Created SN database."),console.log("Successfully created SN configuration")},exports.createUserEnv=async function(e){_d();const t=Nd("node:path"),r=e.rtcpPort??2980,n=e.outputDir,o=kd,s=Cd(e.username,e.ownerKeyPair),a=new i.DID("bns",e.username);let c,u=new i.DID("web",e.hostname);if(e.snBaseHost&&e.snBaseHost.includes(".")){const t=`web3.${e.snBaseHost}`;u=i.DID.fromHostNameByBridge(e.hostname,"bns",t),c=`sn.${e.snBaseHost}`}Id(t.join(n,"user_private_key.pem"),s.privateKeyPem);const l=i.createJwkByX(s.publicKeyX),p=i.newOwnerDocument({did:a,name:e.username,displayName:e.username,publicKeyJwk:l});Td(t.join(n,"user_config.json"),i.ownerDocumentToOrderedJson(p)),console.log(`Created owner config for ${e.username}`);const h=i.parseOODDescription(e.oodName),d=Dd(e.username,h.name,e.deviceKeyPair);let f,g=c;h.netId&&(h.netId.startsWith("wan")&&(g=void 0),h.netId.startsWith("wan_dyn")&&c&&(f=`https://${c}/kapi/sn`));const v=i.oodDescriptionToString(h),w=i.newZoneBootDocument({oods:[v],sn:g,exp:o}),b=u.toRawHostName();Td(t.join(n,`${b}.zone.json`),w),w.id=u.toString();const S=i.newZoneDocument({id:u,ownerDid:a,publicKeyJwk:l}),A=await i.encodeZoneBootDocument(w,s.privateKeyPem);S.boot_jwt=A,S.id=w.id,S.oods=[...w.oods],void 0!==w.sn?S.sn=w.sn:delete S.sn,S.exp=w.exp,S.iat=w.exp-i.DEFAULT_EXPIRE_TIME,S.version_seq=0,S.owner=w.owner??i.DID.undefined().toString(),void 0!==w.owner_key&&(S.verificationMethod[0].publicKeyJwk=w.owner_key),Td(t.join(n,"zone_config.json"),i.zoneDocumentToOrderedJson(S));const E=s.publicKeyX;console.log(`=> ${b} TXT Record(${A.length+6}): BOOT=${A};`),console.log(`=> ${b} TXT Record(${E.length+5}): PKX=${E};`);const k=2980===r?void 0:r,x=i.newDeviceMiniDocument({name:h.name,x:d.publicKeyX,rtcpPort:k,exp:o}),_=await i.deviceMiniDocumentToJwt(x,s.privateKeyPem);console.log(`=> ${b} TXT Record(${_.length+5}): DEV=${_};`);const N=y(h.name,u),I=m(h.name,i.createJwkByX(d.publicKeyX),N);I.support_container=!0,void 0!==h.netId&&(I.net_id=h.netId),I.owner=a.toString(),I.zone_did=u.toString(),void 0!==f&&(I.ddns_sn_url=f),console.log(`${h.name} device config: ${JSON.stringify(i.deviceDocumentToOrderedJson(I),null,2)}`);const T={boot_config_jwt:A,device_mini_doc_jwt:_,pkx:E};return Td(t.join(n,"zone_txt_record.json"),T),console.log(`Successfully created user environment configuration: ${e.username}`),T},exports.decodeDeviceDocumentWithoutVerify=S,exports.deriveDevTestEvmAccount=Th,exports.deriveDevTestEvmAccountFromMnemonic=Ih,exports.deriveDevTestKeyPair=vh,exports.deriveDevTestKeyPairFromMnemonic=mh,exports.devTestKeccak256=_h,exports.deviceIdentityPathsForRoots=f,exports.didWebDocumentUrl=Fp,exports.encodeIdentityDirName=Lp,exports.ensureCa=async function(e,t="devtest"){const r=Bp("node:fs"),i=Bp("node:path"),n=i.join(e,`${t}_ca_cert.pem`),o=i.join(e,`${t}_ca_key.pem`);if(r.existsSync(n)&&r.existsSync(o)){const i=function(e){try{return Yp(new Ip(e))}catch(t){return t instanceof Error?`cannot parse CA certificate: ${t.message}`:"cannot parse CA certificate"}}(r.readFileSync(n,"utf8"));return i?(console.log(`Existing CA at ${n} is invalid (${i}); regenerating`),Zp(e,t)):(console.log(`Use existing CA at: ${n}`),{caCertPath:n,caKeyPath:o})}return Zp(e,t)},exports.generateProvisionKeyPair=cd,exports.getDevTestEvmAccountByIndex=function(e){return Th(e)},exports.getDevTestEvmAccountByUsername=function(e){const t=Dh[e];if(!t)throw new Error(`no deterministic EVM account for seed user ${e}; register it in DEV_TEST_EVM_USER_INDEXES`);return t},exports.getDevTestKeyPairById=Ph,exports.getDevTestKeyPairByIndex=function(e){return vh(e)},exports.hashAdminPassword=sd,exports.identityDirName=Kp,exports.identityFileName=zp,exports.identityRawHostUri=Hp,exports.inspectActivationRoot=vd,exports.loadDeviceDocJwtForRoots=v,exports.loadDeviceMiniDocJwtForRoots=function(e,t){return u("node:fs").readFileSync(f(e,t).deviceMiniDocJwt,"utf8")},exports.loadLocalDeviceDocumentForRoots=async function(e,t,r){const n=v(e,t.device_did),o=r?await i.verifyJwtEdDSA(n,t.owner_public_key):S(n);if(o.id!==t.device_did)throw new Error(`device_doc.jwt id ${o.id} does not match node_identity device_did ${t.device_did}`);return[n,o]},exports.loadLocalNodeIdentityConfig=d,exports.newDeviceDocumentByJwkWithDid=m,exports.newLocalNodeIdentityConfig=h,exports.nodeTestIdentityRoots=jd,exports.normalizePackageMetaForObjId=Md,exports.registerDeviceToSn=async function(e,t,r,n){_d();const o=Nd("node:path"),s=Nd("node:fs"),a=Nd("node:os"),c=o.join(e,t,r),u=o.join(c,"node_identity.json");if(!s.existsSync(u))throw new Error(`Device config not found: ${u}`);const l=d(u),p=i.DID.fromStr(l.owner_did).id,h=f(jd(c),l.device_did),y=s.readFileSync(h.deviceDocJwt,"utf8"),g=s.readFileSync(h.deviceMiniDocJwt,"utf8"),m=await i.verifyJwtEdDSA(y,l.owner_public_key),v=m.id;let w;try{w=i.parseOODDescription(r)}catch{w={name:r,nodeType:"Device"}}try{const n=Bd(o.join(e,t,"zone_config.json")).oods.map(i.parseOODDescription).find((e=>e.name===r));n&&(w=n)}catch{}const b=function(){const e=[],t=Nd("node:os").networkInterfaces();for(const r of Object.values(t))for(const t of r??[])t.internal||"IPv6"===t.family&&t.address.startsWith("fe80")||e.includes(t.address)||e.push(t.address);return e}(),S={...m};w.ip&&(S.ips=[w.ip]),void 0!==w.netId&&(S.net_id=w.netId);const A={...S,arch:Rd(),os:Ud(),update_time:i.buckyosGetUnixTimestamp(),state:"Ready",sys_hostname:a.hostname(),base_os_info:`${a.type()} ${a.release()}`,all_ip:b,cpu_num:a.cpus().length,total_mem:a.totalmem(),mem_usage:a.totalmem()-a.freemem()};let E="127.0.0.1";b.length>0&&(E=b[0]),w.ip&&(E=w.ip),new Pd(n).registerDevice(p,r,v,g,E,JSON.stringify(A,null,2)),console.log(`Successfully registered device ${p}.${r} (DID: ${v}) to SN database at ${n}`)},exports.registerUserToSn=async function(e,t,r){_d();const n=Nd("node:path"),o=Bd(n.join(e,t,"user_config.json")).name;if("string"!=typeof o||!o)throw new Error("user_config.json missing name field");const s=Bd(n.join(e,t,"zone_config.json")),a=i.DID.fromStr(s.id);let c;"bns"!==a.method&&(c=a.toHostName());const u=Bd(n.join(e,t,"zone_txt_record.json")),l=new Pd(r),p=JSON.stringify(Od({kty:"OKP",crv:"Ed25519",x:u.pkx}));l.registerUserDirectly(o,p,u.boot_config_jwt,c),console.log(`Successfully registered user ${o}@${t} to SN database at ${r}`)},exports.saveLocalDeviceIdentityForRoots=b,exports.saveNodeGatewayParams=w,exports.setPkgMeta=async function(e,t){_d();const r=Nd("node:fs");if(!r.existsSync(e))throw new Error(`meta_path ${e} does not exist`);if(!r.existsSync(t))throw new Error(`db_path ${t} does not exist`);const n=r.readFileSync(e,"utf8"),o=n.trimStart().startsWith("{")?JSON.parse(n):i.decodeJwtClaimWithoutVerify(n.trim()),s=Ld(o),a=new Vd(t);return a.initializeDatabase(),a.addPkgMetaBatch({[s]:{metaJwt:n,pkgName:o.name,version:o.version,tag:o.version_tag??void 0,author:o.author,authorPk:""}}),s},exports.uniqueNameToDid=Fd,exports.validateAdminPassword=od,exports.validateOwnerName=rd,exports.validatePublicIp=nd,exports.validateRtcpPort=id,exports.validateZoneDomain=td,exports.versionToInt=$d;
|
|
92
92
|
//# sourceMappingURL=provision.cjs.map
|