buckyos 0.7.170 → 0.7.175
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/core/app.ts +2 -0
- package/cli/core/argv.ts +45 -239
- package/cli/core/command.ts +3 -35
- package/cli/dist/cli.mjs +2151 -673
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/modules/agent.ts +3 -1
- package/cli/modules/app.ts +13 -2
- package/cli/modules/pikg.ts +70 -1
- package/cli/modules/runtime.ts +497 -0
- package/cli/modules/skill.ts +583 -161
- package/cli/modules/skill_lint.ts +462 -0
- package/cli/version.ts +1 -1
- package/dist/account-7a7bde6f.mjs +105 -0
- package/dist/account-7a7bde6f.mjs.map +1 -0
- package/dist/account-b12ac6b9.js +2 -0
- package/dist/account-b12ac6b9.js.map +1 -0
- package/dist/aicc-67851c41.mjs +582 -0
- package/dist/aicc-67851c41.mjs.map +1 -0
- package/dist/aicc-ccb36ef7.js +2 -0
- package/dist/aicc-ccb36ef7.js.map +1 -0
- package/dist/browser.cjs +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +2 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.mjs +204 -194
- package/dist/browser.mjs.map +1 -1
- package/dist/did_object_client-6a1b108a.js +2 -0
- package/dist/did_object_client-6a1b108a.js.map +1 -0
- package/dist/did_object_client-7fa36f90.mjs +87 -0
- package/dist/did_object_client-7fa36f90.mjs.map +1 -0
- package/dist/did_object_client.d.ts +39 -0
- package/dist/did_object_client.d.ts.map +1 -0
- package/dist/{executor_client-5f4d0468.mjs → executor_client-c620d25c.mjs} +233 -748
- package/dist/executor_client-c620d25c.mjs.map +1 -0
- package/dist/executor_client-d4439d54.js +13 -0
- package/dist/executor_client-d4439d54.js.map +1 -0
- package/dist/executor_client.d.ts +129 -0
- package/dist/executor_client.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +209 -199
- package/dist/index.mjs.map +1 -1
- package/dist/internal/command_args.d.ts +67 -0
- package/dist/internal/command_args.d.ts.map +1 -0
- package/dist/krpc_client-26c2dc8b.js +2 -0
- package/dist/krpc_client-26c2dc8b.js.map +1 -0
- package/dist/krpc_client-673448e5.mjs +173 -0
- package/dist/krpc_client-673448e5.mjs.map +1 -0
- package/dist/krpc_client.d.ts +5 -1
- package/dist/krpc_client.d.ts.map +1 -1
- package/dist/{ndn_types-ab30fac0.mjs → ndn_types-0fac2499.mjs} +115 -215
- package/dist/ndn_types-0fac2499.mjs.map +1 -0
- package/dist/ndn_types-5b138882.js +2 -0
- package/dist/ndn_types-5b138882.js.map +1 -0
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.mjs +201 -194
- package/dist/node.mjs.map +1 -1
- package/dist/object_url-8fb5a7bf.js +2 -0
- package/dist/object_url-8fb5a7bf.js.map +1 -0
- package/dist/object_url-f72c1704.mjs +412 -0
- package/dist/object_url-f72c1704.mjs.map +1 -0
- package/dist/openai-ae2978de.mjs +163 -0
- package/dist/openai-ae2978de.mjs.map +1 -0
- package/dist/openai-f560d518.js +2 -0
- package/dist/openai-f560d518.js.map +1 -0
- package/dist/provision.cjs +6 -6
- package/dist/provision.cjs.map +1 -1
- package/dist/provision.mjs +4 -3
- package/dist/provision.mjs.map +1 -1
- package/dist/site_manager-11a7a468.mjs +6410 -0
- package/dist/site_manager-11a7a468.mjs.map +1 -0
- package/dist/site_manager-334b1a51.js +2 -0
- package/dist/site_manager-334b1a51.js.map +1 -0
- package/dist/{tus_client-b231b248.js → tus_client-809c90ab.js} +2 -2
- package/dist/{tus_client-b231b248.js.map → tus_client-809c90ab.js.map} +1 -1
- package/dist/{tus_client-d1ffe2d6.mjs → tus_client-893a3287.mjs} +2 -2
- package/dist/{tus_client-d1ffe2d6.mjs.map → tus_client-893a3287.mjs.map} +1 -1
- package/dist/xllm/core/action_parser.d.ts +15 -0
- package/dist/xllm/core/action_parser.d.ts.map +1 -0
- package/dist/xllm/core/behavior_loop.d.ts +20 -0
- package/dist/xllm/core/behavior_loop.d.ts.map +1 -0
- package/dist/xllm/core/behavior_result.d.ts +11 -0
- package/dist/xllm/core/behavior_result.d.ts.map +1 -0
- package/dist/xllm/core/config.d.ts +62 -0
- package/dist/xllm/core/config.d.ts.map +1 -0
- package/dist/xllm/core/context_window.d.ts +15 -0
- package/dist/xllm/core/context_window.d.ts.map +1 -0
- package/dist/xllm/core/deps.d.ts +97 -0
- package/dist/xllm/core/deps.d.ts.map +1 -0
- package/dist/xllm/core/errors.d.ts +94 -0
- package/dist/xllm/core/errors.d.ts.map +1 -0
- package/dist/xllm/core/interrupt.d.ts +31 -0
- package/dist/xllm/core/interrupt.d.ts.map +1 -0
- package/dist/xllm/core/json.d.ts +11 -0
- package/dist/xllm/core/json.d.ts.map +1 -0
- package/dist/xllm/core/json_check.d.ts +17 -0
- package/dist/xllm/core/json_check.d.ts.map +1 -0
- package/dist/xllm/core/loop.d.ts +135 -0
- package/dist/xllm/core/loop.d.ts.map +1 -0
- package/dist/xllm/core/messages.d.ts +18 -0
- package/dist/xllm/core/messages.d.ts.map +1 -0
- package/dist/xllm/core/observer.d.ts +14 -0
- package/dist/xllm/core/observer.d.ts.map +1 -0
- package/dist/xllm/core/open_runtime.d.ts +22 -0
- package/dist/xllm/core/open_runtime.d.ts.map +1 -0
- package/dist/xllm/core/prepare.d.ts +54 -0
- package/dist/xllm/core/prepare.d.ts.map +1 -0
- package/dist/xllm/core/prompt.d.ts +40 -0
- package/dist/xllm/core/prompt.d.ts.map +1 -0
- package/dist/xllm/core/protocol.d.ts +15 -0
- package/dist/xllm/core/protocol.d.ts.map +1 -0
- package/dist/xllm/core/result.d.ts +12 -0
- package/dist/xllm/core/result.d.ts.map +1 -0
- package/dist/xllm/core/run.d.ts +198 -0
- package/dist/xllm/core/run.d.ts.map +1 -0
- package/dist/xllm/core/rust_text.d.ts +20 -0
- package/dist/xllm/core/rust_text.d.ts.map +1 -0
- package/dist/xllm/core/site_policy.d.ts +5 -0
- package/dist/xllm/core/site_policy.d.ts.map +1 -0
- package/dist/xllm/core/store.d.ts +60 -0
- package/dist/xllm/core/store.d.ts.map +1 -0
- package/dist/xllm/core/suspension.d.ts +13 -0
- package/dist/xllm/core/suspension.d.ts.map +1 -0
- package/dist/xllm/core/tokenizer.d.ts +8 -0
- package/dist/xllm/core/tokenizer.d.ts.map +1 -0
- package/dist/xllm/core/types.d.ts +826 -0
- package/dist/xllm/core/types.d.ts.map +1 -0
- package/dist/xllm/core/xml.d.ts +19 -0
- package/dist/xllm/core/xml.d.ts.map +1 -0
- package/dist/xllm/dev/openai.d.ts +17 -0
- package/dist/xllm/dev/openai.d.ts.map +1 -0
- package/dist/xllm/dev/scripted.d.ts +46 -0
- package/dist/xllm/dev/scripted.d.ts.map +1 -0
- package/dist/xllm/dev.d.ts +5 -0
- package/dist/xllm/dev.d.ts.map +1 -0
- package/dist/xllm/hosts/browser/store.d.ts +41 -0
- package/dist/xllm/hosts/browser/store.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/deno_api.d.ts +103 -0
- package/dist/xllm/hosts/deno/deno_api.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/identity.d.ts +29 -0
- package/dist/xllm/hosts/deno/identity.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/index.d.ts +47 -0
- package/dist/xllm/hosts/deno/index.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/native_runtime.d.ts +93 -0
- package/dist/xllm/hosts/deno/native_runtime.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/native_tools.d.ts +105 -0
- package/dist/xllm/hosts/deno/native_tools.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/provider.d.ts +13 -0
- package/dist/xllm/hosts/deno/provider.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/store.d.ts +60 -0
- package/dist/xllm/hosts/deno/store.d.ts.map +1 -0
- package/dist/xllm/index.d.ts +48 -0
- package/dist/xllm/index.d.ts.map +1 -0
- package/dist/xllm/providers/aicc.d.ts +22 -0
- package/dist/xllm/providers/aicc.d.ts.map +1 -0
- package/dist/xllm/providers/timeout.d.ts +12 -0
- package/dist/xllm/providers/timeout.d.ts.map +1 -0
- package/dist/xllm/runtime/compress.d.ts +149 -0
- package/dist/xllm/runtime/compress.d.ts.map +1 -0
- package/dist/xllm/runtime/did_object_resources.d.ts +21 -0
- package/dist/xllm/runtime/did_object_resources.d.ts.map +1 -0
- package/dist/xllm/runtime/hints.d.ts +23 -0
- package/dist/xllm/runtime/hints.d.ts.map +1 -0
- package/dist/xllm/runtime/site.d.ts +22 -0
- package/dist/xllm/runtime/site.d.ts.map +1 -0
- package/dist/xllm/runtime/site_manager.d.ts +38 -0
- package/dist/xllm/runtime/site_manager.d.ts.map +1 -0
- package/dist/xllm/runtime/site_tools.d.ts +76 -0
- package/dist/xllm/runtime/site_tools.d.ts.map +1 -0
- package/dist/xllm/runtime/step_renderer.d.ts +54 -0
- package/dist/xllm/runtime/step_renderer.d.ts.map +1 -0
- package/dist/xllm/runtime/task_model.d.ts +64 -0
- package/dist/xllm/runtime/task_model.d.ts.map +1 -0
- package/dist/xllm/runtime/tool_result.d.ts +39 -0
- package/dist/xllm/runtime/tool_result.d.ts.map +1 -0
- package/dist/xllm/runtime/types.d.ts +99 -0
- package/dist/xllm/runtime/types.d.ts.map +1 -0
- package/dist/xllm.cjs +2 -0
- package/dist/xllm.cjs.map +1 -0
- package/dist/xllm.mjs +1167 -0
- package/dist/xllm.mjs.map +1 -0
- package/dist/xllm_deno.cjs +2 -0
- package/dist/xllm_deno.cjs.map +1 -0
- package/dist/xllm_deno.mjs +2487 -0
- package/dist/xllm_deno.mjs.map +1 -0
- package/dist/xllm_dev.cjs +2 -0
- package/dist/xllm_dev.cjs.map +1 -0
- package/dist/xllm_dev.mjs +70 -0
- package/dist/xllm_dev.mjs.map +1 -0
- package/package.json +22 -1
- package/src/internal/command_args.ts +268 -0
- package/dist/executor_client-1ee523cf.js +0 -13
- package/dist/executor_client-1ee523cf.js.map +0 -1
- package/dist/executor_client-5f4d0468.mjs.map +0 -1
- package/dist/ndn_types-8c2696d5.js +0 -2
- package/dist/ndn_types-8c2696d5.js.map +0 -1
- package/dist/ndn_types-ab30fac0.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-5b138882.js"),n=require("node:buffer"),o=require("node:crypto"),s=require("./account-b12ac6b9.js"),a="device_doc.jwt",c="device_mini_doc.jwt",u="node_gateway_params.json";function l(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 p(e){return e instanceof i.DID?e:i.DID.fromStr(e)}function h(e,t){const r=l("node:fs"),i=l("node:path");r.mkdirSync(i.dirname(e),{recursive:!0}),r.writeFileSync(e,JSON.stringify(t,null,2))}function d(e){return{schema:i.NODE_IDENTITY_SCHEMA_V2,zone_did:p(e.zoneDid).toString(),owner_did:p(e.ownerDid).toString(),owner_public_key:e.ownerPublicKey,device_name:e.deviceName,device_did:p(e.deviceDid).toString(),zone_iat:e.zoneIat}}function f(e){const t=l("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 y(e,t){const r=l("node:path"),i=p(t).toString(),n=e.publicDir(i);return{publicDir:n,securityDir:e.securityDir(i),didJson:e.publicFile(i,"authentication","did-json"),deviceDocJwt:r.join(n,a),deviceMiniDocJwt:r.join(n,c),authenticationPrivateKey:e.securityFile(i,"authentication","private")}}function g(e,t){const r=e.trim();if(!r)throw new Error("device name is empty");const n=p(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 m(e,t){const r=p(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 v(e,t,r,n){return m(i.newDeviceDocumentByJwk(e,t,n),r)}function w(e,t){return l("node:fs").readFileSync(y(e,t).deviceDocJwt,"utf8")}function b(e,t,r=2980){if(!Number.isInteger(r)||r<1||r>65535)throw new Error(`invalid device RTCP port: ${r}`);h(l("node:path").join(e,u),{params:{device_did:p(t).toString(),rtcp_port:String(r)}})}function S(e,t,r,n,o,s,a){const c=l("node:fs"),u=l("node:path"),p=y(t,r.device_did);return c.mkdirSync(p.publicDir,{recursive:!0}),c.mkdirSync(p.securityDir,{recursive:!0}),h(u.join(e,"node_identity.json"),r),b(e,r.device_did,n.rtcp_port),h(p.didJson,i.deviceDocumentToOrderedJson(n)),c.writeFileSync(p.deviceDocJwt,o),c.writeFileSync(p.deviceMiniDocJwt,s),c.writeFileSync(p.authenticationPrivateKey,a),p}function A(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,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,""))||""}}
|
|
15
|
+
***************************************************************************** */var E,k;k=E||(E={}),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(k);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=k)}();class x{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=x.toUint8Array(e),i=x.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 _="string",N=/^[0-9a-f\s]+$/i,I=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,T=/^[a-zA-Z0-9-_]+$/;class B{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=x.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=x.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===_&&N.test(e)}static isBase64(e){return typeof e===_&&I.test(e)}static isBase64Url(e){return typeof e===_&&T.test(e)}static ToString(e,t="utf8"){const r=x.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=x.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 B.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 B.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=x.toUint8Array(e);let r="";for(let i=0;i<t.length;i++)r+=String.fromCharCode(t[i]);return r}static ToHex(e){const t=x.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,""))||""}}
|
|
16
16
|
/*!
|
|
17
17
|
Copyright (c) Peculiar Ventures, LLC
|
|
18
18
|
*/
|
|
19
|
-
function
|
|
19
|
+
function D(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 j(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 P(...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 R(){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=D(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 D(o,8)-i}function U(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 C(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 $(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;
|
|
52
|
+
*/function $(){if("undefined"==typeof BigInt)throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function M(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 L(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 M(this.items)}}const H=[new Uint8Array([1])],K="0123456789",F="name",z="valueHexView",W="",J=new ArrayBuffer(0),q=new Uint8Array(0),G="EndOfContent",X="OCTET STRING",Y="BIT STRING";function Z(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?x.toUint8Array(r.valueHex):q}fromBER(e,t,r,i){const n=e instanceof ArrayBuffer?new Uint8Array(e):e;if(!L(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",J)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:C.ToHex(this.valueHexView)}}}).NAME="hexBlock",t}class Q{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=x.toUint8Array(i)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:C.ToHex(this.valueBeforeDecodeView)}}}Q.NAME="baseBlock";class ee extends Q{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'")}}ee.NAME="valueBlock";class te extends(Z(Q)){constructor({idBlock:e={}}={}){var t,r,i,n;super(),e?(this.isHexOnly=null!==(t=e.isHexOnly)&&void 0!==t&&t,this.valueHexView=e.valueHex?x.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",J}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=j(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=x.toUint8Array(e);if(!L(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=D(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}}}te.NAME="identificationBlock";class re extends Q{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=x.toUint8Array(e);if(!L(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=D(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=j(this.length,8);if(i.byteLength>127)return this.error="Too big length",J;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}}}re.NAME="lengthBlock";const ie={};class ne extends Q{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 te(i),this.lenBlock=new re(i),this.valueBlock=n?new n(i):new ee(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||oe(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?J: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 oe(e){var t;if(e instanceof ie.Constructed)for(const r of e.valueBlock.value)oe(r)&&(e.lenBlock.isIndefiniteForm=!0);return!!(null===(t=e.lenBlock)||void 0===t?void 0:t.isIndefiniteForm)}ne.NAME="BaseBlock";class se extends ne{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}'`}}se.NAME="BaseStringBlock";class ae extends(Z(ee)){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}}var ce;ae.NAME="PrimitiveValueBlock";class ue extends ne{constructor(e={}){super(e,ae),this.idBlock.isConstructed=!1}}ce=ue,ie.Primitive=ce,ue.NAME="PRIMITIVE";const le=16777216;function pe(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:le}}function he(e,t,r,i){const n=i.depth+1;if(n>i.maxDepth)return function(e){const t=new ne({},ee);return t.error=e,{offset:-1,result:t}}("Maximum ASN.1 nesting depth exceeded");i.depth=n;try{return de(e,t,r,i)}finally{i.depth-=1}}function de(e,t=0,r=e.length,i=pe()){const n=t;let o=new ne({},ee);const s=new Q;if(!L(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=ne;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=ie.EndOfContent;break;case 1:p=ie.Boolean;break;case 2:p=ie.Integer;break;case 3:p=ie.BitString;break;case 4:p=ie.OctetString;break;case 5:p=ie.Null;break;case 6:p=ie.ObjectIdentifier;break;case 10:p=ie.Enumerated;break;case 12:p=ie.Utf8String;break;case 13:p=ie.RelativeObjectIdentifier;break;case 14:p=ie.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:p=ie.Sequence;break;case 17:p=ie.Set;break;case 18:p=ie.NumericString;break;case 19:p=ie.PrintableString;break;case 20:p=ie.TeletexString;break;case 21:p=ie.VideotexString;break;case 22:p=ie.IA5String;break;case 23:p=ie.UTCTime;break;case 24:p=ie.GeneralizedTime;break;case 25:p=ie.GraphicString;break;case 26:p=ie.VisibleString;break;case 27:p=ie.GeneralString;break;case 28:p=ie.UniversalString;break;case 29:p=ie.CharacterString;break;case 30:p=ie.BmpString;break;case 31:p=ie.DATE;break;case 32:p=ie.TimeOfDay;break;case 33:p=ie.DateTime;break;case 34:p=ie.Duration;break;default:{const e=o.idBlock.isConstructed?new ie.Constructed:new ie.Primitive;e.idBlock=o.idBlock,e.lenBlock=o.lenBlock,e.warnings=o.warnings,o=e}}}else p=o.idBlock.isConstructed?ie.Constructed:ie.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 fe(e,t={}){if(!e.byteLength){const e=new ne({},ee);return e.error="Input buffer has zero length",{offset:-1,result:e}}return de(x.toUint8Array(e).slice(),0,e.byteLength,pe(t))}class ye extends ee{constructor({value:e=[],isIndefiniteForm:t=!1,...r}={}){super(r),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,r,i){const n=x.toUint8Array(e),o=null!=i?i:pe();if(!L(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===G)break}var a,c;return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===G?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?J: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 ge,me,ve,we,be;ye.NAME="ConstructedValueBlock";class Se extends ne{constructor(e={}){super(e,ye),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} :`}}ge=Se,ie.Constructed=ge,Se.NAME="CONSTRUCTED";class Ae extends ee{fromBER(e,t,r){return t}toBER(e){return J}}Ae.override="EndOfContentValueBlock";class Ee extends ne{constructor(e={}){super(e,Ae),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}me=Ee,ie.EndOfContent=me,Ee.NAME=G;class ke extends ne{constructor(e={}){super(e,ee),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=ke,ie.Null=ve,ke.NAME="NULL";class xe extends(Z(ee)){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=x.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,r){const i=x.toUint8Array(e);return L(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}}}xe.NAME="BooleanValueBlock";class _e extends ne{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,xe),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}we=_e,ie.Boolean=we,_e.NAME="BOOLEAN";class Ne extends(Z(ye)){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=ye.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===G){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?ye.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}Ne.NAME="OctetStringValueBlock";let Ie=class extends ne{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},Ne),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:pe(),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 Se.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 be&&e.push(t.valueBlock.valueHexView);return x.concat(e)}};be=Ie,ie.OctetString=be,Ie.NAME=X;class Te extends(Z(ye)){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=ye.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===G){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(t!==Y)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=x.toUint8Array(e);if(!L(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:pe(),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 ye.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 Be;Te.NAME="BitStringValueBlock";let Oe=class extends ne{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 Se.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,De,je,Pe,Re,Ue,$e;function Me(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=P(new Uint8Array([u%10]),o);else o[s-l]=u%10}return r[0]>0&&(o=P(r,o)),o}function Le(e){if(e>=H.length)for(let t=H.length;t<=e;t++){const e=new Uint8Array([0]);let r=H[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=P(e,r)),H.push(r)}return H[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 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()}Be=Oe,ie.BitString=Be,Oe.NAME=Y;class He extends(Z(ee)){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=j(r-t,8,i);return new Uint8Array(e)[0]|=128,e}let n=j(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(Le(i),r),o="-";else r=Me(r,Le(i));i++,t>>=1}}for(let a=0;a<r.length;a++)r[a]&&(s=!0),s&&(o+=K.charAt(r[a]));return!1===s&&(o+=K.charAt(0)),o}}Ce=He,He.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 Ke extends ne{constructor(e={}){super(e,He),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return $(),BigInt(this.valueBlock.toString())}static fromBigInt(e){$();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=x.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 De({valueHex:r.final()})}convertToDER(){const e=new De({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new De({valueHex:0===this.valueBlock.valueHexView[0]?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}De=Ke,ie.Integer=De,Ke.NAME="INTEGER";class Fe extends Ke{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}je=Fe,ie.Enumerated=je,Fe.NAME="ENUMERATED";class ze extends(Z(ee)){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=x.toUint8Array(e);if(!L(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=D(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){$();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=j(this.valueDec,7);if(0===t.byteLength)return this.error="Error during encoding SID value",J;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}}}ze.NAME="sidBlock";class We extends ee{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 ze;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,J;t.push(i)}return M(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 ze;if(i>Number.MAX_SAFE_INTEGER){$();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}}We.NAME="ObjectIdentifierValueBlock";class Je extends ne{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,We),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}Pe=Je,ie.ObjectIdentifier=Pe,Je.NAME="OBJECT IDENTIFIER";class qe extends(Z(Q)){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,r){if(0===r)return t;const i=x.toUint8Array(e);if(!L(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=D(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=j(this.valueDec,7);if(0===t.byteLength)return this.error="Error during encoding SID value",J;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 Ge extends ee{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,J;r.push(t)}return M(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}}Ge.NAME="RelativeObjectIdentifierValueBlock";class Xe extends ne{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Ge),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,ie.RelativeObjectIdentifier=Re,Xe.NAME="RelativeObjectIdentifier";class Ye extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}Ue=Ye,ie.Sequence=Ue,Ye.NAME="SEQUENCE";let Ze=class extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};$e=Ze,ie.Set=$e,Ze.NAME="SET";class Qe extends(Z(ee)){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=W}toJSON(){return{...super.toJSON(),value:this.value}}}Qe.NAME="StringValueBlock";class et extends Qe{}et.NAME="SimpleStringValueBlock";class tt extends se{constructor({...e}={}){super(e,et)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,x.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}}tt.NAME="SIMPLE STRING";class rt extends tt{fromBuffer(e){this.valueBlock.valueHexView=x.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 it,nt,ot,st,at,ct,ut,lt,pt,ht,dt,ft,yt,gt,mt,vt,wt,bt,St;rt.NAME="Utf8StringValueBlock";class At extends rt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}it=At,ie.Utf8String=it,At.NAME="UTF8String";class Et extends tt{fromBuffer(e){this.valueBlock.value=C.ToUtf16String(e),this.valueBlock.valueHexView=x.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(C.FromUtf16String(e))}}Et.NAME="BmpStringValueBlock";class kt extends Et{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}nt=kt,ie.BmpString=nt,kt.NAME="BMPString";class xt extends tt{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=j(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}}xt.NAME="UniversalStringValueBlock";class _t extends xt{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}ot=_t,ie.UniversalString=ot,_t.NAME="UniversalString";class Nt extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}st=Nt,ie.NumericString=st,Nt.NAME="NumericString";class It extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}at=It,ie.PrintableString=at,It.NAME="PrintableString";class Tt extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}ct=Tt,ie.TeletexString=ct,Tt.NAME="TeletexString";class Bt extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}ut=Bt,ie.VideotexString=ut,Bt.NAME="VideotexString";class Ot extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}lt=Ot,ie.IA5String=lt,Ot.NAME="IA5String";class Ct extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}pt=Ct,ie.GraphicString=pt,Ct.NAME="GraphicString";class Dt extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}ht=Dt,ie.VisibleString=ht,Dt.NAME="VisibleString";class jt extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}dt=jt,ie.GeneralString=dt,jt.NAME="GeneralString";class Pt extends tt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}ft=Pt,ie.CharacterString=ft,Pt.NAME="CharacterString";class Rt extends Dt{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,x.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]=U(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=U(this.month,2),e[2]=U(this.day,2),e[3]=U(this.hour,2),e[4]=U(this.minute,2),e[5]=U(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}}}yt=Rt,ie.UTCTime=yt,Rt.NAME="UTCTime";class Ut 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(U(this.year,4)),e.push(U(this.month,2)),e.push(U(this.day,2)),e.push(U(this.hour,2)),e.push(U(this.minute,2)),e.push(U(this.second,2)),0!==this.millisecond&&(e.push("."),e.push(U(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}gt=Ut,ie.GeneralizedTime=gt,Ut.NAME="GeneralizedTime";class $t extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}}mt=$t,ie.DATE=mt,$t.NAME="DATE";class Mt extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}vt=Mt,ie.TimeOfDay=vt,Mt.NAME="TimeOfDay";class Lt extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}wt=Lt,ie.DateTime=wt,Lt.NAME="DateTime";class Vt extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}bt=Vt,ie.Duration=bt,Vt.NAME="Duration";class Ht extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}St=Ht,ie.TIME=St,Ht.NAME="TIME";class Kt{constructor({name:e="",optional:t=!1}={}){this.name=e,this.optional=t}}class Ft extends Kt{constructor({value:e=[],...t}={}){super(t),this.value=e}}class zt extends Kt{constructor({value:e=new Kt,local:t=!1,...r}={}){super(r),this.value=e,this.local=t}}function Wt(e,t,r){if(r instanceof Ft){for(const i of r.value){if(Wt(e,t,i).verified)return{verified:!0,result:e}}{const e={verified:!1,result:{error:"Wrong values for Choice type"}};return r.hasOwnProperty(F)&&(e.name=r.name),e}}if(r instanceof Kt)return r.hasOwnProperty(F)&&(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(z 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,W),r.name&&(e[r.name]=t)),r instanceof ie.Constructed){let i=0,n={verified:!1,result:{error:"Unknown error"}},o=r.valueBlock.value.length;if(o>0&&r.valueBlock.value[0]instanceof zt&&(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,W),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,W),r.name&&(delete e[r.name],t.name=r.name)),t}}else if(r.valueBlock.value[0]instanceof zt){if(n=Wt(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,W),r.name&&delete e[r.name]),n;i++}if(F 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=Wt(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,W),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,W),r.name&&(delete e[r.name],t.name=r.name)),t}return{verified:!0,result:e}}if(r.primitiveSchema&&z in t.valueBlock){const i=de(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,W),r.name&&(delete e[r.name],t.name=r.name)),t}return Wt(e,i.result,r.primitiveSchema)}return{verified:!0,result:e}}const Jt=Object.freeze(Object.defineProperty({__proto__:null,Any:Kt,BaseBlock:ne,BaseStringBlock:se,BitString:Oe,BmpString:kt,Boolean:_e,CharacterString:Pt,Choice:Ft,Constructed:Se,DATE:$t,DEFAULT_MAX_CONTENT_LENGTH:le,DEFAULT_MAX_DEPTH:100,DEFAULT_MAX_NODES:1e4,DateTime:Lt,Duration:Vt,EndOfContent:Ee,Enumerated:Fe,GeneralString:jt,GeneralizedTime:Ut,GraphicString:Ct,HexBlock:Z,IA5String:Ot,Integer:Ke,Null:ke,NumericString:Nt,ObjectIdentifier:Je,OctetString:Ie,Primitive:ue,PrintableString:It,RawData:class{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=x.toUint8Array(e)}constructor({data:e=q}={}){this.dataView=x.toUint8Array(e)}fromBER(e,t,r){const i=t+r;return this.dataView=x.toUint8Array(e).subarray(t,i),i}toBER(e){return this.dataView.slice().buffer}},RelativeObjectIdentifier:Xe,Repeated:zt,Sequence:Ye,Set:Ze,TIME:Ht,TeletexString:Tt,TimeOfDay:Mt,UTCTime:Rt,UniversalString:_t,Utf8String:At,ValueBlock:ee,VideotexString:Bt,ViewWriter:V,VisibleString:Dt,compareSchema:Wt,fromBER:fe,verifySchema:function(e,t){if(t instanceof Object==!1)return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};const r=de(x.toUint8Array(e));return-1===r.offset?{verified:!1,result:r.result}:Wt(r.result,r.result,t)}},Symbol.toStringTag,{value:"Module"}));function qt(e){return Object.prototype.toString.call(e)}function Gt(e){return"[object ArrayBuffer]"===qt(e)}function Xt(e){return Gt(e)||function(e){return"undefined"!=typeof SharedArrayBuffer&&"[object SharedArrayBuffer]"===qt(e)}(e)}function Yt(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 Zt(e){return Xt(e)||Yt(e)}function Qt(e){if(!Zt(e))throw new TypeError("Expected ArrayBuffer, SharedArrayBuffer, or ArrayBufferView")}function er(e){return Qt(e),Xt(e)?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function tr(e){if(Qt(e),Gt(e))return e;const t=new ArrayBuffer(e.byteLength);return new Uint8Array(t).set(er(e)),t}var rr,ir,nr,or;(ir=rr||(rr={}))[ir.Sequence=0]="Sequence",ir[ir.Set=1]="Set",ir[ir.Choice=2]="Choice",(or=nr||(nr={}))[or.Any=1]="Any",or[or.Boolean=2]="Boolean",or[or.OctetString=3]="OctetString",or[or.BitString=4]="BitString",or[or.Integer=5]="Integer",or[or.Enumerated=6]="Enumerated",or[or.ObjectIdentifier=7]="ObjectIdentifier",or[or.Utf8String=8]="Utf8String",or[or.BmpString=9]="BmpString",or[or.UniversalString=10]="UniversalString",or[or.NumericString=11]="NumericString",or[or.PrintableString=12]="PrintableString",or[or.TeletexString=13]="TeletexString",or[or.VideotexString=14]="VideotexString",or[or.IA5String=15]="IA5String",or[or.GraphicString=16]="GraphicString",or[or.VisibleString=17]="VisibleString",or[or.GeneralString=18]="GeneralString",or[or.CharacterString=19]="CharacterString",or[or.UTCTime=20]="UTCTime",or[or.GeneralizedTime=21]="GeneralizedTime",or[or.DATE=22]="DATE",or[or.TimeOfDay=23]="TimeOfDay",or[or.DateTime=24]="DateTime",or[or.Duration=25]="Duration",or[or.TIME=26]="TIME",or[or.Null=27]="Null";class sr{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(!Zt(e))throw TypeError("Unsupported type of 'params' argument for BitString");this.unusedBits=t,this.value=tr(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=tr(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 ar{constructor(e){r(this,"buffer"),"number"==typeof e?this.buffer=new ArrayBuffer(e):Zt(e)?this.buffer=tr(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 Ie))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=tr(e.valueBlock.valueHex),this}toASN(){return new Ie({valueHex:this.buffer})}toSchema(e){return new Ie({name:e})}}const cr={fromASN:e=>e instanceof ke?null:tr(e.valueBeforeDecodeView),toASN:e=>{if(null===e)return new ke;const t=fe(e);if(t.result.error)throw new Error(t.result.error);return t.result}},ur={fromASN:e=>e.valueBlock.valueHexView.byteLength>=4?e.valueBlock.toString():e.valueBlock.valueDec,toASN:e=>new Ke({value:+e})},lr={fromASN:e=>e.valueBlock.valueDec,toASN:e=>new Fe({value:e})},pr={fromASN:e=>tr(e.valueBlock.valueHexView),toASN:e=>new Ke({valueHex:e})},hr={fromASN:e=>tr(e.valueBlock.valueHexView),toASN:e=>new Oe({valueHex:e})},dr={fromASN:e=>e.valueBlock.toString(),toASN:e=>new Je({value:e})},fr={fromASN:e=>e.valueBlock.value,toASN:e=>new _e({value:e})},yr={fromASN:e=>tr(e.valueBlock.valueHexView),toASN:e=>new Ie({valueHex:e})},gr={fromASN:e=>new ar(e.getValue()),toASN:e=>e.toASN()};function mr(e){return{fromASN:e=>e.valueBlock.value,toASN:t=>new e({value:t})}}const vr=mr(At),wr=mr(kt),br=mr(_t),Sr=mr(Nt),Ar=mr(It),Er=mr(Tt),kr=mr(Bt),xr=mr(Ot),_r=mr(Ct),Nr=mr(Dt),Ir=mr(jt),Tr=mr(Pt),Br={fromASN:e=>e.toDate(),toASN:e=>new Rt({valueDate:e})},Or={fromASN:e=>e.toDate(),toASN:e=>new Ut({valueDate:e})},Cr={fromASN:()=>null,toASN:()=>new ke};function Dr(e){switch(e){case nr.Any:return cr;case nr.BitString:return hr;case nr.BmpString:return wr;case nr.Boolean:return fr;case nr.CharacterString:return Tr;case nr.Enumerated:return lr;case nr.GeneralString:return Ir;case nr.GeneralizedTime:return Or;case nr.GraphicString:return _r;case nr.IA5String:return xr;case nr.Integer:return ur;case nr.Null:return Cr;case nr.NumericString:return Sr;case nr.ObjectIdentifier:return dr;case nr.OctetString:return yr;case nr.PrintableString:return Ar;case nr.TeletexString:return Er;case nr.UTCTime:return Br;case nr.UniversalString:return br;case nr.Utf8String:return vr;case nr.VideotexString:return kr;case nr.VisibleString:return Nr;default:return null}}function jr(e){return"function"==typeof e&&e.prototype?!(!e.prototype.toASN||!e.prototype.fromASN)||jr(e.prototype):!!(e&&"object"==typeof e&&"toASN"in e&&"fromASN"in e)}function Pr(e){var t;if(e){const r=Object.getPrototypeOf(e);return(null==(t=null==r?void 0:r.prototype)?void 0:t.constructor)===Array||Pr(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 Ur=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:rr.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=nr[e.type],r=Jt[t];if(!r)throw new Error(`Cannot get ASN1 class by name '${t}'`);s=new r({name:o})}else if(jr(e.type)){s=(new e.type).toSchema(o)}else if(e.optional){this.get(e.type).type===rr.Choice?s=new Kt({name:o}):(s=this.create(e.type,!1),s.name=o)}else s=new Kt({name:o});const a=!!e.optional||void 0!==e.defaultValue;if(e.repeated){s.name="";s=new("set"===e.repeated?Ze:Ye)({name:"",value:[new zt({name:o,value:s})]})}if(null!==e.context&&void 0!==e.context)if(e.implicit)if("number"==typeof e.type||jr(e.type)){const t=e.repeated?Se:ue;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 Se({name:t?"":o,optional:a,idBlock:{tagClass:3,tagNumber:e.context},value:r}))}else i.push(new Se({optional:a,idBlock:{tagClass:3,tagNumber:e.context},value:[s]}));else s.optional=a,i.push(s)}switch(r.type){case rr.Sequence:return new Ye({value:i,name:""});case rr.Set:return new Ze({value:i,name:""});case rr.Choice:return new Ft({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}},$r=e=>t=>{let r;Ur.has(t)?r=Ur.get(t):(r=Ur.createDefault(t),Ur.set(t,r)),Object.assign(r,e)},Mr=e=>(t,r)=>{let i;Ur.has(t.constructor)?i=Ur.get(t.constructor):(i=Ur.createDefault(t.constructor),Ur.set(t.constructor,i));const n=Object.assign({},e);if("number"==typeof n.type&&!n.converter){const i=Dr(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 Lr extends Error{constructor(){super(...arguments),r(this,"schemas",[])}}class Vr{static parse(e,t,r){const i=fe(tr(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(jr(t)){return(new t).fromASN(e)}const i=Ur.get(t);Ur.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 Pr(t)?this.handleArrayTypes(e,i,t,r):(this.processSchemaItems(i,s,a,r),a)}catch(i){throw i instanceof Lr&&i.schemas.push(t.name),i}}static handleChoiceTypes(e,t,r,i,n){if(e.constructor===Se&&t.type===rr.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&&Ur.has(i.type)){const t=Ur.get(i.type);if(t&&t.type===rr.Sequence){const t=new Ye;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===Se&&t.type!==rr.Choice){const r=new Se({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===rr.Sequence){const t=Wt({},e,i);if(!t.verified)throw new Lr(`Data does not match to ${r.name} ASN1 schema.${t.result.error?` ${t.result.error}`:""}`);return t}{const t=Wt({},e,i);if(!t.verified)throw new Lr(`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=Dr(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=Dr(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&&Ur.has(e.type)&&Ur.get(e.type).type===rr.Choice}static processOptionalChoiceField(e,t){try{return{processed:!0,value:this.fromASN(e,t.type)}}catch(r){if(r instanceof Lr&&/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=Dr(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||jr(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??(jr(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?Ye:Ze);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(jr(r))e=(new r).toSchema("");else{const t=nr[r],i=Jt[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 Lr&&/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=Ur.get(r);if(t.type===rr.Sequence){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}else if(t.type===rr.Set){const t=new Ze;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 Hr{static serialize(e){return e instanceof ne?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&"object"==typeof e&&jr(e))return e.toASN();if(!e||"object"!=typeof e)throw new TypeError("Parameter 1 should be type of Object.");const t=e.constructor,r=Ur.get(t);Ur.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=Dr(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=Hr.toAsnItem(i,o,t,s);if("number"==typeof i.context)if(i.implicit)if(i.repeated||"number"!=typeof i.type&&!jr(i.type))n.push(new Se({optional:i.optional,idBlock:{tagClass:3,tagNumber:i.context},value:a.valueBlock.value}));else{const e={};e.valueHex=a instanceof ke?tr(a.valueBeforeDecodeView):a.valueBlock.toBER(),n.push(new ue({optional:i.optional,idBlock:{tagClass:3,tagNumber:i.context},...e}))}else n.push(new Se({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 rr.Sequence:i=new Ye({value:n});break;case rr.Set:i=new Ze({value:n});break;case rr.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 ${nr[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?Ye:Ze)({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?Ye:Ze)({value:t})}else n=this.toASN(i);return n}}class Kr extends Array{constructor(e=[]){if("number"==typeof e)super(e);else{super();for(const t of e)this.push(t)}}}class Fr{static serialize(e){return Hr.serialize(e)}static parse(e,t,r){return Vr.parse(e,t,r)}static toString(e,t){const r=fe(Zt(e)?tr(e):Fr.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 zr(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 Wr(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 Jr(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 Gr(e,t={}){const r=er(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(Gr(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 Yr,Zr,Qr;let ei=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||""}};zr([Mr({type:nr.TeletexString})],ei.prototype,"teletexString",void 0),zr([Mr({type:nr.PrintableString})],ei.prototype,"printableString",void 0),zr([Mr({type:nr.UniversalString})],ei.prototype,"universalString",void 0),zr([Mr({type:nr.Utf8String})],ei.prototype,"utf8String",void 0),zr([Mr({type:nr.BmpString})],ei.prototype,"bmpString",void 0),ei=zr([$r({type:rr.Choice})],ei);let ti=class extends ei{constructor(e={}){super(e),r(this,"ia5String"),r(this,"anyValue"),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?Gr(this.anyValue):super.toString())}};zr([Mr({type:nr.IA5String})],ti.prototype,"ia5String",void 0),zr([Mr({type:nr.Any})],ti.prototype,"anyValue",void 0),ti=zr([$r({type:rr.Choice})],ti);class ri{constructor(e={}){r(this,"type",""),r(this,"value",new ti),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],ri.prototype,"type",void 0),zr([Mr({type:ti})],ri.prototype,"value",void 0);let ii=Yr=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Yr.prototype)}};ii=Yr=zr([$r({type:rr.Set,itemType:ri})],ii);let ni=Zr=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Zr.prototype)}};ni=Zr=zr([$r({type:rr.Sequence,itemType:ii})],ni);let oi=Qr=class extends ni{constructor(e){super(e),Object.setPrototypeOf(this,Qr.prototype)}};oi=Qr=zr([$r({type:rr.Sequence})],oi);const si={fromASN:e=>Xr.toString(yr.fromASN(e)),toASN:e=>yr.toASN(Xr.fromString(e))};class ai{constructor(e={}){r(this,"typeId",""),r(this,"value",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],ai.prototype,"typeId",void 0),zr([Mr({type:nr.Any,context:0})],ai.prototype,"value",void 0);class ci{constructor(e={}){r(this,"nameAssigner"),r(this,"partyName",new ei),Object.assign(this,e)}}zr([Mr({type:ei,optional:!0,context:0,implicit:!0})],ci.prototype,"nameAssigner",void 0),zr([Mr({type:ei,context:1,implicit:!0})],ci.prototype,"partyName",void 0);let ui=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)}};zr([Mr({type:ai,context:0,implicit:!0})],ui.prototype,"otherName",void 0),zr([Mr({type:nr.IA5String,context:1,implicit:!0})],ui.prototype,"rfc822Name",void 0),zr([Mr({type:nr.IA5String,context:2,implicit:!0})],ui.prototype,"dNSName",void 0),zr([Mr({type:nr.Any,context:3,implicit:!0})],ui.prototype,"x400Address",void 0),zr([Mr({type:oi,context:4,implicit:!1})],ui.prototype,"directoryName",void 0),zr([Mr({type:ci,context:5})],ui.prototype,"ediPartyName",void 0),zr([Mr({type:nr.IA5String,context:6,implicit:!0})],ui.prototype,"uniformResourceIdentifier",void 0),zr([Mr({type:nr.OctetString,context:7,implicit:!0,converter:si})],ui.prototype,"iPAddress",void 0),zr([Mr({type:nr.ObjectIdentifier,context:8,implicit:!0})],ui.prototype,"registeredID",void 0),ui=zr([$r({type:rr.Choice})],ui);const li="1.3.6.1.5.5.7",pi=`${li}.3`,hi=`${li}.48`,di=`${hi}.1`,fi=`${hi}.2`,yi=`${hi}.3`,gi=`${hi}.5`,mi="2.5.29";var vi;const wi=`${`${li}.1`}.1`;class bi{constructor(e={}){r(this,"accessMethod",""),r(this,"accessLocation",new ui),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],bi.prototype,"accessMethod",void 0),zr([Mr({type:ui})],bi.prototype,"accessLocation",void 0);let Si=vi=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,vi.prototype)}};Si=vi=zr([$r({type:rr.Sequence,itemType:bi})],Si);const Ai=`${mi}.35`;class Ei extends ar{}class ki{constructor(e={}){r(this,"keyIdentifier"),r(this,"authorityCertIssuer"),r(this,"authorityCertSerialNumber"),e&&Object.assign(this,e)}}zr([Mr({type:Ei,context:0,optional:!0,implicit:!0})],ki.prototype,"keyIdentifier",void 0),zr([Mr({type:ui,context:1,optional:!0,implicit:!0,repeated:"sequence"})],ki.prototype,"authorityCertIssuer",void 0),zr([Mr({type:nr.Integer,context:2,optional:!0,implicit:!0,converter:pr})],ki.prototype,"authorityCertSerialNumber",void 0);const xi=`${mi}.19`;class _i{constructor(e={}){r(this,"cA",!1),r(this,"pathLenConstraint"),Object.assign(this,e)}}var Ni;zr([Mr({type:nr.Boolean,defaultValue:!1})],_i.prototype,"cA",void 0),zr([Mr({type:nr.Integer,optional:!0})],_i.prototype,"pathLenConstraint",void 0);let Ii=Ni=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Ni.prototype)}};var Ti;Ii=Ni=zr([$r({type:rr.Sequence,itemType:ui})],Ii);let Bi=Ti=class extends Ii{constructor(e){super(e),Object.setPrototypeOf(this,Ti.prototype)}};var Oi;Bi=Ti=zr([$r({type:rr.Sequence})],Bi);const Ci=`${mi}.32`;let Di=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||""}};zr([Mr({type:nr.IA5String})],Di.prototype,"ia5String",void 0),zr([Mr({type:nr.VisibleString})],Di.prototype,"visibleString",void 0),zr([Mr({type:nr.BmpString})],Di.prototype,"bmpString",void 0),zr([Mr({type:nr.Utf8String})],Di.prototype,"utf8String",void 0),Di=zr([$r({type:rr.Choice})],Di);class ji{constructor(e={}){r(this,"organization",new Di),r(this,"noticeNumbers",[]),Object.assign(this,e)}}zr([Mr({type:Di})],ji.prototype,"organization",void 0),zr([Mr({type:nr.Integer,repeated:"sequence"})],ji.prototype,"noticeNumbers",void 0);class Pi{constructor(e={}){r(this,"noticeRef"),r(this,"explicitText"),Object.assign(this,e)}}zr([Mr({type:ji,optional:!0})],Pi.prototype,"noticeRef",void 0),zr([Mr({type:Di,optional:!0})],Pi.prototype,"explicitText",void 0);let Ri=class{constructor(e={}){r(this,"cPSuri"),r(this,"userNotice"),Object.assign(this,e)}};zr([Mr({type:nr.IA5String})],Ri.prototype,"cPSuri",void 0),zr([Mr({type:Pi})],Ri.prototype,"userNotice",void 0),Ri=zr([$r({type:rr.Choice})],Ri);class Ui{constructor(e={}){r(this,"policyQualifierId",""),r(this,"qualifier",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],Ui.prototype,"policyQualifierId",void 0),zr([Mr({type:nr.Any})],Ui.prototype,"qualifier",void 0);class $i{constructor(e={}){r(this,"policyIdentifier",""),r(this,"policyQualifiers"),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],$i.prototype,"policyIdentifier",void 0),zr([Mr({type:Ui,repeated:"sequence",optional:!0})],$i.prototype,"policyQualifiers",void 0);let Mi=Oi=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Oi.prototype)}};Mi=Oi=zr([$r({type:rr.Sequence,itemType:$i})],Mi);let Li=class{constructor(e=0){r(this,"value"),this.value=e}};zr([Mr({type:nr.Integer})],Li.prototype,"value",void 0),Li=zr([$r({type:rr.Choice})],Li);let Vi=class extends Li{};var Hi;Vi=zr([$r({type:rr.Choice})],Vi);const Ki=`${mi}.31`;var Fi,zi;(zi=Fi||(Fi={}))[zi.unused=1]="unused",zi[zi.keyCompromise=2]="keyCompromise",zi[zi.cACompromise=4]="cACompromise",zi[zi.affiliationChanged=8]="affiliationChanged",zi[zi.superseded=16]="superseded",zi[zi.cessationOfOperation=32]="cessationOfOperation",zi[zi.certificateHold=64]="certificateHold",zi[zi.privilegeWithdrawn=128]="privilegeWithdrawn",zi[zi.aACompromise=256]="aACompromise";class Wi extends sr{toJSON(){const e=[],t=this.toNumber();return t&Fi.aACompromise&&e.push("aACompromise"),t&Fi.affiliationChanged&&e.push("affiliationChanged"),t&Fi.cACompromise&&e.push("cACompromise"),t&Fi.certificateHold&&e.push("certificateHold"),t&Fi.cessationOfOperation&&e.push("cessationOfOperation"),t&Fi.keyCompromise&&e.push("keyCompromise"),t&Fi.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&Fi.superseded&&e.push("superseded"),t&Fi.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}}let Ji=class{constructor(e={}){r(this,"fullName"),r(this,"nameRelativeToCRLIssuer"),Object.assign(this,e)}};zr([Mr({type:ui,context:0,repeated:"sequence",implicit:!0})],Ji.prototype,"fullName",void 0),zr([Mr({type:ii,context:1,implicit:!0})],Ji.prototype,"nameRelativeToCRLIssuer",void 0),Ji=zr([$r({type:rr.Choice})],Ji);class qi{constructor(e={}){r(this,"distributionPoint"),r(this,"reasons"),r(this,"cRLIssuer"),Object.assign(this,e)}}zr([Mr({type:Ji,context:0,optional:!0})],qi.prototype,"distributionPoint",void 0),zr([Mr({type:Wi,context:1,optional:!0,implicit:!0})],qi.prototype,"reasons",void 0),zr([Mr({type:ui,context:2,optional:!0,repeated:"sequence",implicit:!0})],qi.prototype,"cRLIssuer",void 0);let Gi=Hi=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Hi.prototype)}};var Xi;Gi=Hi=zr([$r({type:rr.Sequence,itemType:qi})],Gi);let Yi=Xi=class extends Gi{constructor(e){super(e),Object.setPrototypeOf(this,Xi.prototype)}};Yi=Xi=zr([$r({type:rr.Sequence,itemType:qi})],Yi);const Zi=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(Zi,"ONLY",!1);let Qi=Zi;var en,tn;zr([Mr({type:Ji,context:0,optional:!0})],Qi.prototype,"distributionPoint",void 0),zr([Mr({type:nr.Boolean,context:1,defaultValue:Qi.ONLY,implicit:!0})],Qi.prototype,"onlyContainsUserCerts",void 0),zr([Mr({type:nr.Boolean,context:2,defaultValue:Qi.ONLY,implicit:!0})],Qi.prototype,"onlyContainsCACerts",void 0),zr([Mr({type:Wi,context:3,optional:!0,implicit:!0})],Qi.prototype,"onlySomeReasons",void 0),zr([Mr({type:nr.Boolean,context:4,defaultValue:Qi.ONLY,implicit:!0})],Qi.prototype,"indirectCRL",void 0),zr([Mr({type:nr.Boolean,context:5,defaultValue:Qi.ONLY,implicit:!0})],Qi.prototype,"onlyContainsAttributeCerts",void 0),(tn=en||(en={}))[tn.unspecified=0]="unspecified",tn[tn.keyCompromise=1]="keyCompromise",tn[tn.cACompromise=2]="cACompromise",tn[tn.affiliationChanged=3]="affiliationChanged",tn[tn.superseded=4]="superseded",tn[tn.cessationOfOperation=5]="cessationOfOperation",tn[tn.certificateHold=6]="certificateHold",tn[tn.removeFromCRL=8]="removeFromCRL",tn[tn.privilegeWithdrawn=9]="privilegeWithdrawn",tn[tn.aACompromise=10]="aACompromise";let rn=class{constructor(e=en.unspecified){r(this,"reason",en.unspecified),this.reason=e}toJSON(){return en[this.reason]}toString(){return this.toJSON()}};var nn;zr([Mr({type:nr.Enumerated})],rn.prototype,"reason",void 0),rn=zr([$r({type:rr.Choice})],rn);const on=`${mi}.37`;let sn=nn=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,nn.prototype)}};sn=nn=zr([$r({type:rr.Sequence,itemType:nr.ObjectIdentifier})],sn);const an=`${pi}.1`,cn=`${pi}.2`,un=`${pi}.3`,ln=`${pi}.4`,pn=`${pi}.8`,hn=`${pi}.9`;let dn=class{constructor(e=new ArrayBuffer(0)){r(this,"value"),this.value=e}};zr([Mr({type:nr.Integer,converter:pr})],dn.prototype,"value",void 0),dn=zr([$r({type:rr.Choice})],dn);let fn=class{constructor(e){r(this,"value",new Date),e&&(this.value=e)}};var yn;zr([Mr({type:nr.GeneralizedTime})],fn.prototype,"value",void 0),fn=zr([$r({type:rr.Choice})],fn);const gn=`${mi}.18`;let mn=yn=class extends Ii{constructor(e){super(e),Object.setPrototypeOf(this,yn.prototype)}};mn=yn=zr([$r({type:rr.Sequence})],mn);const vn=`${mi}.15`;var wn,bn,Sn;(bn=wn||(wn={}))[bn.digitalSignature=1]="digitalSignature",bn[bn.nonRepudiation=2]="nonRepudiation",bn[bn.keyEncipherment=4]="keyEncipherment",bn[bn.dataEncipherment=8]="dataEncipherment",bn[bn.keyAgreement=16]="keyAgreement",bn[bn.keyCertSign=32]="keyCertSign",bn[bn.cRLSign=64]="cRLSign",bn[bn.encipherOnly=128]="encipherOnly",bn[bn.decipherOnly=256]="decipherOnly";class An extends sr{toJSON(){const e=this.toNumber(),t=[];return e&wn.cRLSign&&t.push("crlSign"),e&wn.dataEncipherment&&t.push("dataEncipherment"),e&wn.decipherOnly&&t.push("decipherOnly"),e&wn.digitalSignature&&t.push("digitalSignature"),e&wn.encipherOnly&&t.push("encipherOnly"),e&wn.keyAgreement&&t.push("keyAgreement"),e&wn.keyCertSign&&t.push("keyCertSign"),e&wn.keyEncipherment&&t.push("keyEncipherment"),e&wn.nonRepudiation&&t.push("nonRepudiation"),t}toString(){return`[${this.toJSON().join(", ")}]`}}class En{constructor(e={}){r(this,"base",new ui),r(this,"minimum",0),r(this,"maximum"),Object.assign(this,e)}}zr([Mr({type:ui})],En.prototype,"base",void 0),zr([Mr({type:nr.Integer,context:0,defaultValue:0,implicit:!0})],En.prototype,"minimum",void 0),zr([Mr({type:nr.Integer,context:1,optional:!0,implicit:!0})],En.prototype,"maximum",void 0);let kn=Sn=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Sn.prototype)}};kn=Sn=zr([$r({type:rr.Sequence,itemType:En})],kn);class xn{constructor(e={}){r(this,"permittedSubtrees"),r(this,"excludedSubtrees"),Object.assign(this,e)}}zr([Mr({type:kn,context:0,optional:!0,implicit:!0})],xn.prototype,"permittedSubtrees",void 0),zr([Mr({type:kn,context:1,optional:!0,implicit:!0})],xn.prototype,"excludedSubtrees",void 0);class _n{constructor(e={}){r(this,"requireExplicitPolicy"),r(this,"inhibitPolicyMapping"),Object.assign(this,e)}}var Nn;zr([Mr({type:nr.Integer,context:0,implicit:!0,optional:!0,converter:pr})],_n.prototype,"requireExplicitPolicy",void 0),zr([Mr({type:nr.Integer,context:1,implicit:!0,optional:!0,converter:pr})],_n.prototype,"inhibitPolicyMapping",void 0);class In{constructor(e={}){r(this,"issuerDomainPolicy",""),r(this,"subjectDomainPolicy",""),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],In.prototype,"issuerDomainPolicy",void 0),zr([Mr({type:nr.ObjectIdentifier})],In.prototype,"subjectDomainPolicy",void 0);let Tn=Nn=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Nn.prototype)}};var Bn;Tn=Nn=zr([$r({type:rr.Sequence,itemType:In})],Tn);const On=`${mi}.17`;let Cn=Bn=class extends Ii{constructor(e){super(e),Object.setPrototypeOf(this,Bn.prototype)}};Cn=Bn=zr([$r({type:rr.Sequence})],Cn);let Dn=class{constructor(e={}){r(this,"type",""),r(this,"values",[]),Object.assign(this,e)}};var jn;zr([Mr({type:nr.ObjectIdentifier})],Dn.prototype,"type",void 0),zr([Mr({type:nr.Any,repeated:"set"})],Dn.prototype,"values",void 0);let Pn=jn=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,jn.prototype)}};Pn=jn=zr([$r({type:rr.Sequence,itemType:Dn})],Pn);const Rn=`${mi}.14`;class Un extends Ei{}class $n{constructor(e={}){r(this,"notBefore"),r(this,"notAfter"),Object.assign(this,e)}}var Mn,Ln,Vn;zr([Mr({type:nr.GeneralizedTime,context:0,implicit:!0,optional:!0})],$n.prototype,"notBefore",void 0),zr([Mr({type:nr.GeneralizedTime,context:1,implicit:!0,optional:!0})],$n.prototype,"notAfter",void 0),(Ln=Mn||(Mn={}))[Ln.keyUpdateAllowed=1]="keyUpdateAllowed",Ln[Ln.newExtensions=2]="newExtensions",Ln[Ln.pKIXCertificate=4]="pKIXCertificate";class Hn extends sr{toJSON(){const e=[],t=this.toNumber();return t&Mn.pKIXCertificate&&e.push("pKIXCertificate"),t&Mn.newExtensions&&e.push("newExtensions"),t&Mn.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}}class Kn{constructor(e={}){r(this,"entrustVers",""),r(this,"entrustInfoFlags",new Hn),Object.assign(this,e)}}zr([Mr({type:nr.GeneralString})],Kn.prototype,"entrustVers",void 0),zr([Mr({type:Hn})],Kn.prototype,"entrustInfoFlags",void 0);let Fn=Vn=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Vn.prototype)}};Fn=Vn=zr([$r({type:rr.Sequence,itemType:bi})],Fn);class zn{constructor(e={}){r(this,"algorithm",""),r(this,"parameters"),Object.assign(this,e)}isEqual(e){return e instanceof zn&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&function(e,t,r={}){const i=er(e),n=er(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)}}zr([Mr({type:nr.ObjectIdentifier})],zn.prototype,"algorithm",void 0),zr([Mr({type:nr.Any,optional:!0})],zn.prototype,"parameters",void 0);class Wn{constructor(e={}){r(this,"algorithm",new zn),r(this,"subjectPublicKey",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:zn})],Wn.prototype,"algorithm",void 0),zr([Mr({type:nr.BitString})],Wn.prototype,"subjectPublicKey",void 0);let Jn=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}};zr([Mr({type:nr.UTCTime})],Jn.prototype,"utcTime",void 0),zr([Mr({type:nr.GeneralizedTime})],Jn.prototype,"generalTime",void 0),Jn=zr([$r({type:rr.Choice})],Jn);class qn{constructor(e){r(this,"notBefore",new Jn(new Date)),r(this,"notAfter",new Jn(new Date)),e&&(this.notBefore=new Jn(e.notBefore),this.notAfter=new Jn(e.notAfter))}}var Gn;zr([Mr({type:Jn})],qn.prototype,"notBefore",void 0),zr([Mr({type:Jn})],qn.prototype,"notAfter",void 0);let Xn=(e=class{constructor(t={}){r(this,"extnID",""),r(this,"critical",e.CRITICAL),r(this,"extnValue",new ar),Object.assign(this,t)}},r(e,"CRITICAL",!1),e);zr([Mr({type:nr.ObjectIdentifier})],Xn.prototype,"extnID",void 0),zr([Mr({type:nr.Boolean,defaultValue:Xn.CRITICAL})],Xn.prototype,"critical",void 0),zr([Mr({type:ar})],Xn.prototype,"extnValue",void 0);let Yn=Gn=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Gn.prototype)}};var Zn,Qn;Yn=Gn=zr([$r({type:rr.Sequence,itemType:Xn})],Yn),(Qn=Zn||(Zn={}))[Qn.v1=0]="v1",Qn[Qn.v2=1]="v2",Qn[Qn.v3=2]="v3";class eo{constructor(e={}){r(this,"version",Zn.v1),r(this,"serialNumber",new ArrayBuffer(0)),r(this,"signature",new zn),r(this,"issuer",new oi),r(this,"validity",new qn),r(this,"subject",new oi),r(this,"subjectPublicKeyInfo",new Wn),r(this,"issuerUniqueID"),r(this,"subjectUniqueID"),r(this,"extensions"),Object.assign(this,e)}}zr([Mr({type:nr.Integer,context:0,defaultValue:Zn.v1})],eo.prototype,"version",void 0),zr([Mr({type:nr.Integer,converter:pr})],eo.prototype,"serialNumber",void 0),zr([Mr({type:zn})],eo.prototype,"signature",void 0),zr([Mr({type:oi})],eo.prototype,"issuer",void 0),zr([Mr({type:qn})],eo.prototype,"validity",void 0),zr([Mr({type:oi})],eo.prototype,"subject",void 0),zr([Mr({type:Wn})],eo.prototype,"subjectPublicKeyInfo",void 0),zr([Mr({type:nr.BitString,context:1,implicit:!0,optional:!0})],eo.prototype,"issuerUniqueID",void 0),zr([Mr({type:nr.BitString,context:2,implicit:!0,optional:!0})],eo.prototype,"subjectUniqueID",void 0),zr([Mr({type:Yn,context:3,optional:!0})],eo.prototype,"extensions",void 0);class to{constructor(e={}){r(this,"tbsCertificate",new eo),r(this,"tbsCertificateRaw"),r(this,"signatureAlgorithm",new zn),r(this,"signatureValue",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:eo,raw:!0})],to.prototype,"tbsCertificate",void 0),zr([Mr({type:zn})],to.prototype,"signatureAlgorithm",void 0),zr([Mr({type:nr.BitString})],to.prototype,"signatureValue",void 0);class ro{constructor(e={}){r(this,"userCertificate",new ArrayBuffer(0)),r(this,"revocationDate",new Jn),r(this,"crlEntryExtensions"),Object.assign(this,e)}}zr([Mr({type:nr.Integer,converter:pr})],ro.prototype,"userCertificate",void 0),zr([Mr({type:Jn})],ro.prototype,"revocationDate",void 0),zr([Mr({type:Xn,optional:!0,repeated:"sequence"})],ro.prototype,"crlEntryExtensions",void 0);class io{constructor(e={}){r(this,"version"),r(this,"signature",new zn),r(this,"issuer",new oi),r(this,"thisUpdate",new Jn),r(this,"nextUpdate"),r(this,"revokedCertificates"),r(this,"crlExtensions"),Object.assign(this,e)}}zr([Mr({type:nr.Integer,optional:!0})],io.prototype,"version",void 0),zr([Mr({type:zn})],io.prototype,"signature",void 0),zr([Mr({type:oi})],io.prototype,"issuer",void 0),zr([Mr({type:Jn})],io.prototype,"thisUpdate",void 0),zr([Mr({type:Jn,optional:!0})],io.prototype,"nextUpdate",void 0),zr([Mr({type:ro,repeated:"sequence",optional:!0})],io.prototype,"revokedCertificates",void 0),zr([Mr({type:Xn,optional:!0,context:0,repeated:"sequence"})],io.prototype,"crlExtensions",void 0);class no{constructor(e={}){r(this,"tbsCertList",new io),r(this,"tbsCertListRaw"),r(this,"signatureAlgorithm",new zn),r(this,"signature",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:io,raw:!0})],no.prototype,"tbsCertList",void 0),zr([Mr({type:zn})],no.prototype,"signatureAlgorithm",void 0),zr([Mr({type:nr.BitString})],no.prototype,"signature",void 0);class oo{constructor(e={}){r(this,"issuer",new oi),r(this,"serialNumber",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:oi})],oo.prototype,"issuer",void 0),zr([Mr({type:nr.Integer,converter:pr})],oo.prototype,"serialNumber",void 0);let so=class{constructor(e={}){r(this,"subjectKeyIdentifier"),r(this,"issuerAndSerialNumber"),Object.assign(this,e)}};var ao,co;zr([Mr({type:Un,context:0,implicit:!0})],so.prototype,"subjectKeyIdentifier",void 0),zr([Mr({type:oo})],so.prototype,"issuerAndSerialNumber",void 0),so=zr([$r({type:rr.Choice})],so),(co=ao||(ao={}))[co.v0=0]="v0",co[co.v1=1]="v1",co[co.v2=2]="v2",co[co.v3=3]="v3",co[co.v4=4]="v4",co[co.v5=5]="v5";let uo=class extends zn{};uo=zr([$r({type:rr.Sequence})],uo);let lo=class extends zn{};lo=zr([$r({type:rr.Sequence})],lo);let po=class extends zn{};po=zr([$r({type:rr.Sequence})],po);let ho=class extends zn{};ho=zr([$r({type:rr.Sequence})],ho);let fo=class extends zn{};fo=zr([$r({type:rr.Sequence})],fo);let yo=class extends zn{};yo=zr([$r({type:rr.Sequence})],yo);let go=class{constructor(e={}){r(this,"attrType",""),r(this,"attrValues",[]),Object.assign(this,e)}};var mo;zr([Mr({type:nr.ObjectIdentifier})],go.prototype,"attrType",void 0),zr([Mr({type:nr.Any,repeated:"set"})],go.prototype,"attrValues",void 0);class vo{constructor(e={}){r(this,"version",ao.v0),r(this,"sid",new so),r(this,"digestAlgorithm",new uo),r(this,"signedAttrs"),r(this,"signedAttrsRaw"),r(this,"signatureAlgorithm",new lo),r(this,"signature",new ar),r(this,"unsignedAttrs"),Object.assign(this,e)}}zr([Mr({type:nr.Integer})],vo.prototype,"version",void 0),zr([Mr({type:so})],vo.prototype,"sid",void 0),zr([Mr({type:uo})],vo.prototype,"digestAlgorithm",void 0),zr([Mr({type:go,repeated:"set",context:0,implicit:!0,optional:!0,raw:!0})],vo.prototype,"signedAttrs",void 0),zr([Mr({type:lo})],vo.prototype,"signatureAlgorithm",void 0),zr([Mr({type:ar})],vo.prototype,"signature",void 0),zr([Mr({type:go,repeated:"set",context:1,implicit:!0,optional:!0})],vo.prototype,"unsignedAttrs",void 0);let wo=mo=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,mo.prototype)}};wo=mo=zr([$r({type:rr.Set,itemType:vo})],wo);let bo=class extends vo{};bo=zr([$r({type:rr.Sequence})],bo);let So=class extends Jn{};So=zr([$r({type:rr.Choice})],So);class Ao{constructor(e={}){r(this,"acIssuer",new ui),r(this,"acSerial",0),r(this,"attrs",[]),Object.assign(this,e)}}var Eo;zr([Mr({type:ui})],Ao.prototype,"acIssuer",void 0),zr([Mr({type:nr.Integer})],Ao.prototype,"acSerial",void 0),zr([Mr({type:Dn,repeated:"sequence"})],Ao.prototype,"attrs",void 0);let ko=Eo=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Eo.prototype)}};ko=Eo=zr([$r({type:rr.Sequence,itemType:nr.ObjectIdentifier})],ko);class xo{constructor(e={}){r(this,"pathLenConstraint"),r(this,"permittedAttrs"),r(this,"excludedAttrs"),r(this,"permitUnSpecified",!0),Object.assign(this,e)}}zr([Mr({type:nr.Integer,optional:!0})],xo.prototype,"pathLenConstraint",void 0),zr([Mr({type:ko,implicit:!0,context:0,optional:!0})],xo.prototype,"permittedAttrs",void 0),zr([Mr({type:ko,implicit:!0,context:1,optional:!0})],xo.prototype,"excludedAttrs",void 0),zr([Mr({type:nr.Boolean,defaultValue:!0})],xo.prototype,"permitUnSpecified",void 0);class _o{constructor(e={}){r(this,"issuer",new Ii),r(this,"serial",new ArrayBuffer(0)),r(this,"issuerUID",new ArrayBuffer(0)),Object.assign(this,e)}}var No,Io;zr([Mr({type:Ii})],_o.prototype,"issuer",void 0),zr([Mr({type:nr.Integer,converter:pr})],_o.prototype,"serial",void 0),zr([Mr({type:nr.BitString,optional:!0})],_o.prototype,"issuerUID",void 0),(Io=No||(No={}))[Io.publicKey=0]="publicKey",Io[Io.publicKeyCert=1]="publicKeyCert",Io[Io.otherObjectTypes=2]="otherObjectTypes";class To{constructor(e={}){r(this,"digestedObjectType",No.publicKey),r(this,"otherObjectTypeID"),r(this,"digestAlgorithm",new zn),r(this,"objectDigest",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.Enumerated})],To.prototype,"digestedObjectType",void 0),zr([Mr({type:nr.ObjectIdentifier,optional:!0})],To.prototype,"otherObjectTypeID",void 0),zr([Mr({type:zn})],To.prototype,"digestAlgorithm",void 0),zr([Mr({type:nr.BitString})],To.prototype,"objectDigest",void 0);class Bo{constructor(e={}){r(this,"issuerName"),r(this,"baseCertificateID"),r(this,"objectDigestInfo"),Object.assign(this,e)}}zr([Mr({type:Ii,optional:!0})],Bo.prototype,"issuerName",void 0),zr([Mr({type:_o,context:0,implicit:!0,optional:!0})],Bo.prototype,"baseCertificateID",void 0),zr([Mr({type:To,context:1,implicit:!0,optional:!0})],Bo.prototype,"objectDigestInfo",void 0);let Oo=class{constructor(e={}){r(this,"v1Form"),r(this,"v2Form"),Object.assign(this,e)}};zr([Mr({type:ui,repeated:"sequence"})],Oo.prototype,"v1Form",void 0),zr([Mr({type:Bo,context:0,implicit:!0})],Oo.prototype,"v2Form",void 0),Oo=zr([$r({type:rr.Choice})],Oo);class Co{constructor(e={}){r(this,"notBeforeTime",new Date),r(this,"notAfterTime",new Date),Object.assign(this,e)}}zr([Mr({type:nr.GeneralizedTime})],Co.prototype,"notBeforeTime",void 0),zr([Mr({type:nr.GeneralizedTime})],Co.prototype,"notAfterTime",void 0);class Do{constructor(e={}){r(this,"baseCertificateID"),r(this,"entityName"),r(this,"objectDigestInfo"),Object.assign(this,e)}}var jo,Po,Ro,Uo,$o;zr([Mr({type:_o,implicit:!0,context:0,optional:!0})],Do.prototype,"baseCertificateID",void 0),zr([Mr({type:Ii,implicit:!0,context:1,optional:!0})],Do.prototype,"entityName",void 0),zr([Mr({type:To,implicit:!0,context:2,optional:!0})],Do.prototype,"objectDigestInfo",void 0),(Po=jo||(jo={}))[Po.v2=1]="v2";class Mo{constructor(e={}){r(this,"version",jo.v2),r(this,"holder",new Do),r(this,"issuer",new Oo),r(this,"signature",new zn),r(this,"serialNumber",new ArrayBuffer(0)),r(this,"attrCertValidityPeriod",new Co),r(this,"attributes",[]),r(this,"issuerUniqueID"),r(this,"extensions"),Object.assign(this,e)}}zr([Mr({type:nr.Integer})],Mo.prototype,"version",void 0),zr([Mr({type:Do})],Mo.prototype,"holder",void 0),zr([Mr({type:Oo})],Mo.prototype,"issuer",void 0),zr([Mr({type:zn})],Mo.prototype,"signature",void 0),zr([Mr({type:nr.Integer,converter:pr})],Mo.prototype,"serialNumber",void 0),zr([Mr({type:Co})],Mo.prototype,"attrCertValidityPeriod",void 0),zr([Mr({type:Dn,repeated:"sequence"})],Mo.prototype,"attributes",void 0),zr([Mr({type:nr.BitString,optional:!0})],Mo.prototype,"issuerUniqueID",void 0),zr([Mr({type:Yn,optional:!0})],Mo.prototype,"extensions",void 0);class Lo{constructor(e={}){r(this,"acinfo",new Mo),r(this,"signatureAlgorithm",new zn),r(this,"signatureValue",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:Mo})],Lo.prototype,"acinfo",void 0),zr([Mr({type:zn})],Lo.prototype,"signatureAlgorithm",void 0),zr([Mr({type:nr.BitString})],Lo.prototype,"signatureValue",void 0),(Uo=Ro||(Ro={}))[Uo.unmarked=1]="unmarked",Uo[Uo.unclassified=2]="unclassified",Uo[Uo.restricted=4]="restricted",Uo[Uo.confidential=8]="confidential",Uo[Uo.secret=16]="secret",Uo[Uo.topSecret=32]="topSecret";class Vo extends sr{}class Ho{constructor(e={}){r(this,"type",""),r(this,"value",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier,implicit:!0,context:0})],Ho.prototype,"type",void 0),zr([Mr({type:nr.Any,implicit:!0,context:1})],Ho.prototype,"value",void 0);class Ko{constructor(e={}){r(this,"policyId",""),r(this,"classList",new Vo(Ro.unclassified)),r(this,"securityCategories"),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],Ko.prototype,"policyId",void 0),zr([Mr({type:Vo,defaultValue:new Vo(Ro.unclassified)})],Ko.prototype,"classList",void 0),zr([Mr({type:Ho,repeated:"set"})],Ko.prototype,"securityCategories",void 0);class Fo{constructor(e={}){r(this,"cotets"),r(this,"oid"),r(this,"string"),Object.assign(this,e)}}zr([Mr({type:ar})],Fo.prototype,"cotets",void 0),zr([Mr({type:nr.ObjectIdentifier})],Fo.prototype,"oid",void 0),zr([Mr({type:nr.Utf8String})],Fo.prototype,"string",void 0);class zo{constructor(e={}){r(this,"policyAuthority"),r(this,"values",[]),Object.assign(this,e)}}zr([Mr({type:Ii,implicit:!0,context:0,optional:!0})],zo.prototype,"policyAuthority",void 0),zr([Mr({type:Fo,repeated:"sequence"})],zo.prototype,"values",void 0);class Wo{constructor(e={}){r(this,"targetCertificate",new _o),r(this,"targetName"),r(this,"certDigestInfo"),Object.assign(this,e)}}zr([Mr({type:_o})],Wo.prototype,"targetCertificate",void 0),zr([Mr({type:ui,optional:!0})],Wo.prototype,"targetName",void 0),zr([Mr({type:To,optional:!0})],Wo.prototype,"certDigestInfo",void 0);let Jo=class{constructor(e={}){r(this,"targetName"),r(this,"targetGroup"),r(this,"targetCert"),Object.assign(this,e)}};zr([Mr({type:ui,context:0,implicit:!0})],Jo.prototype,"targetName",void 0),zr([Mr({type:ui,context:1,implicit:!0})],Jo.prototype,"targetGroup",void 0),zr([Mr({type:Wo,context:2,implicit:!0})],Jo.prototype,"targetCert",void 0),Jo=zr([$r({type:rr.Choice})],Jo);let qo=$o=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,$o.prototype)}};var Go;qo=$o=zr([$r({type:rr.Sequence,itemType:Jo})],qo);let Xo=Go=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Go.prototype)}};Xo=Go=zr([$r({type:rr.Sequence,itemType:qo})],Xo);class Yo{constructor(e={}){r(this,"roleAuthority"),r(this,"roleName"),Object.assign(this,e)}}zr([Mr({type:Ii,implicit:!0,context:0,optional:!0})],Yo.prototype,"roleAuthority",void 0),zr([Mr({type:ui,implicit:!0,context:1})],Yo.prototype,"roleName",void 0);class Zo{constructor(e={}){r(this,"service",new ui),r(this,"ident",new ui),r(this,"authInfo"),Object.assign(this,e)}}var Qo;zr([Mr({type:ui})],Zo.prototype,"service",void 0),zr([Mr({type:ui})],Zo.prototype,"ident",void 0),zr([Mr({type:ar,optional:!0})],Zo.prototype,"authInfo",void 0);class es{constructor(e={}){r(this,"otherCertFormat",""),r(this,"otherCert",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],es.prototype,"otherCertFormat",void 0),zr([Mr({type:nr.Any})],es.prototype,"otherCert",void 0);let ts=class{constructor(e={}){r(this,"certificate"),r(this,"v2AttrCert"),r(this,"other"),Object.assign(this,e)}};zr([Mr({type:to})],ts.prototype,"certificate",void 0),zr([Mr({type:Lo,context:2,implicit:!0})],ts.prototype,"v2AttrCert",void 0),zr([Mr({type:es,context:3,implicit:!0})],ts.prototype,"other",void 0),ts=zr([$r({type:rr.Choice})],ts);let rs=Qo=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Qo.prototype)}};rs=Qo=zr([$r({type:rr.Set,itemType:ts})],rs);class is{constructor(e={}){r(this,"contentType",""),r(this,"content",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],is.prototype,"contentType",void 0),zr([Mr({type:nr.Any,context:0})],is.prototype,"content",void 0);let ns=class{constructor(e={}){r(this,"single"),r(this,"any"),Object.assign(this,e)}};zr([Mr({type:ar})],ns.prototype,"single",void 0),zr([Mr({type:nr.Any})],ns.prototype,"any",void 0),ns=zr([$r({type:rr.Choice})],ns);class os{constructor(e={}){r(this,"eContentType",""),r(this,"eContent"),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],os.prototype,"eContentType",void 0),zr([Mr({type:ns,context:0,optional:!0})],os.prototype,"eContent",void 0);let ss=class{constructor(e={}){r(this,"value"),r(this,"constructedValue"),Object.assign(this,e)}};zr([Mr({type:ar,context:0,implicit:!0,optional:!0})],ss.prototype,"value",void 0),zr([Mr({type:ar,converter:gr,context:0,implicit:!0,optional:!0,repeated:"sequence"})],ss.prototype,"constructedValue",void 0),ss=zr([$r({type:rr.Choice})],ss);class as{constructor(e={}){r(this,"contentType",""),r(this,"contentEncryptionAlgorithm",new ho),r(this,"encryptedContent"),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],as.prototype,"contentType",void 0),zr([Mr({type:ho})],as.prototype,"contentEncryptionAlgorithm",void 0),zr([Mr({type:ss,optional:!0})],as.prototype,"encryptedContent",void 0);class cs{constructor(e={}){r(this,"keyAttrId",""),r(this,"keyAttr"),Object.assign(this,e)}}var us;zr([Mr({type:nr.ObjectIdentifier})],cs.prototype,"keyAttrId",void 0),zr([Mr({type:nr.Any,optional:!0})],cs.prototype,"keyAttr",void 0);class ls{constructor(e={}){r(this,"subjectKeyIdentifier",new Un),r(this,"date"),r(this,"other"),Object.assign(this,e)}}zr([Mr({type:Un})],ls.prototype,"subjectKeyIdentifier",void 0),zr([Mr({type:nr.GeneralizedTime,optional:!0})],ls.prototype,"date",void 0),zr([Mr({type:cs,optional:!0})],ls.prototype,"other",void 0);let ps=class{constructor(e={}){r(this,"rKeyId"),r(this,"issuerAndSerialNumber"),Object.assign(this,e)}};zr([Mr({type:ls,context:0,implicit:!0,optional:!0})],ps.prototype,"rKeyId",void 0),zr([Mr({type:oo,optional:!0})],ps.prototype,"issuerAndSerialNumber",void 0),ps=zr([$r({type:rr.Choice})],ps);class hs{constructor(e={}){r(this,"rid",new ps),r(this,"encryptedKey",new ar),Object.assign(this,e)}}zr([Mr({type:ps})],hs.prototype,"rid",void 0),zr([Mr({type:ar})],hs.prototype,"encryptedKey",void 0);let ds=us=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,us.prototype)}};ds=us=zr([$r({type:rr.Sequence,itemType:hs})],ds);class fs{constructor(e={}){r(this,"algorithm",new zn),r(this,"publicKey",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:zn})],fs.prototype,"algorithm",void 0),zr([Mr({type:nr.BitString})],fs.prototype,"publicKey",void 0);let ys=class{constructor(e={}){r(this,"subjectKeyIdentifier"),r(this,"originatorKey"),r(this,"issuerAndSerialNumber"),Object.assign(this,e)}};zr([Mr({type:Un,context:0,implicit:!0,optional:!0})],ys.prototype,"subjectKeyIdentifier",void 0),zr([Mr({type:fs,context:1,implicit:!0,optional:!0})],ys.prototype,"originatorKey",void 0),zr([Mr({type:oo,optional:!0})],ys.prototype,"issuerAndSerialNumber",void 0),ys=zr([$r({type:rr.Choice})],ys);class gs{constructor(e={}){r(this,"version",ao.v3),r(this,"originator",new ys),r(this,"ukm"),r(this,"keyEncryptionAlgorithm",new po),r(this,"recipientEncryptedKeys",new ds),Object.assign(this,e)}}zr([Mr({type:nr.Integer})],gs.prototype,"version",void 0),zr([Mr({type:ys,context:0})],gs.prototype,"originator",void 0),zr([Mr({type:ar,context:1,optional:!0})],gs.prototype,"ukm",void 0),zr([Mr({type:po})],gs.prototype,"keyEncryptionAlgorithm",void 0),zr([Mr({type:ds})],gs.prototype,"recipientEncryptedKeys",void 0);let ms=class{constructor(e={}){r(this,"subjectKeyIdentifier"),r(this,"issuerAndSerialNumber"),Object.assign(this,e)}};zr([Mr({type:Un,context:0,implicit:!0})],ms.prototype,"subjectKeyIdentifier",void 0),zr([Mr({type:oo})],ms.prototype,"issuerAndSerialNumber",void 0),ms=zr([$r({type:rr.Choice})],ms);class vs{constructor(e={}){r(this,"version",ao.v0),r(this,"rid",new ms),r(this,"keyEncryptionAlgorithm",new po),r(this,"encryptedKey",new ar),Object.assign(this,e)}}zr([Mr({type:nr.Integer})],vs.prototype,"version",void 0),zr([Mr({type:ms})],vs.prototype,"rid",void 0),zr([Mr({type:po})],vs.prototype,"keyEncryptionAlgorithm",void 0),zr([Mr({type:ar})],vs.prototype,"encryptedKey",void 0);class ws{constructor(e={}){r(this,"keyIdentifier",new ar),r(this,"date"),r(this,"other"),Object.assign(this,e)}}zr([Mr({type:ar})],ws.prototype,"keyIdentifier",void 0),zr([Mr({type:nr.GeneralizedTime,optional:!0})],ws.prototype,"date",void 0),zr([Mr({type:cs,optional:!0})],ws.prototype,"other",void 0);class bs{constructor(e={}){r(this,"version",ao.v4),r(this,"kekid",new ws),r(this,"keyEncryptionAlgorithm",new po),r(this,"encryptedKey",new ar),Object.assign(this,e)}}zr([Mr({type:nr.Integer})],bs.prototype,"version",void 0),zr([Mr({type:ws})],bs.prototype,"kekid",void 0),zr([Mr({type:po})],bs.prototype,"keyEncryptionAlgorithm",void 0),zr([Mr({type:ar})],bs.prototype,"encryptedKey",void 0);class Ss{constructor(e={}){r(this,"version",ao.v0),r(this,"keyDerivationAlgorithm"),r(this,"keyEncryptionAlgorithm",new po),r(this,"encryptedKey",new ar),Object.assign(this,e)}}zr([Mr({type:nr.Integer})],Ss.prototype,"version",void 0),zr([Mr({type:yo,context:0,optional:!0})],Ss.prototype,"keyDerivationAlgorithm",void 0),zr([Mr({type:po})],Ss.prototype,"keyEncryptionAlgorithm",void 0),zr([Mr({type:ar})],Ss.prototype,"encryptedKey",void 0);class As{constructor(e={}){r(this,"oriType",""),r(this,"oriValue",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],As.prototype,"oriType",void 0),zr([Mr({type:nr.Any})],As.prototype,"oriValue",void 0);let Es=class{constructor(e={}){r(this,"ktri"),r(this,"kari"),r(this,"kekri"),r(this,"pwri"),r(this,"ori"),Object.assign(this,e)}};var ks;zr([Mr({type:vs,optional:!0})],Es.prototype,"ktri",void 0),zr([Mr({type:gs,context:1,implicit:!0,optional:!0})],Es.prototype,"kari",void 0),zr([Mr({type:bs,context:2,implicit:!0,optional:!0})],Es.prototype,"kekri",void 0),zr([Mr({type:Ss,context:3,implicit:!0,optional:!0})],Es.prototype,"pwri",void 0),zr([Mr({type:As,context:4,implicit:!0,optional:!0})],Es.prototype,"ori",void 0),Es=zr([$r({type:rr.Choice})],Es);let xs=ks=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,ks.prototype)}};var _s;xs=ks=zr([$r({type:rr.Set,itemType:Es})],xs);class Ns{constructor(e={}){r(this,"otherRevInfoFormat",""),r(this,"otherRevInfo",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],Ns.prototype,"otherRevInfoFormat",void 0),zr([Mr({type:nr.Any})],Ns.prototype,"otherRevInfo",void 0);let Is=class{constructor(e={}){r(this,"other",new Ns),Object.assign(this,e)}};zr([Mr({type:Ns,context:1,implicit:!0})],Is.prototype,"other",void 0),Is=zr([$r({type:rr.Choice})],Is);let Ts=_s=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,_s.prototype)}};Ts=_s=zr([$r({type:rr.Set,itemType:Is})],Ts);class Bs{constructor(e={}){r(this,"certs"),r(this,"crls"),Object.assign(this,e)}}var Os;zr([Mr({type:rs,context:0,implicit:!0,optional:!0})],Bs.prototype,"certs",void 0),zr([Mr({type:Ts,context:1,implicit:!0,optional:!0})],Bs.prototype,"crls",void 0);let Cs=Os=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Os.prototype)}};Cs=Os=zr([$r({type:rr.Set,itemType:go})],Cs);class Ds{constructor(e={}){r(this,"version",ao.v0),r(this,"originatorInfo"),r(this,"recipientInfos",new xs),r(this,"encryptedContentInfo",new as),r(this,"unprotectedAttrs"),Object.assign(this,e)}}zr([Mr({type:nr.Integer})],Ds.prototype,"version",void 0),zr([Mr({type:Bs,context:0,implicit:!0,optional:!0})],Ds.prototype,"originatorInfo",void 0),zr([Mr({type:xs})],Ds.prototype,"recipientInfos",void 0),zr([Mr({type:as})],Ds.prototype,"encryptedContentInfo",void 0),zr([Mr({type:Cs,context:1,implicit:!0,optional:!0})],Ds.prototype,"unprotectedAttrs",void 0);const js="1.2.840.113549.1.7.2";var Ps;let Rs=Ps=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Ps.prototype)}};Rs=Ps=zr([$r({type:rr.Set,itemType:uo})],Rs);class Us{constructor(e={}){r(this,"version",ao.v0),r(this,"digestAlgorithms",new Rs),r(this,"encapContentInfo",new os),r(this,"certificates"),r(this,"crls"),r(this,"signerInfos",new wo),Object.assign(this,e)}}zr([Mr({type:nr.Integer})],Us.prototype,"version",void 0),zr([Mr({type:Rs})],Us.prototype,"digestAlgorithms",void 0),zr([Mr({type:os})],Us.prototype,"encapContentInfo",void 0),zr([Mr({type:rs,context:0,implicit:!0,optional:!0})],Us.prototype,"certificates",void 0),zr([Mr({type:Ts,context:1,implicit:!0,optional:!0})],Us.prototype,"crls",void 0),zr([Mr({type:wo})],Us.prototype,"signerInfos",void 0);const $s="1.2.840.10045.2.1",Ms="1.2.840.10045.4.1",Ls="1.2.840.10045.4.3.1",Vs="1.2.840.10045.4.3.2",Hs="1.2.840.10045.4.3.3",Ks="1.2.840.10045.4.3.4",Fs="1.2.840.10045.3.1.7",zs="1.3.132.0.34",Ws="1.3.132.0.35";function Js(e){return new zn({algorithm:e})}const qs=Js(Ms);Js(Ls);const Gs=Js(Vs),Xs=Js(Hs),Ys=Js(Ks);let Zs=class{constructor(e={}){r(this,"fieldType"),r(this,"parameters"),Object.assign(this,e)}};zr([Mr({type:nr.ObjectIdentifier})],Zs.prototype,"fieldType",void 0),zr([Mr({type:nr.Any})],Zs.prototype,"parameters",void 0),Zs=zr([$r({type:rr.Sequence})],Zs);let Qs=class{constructor(e={}){r(this,"a"),r(this,"b"),r(this,"seed"),Object.assign(this,e)}};var ea,ta;zr([Mr({type:nr.OctetString})],Qs.prototype,"a",void 0),zr([Mr({type:nr.OctetString})],Qs.prototype,"b",void 0),zr([Mr({type:nr.BitString,optional:!0})],Qs.prototype,"seed",void 0),Qs=zr([$r({type:rr.Sequence})],Qs),(ta=ea||(ea={}))[ta.ecpVer1=1]="ecpVer1";let ra=class{constructor(e={}){r(this,"version",ea.ecpVer1),r(this,"fieldID"),r(this,"curve"),r(this,"base"),r(this,"order"),r(this,"cofactor"),Object.assign(this,e)}};zr([Mr({type:nr.Integer})],ra.prototype,"version",void 0),zr([Mr({type:Zs})],ra.prototype,"fieldID",void 0),zr([Mr({type:Qs})],ra.prototype,"curve",void 0),zr([Mr({type:class extends ar{}})],ra.prototype,"base",void 0),zr([Mr({type:nr.Integer,converter:pr})],ra.prototype,"order",void 0),zr([Mr({type:nr.Integer,optional:!0})],ra.prototype,"cofactor",void 0),ra=zr([$r({type:rr.Sequence})],ra);let ia=class{constructor(e={}){r(this,"namedCurve"),r(this,"implicitCurve"),r(this,"specifiedCurve"),Object.assign(this,e)}};zr([Mr({type:nr.ObjectIdentifier})],ia.prototype,"namedCurve",void 0),zr([Mr({type:nr.Null})],ia.prototype,"implicitCurve",void 0),zr([Mr({type:ra})],ia.prototype,"specifiedCurve",void 0),ia=zr([$r({type:rr.Choice})],ia);class na{constructor(e={}){r(this,"version",1),r(this,"privateKey",new ar),r(this,"parameters"),r(this,"publicKey"),Object.assign(this,e)}}zr([Mr({type:nr.Integer})],na.prototype,"version",void 0),zr([Mr({type:ar})],na.prototype,"privateKey",void 0),zr([Mr({type:ia,context:0,optional:!0})],na.prototype,"parameters",void 0),zr([Mr({type:nr.BitString,context:1,optional:!0})],na.prototype,"publicKey",void 0);class oa{constructor(e={}){r(this,"r",new ArrayBuffer(0)),r(this,"s",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.Integer,converter:pr})],oa.prototype,"r",void 0),zr([Mr({type:nr.Integer,converter:pr})],oa.prototype,"s",void 0);const sa="1.2.840.113549.1.1",aa=`${sa}.1`,ca=`${sa}.7`,ua=`${sa}.9`,la=`${sa}.10`,pa=`${sa}.2`,ha=`${sa}.4`,da=`${sa}.5`,fa=`${sa}.14`,ya=`${sa}.11`,ga=`${sa}.12`,ma=`${sa}.13`,va=`${sa}.15`,wa=`${sa}.16`,ba="1.3.14.3.2.26",Sa="2.16.840.1.101.3.4.2.4",Aa="2.16.840.1.101.3.4.2.1",Ea="2.16.840.1.101.3.4.2.2",ka="2.16.840.1.101.3.4.2.3",xa=`${sa}.8`;function _a(e){return new zn({algorithm:e,parameters:null})}_a("1.2.840.113549.2.2"),_a("1.2.840.113549.2.5");const Na=_a(ba);_a(Sa),_a(Aa),_a(Ea),_a(ka),_a("2.16.840.1.101.3.4.2.5"),_a("2.16.840.1.101.3.4.2.6");const Ia=new zn({algorithm:xa,parameters:Fr.serialize(Na)}),Ta=new zn({algorithm:ua,parameters:Fr.serialize(yr.toASN(new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer))});_a(aa),_a(pa),_a(ha),_a(da),_a(va),_a(wa),_a(ga),_a(ma),_a(va),_a(wa);class Ba{constructor(e={}){r(this,"hashAlgorithm",new zn(Na)),r(this,"maskGenAlgorithm",new zn({algorithm:xa,parameters:Fr.serialize(Na)})),r(this,"pSourceAlgorithm",new zn(Ta)),Object.assign(this,e)}}zr([Mr({type:zn,context:0,defaultValue:Na})],Ba.prototype,"hashAlgorithm",void 0),zr([Mr({type:zn,context:1,defaultValue:Ia})],Ba.prototype,"maskGenAlgorithm",void 0),zr([Mr({type:zn,context:2,defaultValue:Ta})],Ba.prototype,"pSourceAlgorithm",void 0),new zn({algorithm:ca,parameters:Fr.serialize(new Ba)});class Oa{constructor(e={}){r(this,"hashAlgorithm",new zn(Na)),r(this,"maskGenAlgorithm",new zn({algorithm:xa,parameters:Fr.serialize(Na)})),r(this,"saltLength",20),r(this,"trailerField",1),Object.assign(this,e)}}zr([Mr({type:zn,context:0,defaultValue:Na})],Oa.prototype,"hashAlgorithm",void 0),zr([Mr({type:zn,context:1,defaultValue:Ia})],Oa.prototype,"maskGenAlgorithm",void 0),zr([Mr({type:nr.Integer,context:2,defaultValue:20})],Oa.prototype,"saltLength",void 0),zr([Mr({type:nr.Integer,context:3,defaultValue:1})],Oa.prototype,"trailerField",void 0),new zn({algorithm:la,parameters:Fr.serialize(new Oa)});class Ca{constructor(e={}){r(this,"digestAlgorithm",new zn),r(this,"digest",new ar),Object.assign(this,e)}}var Da;zr([Mr({type:zn})],Ca.prototype,"digestAlgorithm",void 0),zr([Mr({type:ar})],Ca.prototype,"digest",void 0);class ja{constructor(e={}){r(this,"prime",new ArrayBuffer(0)),r(this,"exponent",new ArrayBuffer(0)),r(this,"coefficient",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.Integer,converter:pr})],ja.prototype,"prime",void 0),zr([Mr({type:nr.Integer,converter:pr})],ja.prototype,"exponent",void 0),zr([Mr({type:nr.Integer,converter:pr})],ja.prototype,"coefficient",void 0);let Pa=Da=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Da.prototype)}};Pa=Da=zr([$r({type:rr.Sequence,itemType:ja})],Pa);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)}}zr([Mr({type:nr.Integer})],Ra.prototype,"version",void 0),zr([Mr({type:nr.Integer,converter:pr})],Ra.prototype,"modulus",void 0),zr([Mr({type:nr.Integer,converter:pr})],Ra.prototype,"publicExponent",void 0),zr([Mr({type:nr.Integer,converter:pr})],Ra.prototype,"privateExponent",void 0),zr([Mr({type:nr.Integer,converter:pr})],Ra.prototype,"prime1",void 0),zr([Mr({type:nr.Integer,converter:pr})],Ra.prototype,"prime2",void 0),zr([Mr({type:nr.Integer,converter:pr})],Ra.prototype,"exponent1",void 0),zr([Mr({type:nr.Integer,converter:pr})],Ra.prototype,"exponent2",void 0),zr([Mr({type:nr.Integer,converter:pr})],Ra.prototype,"coefficient",void 0),zr([Mr({type:Pa,optional:!0})],Ra.prototype,"otherPrimeInfos",void 0);class Ua{constructor(e={}){r(this,"modulus",new ArrayBuffer(0)),r(this,"publicExponent",new ArrayBuffer(0)),Object.assign(this,e)}}var $a,Ma;zr([Mr({type:nr.Integer,converter:pr})],Ua.prototype,"modulus",void 0),zr([Mr({type:nr.Integer,converter:pr})],Ua.prototype,"publicExponent",void 0),(Ma=$a||($a={}))[Ma.Transient=0]="Transient",Ma[Ma.Singleton=1]="Singleton",Ma[Ma.ResolutionScoped=2]="ResolutionScoped",Ma[Ma.ContainerScoped=3]="ContainerScoped";const La=$a;
|
|
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 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);
|
|
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 Ha(e,t){function r(){this.constructor=e}Va(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function Ka(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 Fa(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 za(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 Wa(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 Ja(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(Wa(arguments[t]));return e}function qa(e){return!!e.useClass}function Ga(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,Ja(t))}})),t},e}();function Ya(e){return"string"==typeof e||"symbol"==typeof e}function Za(e){return"object"==typeof e&&"token"in e&&"transform"in e}function Qa(e){return!!e.useToken}function ec(e){return null!=e.useValue}var tc=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}(),rc=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Ha(t,e),t}(tc),ic=function(){this.scopedResolutions=new Map};function nc(e,t,r){var i,n,o=Wa(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=" "),Ja([i],r.message.split("\n").map((function(e){return n+e}))).join("\n")}var oc,sc=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Ha(t,e),t}(tc),ac=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Ha(t,e),t}(tc),cc=function(){this.preResolution=new sc,this.postResolution=new ac},uc=new Map,lc=new(function(){function e(e){this.parent=e,this._registry=new rc,this.interceptors=new cc,this.disposed=!1,this.disposables=new Set}return e.prototype.register=function(e,t,r){var i;if(void 0===r&&(r={lifecycle:La.Transient}),this.ensureNotDisposed(),i=function(e){return qa(e)||ec(e)||Qa(e)||Ga(e)}(t)?t:{useClass:t},Qa(i))for(var n=[e],o=i;null!=o;){var s=o.useToken;if(n.includes(s))throw new Error("Token registration cycle detected! "+Ja(n,[s]).join(" -> "));n.push(s);var a=this._registry.get(s);o=a&&Qa(a.provider)?a.provider:null}if((r.lifecycle===La.Singleton||r.lifecycle==La.ContainerScoped||r.lifecycle==La.ResolutionScoped)&&(ec(i)||Ga(i)))throw new Error('Cannot use lifecycle "'+La[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(),Ya(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(),Ya(e)){if(Ya(t))return this.register(e,{useToken:t},{lifecycle:La.Singleton});if(t)return this.register(e,{useClass:t},{lifecycle:La.Singleton});throw new Error('Cannot register a type name as a singleton without a "to" token')}var r=e;return t&&!Ya(t)&&(r=t),this.register(e,{useClass:r},{lifecycle:La.Singleton})},e.prototype.resolve=function(e,t,r){void 0===t&&(t=new ic),void 0===r&&(r=!1),this.ensureNotDisposed();var i=this.getRegistration(e);if(!i&&Ya(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=za(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=za(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===La.ResolutionScoped&&t.scopedResolutions.has(e))return t.scopedResolutions.get(e);var r,i=e.options.lifecycle===La.Singleton,n=e.options.lifecycle===La.ContainerScoped,o=i||n;return r=ec(e.provider)?e.provider.useValue:Qa(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):Ga(e.provider)?e.provider.useFactory(this):this.construct(e.provider,t),e.options.lifecycle===La.ResolutionScoped&&t.scopedResolutions.set(e,r),r},e.prototype.resolveAll=function(e,t,r){var i=this;void 0===t&&(t=new ic),void 0===r&&(r=!1),this.ensureNotDisposed();var n=this.getAllRegistrations(e);if(!n&&Ya(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=za(this._registry.entries()),i=r.next();!i.done;i=r.next()){var n=Wa(i.value,2),o=n[0],s=n[1];this._registry.setAll(o,s.filter((function(e){return!ec(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=za(this._registry.entries()),o=n.next();!o.done;o=n.next()){var s=Wa(o.value,2),a=s[0],c=s[1];c.some((function(e){return e.options.lifecycle===La.ContainerScoped}))&&i._registry.setAll(a,c.map((function(e){return e.options.lifecycle===La.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 Ka(this,void 0,void 0,(function(){var e;return Fa(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=uc.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,Ja([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?Za(i)?i.multiple?(o=r.resolve(i.transform)).transform.apply(o,Ja([r.resolveAll(i.token,new ic,i.isOptional)],i.transformArgs)):(s=r.resolve(i.transform)).transform.apply(s,Ja([r.resolve(i.token,e,i.isOptional)],i.transformArgs)):i.multiple?r.resolveAll(i.token,new ic,i.isOptional):r.resolve(i.token,e,i.isOptional):Za(i)?(a=r.resolve(i.transform,e)).transform.apply(a,Ja([r.resolve(i.token,e)],i.transformArgs)):r.resolve(i,e)}catch(u){throw new Error(nc(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 pc(e){return function(t){uc.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){lc.register(e,t)})):lc.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)}}zr([Mr({type:nr.ObjectIdentifier})],hc.prototype,"attrId",void 0),zr([Mr({type:nr.Any,repeated:"set"})],hc.prototype,"attrValues",void 0);let dc=oc=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,oc.prototype)}};var fc;dc=oc=zr([$r({type:rr.Sequence,itemType:hc})],dc);let yc=fc=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,fc.prototype)}};yc=fc=zr([$r({type:rr.Sequence,itemType:is})],yc);class gc{constructor(e={}){r(this,"certId",""),r(this,"certValue",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],gc.prototype,"certId",void 0),zr([Mr({type:nr.Any,context:0})],gc.prototype,"certValue",void 0);class mc{constructor(e={}){r(this,"crlId",""),r(this,"crltValue",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],mc.prototype,"crlId",void 0),zr([Mr({type:nr.Any,context:0})],mc.prototype,"crltValue",void 0);class vc extends ar{}let wc=class{constructor(e={}){r(this,"encryptionAlgorithm",new zn),r(this,"encryptedData",new vc),Object.assign(this,e)}};var bc,Sc;zr([Mr({type:zn})],wc.prototype,"encryptionAlgorithm",void 0),zr([Mr({type:vc})],wc.prototype,"encryptedData",void 0),function(e){e[e.v1=0]="v1"}(Sc||(Sc={}));class Ac extends ar{}let Ec=bc=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,bc.prototype)}};Ec=bc=zr([$r({type:rr.Sequence,itemType:Dn})],Ec);class kc{constructor(e={}){r(this,"version",Sc.v1),r(this,"privateKeyAlgorithm",new zn),r(this,"privateKey",new Ac),r(this,"attributes"),Object.assign(this,e)}}zr([Mr({type:nr.Integer})],kc.prototype,"version",void 0),zr([Mr({type:zn})],kc.prototype,"privateKeyAlgorithm",void 0),zr([Mr({type:Ac})],kc.prototype,"privateKey",void 0),zr([Mr({type:Ec,implicit:!0,context:0,optional:!0})],kc.prototype,"attributes",void 0);let xc=class extends kc{};xc=zr([$r({type:rr.Sequence})],xc);let _c=class extends wc{};_c=zr([$r({type:rr.Sequence})],_c);class Nc{constructor(e={}){r(this,"secretTypeId",""),r(this,"secretValue",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:nr.ObjectIdentifier})],Nc.prototype,"secretTypeId",void 0),zr([Mr({type:nr.Any,context:0})],Nc.prototype,"secretValue",void 0);class Ic{constructor(e={}){r(this,"mac",new Ca),r(this,"macSalt",new ar),r(this,"iterations",1),Object.assign(this,e)}}zr([Mr({type:Ca})],Ic.prototype,"mac",void 0),zr([Mr({type:ar})],Ic.prototype,"macSalt",void 0),zr([Mr({type:nr.Integer,defaultValue:1})],Ic.prototype,"iterations",void 0);class Tc{constructor(e={}){r(this,"version",3),r(this,"authSafe",new is),r(this,"macData",new Ic),Object.assign(this,e)}}var Bc;zr([Mr({type:nr.Integer})],Tc.prototype,"version",void 0),zr([Mr({type:is})],Tc.prototype,"authSafe",void 0),zr([Mr({type:Ic,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)}}zr([Mr({type:nr.ObjectIdentifier})],Oc.prototype,"bagId",void 0),zr([Mr({type:nr.Any,context:0})],Oc.prototype,"bagValue",void 0),zr([Mr({type:hc,repeated:"set",optional:!0})],Oc.prototype,"bagAttributes",void 0);let Cc=Bc=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Bc.prototype)}};var Dc,jc,Pc;Cc=Bc=zr([$r({type:rr.Sequence,itemType:Oc})],Cc);const Rc="1.2.840.113549.1.9",Uc=`${Rc}.7`,$c=`${Rc}.14`;let Mc=class extends ei{constructor(e={}){super(e),r(this,"ia5String")}toString(){return this.ia5String||super.toString()}};zr([Mr({type:nr.IA5String})],Mc.prototype,"ia5String",void 0),Mc=zr([$r({type:rr.Choice})],Mc);let Lc=class extends is{};Lc=zr([$r({type:rr.Sequence})],Lc);let Vc=class extends Tc{};Vc=zr([$r({type:rr.Sequence})],Vc);let Hc=class extends wc{};Hc=zr([$r({type:rr.Sequence})],Hc);let Kc=class{constructor(e=""){r(this,"value"),this.value=e}toString(){return this.value}};zr([Mr({type:nr.IA5String})],Kc.prototype,"value",void 0),Kc=zr([$r({type:rr.Choice})],Kc);let Fc=class extends Mc{};Fc=zr([$r({type:rr.Choice})],Fc);let zc=class extends ei{};zc=zr([$r({type:rr.Choice})],zc);let Wc=class{constructor(e=new Date){r(this,"value"),this.value=e}};zr([Mr({type:nr.GeneralizedTime})],Wc.prototype,"value",void 0),Wc=zr([$r({type:rr.Choice})],Wc);let Jc=class extends ei{};Jc=zr([$r({type:rr.Choice})],Jc);let qc=class{constructor(e="M"){r(this,"value"),this.value=e}toString(){return this.value}};zr([Mr({type:nr.PrintableString})],qc.prototype,"value",void 0),qc=zr([$r({type:rr.Choice})],qc);let Gc=class{constructor(e=""){r(this,"value"),this.value=e}toString(){return this.value}};zr([Mr({type:nr.PrintableString})],Gc.prototype,"value",void 0),Gc=zr([$r({type:rr.Choice})],Gc);let Xc=class extends Gc{};Xc=zr([$r({type:rr.Choice})],Xc);let Yc=class extends ei{};Yc=zr([$r({type:rr.Choice})],Yc);let Zc=class{constructor(e=""){r(this,"value"),this.value=e}toString(){return this.value}};zr([Mr({type:nr.ObjectIdentifier})],Zc.prototype,"value",void 0),Zc=zr([$r({type:rr.Choice})],Zc);let Qc=class extends Jn{};Qc=zr([$r({type:rr.Choice})],Qc);let eu=class{constructor(e=0){r(this,"value"),this.value=e}toString(){return this.value.toString()}};zr([Mr({type:nr.Integer})],eu.prototype,"value",void 0),eu=zr([$r({type:rr.Choice})],eu);let tu=class extends vo{};tu=zr([$r({type:rr.Sequence})],tu);let ru=class extends ei{};ru=zr([$r({type:rr.Choice})],ru);let iu=Dc=class extends Yn{constructor(e){super(e),Object.setPrototypeOf(this,Dc.prototype)}};iu=Dc=zr([$r({type:rr.Sequence})],iu);let nu=jc=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,jc.prototype)}};nu=jc=zr([$r({type:rr.Set,itemType:go})],nu);let ou=class{constructor(e=""){r(this,"value"),this.value=e}toString(){return this.value}};zr([Mr({type:nr.BmpString})],ou.prototype,"value",void 0),ou=zr([$r({type:rr.Choice})],ou);let su=class extends zn{};su=zr([$r({type:rr.Sequence})],su);let au=Pc=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,Pc.prototype)}};var cu;au=Pc=zr([$r({type:rr.Sequence,itemType:su})],au);let uu=cu=class extends Kr{constructor(e){super(e),Object.setPrototypeOf(this,cu.prototype)}};uu=cu=zr([$r({type:rr.Sequence,itemType:Dn})],uu);class lu{constructor(e={}){r(this,"version",0),r(this,"subject",new oi),r(this,"subjectPKInfo",new Wn),r(this,"attributes",new uu),Object.assign(this,e)}}zr([Mr({type:nr.Integer})],lu.prototype,"version",void 0),zr([Mr({type:oi})],lu.prototype,"subject",void 0),zr([Mr({type:Wn})],lu.prototype,"subjectPKInfo",void 0),zr([Mr({type:uu,implicit:!0,context:0,optional:!0})],lu.prototype,"attributes",void 0);class pu{constructor(e={}){r(this,"certificationRequestInfo",new lu),r(this,"certificationRequestInfoRaw"),r(this,"signatureAlgorithm",new zn),r(this,"signature",new ArrayBuffer(0)),Object.assign(this,e)}}zr([Mr({type:lu,raw:!0})],pu.prototype,"certificationRequestInfo",void 0),zr([Mr({type:zn})],pu.prototype,"signatureAlgorithm",void 0),zr([Mr({type:nr.BitString})],pu.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 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(e,"security","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,!0),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],[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))});b.push({path:"security/start_config.json",role:"start_config",required:!0,secret:!0,present:Yh(t.join(r,"security","start_config.json"))});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",`security/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",`security/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",`security/start_config.json is missing ${t}`);m.zone_name!==p.toString()&&l("START_CONFIG_ZONE",`security/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",`security/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","security/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","security/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",`security/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})}async function Sd(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);!function(e){var t;const r=Kh("node:fs"),i=Kh("node:path").join(e,"etc","product.json");return!r.existsSync(i)||!1!==(null==(t=JSON.parse(r.readFileSync(i,"utf8")).capabilities)?void 0:t.container)}(e.rootDir)?w.support_container=!1: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:{},owner_telegram_account_id:""},gatewayParams:{params:{device_did:p,rtcp_port:String(e.rtcpPort)}},dnsRecords:ad(e.domain,e.publicIp)}}function Ad(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 Ed(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 kd=1743478939,xd=2058838939;function _d(e){const t=e.split(".");return[Number(t[0])||0,Number(t[1])||0]}function Nd(){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]=_d(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]=_d(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 Id(e){Nd();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 Td(e,t){const r=Id("node:fs"),i=Id("node:path");r.mkdirSync(i.dirname(e),{recursive:!0}),r.writeFileSync(e,t),console.log(`# Write file: ${e}`)}function Bd(e,t){Td(e,JSON.stringify(t,null,2))}function Od(e){const t=Id("node:fs");return JSON.parse(t.readFileSync(e,"utf8"))}function Cd(e){if(Array.isArray(e))return e.map(Cd);if(null!==e&&"object"==typeof e){const t={};for(const r of Object.keys(e).sort())t[r]=Cd(e[r]);return t}return e}function Dd(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 jd(e,t,r){return r||Ph(`${e}.${t}`)}function Pd(e){const t=Id("node:path");return new qp(t.join(e,"local","identity"),t.join(e,"security"))}class Rd{constructor(e){Nd(),this.dbPath=e}connect(){const{DatabaseSync:e}=Id("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 Ud(){var e;const t=(null==(e=globalThis.process)?void 0:e.arch)??"";return"x64"===t?"amd64":"arm64"===t?"aarch64":t}function $d(){var e;const t=(null==(e=globalThis.process)?void 0:e.platform)??"";return"darwin"===t?"apple":"win32"===t?"windows":t}function Md(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}class Ld{constructor(e){Nd(),this.dbPath=e}connect(){const{DatabaseSync:e}=Id("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=Md(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 Vd=[{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"}],Hd="0.7.0";function Kd(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.calcPkgMetaObjId=i.calcPkgMetaObjId,exports.normalizePackageMetaForObjId=i.normalizePackageMetaForObjId,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=Rd,exports.IDENTITY_MATERIALS=Pp,exports.IDENTITY_USAGES=jp,exports.IdentityRoots=qp,exports.KERNEL_SERVICE_DOC_VERSION=Hd,exports.MetaIndexDb=Ld,exports.NODE_GATEWAY_PARAMS_FILE_NAME=c,exports.PROVISION_BASE_TIME=kd,exports.PROVISION_DEFAULT_EXP=xd,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 Sd(r,n,s,a),u=pd(r.rootDir,r.zoneDid,r.deviceDid),l=hd(r.rootDir,u),p=[],h={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,h);const d=()=>{try{t.rmSync(u.lockPath,{force:!0})}catch{}};let f;try{f=await wd(e)}catch(v){throw d(),v}const y=f.problems.filter((e=>"ACTIVATION_IN_PROGRESS"!==e.code));if(y.length>0)throw d(),bd({...f,problems:y});for(const i of l)if(qh(i.absolutePath))throw d(),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(v){d();const e=v.code;throw new Hh("EEXIST"===e?"OWNER_KEY_BACKUP_EXISTS":"OWNER_KEY_BACKUP_FAILED",`owner key backup could not be saved: ${v instanceof Error?v.message:String(v)}`,{owner_key_backup:{path:r.ownerKeyBackupPath,saved:!1},committed_files:[]})}h.stage="backup_saved";const g=[],m=(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:g,lock_file:u.lockPath,recovery:Ed(u.lockPath,r.ownerKeyBackupPath,g.map((e=>e.path)))})};try{yd(u.lockPath,h)}catch(v){m(v,"lock:backup_saved")}h.stage="committing";for(const i of l){const e=Ad(i,c,a,r.domain);try{ed(i.absolutePath,e,i.mode,i.dirMode)}catch(v){m(v,i.path)}g.push({...dd(i),sha256:i.secret?null:Wh(e)}),h.committed=g.map((e=>e.path));try{yd(u.lockPath,h)}catch(v){m(v,`lock:${i.path}`)}}h.stage="committed";try{yd(u.lockPath,h),t.rmSync(u.lockPath,{force:!0})}catch(v){p.push(`activation completed but the lock ${u.lockPath} could not be removed: ${v instanceof Error?v.message:String(v)}`)}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:g,warnings:p}},exports.assertProvisionRuntime=Nd,exports.bindDeviceDocumentDid=g,exports.buildActivationDnsRecords=ad,exports.buildDeviceDid=y,exports.buildDidDocs=function(e,t){Nd();const r=Id("node:path"),n=(null==t?void 0:t.version)??Hd,o=(null==t?void 0:t.now)??i.buckyosGetUnixTimestamp(),s=[];for(const i of Vd){const t=Kd(i.uniqueId),a=Cd({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`);Bd(c,a),s.push(c)}return s},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){Nd();const t=Id("node:path"),r=e.envDir,n=Od(t.join(r,"user_config.json")).name;if("string"!=typeof n||!n)throw new Error("user_config.json missing name field");const o=Od(t.join(r,"zone_config.json")),s=i.DID.fromStr(o.id),a=Dd(n,e.ownerKeyPair),c=jd(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);Td(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:kd});if(b(u,Pd(u),w,d,f,v,c.privateKeyPem),e.deviceName.startsWith("ood")){const e=Cd({admin_password_hash:sd(n,"bucky2025"),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"});Bd(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){Nd();const t=Id("node:path"),r=t.join(e.outputDir,"sn_server"),n=Ph("sn_owner"),o=Ph("sn_server"),s=xd;Td(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)});Bd(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",Bd(t.join(r,"sn_device_config.json"),i.deviceDocumentToOrderedJson(l)),Td(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=Cd({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"}});Bd(t.join(r,"params.json"),h),console.log("- Created params.json.");const d=new Rd(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){Nd();const t=Id("node:path"),r=e.rtcpPort??2980,n=e.outputDir,o=xd,s=Dd(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}`}Td(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});Bd(t.join(n,"user_config.json"),i.ownerDocumentToOrderedJson(p)),console.log(`Created owner config for ${e.username}`);const h=i.parseOODDescription(e.oodName),d=jd(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();Bd(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),Bd(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 Bd(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=Pd,exports.registerDeviceToSn=async function(e,t,r,n){Nd();const o=Id("node:path"),s=Id("node:fs"),a=Id("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(Pd(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=Od(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=Id("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:Ud(),os:$d(),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 Rd(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){Nd();const n=Id("node:path"),o=Od(n.join(e,t,"user_config.json")).name;if("string"!=typeof o||!o)throw new Error("user_config.json missing name field");const s=Od(n.join(e,t,"zone_config.json")),a=i.DID.fromStr(s.id);let c;"bns"!==a.method&&(c=a.toHostName());const u=Od(n.join(e,t,"zone_txt_record.json")),l=new Rd(r),p=JSON.stringify(Cd({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){Nd();const r=Id("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=i.calcPkgMetaObjId(o),a=new Ld(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=Kd,exports.validateAdminPassword=od,exports.validateOwnerName=rd,exports.validatePublicIp=nd,exports.validateRtcpPort=id,exports.validateZoneDomain=td,exports.versionToInt=Md;
|
|
91
|
+
const hu="crypto.algorithm";const du="crypto.algorithmProvider";var fu;lc.registerSingleton(du,class{getAlgorithms(){return lc.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 zn({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 yu="1.3.36.3.3.2.8.1.1",gu=`${yu}.1`,mu=`${yu}.2`,vu=`${yu}.3`,wu=`${yu}.4`,bu=`${yu}.5`,Su=`${yu}.6`,Au=`${yu}.7`,Eu=`${yu}.8`,ku=`${yu}.9`,xu=`${yu}.10`,_u=`${yu}.11`,Nu=`${yu}.12`,Iu=`${yu}.13`,Tu=`${yu}.14`,Bu="brainpoolP160r1",Ou="brainpoolP160t1",Cu="brainpoolP192r1",Du="brainpoolP192t1",ju="brainpoolP224r1",Pu="brainpoolP224t1",Ru="brainpoolP256r1",Uu="brainpoolP256t1",$u="brainpoolP320r1",Mu="brainpoolP320t1",Lu="brainpoolP384r1",Vu="brainpoolP384t1",Hu="brainpoolP512r1",Ku="brainpoolP512t1",Fu="ECDSA";let zu=fu=class{toAsnAlgorithm(e){if(e.name.toLowerCase()===Fu.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 Gs;case"sha-384":return Xs;case"sha-512":return Ys}}else if("namedCurve"in e){let t="";switch(e.namedCurve){case"P-256":t=Fs;break;case"K-256":t=fu.SECP256K1;break;case"P-384":t=zs;break;case"P-521":t=Ws;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;break;case Ku:t=Tu}if(t)return new zn({algorithm:$s,parameters:Fr.serialize(new ia({namedCurve:t}))})}return null}toWebAlgorithm(e){switch(e.algorithm){case Ms:return{name:Fu,hash:{name:"SHA-1"}};case Vs:return{name:Fu,hash:{name:"SHA-256"}};case Hs:return{name:Fu,hash:{name:"SHA-384"}};case Ks:return{name:Fu,hash:{name:"SHA-512"}};case $s:if(!e.parameters)throw new TypeError("Cannot get required parameters from EC algorithm");switch(Fr.parse(e.parameters,ia).namedCurve){case Fs:return{name:Fu,namedCurve:"P-256"};case fu.SECP256K1:return{name:Fu,namedCurve:"K-256"};case zs:return{name:Fu,namedCurve:"P-384"};case Ws:return{name:Fu,namedCurve:"P-521"};case gu:return{name:Fu,namedCurve:Bu};case mu:return{name:Fu,namedCurve:Ou};case vu:return{name:Fu,namedCurve:Cu};case wu:return{name:Fu,namedCurve:Du};case bu:return{name:Fu,namedCurve:ju};case Su:return{name:Fu,namedCurve:Pu};case Au:return{name:Fu,namedCurve:Ru};case Eu:return{name:Fu,namedCurve:Uu};case ku:return{name:Fu,namedCurve:$u};case xu:return{name:Fu,namedCurve:Mu};case _u:return{name:Fu,namedCurve:Lu};case Nu:return{name:Fu,namedCurve:Vu};case Iu:return{name:Fu,namedCurve:Hu};case Tu:return{name:Fu,namedCurve:Ku}}}return null}};zu.SECP256K1="1.3.132.0.10",zu=fu=zr([pc()],zu),lc.registerSingleton(hu,zu);const Wu=Symbol("name"),Ju=Symbol("value");class qu{constructor(e,t={},r=""){this[Wu]=e,this[Ju]=r;for(const i in t)this[i]=t[i]}}qu.NAME=Wu,qu.VALUE=Ju;class Gu{static toString(e){const t=this.items[e];return t||e}}Gu.items={[ba]:"sha1",[Sa]:"sha224",[Aa]:"sha256",[Ea]:"sha384",[ka]:"sha512",[aa]:"rsaEncryption",[da]:"sha1WithRSAEncryption",[fa]:"sha224WithRSAEncryption",[ya]:"sha256WithRSAEncryption",[ga]:"sha384WithRSAEncryption",[ma]:"sha512WithRSAEncryption",[$s]:"ecPublicKey",[Ms]:"ecdsaWithSHA1",[Ls]:"ecdsaWithSHA224",[Vs]:"ecdsaWithSHA256",[Hs]:"ecdsaWithSHA384",[Ks]:"ecdsaWithSHA512",[an]:"TLS WWW server authentication",[cn]:"TLS WWW client authentication",[un]:"Code Signing",[ln]:"E-mail Protection",[pn]:"Time Stamping",[hn]:"OCSP Signing",[js]:"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(x.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=x.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 Yu,Zu;Xu.oidSerializer=Gu,Xu.algorithmSerializer=class{static toTextObject(e){const t=new qu("Algorithm Identifier",{},Gu.toString(e.algorithm));if(e.parameters)switch(e.algorithm){case $s:{const r=(new zu).toWebAlgorithm(e);r&&"namedCurve"in r?t["Named Curve"]=r.namedCurve:t.Parameters=e.parameters;break}default:t.Parameters=e.parameters}return t}};class Qu{get rawData(){return Wr(this,Yu,"f")||Jr(this,Yu,Fr.serialize(this.asn),"f"),Wr(this,Yu,"f")}constructor(...e){Yu.set(this,void 0),x.isBufferSource(e[0])?(this.asn=Fr.parse(e[0],e[1]),Jr(this,Yu,x.toArrayBuffer(e[0]),"f"),this.onInit(this.asn)):(this.asn=e[0],this.onInit(this.asn))}equal(e){return e instanceof Qu&&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 Fr.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)}}Yu=new WeakMap,Qu.NAME="ASN";class el extends Qu{constructor(...e){let t;t=x.isBufferSource(e[0])?x.toArrayBuffer(e[0]):Fr.serialize(new Xn({extnID:e[0],critical:e[1],extnValue:new ar(x.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]===el.NAME&&(e[qu.NAME]=Gu.toString(this.type)),e}}class tl{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[Zu]="CryptoProvider","undefined"!=typeof self&&"undefined"!=typeof crypto?this.set(tl.DEFAULT,crypto):"undefined"!=typeof global&&global.crypto&&global.crypto.subtle&&this.set(tl.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=tl.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(tl.DEFAULT,e);return this}}Zu=Symbol.toStringTag,tl.DEFAULT="default";const rl=new tl,il=/^[0-2](?:\.[1-9][0-9]*)+$/;class nl{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(il).test(t)?e:this.get(e);var t}register(e,t){this.items[e]=t,this.items[t]=e}}const ol=new nl;function sl(e,t){return`\\${C.ToHex(C.FromUtf8String(t)).toUpperCase()}`}ol.register("CN","2.5.4.3"),ol.register("L","2.5.4.7"),ol.register("ST","2.5.4.8"),ol.register("O","2.5.4.10"),ol.register("OU","2.5.4.11"),ol.register("C","2.5.4.6"),ol.register("DC","0.9.2342.19200300.100.1.25"),ol.register("E","1.2.840.113549.1.9.1"),ol.register("G","2.5.4.42"),ol.register("I","2.5.4.43"),ol.register("SN","2.5.4.4"),ol.register("T","2.5.4.12");class al{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 nl,this.asn=new oi;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 oi?this.asn=e:x.isBufferSource(e)?this.asn=Fr.parse(e,oi):this.asn=this.fromJSON(e)}getField(e){const t=this.extraNames.findId(e)||ol.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)||ol.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])/,sl)}`)).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 oi,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 ii([a])),n=s}return t}fromJSON(e){const t=new oi;for(const r of e){const e=new ii;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 ri({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:al.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 Fr.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]||rl.get()):r=e[0]||rl.get(),await r.subtle.digest(i,this.toArrayBuffer())}}const cl="Cannot initialize GeneralName from ASN.1 data.",ul=`${cl} Unsupported string format in use.`,ll=`${cl} Value doesn't match to GUID regular expression.`,pl=/^([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",dl="1.3.6.1.4.1.311.20.2.3",fl="dns",yl="dn",gl="email",ml="ip",vl="url",wl="guid",bl="upn",Sl="id";class Al extends Qu{constructor(...e){let t;if(2===e.length)switch(e[0]){case yl:{const r=new al(e[1]).toArrayBuffer(),i=Fr.parse(r,oi);t=new ui({directoryName:i});break}case fl:t=new ui({dNSName:e[1]});break;case gl:t=new ui({rfc822Name:e[1]});break;case wl:{const r=new RegExp(pl,"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 ui({otherName:new ai({typeId:hl,value:Fr.serialize(new ar(C.FromHex(i)))})});break}case ml:t=new ui({iPAddress:e[1]});break;case Sl:t=new ui({registeredID:e[1]});break;case bl:t=new ui({otherName:new ai({typeId:dl,value:Fr.serialize(vr.toASN(e[1]))})});break;case vl:t=new ui({uniformResourceIdentifier:e[1]});break;default:throw new Error("Cannot create GeneralName. Unsupported type of the name")}else t=x.isBufferSource(e[0])?Fr.parse(e[0],ui):e[0];super(t)}onInit(e){if(null!=e.dNSName)this.type=fl,this.value=e.dNSName;else if(null!=e.rfc822Name)this.type=gl,this.value=e.rfc822Name;else if(null!=e.iPAddress)this.type=ml,this.value=e.iPAddress;else if(null!=e.uniformResourceIdentifier)this.type=vl,this.value=e.uniformResourceIdentifier;else if(null!=e.registeredID)this.type=Sl,this.value=e.registeredID;else if(null!=e.directoryName)this.type=yl,this.value=new al(e.directoryName).toString();else{if(null==e.otherName)throw new Error(ul);if(e.otherName.typeId===hl){this.type=wl;const t=Fr.parse(e.otherName.value,ar),r=new RegExp(pl,"i").exec(C.ToHex(t));if(!r)throw new Error(ll);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!==dl)throw new Error(ul);this.type=bl,this.value=Fr.parse(e.otherName.value,ei).toString()}}}toJSON(){return{type:this.type,value:this.value}}toTextObject(){let e;switch(this.type){case yl:case fl:case wl:case ml:case Sl:case bl:case vl:e=this.type.toUpperCase();break;case gl:e="Email";break;default:throw new Error("Unsupported GeneralName type")}let t=this.value;return this.type===Sl&&(t=Gu.toString(t)),new qu(e,void 0,t)}}class El extends Qu{constructor(e){let t;if(e instanceof Ii)t=e;else if(Array.isArray(e)){const r=[];for(const t of e)if(t instanceof ui)r.push(t);else{const e=Fr.parse(new Al(t.type,t.value).rawData,ui);r.push(e)}t=new Ii(r)}else{if(!x.isBufferSource(e))throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");t=Fr.parse(e,Ii)}super(t)}onInit(e){const t=[];for(const r of e){let e=null;try{e=new Al(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}}El.NAME="GeneralNames";const kl="-{5}",xl="\\n",_l="\\n",Nl=`${`${kl}BEGIN (${`[^${xl}]+`}(?=${kl}))${kl}`}${_l}(?:((?:${`[^:${xl}]+`}: ${`(?:[^${xl}]+${_l}(?: +[^${xl}]+${_l})*)`})+))?${_l}?(${`(?:[a-zA-Z0-9=+/]+${_l})+`})${`${kl}END \\1${kl}`}`;class Il{static isPem(e){return"string"==typeof e&&new RegExp(Nl,"g").test(e.replace(/\r/g,""))}static decodeWithHeaders(e){e=e.replace(/\r/g,"");const t=new RegExp(Nl,"g"),r=[];let i=null;for(;i=t.exec(e);){const e=i[3].replace(new RegExp(`[${xl}]+`,"g"),""),t={type:i[1],headers:[],rawData:C.FromBase64(e)},n=i[2];if(n){const e=n.split(new RegExp(_l,"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(!x.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:x.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:x.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")}}Il.CertificateTag="CERTIFICATE",Il.CrlTag="CRL",Il.CertificateRequestTag="CERTIFICATE REQUEST",Il.PublicKeyTag="PUBLIC KEY",Il.PrivateKeyTag="PRIVATE KEY";class Tl extends Qu{static isAsnEncoded(e){return x.isBufferSource(e)||"string"==typeof e}static toArrayBuffer(e){if("string"==typeof e){if(Il.isPem(e))return Il.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=x.toUint8Array(e);if(t.length>0&&48===t[0])return x.toArrayBuffer(e);const r=C.ToBinary(e);if(Il.isPem(r))return Il.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?Il.encode(this.rawData,this.tag):super.toString(e)}}class Bl extends Tl{static async create(e,t=rl.get()){if(e instanceof Bl)return e;if(tl.isCryptoKey(e)){if("public"!==e.type)throw new TypeError("Public key is required");const r=await t.subtle.exportKey("spki",e);return new Bl(r)}if(e.publicKey)return e.publicKey;if(x.isBufferSource(e))return new Bl(e);throw new TypeError("Unsupported PublicKeyType")}constructor(e){Tl.isAsnEncoded(e)?super(e,Wn):super(e),this.tag=Il.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]||rl.get()):t=e[0]||rl.get();let n=this.rawData;const o=Fr.parse(this.rawData,Wn);return o.algorithm.algorithm===la&&(n=function(e,t){return e.algorithm=new zn({algorithm:aa,parameters:null}),t=Fr.serialize(e),t}(o,n)),t.subtle.importKey("spki",n,i,!0,r)}onInit(e){const t=lc.resolve(du),r=this.algorithm=t.toWebAlgorithm(e.algorithm);switch(e.algorithm.algorithm){case aa:{const t=Fr.parse(e.subjectPublicKey,Ua),i=x.toUint8Array(t.modulus);r.publicExponent=x.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]||rl.get()):r=e[0]||rl.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=rl.get()):t=e[0]:2===e.length?(r=e[0],t=e[1]):t=rl.get();const i=Fr.parse(this.rawData,Wn);return await t.subtle.digest(r,i.subjectPublicKey)}toTextObject(){const e=this.toTextObjectEmpty(),t=Fr.parse(this.rawData,Wn);if(e.Algorithm=Xu.serializeAlgorithm(t.algorithm),t.algorithm.algorithm===$s)e["EC Point"]=t.subjectPublicKey;else e["Raw Data"]=t.subjectPublicKey;return e}}class Ol extends el{static async create(e,t=!1,r=rl.get()){if("name"in e&&"serialNumber"in e)return new Ol(e,t);const i=await Bl.create(e,r),n=await i.getKeyIdentifier(r);return new Ol(C.ToHex(n),t)}constructor(...e){if(x.isBufferSource(e[0]))super(e[0]);else if("string"==typeof e[0]){const t=new ki({keyIdentifier:new Ei(C.FromHex(e[0]))});super(Ai,e[1],Fr.serialize(t))}else{const t=e[0],r=t.name instanceof El?Fr.parse(t.name.rawData,Ii):t.name,i=new ki({authorityCertIssuer:r,authorityCertSerialNumber:C.FromHex(t.serialNumber)});super(Ai,e[1],Fr.serialize(i))}}onInit(e){super.onInit(e);const t=Fr.parse(e.extnValue,ki);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=Fr.parse(this.value,ki);return t.authorityCertIssuer&&(e["Authority Issuer"]=new El(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 el{constructor(...e){if(x.isBufferSource(e[0])){super(e[0]);const t=Fr.parse(this.value,_i);this.ca=t.cA,this.pathLength=t.pathLenConstraint}else{const t=new _i({cA:e[0],pathLenConstraint:e[1]});super(xi,e[2],Fr.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 Dl,jl,Pl;Cl.NAME="Basic Constraints",(jl=Dl||(Dl={})).serverAuth="1.3.6.1.5.5.7.3.1",jl.clientAuth="1.3.6.1.5.5.7.3.2",jl.codeSigning="1.3.6.1.5.5.7.3.3",jl.emailProtection="1.3.6.1.5.5.7.3.4",jl.timeStamping="1.3.6.1.5.5.7.3.8",jl.ocspSigning="1.3.6.1.5.5.7.3.9";class Rl extends el{constructor(...e){if(x.isBufferSource(e[0])){super(e[0]);const t=Fr.parse(this.value,sn);this.usages=t.map((e=>e))}else{const t=new sn(e[0]);super(on,e[1],Fr.serialize(t)),this.usages=e[0]}}toTextObject(){const e=this.toTextObjectWithoutValue();return e[""]=this.usages.map((e=>Gu.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"}(Pl||(Pl={}));class Ul extends el{constructor(...e){if(x.isBufferSource(e[0])){super(e[0]);const t=Fr.parse(this.value,An);this.usages=t.toNumber()}else{const t=new An(e[0]);super(vn,e[1],Fr.serialize(t)),this.usages=e[0]}}toTextObject(){const e=this.toTextObjectWithoutValue(),t=Fr.parse(this.value,An);return e[""]=t.toJSON().join(", "),e}}Ul.NAME="Key Usages";class $l extends el{static async create(e,t=!1,r=rl.get()){const i=await Bl.create(e,r),n=await i.getKeyIdentifier(r);return new $l(C.ToHex(n),t)}constructor(...e){if(x.isBufferSource(e[0])){super(e[0]);const t=Fr.parse(this.value,Un);this.keyId=C.ToHex(t)}else{const t="string"==typeof e[0]?C.FromHex(e[0]):e[0],r=new Un(t);super(Rn,e[1],Fr.serialize(r)),this.keyId=C.ToHex(t)}}toTextObject(){const e=this.toTextObjectWithoutValue(),t=Fr.parse(this.value,Un);return e[""]=t,e}}$l.NAME="Subject Key Identifier";class Ml extends el{constructor(...e){x.isBufferSource(e[0])?super(e[0]):super(On,e[1],new El(e[0]||[]).rawData)}onInit(e){super.onInit(e);const t=Fr.parse(e.extnValue,Cn);this.names=new El(t)}toTextObject(){const e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(const r in t)e[r]=t[r];return e}}Ml.NAME="Subject Alternative Name";class Ll{static register(e,t){this.items.set(e,t)}static create(e){const t=new el(e),r=this.items.get(t.type);return r?new r(e):t}}Ll.items=new Map;class Vl extends el{constructor(...e){var t;if(x.isBufferSource(e[0])){super(e[0]);const t=Fr.parse(this.value,Mi);this.policies=t.map((e=>e.policyIdentifier))}else{const r=e[0],i=null!==(t=e[1])&&void 0!==t&&t,n=new Mi(r.map((e=>new $i({policyIdentifier:e}))));super(Ci,i,Fr.serialize(n)),this.policies=r}}toTextObject(){const e=this.toTextObjectWithoutValue();return e.Policy=this.policies.map((e=>new qu("",{},Gu.toString(e)))),e}}Vl.NAME="Certificate Policies",Ll.register(Ci,Vl);class Hl extends el{constructor(...e){var t;if(x.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 Ji({fullName:[new ui({uniformResourceIdentifier:e})]})}))),r=new Gi(t);super(Ki,e[1],Fr.serialize(r))}else{const t=new Gi(e[0]);super(Ki,e[1],Fr.serialize(t))}null!==(t=this.distributionPoints)&&void 0!==t||(this.distributionPoints=[])}onInit(e){super.onInit(e);const t=Fr.parse(e.extnValue,Gi);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 Al(e).toString())).join(", ")),e.reasons&&(r.Reasons=e.reasons.toString()),e.cRLIssuer&&(r["CRL Issuer"]=e.cRLIssuer.map((e=>e.toString())).join(", ")),r})),e}}Hl.NAME="CRL Distribution Points";class Kl extends el{constructor(...e){var t,r,i,n;if(x.isBufferSource(e[0]))super(e[0]);else if(e[0]instanceof Si){const t=new Si(e[0]);super(wi,e[1],Fr.serialize(t))}else{const t=e[0],r=new Si;zl(r,t,di,"ocsp"),zl(r,t,fi,"caIssuers"),zl(r,t,yi,"timeStamping"),zl(r,t,gi,"caRepository"),super(wi,e[1],Fr.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=[];Fr.parse(e.extnValue,Si).forEach((e=>{switch(e.accessMethod){case di:this.ocsp.push(new Al(e.accessLocation));break;case fi:this.caIssuers.push(new Al(e.accessLocation));break;case yi:this.timeStamping.push(new Al(e.accessLocation));break;case gi:this.caRepository.push(new Al(e.accessLocation))}}))}toTextObject(){const e=this.toTextObjectWithoutValue();return this.ocsp.length&&Fl(e,"OCSP",this.ocsp),this.caIssuers.length&&Fl(e,"CA Issuers",this.caIssuers),this.timeStamping.length&&Fl(e,"Time Stamping",this.timeStamping),this.caRepository.length&&Fl(e,"CA Repository",this.caRepository),e}}function Fl(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 zl(e,t,r,i){const n=t[i];if(n){(Array.isArray(n)?n:[n]).forEach((t=>{"string"==typeof t&&(t=new Al("url",t)),e.push(new bi({accessMethod:r,accessLocation:Fr.parse(t.rawData,ui)}))}))}}Kl.NAME="Authority Info Access";class Wl extends el{constructor(...e){x.isBufferSource(e[0])?super(e[0]):super(gn,e[1],new El(e[0]||[]).rawData)}onInit(e){super.onInit(e);const t=Fr.parse(e.extnValue,Ii);this.names=new El(t)}toTextObject(){const e=this.toTextObjectWithoutValue(),t=this.names.toTextObject();for(const r in t)e[r]=t[r];return e}}Wl.NAME="Issuer Alternative Name";class Jl extends Qu{constructor(...e){let t;if(x.isBufferSource(e[0]))t=x.toArrayBuffer(e[0]);else{const r=e[0],i=Array.isArray(e[1])?e[1].map((e=>x.toArrayBuffer(e))):[];t=Fr.serialize(new Dn({type:r,values:i}))}super(t,Dn)}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]===Jl.NAME&&(e[qu.NAME]=Gu.toString(this.type)),e}}Jl.NAME="Attribute";class ql extends Jl{constructor(...e){var t;if(x.isBufferSource(e[0]))super(e[0]);else{const t=new ru({printableString:e[0]});super(Uc,[Fr.serialize(t)])}null!==(t=this.password)&&void 0!==t||(this.password="")}onInit(e){if(super.onInit(e),this.values[0]){const e=Fr.parse(this.values[0],ru);this.password=e.toString()}}toTextObject(){const e=this.toTextObjectWithoutValue();return e[qu.VALUE]=this.password,e}}ql.NAME="Challenge Password";class Gl extends Jl{constructor(...e){var t;if(x.isBufferSource(e[0]))super(e[0]);else{const t=e[0],r=new Yn;for(const e of t)r.push(Fr.parse(e.rawData,Xn));super($c,[Fr.serialize(r)])}null!==(t=this.items)&&void 0!==t||(this.items=[])}onInit(e){if(super.onInit(e),this.values[0]){const e=Fr.parse(this.values[0],Yn);this.items=e.map((e=>Ll.create(Fr.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}}Gl.NAME="Extensions";class Xl{static register(e,t){this.items.set(e,t)}static create(e){const t=new Jl(e),r=this.items.get(t.type);return r?new r(e):t}}Xl.items=new Map;const Yl="crypto.signatureFormatter";var Zl;let Ql=Zl=class{static createPssParams(e,t){const r=Zl.getHashAlgorithm(e);return r?new Oa({hashAlgorithm:r,maskGenAlgorithm:new zn({algorithm:xa,parameters:Fr.serialize(r)}),saltLength:t}):null}static getHashAlgorithm(e){const t=lc.resolve(du);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 zn({algorithm:aa,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 zn({algorithm:da,parameters:null});case"sha-256":return new zn({algorithm:ya,parameters:null});case"sha-384":return new zn({algorithm:ga,parameters:null});case"sha-512":return new zn({algorithm:ma,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=Zl.createPssParams(e.hash,e.saltLength);if(!t)throw new Error("Cannot create PSS parameters");return new zn({algorithm:la,parameters:Fr.serialize(t)})}return new zn({algorithm:la,parameters:null})}return null}toWebAlgorithm(e){switch(e.algorithm){case aa:return{name:"RSASSA-PKCS1-v1_5"};case da:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case ya:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case ga:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case ma:return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case la:if(e.parameters){const t=Fr.parse(e.parameters,Oa);return{name:"RSA-PSS",hash:lc.resolve(du).toWebAlgorithm(t.hashAlgorithm),saltLength:t.saltLength}}return{name:"RSA-PSS"}}return null}};Ql=Zl=zr([pc()],Ql),lc.registerSingleton(hu,Ql);let ep=class{toAsnAlgorithm(e){switch(e.name.toLowerCase()){case"sha-1":return new zn({algorithm:ba});case"sha-256":return new zn({algorithm:Aa});case"sha-384":return new zn({algorithm:Ea});case"sha-512":return new zn({algorithm:ka})}return null}toWebAlgorithm(e){switch(e.algorithm){case ba:return{name:"SHA-1"};case Aa:return{name:"SHA-256"};case Ea:return{name:"SHA-384"};case ka:return{name:"SHA-512"}}return null}};ep=zr([pc()],ep),lc.registerSingleton(hu,ep);class tp{addPadding(e,t){const r=x.toUint8Array(t),i=new Uint8Array(e);return i.set(r,e-r.length),i.buffer}removePadding(e,t=!1){let r=x.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=tp.namedCurveSize.get(r)||tp.defaultNamedCurveSize,n=new oa,o=x.toUint8Array(t);return n.r=this.removePadding(o.slice(0,i),!0),n.s=this.removePadding(o.slice(i,i+i),!0),Fr.serialize(n)}return null}toWebSignature(e,t){if("ECDSA"===e.name){const r=Fr.parse(t,oa),i=e.namedCurve,n=tp.namedCurveSize.get(i)||tp.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}}tp.namedCurveSize=new Map,tp.defaultNamedCurveSize=32;const rp="1.3.101.110",ip="1.3.101.111",np="1.3.101.112",op="1.3.101.113";let sp=class{toAsnAlgorithm(e){let t=null;switch(e.name.toLowerCase()){case"ed25519":t=np;break;case"x25519":t=rp;break;case"eddsa":switch(e.namedCurve.toLowerCase()){case"ed25519":t=np;break;case"ed448":t=op}break;case"ecdh-es":switch(e.namedCurve.toLowerCase()){case"x25519":t=rp;break;case"x448":t=ip}}return t?new zn({algorithm:t}):null}toWebAlgorithm(e){switch(e.algorithm){case np:return{name:"Ed25519"};case op:return{name:"EdDSA",namedCurve:"Ed448"};case rp:return{name:"X25519"};case ip:return{name:"ECDH-ES",namedCurve:"X448"}}return null}};var ap,cp,up,lp,pp,hp,dp,fp,yp,gp,mp,vp,wp,bp,Sp,Ap,Ep,kp,xp,_p,Np,Ip;sp=zr([pc()],sp),lc.registerSingleton(hu,sp);ap=new WeakMap,cp=new WeakMap,up=new WeakMap,lp=new WeakMap,pp=new WeakMap,hp=new WeakMap,dp=new WeakMap,fp=new WeakMap,class extends Tl{get subjectName(){return Wr(this,cp,"f")||Jr(this,cp,new al(this.asn.certificationRequestInfo.subject),"f"),Wr(this,cp,"f")}get subject(){return Wr(this,up,"f")||Jr(this,up,this.subjectName.toString(),"f"),Wr(this,up,"f")}get signatureAlgorithm(){if(!Wr(this,lp,"f")){const e=lc.resolve(du);Jr(this,lp,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return Wr(this,lp,"f")}get signature(){return Wr(this,pp,"f")||Jr(this,pp,this.asn.signature,"f"),Wr(this,pp,"f")}get publicKey(){return Wr(this,hp,"f")||Jr(this,hp,new Bl(this.asn.certificationRequestInfo.subjectPKInfo),"f"),Wr(this,hp,"f")}get attributes(){return Wr(this,dp,"f")||Jr(this,dp,this.asn.certificationRequestInfo.attributes.map((e=>Xl.create(Fr.serialize(e)))),"f"),Wr(this,dp,"f")}get extensions(){if(!Wr(this,fp,"f")){Jr(this,fp,[],"f");const e=this.getAttribute($c);e instanceof Gl&&Jr(this,fp,e.items,"f")}return Wr(this,fp,"f")}get tbs(){return Wr(this,ap,"f")||Jr(this,ap,this.asn.certificationRequestInfoRaw||Fr.serialize(this.asn.certificationRequestInfo),"f"),Wr(this,ap,"f")}constructor(e){const t=Tl.isAsnEncoded(e)?[e,pu]:[e];super(t[0],t[1]),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),fp.set(this,void 0),this.tag=Il.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=rl.get()){const t={...this.publicKey.algorithm,...this.signatureAlgorithm},r=await this.publicKey.export(t,["verify"],e),i=lc.resolveAll(Yl).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=Fr.parse(this.rawData,pu),r=t.certificationRequestInfo,i=new qu("",{Version:`${Zn[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 Tp extends Tl{get publicKey(){return Wr(this,_p,"f")||Jr(this,_p,new Bl(this.asn.tbsCertificate.subjectPublicKeyInfo),"f"),Wr(this,_p,"f")}get serialNumber(){if(!Wr(this,gp,"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)),Jr(this,gp,C.ToHex(t),"f")}return Wr(this,gp,"f")}get subjectName(){return Wr(this,mp,"f")||Jr(this,mp,new al(this.asn.tbsCertificate.subject),"f"),Wr(this,mp,"f")}get subject(){return Wr(this,vp,"f")||Jr(this,vp,this.subjectName.toString(),"f"),Wr(this,vp,"f")}get issuerName(){return Wr(this,wp,"f")||Jr(this,wp,new al(this.asn.tbsCertificate.issuer),"f"),Wr(this,wp,"f")}get issuer(){return Wr(this,bp,"f")||Jr(this,bp,this.issuerName.toString(),"f"),Wr(this,bp,"f")}get notBefore(){if(!Wr(this,Sp,"f")){const e=this.asn.tbsCertificate.validity.notBefore.utcTime||this.asn.tbsCertificate.validity.notBefore.generalTime;if(!e)throw new Error("Cannot get 'notBefore' value");Jr(this,Sp,e,"f")}return Wr(this,Sp,"f")}get notAfter(){if(!Wr(this,Ap,"f")){const e=this.asn.tbsCertificate.validity.notAfter.utcTime||this.asn.tbsCertificate.validity.notAfter.generalTime;if(!e)throw new Error("Cannot get 'notAfter' value");Jr(this,Ap,e,"f")}return Wr(this,Ap,"f")}get signatureAlgorithm(){if(!Wr(this,Ep,"f")){const e=lc.resolve(du);Jr(this,Ep,e.toWebAlgorithm(this.asn.signatureAlgorithm),"f")}return Wr(this,Ep,"f")}get signature(){return Wr(this,kp,"f")||Jr(this,kp,this.asn.signatureValue,"f"),Wr(this,kp,"f")}get extensions(){return Wr(this,xp,"f")||(Jr(this,xp,[],"f"),this.asn.tbsCertificate.extensions&&Jr(this,xp,this.asn.tbsCertificate.extensions.map((e=>Ll.create(Fr.serialize(e)))),"f")),Wr(this,xp,"f")}get tbs(){return Wr(this,yp,"f")||Jr(this,yp,this.asn.tbsCertificateRaw||Fr.serialize(this.asn.tbsCertificate),"f"),Wr(this,yp,"f")}constructor(e){const t=Tl.isAsnEncoded(e)?[e,to]:[e];super(t[0],t[1]),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),_p.set(this,void 0),this.tag=Il.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=rl.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 Bl)r={...n.algorithm,...this.signatureAlgorithm},i=await n.export(r,["verify"],t);else if(x.isBufferSource(n)){const e=new Bl(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=lc.resolveAll(Yl).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=rl.get()),await t.subtle.digest(r,this.rawData)}async isSelfSigned(e=rl.get()){return this.subject===this.issuer&&await this.verify({signatureOnly:!0},e)}toTextObject(){const e=this.toTextObjectEmpty(),t=Fr.parse(this.rawData,to),r=t.tbsCertificate,i=new qu("",{Version:`${Zn[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}}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,_p=new WeakMap,Tp.NAME="Certificate";class Bp{static async createSelfSigned(e,t=rl.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=rl.get()){var r;let i;i=e.publicKey instanceof Bl?e.publicKey.rawData:"publicKey"in e.publicKey?e.publicKey.publicKey.rawData:x.isBufferSource(e.publicKey)?e.publicKey:await t.subtle.exportKey("spki",e.publicKey);const n=function(e,t=rl.get()){const r=x.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 to({tbsCertificate:new eo({version:Zn.v3,serialNumber:n,validity:new qn({notBefore:o,notAfter:s}),extensions:new Yn((null===(r=e.extensions)||void 0===r?void 0:r.map((e=>Fr.parse(e.rawData,Xn))))||[]),subjectPublicKeyInfo:Fr.parse(i,Wn)})});if(e.subject){const t=e.subject instanceof al?e.subject:new al(e.subject);a.tbsCertificate.subject=Fr.parse(t.toArrayBuffer(),oi)}if(e.issuer){const t=e.issuer instanceof al?e.issuer:new al(e.issuer);a.tbsCertificate.issuer=Fr.parse(t.toArrayBuffer(),oi)}const c={hash:"SHA-256"},u="signingKey"in e?{...c,...e.signingAlgorithm,...e.signingKey.algorithm}:{...c,...e.signingAlgorithm},l=lc.resolve(du);a.tbsCertificate.signature=a.signatureAlgorithm=l.toAsnAlgorithm(u);const p=Fr.serialize(a.tbsCertificate),h="signingKey"in e?await t.subtle.sign(u,e.signingKey,p):e.signature,d=lc.resolveAll(Yl).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 Tp(Fr.serialize(a))}}function Op(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 Cp(){const e=globalThis.crypto;if(null==e?void 0:e.subtle)return e;return Op("node:crypto").webcrypto}(Ip=Np||(Np={}))[Ip.unspecified=0]="unspecified",Ip[Ip.keyCompromise=1]="keyCompromise",Ip[Ip.cACompromise=2]="cACompromise",Ip[Ip.affiliationChanged=3]="affiliationChanged",Ip[Ip.superseded=4]="superseded",Ip[Ip.cessationOfOperation=5]="cessationOfOperation",Ip[Ip.certificateHold=6]="certificateHold",Ip[Ip.removeFromCRL=8]="removeFromCRL",Ip[Ip.privilegeWithdrawn=9]="privilegeWithdrawn",Ip[Ip.aACompromise=10]="aACompromise",Ll.register(xi,Cl),Ll.register(on,Rl),Ll.register(vn,Ul),Ll.register(Rn,$l),Ll.register(Ai,Ol),Ll.register(On,Ml),Ll.register(Ki,Hl),Ll.register(wi,Kl),Ll.register(gn,Wl),Xl.register(Uc,ql),Xl.register($c,Gl),lc.registerSingleton(Yl,class{toAsnSignature(e,t){return x.toArrayBuffer(t)}toWebSignature(e,t){return x.toArrayBuffer(t)}}),lc.registerSingleton(Yl,tp),tp.namedCurveSize.set("P-256",32),tp.namedCurveSize.set("K-256",32),tp.namedCurveSize.set("P-384",48),tp.namedCurveSize.set("P-521",66);const Dp={name:"RSASSA-PKCS1-v1_5",hash:"SHA-256",publicExponent:new Uint8Array([1,0,1]),modulusLength:4096},jp={...Dp,modulusLength:2048},Pp=["server","client","authentication","assertion","key-agreement","capability"],Rp=["did-json","did-meta","cert","chain","fullchain","ca","public","csr","meta","private","keyref","verification-method"];function Up(){const e=new Uint8Array(16);return Cp().getRandomValues(e),e[0]&=127,e[0]|=1,Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join("")}function $p(e){return new Date(Date.now()+24*e*3600*1e3)}async function Mp(e){const t=new Uint8Array(await Cp().subtle.exportKey("pkcs8",e));return Il.encode(t,"PRIVATE KEY")}function Lp(e){return Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join("")}function Vp(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=Op("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 Hp(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 Kp(e){return Hp(e).toRawHostUri()}function Fp(e){return Vp(Kp(e))}function zp(e){const t=Hp(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 Wp(e,t){switch(function(e){if(!Pp.includes(e))throw new Error(`Unsupported identity usage: ${e}`)}(e),function(e){if(!Rp.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 Jp(e){if("string"!=typeof e)return null;const t=e.trim();return t.length>0?t:null}function qp(e,t,r){const i=Op("node:path");return{cert:i.join(e,Wp(r,"cert")),chain:i.join(e,Wp(r,"chain")),fullchain:i.join(e,Wp(r,"fullchain")),ca:i.join(e,Wp(r,"ca")),metadata:i.join(e,Wp(r,"meta")),keyref:i.join(t,Wp(r,"keyref")),privateKey:i.join(t,Wp(r,"private"))}}class Gp{constructor(e,t){const r=Op("node:path");this.publicRoot=r.resolve(e),this.securityRoot=r.resolve(t)}static fromEnvOrBuckyosRoot(e={}){const t=Op("node:path"),r=function(){const e=globalThis.process;return(null==e?void 0:e.env)??{}}(),i=Jp(e.buckyosRoot)??Jp(r.BUCKYOS_ROOT)??"/opt/buckyos",n=Jp(e.publicRoot)??Jp(r.BUCKYOS_IDENTITY_ROOT)??t.join(i,"local","identity"),o=Jp(e.securityRoot)??Jp(r.BUCKYOS_SECURITY_ROOT)??t.join(i,"security");return new Gp(n,o)}rawHostUri(e){return Kp(e)}dirName(e){return Fp(e)}publicDir(e){return Op("node:path").join(this.publicRoot,this.dirName(e))}securityDir(e){return Op("node:path").join(this.securityRoot,this.dirName(e))}publicFile(e,t,r){return Op("node:path").join(this.publicDir(e),Wp(t,r))}securityFile(e,t,r){return Op("node:path").join(this.securityDir(e),Wp(t,r))}x509Paths(e,t="server"){return qp(this.publicDir(e),this.securityDir(e),t)}identityDirMatch(e){const t=this.rawHostUri(e),r=Vp(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=Op("node:fs"),i=this.identityDirMatch(e),n=qp(i.publicDir,i.securityDir,t);if(r.existsSync(n.fullchain)||r.existsSync(n.cert))return{match:i,paths:n};const o=Hp(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=Vp(a),u=Op("node:path"),l=u.join(this.publicRoot,c),p=u.join(this.securityRoot,c),h=qp(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 Xp(e){const t=Cp();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=Yp(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),Yp(48,n)}(new Uint8Array(Il.decode(e)[0]));return t.subtle.importKey("pkcs8",r,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["sign"])}const r=new Uint8Array(Il.decode(e)[0]);return t.subtle.importKey("pkcs8",r,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["sign"])}function Yp(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 Zp(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 Ul));return!r||r.usages&Pl.keyCertSign?void 0:"keyUsage does not allow certificate signing"}async function Qp(e,t="devtest"){const r=Op("node:fs"),i=Op("node:path"),n=Cp();rl.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(Dp,!0,["sign","verify"]),u=await Bp.createSelfSigned({serialNumber:Up(),name:a,notBefore:new Date,notAfter:$p(3650),signingAlgorithm:{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},keys:c,extensions:[new Cl(!0,void 0,!0),new Ul(Pl.keyCertSign|Pl.cRLSign|Pl.digitalSignature,!0),await $l.create(c.publicKey)]});return r.writeFileSync(o,await Mp(c.privateKey)),r.writeFileSync(s,u.toString("pem")),console.log(`CA certificate created: ${s}`),{caCertPath:s,caKeyPath:o}}async function eh(e,t,r=[],i="server"){const n=Op("node:fs"),o=Cp();rl.set(o);const{caCertPath:s,caKeyPath:a}=function(e){const t=Op("node:fs"),r=Op("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 Tp(c),l=Zp(u);if(l)throw new Error(`Invalid CA certificate at ${s}: ${l}`);const p=await Xp(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(jp,!0,["sign","verify"]),f=new Uint8Array(await o.subtle.exportKey("spki",d.publicKey)),y=await async function(e){const t=await Cp().subtle.digest("SHA-256",e);return`sha256:${Lp(new Uint8Array(t))}`}(f),g=[...t.map((e=>({type:"dns",value:e}))),...r.map((e=>({type:"url",value:e})))],m=await Bp.create({serialNumber:Up(),subject:`CN=${h}`,issuer:u.subjectName,notBefore:new Date,notAfter:$p(365),signingAlgorithm:{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},publicKey:d.publicKey,signingKey:p,extensions:[new Ul(Pl.digitalSignature|Pl.keyEncipherment,!0),new Rl(["client"===i?Dl.clientAuth:Dl.serverAuth]),new Ml(g),await $l.create(d.publicKey),await Ol.create(u)]});return{cert:m,certPem:m.toString("pem"),privateKeyPem:await Mp(d.privateKey),caCertPem:c,publicKeyFingerprint:y}}function th(e){return`${e.trimEnd()}\n`}function rh(e,t,r){const i=Op("node:fs"),n=Op("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 ih(e){const t=e.toRawHostName();return t.startsWith("_.")?`*.${t.slice(2)}`:t}function nh(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:zp(t)}}async function oh(e,t,r,i,n){const o=function(e){const t=e.extensions.find((e=>e instanceof Ml)),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",Cp());return`sha256:${Lp(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:Wp(t,"cert"),chain:Wp(t,"chain"),fullchain:Wp(t,"fullchain"),ca:Wp(t,"ca")},did_binding:nh(e),updated_at:c,generation:`${c.replace(/[-:.]/g,"")}-${s}`}}const sh="test test test test test test test test test test test junk",ah=2147483648,ch=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),uh=(1n<<64n)-1n,lh=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n],ph=[[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 hh(e,t=""){return o.pbkdf2Sync(n.Buffer.from(e.normalize("NFKD"),"utf8"),n.Buffer.from(`mnemonic${t}`.normalize("NFKD"),"utf8"),2048,64,"sha512")}function dh(e,t){return o.createHmac("sha512",e).update(t).digest()}function fh(e){const t=n.Buffer.alloc(4);return t.writeUInt32BE(e>>>0,0),t}function yh(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 gh(e,t,r){const i=dh(t,n.Buffer.concat([n.Buffer.from([0]),e,fh(r+ah)]));return{key:i.subarray(0,32),chainCode:i.subarray(32)}}function mh(e,t,r){let i=function(e){const t=dh("ed25519 seed",e);return{key:t.subarray(0,32),chainCode:t.subarray(32)}}(hh(e,t));for(const n of[9777,0,r])i=gh(i.key,i.chainCode,n);return n.Buffer.from(i.key)}function vh(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`}(mh(e,t??"",r));return{privateKeyPem:i,publicKeyX:yh(i)}}function wh(e){return vh(sh,void 0,e)}function bh(e){const t=e.toString(16).padStart(64,"0");return n.Buffer.from(t,"hex")}function Sh(e){return BigInt(`0x${e.toString("hex")}`)}function Ah(e,t){const r=o.createECDH("secp256k1");return r.setPrivateKey(e),r.getPublicKey(void 0,t?"compressed":"uncompressed")}function Eh(e,t,r){const i=dh(t,r>=ah?n.Buffer.concat([n.Buffer.from([0]),e,fh(r)]):n.Buffer.concat([Ah(e,!0),fh(r)])),o=Sh(i.subarray(0,32));if(o>=ch)throw new Error(`invalid secp256k1 child tweak at index ${r}`);const s=(o+Sh(e))%ch;if(0n===s)throw new Error(`invalid secp256k1 child key at index ${r}`);return{privateKey:bh(s),chainCode:i.subarray(32)}}function kh(e){return`m/44'/60'/0'/0/${e}`}function xh(e,t){if(0===t)return e&uh;const r=BigInt(t);return(e<<r|e>>64n-r)&uh}function _h(e){for(const t of lh){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]^xh(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])&uh;for(let t=0;t<5;t+=1)for(let r=0;r<5;r+=1)n[r+(2*t+3*r)%5*5]=xh(e[t+5*r],ph[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]&uh&n[(t+2)%5+5*r])&uh;e[0]=(e[0]^t)&uh}}function Nh(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);_h(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 Ih(e){const t=e.toString("hex"),r=Nh(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 Th(e,t,r){let i=function(e){const t=dh("Bitcoin seed",e),r=t.subarray(0,32),i=Sh(r);if(i<=0n||i>=ch)throw new Error("invalid secp256k1 master key");return{privateKey:n.Buffer.from(r),chainCode:t.subarray(32)}}(hh(e,t??""));for(const n of function(e){return[2147483692,2147483708,ah,0,e]}(r))i=Eh(i.privateKey,i.chainCode,n);const o=Ah(i.privateKey,!1),s=Ah(i.privateKey,!0),a=Nh(o.subarray(1)),c=i.privateKey.toString("hex");return{derivationPath:kh(r),privateKey:`0x${c}`,privateKeyHex:c,publicKeyCompressedHex:s.toString("hex"),publicKeyUncompressedHex:o.toString("hex"),address:Ih(a.subarray(12))}}function Bh(e){return Th(sh,void 0,e)}const Oh={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},Ch={alice:1,bob:2,charlie:3,dave:4},Dh=Object.fromEntries(Object.entries(Oh).map((([e,t])=>[e,wh(t)]))),jh=Object.fromEntries(Object.entries(Ch).map((([e,t])=>[e,Bh(t)]))),Ph=Bh(0);function Rh(e){const t=Dh[e];if(!t)throw new Error(`unknown dev test key pair id: ${e}`);return t}const Uh="ood1",$h="wan",Mh=i.DEFAULT_EXPIRE_TIME,Lh="provision_activation.lock",Vh="zone_dns_records.json",Hh="zone_document.jwt";class Kh extends Error{constructor(e,t,r={}){super(t),this.name="ActivationError",this.code=e,this.details=r}}function Fh(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 Kh("RUNTIME_UNSUPPORTED",`buckyos provision cannot load builtin module ${e} in this runtime (Node >= 22.13 or Deno >= 2.2 is required)`)}function zh(){var e;return"win32"===(null==(e=globalThis.process)?void 0:e.platform)}function Wh(e,t){const r=Fh("node:path");return r.relative(e,t).split(r.sep).join("/")}function Jh(e){return Fh("node:crypto").createHash("sha256").update(e,"utf8").digest("hex")}function qh(){return Fh("node:crypto").randomBytes(6).toString("hex")}function Gh(e){const t=Fh("node:fs");try{return t.lstatSync(e)}catch(r){const e=r.code;if("ENOENT"===e||"ENOTDIR"===e)return null;throw r}}function Xh(e){const t=Fh("node:fs");try{return t.statSync(e)}catch(r){if("ENOENT"===r.code||"ENOTDIR"===r.code)return null;throw r}}function Yh(e){var t;return!0===(null==(t=Xh(e))?void 0:t.isDirectory())}function Zh(e){var t;return!0===(null==(t=Xh(e))?void 0:t.isFile())}function Qh(e){const t=Fh("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 ed(e){return JSON.stringify(e,null,2)}function td(e,t,r,i){const n=Fh("node:fs"),o=Fh("node:path"),s=o.dirname(e);if(n.mkdirSync(s,{recursive:!0,mode:i}),zh()||n.chmodSync(s,i),Gh(e))throw new Error(`refusing to overwrite existing file: ${e}`);const a=o.join(s,`.${o.basename(e)}.provision-${qh()}`);try{n.writeFileSync(a,t,{mode:r,flag:"wx"}),zh()||n.chmodSync(a,r),n.renameSync(a,e)}finally{Gh(a)&&n.rmSync(a,{force:!0})}}function rd(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 Kh("INVALID_ARGUMENT",`invalid did:web domain: ${e}`,{field:"domain"});return t}function id(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 Kh("INVALID_ARGUMENT","owner name must be a lowercase DNS label (letters, digits, and hyphens)",{field:"owner_name"});return t}function nd(e){const t=e??2980;if(!Number.isInteger(t)||t<1||t>65535)throw new Kh("INVALID_ARGUMENT",`invalid RTCP port: ${String(e)}`,{field:"rtcp_port"});return t}function od(e){const t=(null==e?void 0:e.trim())||void 0;if(void 0===t)return;if(0===Fh("node:net").isIP(t))throw new Kh("INVALID_ARGUMENT",`invalid public IP address: ${t}`,{field:"public_ip"});return t}function sd(e){if("string"!=typeof e||e.length<8)throw new Kh("INVALID_ARGUMENT","administrator password must contain at least 8 characters",{field:"admin_password"});return e}function ad(e,t){return s.hashPassword(e,t,null)}function cd(e,t){const r=[];if(t){const i=Fh("node:net");r.push({type:6===i.isIP(t)?"AAAA":"A",name:e,value:t})}return r}function ud(){const e=Fh("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 Kh("KEY_GENERATION_FAILED","generated Ed25519 public key has no x coordinate");return{privateKeyPem:t.export({format:"pem",type:"pkcs8"}).toString(),publicKeyX:i.x}}function ld(e){const t=Fh("node:path");if("string"!=typeof e.rootDir||0===e.rootDir.trim().length)throw new Kh("INVALID_ARGUMENT","target root is required",{field:"root"});if("string"!=typeof e.ownerKeyBackupPath||0===e.ownerKeyBackupPath.trim().length)throw new Kh("INVALID_ARGUMENT","owner key backup path is required",{field:"owner_key_backup"});const r=rd(e.domain),n=new i.DID("web",r);return{rootDir:t.resolve(e.rootDir),domain:r,ownerName:id(e.ownerName),ownerKeyBackupPath:t.resolve(e.ownerKeyBackupPath),rtcpPort:nd(e.rtcpPort),guestAccess:e.guestAccess??!1,publicIp:od(e.publicIp),ownerDid:n,zoneDid:n,deviceDid:g(Uh,n)}}function pd(e){const t=Fh("node:path");return new Gp(t.join(e,"local","identity"),t.join(e,"security"))}function hd(e,t,r){const i=Fh("node:path"),n=i.join(e,"etc"),o=y(pd(e),r);return{etcDir:n,lockPath:i.join(n,Lh),nodeIdentityPath:i.join(n,"node_identity.json"),startConfigPath:i.join(e,"security","start_config.json"),zoneDocumentJwtPath:i.join(n,Hh),gatewayParamsPath:i.join(n,"node_gateway_params.json"),dnsRecordsPath:i.join(n,Vh),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 dd(e,t){const r=(t,r,i,n)=>({path:Wh(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,!0),r(t.gatewayParamsPath,"gateway_params",!0,!1),r(t.nodeIdentityPath,"node_identity",!0,!1)]}function fd(e){return{path:e.path,role:e.role,required:e.required,secret:e.secret}}function yd(e){if(!Gh(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=Qh(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 gd(e,t){const r=Fh("node:fs"),i=Fh("node:path"),n=i.join(i.dirname(e),`.${Lh}.${qh()}`);try{r.writeFileSync(n,ed(t),{mode:384,flag:"wx"}),r.renameSync(n,e)}finally{Gh(n)&&r.rmSync(n,{force:!0})}}function md(e){const t=Fh("node:fs");return Yh(e)?t.readdirSync(e,{withFileTypes:!0}).filter((e=>e.isDirectory())).map((e=>e.name)).sort():[]}function vd(e){try{return i.getXFromJwk(e)}catch{return null}}async function wd(e){const t=Fh("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(!Yh(r))return o.push({code:"ROOT_MISSING",message:`BUCKYOS_ROOT does not exist: ${r}`}),a("not_installed");const c=["bin","etc"].filter((e=>!Yh(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=yd(t.join(u,Lh)),p=function(e,t){if(!Zh(e))return{nodeIdentity:null,zoneDid:null,deviceDid:null};try{const r=Qh(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 f=md(t.join(r,"local","identity")),m=md(t.join(r,"security")),v=function(e,t){const r=Fh("node:fs");return Yh(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=g(Uh,h));const w=[...f,...m].filter((e=>!d||e!==t.basename(y(pd(r),d).publicDir))),b=[];let S=null;if(h&&d){S=hd(r,h,d);for(const e of dd(r,S))b.push({...fd(e),present:Zh(e.absolutePath)})}else{for(const[e,r,i]of[["node_identity.json","node_identity",!0],[Hh,"zone_document_jwt",!0],["node_gateway_params.json","gateway_params",!0],[Vh,"dns_records",!1]])b.push({path:`etc/${e}`,role:r,required:i,secret:!1,present:Zh(t.join(u,e))});b.push({path:"security/start_config.json",role:"start_config",required:!0,secret:!0,present:Zh(t.join(r,"security","start_config.json"))});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=Qh(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?Uh: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=Fh("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 y=g(String(u.device_name),p).toString();if(h.toString()!==y&&l("DEVICE_DID_MISMATCH",`device DID ${h.toString()} is not ${y}`),!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=Qh(t.startConfigPath)}catch(O){l("START_CONFIG_UNREADABLE",`security/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",`security/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",`security/start_config.json is missing ${t}`);m.zone_name!==p.toString()&&l("START_CONFIG_ZONE",`security/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",`security/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&&vd(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","security/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","security/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",`security/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,Wh(e,t.deviceDocJwtPath)))?void 0:s.trim())??null,E=(null==(a=b(t.deviceMiniDocJwtPath,Wh(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=Qh(t.zoneBootOverridePath);JSON.stringify(r)!==JSON.stringify(x)&&l("BOOT_OVERRIDE_MISMATCH",`${Wh(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?vd(r.publicKeyJwk):null,B||l("DEVICE_DOCUMENT","device document has no #main_key");try{Qh(t.didJsonPath).id!==h.toString()&&l("DEVICE_DID_JSON",`${Wh(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(!zh()){const e=Gh(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 bd(e){const t=ld(e),r=await wd(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=Fh("node:path").dirname(e),i=Yh(r),n=null!==Gh(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=hd(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:Uh,accessHostname:t.domain,rtcpPort:t.rtcpPort,guestAccess:t.guestAccess,publicIp:t.publicIp??null,dnsRecords:cd(t.domain,t.publicIp),ownerKeyBackup:o,plannedFiles:dd(t.rootDir,s).map(fd),problems:i,status:r}}function Sd(e){const t=e.problems[0];return new Kh(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})}async function Ad(e,t,r,n){const o=i.buckyosGetUnixTimestamp(),s=o+Mh,a=i.createJwkByX(r.publicKeyX),c=i.createJwkByX(n.publicKeyX),u=e.ownerDid.toString(),l=e.zoneDid.toString(),p=e.deviceDid.toString(),h=i.newOwnerDocument({did:e.ownerDid,name:e.ownerName,displayName:e.ownerName,publicKeyJwk:a,now:o});h.exp=s,i.ownerDocumentSetDefaultZoneDid(h,e.zoneDid);const f=i.ownerDocumentToOrderedJson(h),y=i.oodDescriptionToString(i.parseOODDescription(`${Uh}@${$h}`)),g=await i.encodeZoneBootDocument(i.newZoneBootDocument({id:e.zoneDid,oods:[y],exp:s}),r.privateKeyPem),m=i.decodeJwtClaimWithoutVerify(g),w=v(Uh,c,e.deviceDid,o);!function(e){var t;const r=Fh("node:fs"),i=Fh("node:path").join(e,"etc","product.json");return!r.existsSync(i)||!1!==(null==(t=JSON.parse(r.readFileSync(i,"utf8")).capabilities)?void 0:t.container)}(e.rootDir)?w.support_container=!1:delete w.support_container,w.owner=u,w.zone_did=l,w.net_id=$h,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={[Uh]:b},k.mini_device_jwts={[Uh]: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 Kh("ZONE_DOCUMENT_TOO_LARGE","zone document JWT exceeds the 4096 byte inline limit");return{documentIat:o,documentExp:s,ownerDocument:f,bootDocument:m,bootJwt:g,deviceDocument:b,deviceDocJwt:S,deviceMiniDocJwt:E,zoneDocumentJwt:x,nodeIdentity:d({zoneDid:e.zoneDid,ownerDid:e.ownerDid,ownerPublicKey:a,deviceName:Uh,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:ad(e.ownerName,t),guest_access:e.guestAccess,friend_passcode:"",enabled_features:{},ai_provider_config:{},owner_telegram_account_id:""},gatewayParams:{params:{device_did:p,rtcp_port:String(e.rtcpPort)}},dnsRecords:cd(e.domain,e.publicIp)}}function Ed(e,t,r,i){switch(e.role){case"device_private_key":return r.privateKeyPem;case"device_document":return ed(t.deviceDocument);case"device_document_jwt":return t.deviceDocJwt;case"device_mini_document_jwt":return t.deviceMiniDocJwt;case"zone_boot_override":return ed(t.bootDocument);case"zone_document_jwt":return t.zoneDocumentJwt;case"dns_records":return ed({hostname:i,records:t.dnsRecords});case"start_config":return ed(t.startConfig);case"gateway_params":return ed(t.gatewayParams);case"node_identity":return ed(t.nodeIdentity)}}function kd(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 xd=1743478939,_d=2058838939;function Nd(e){const t=e.split(".");return[Number(t[0])||0,Number(t[1])||0]}function Id(){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]=Nd(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]=Nd(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 Td(e){Id();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 Bd(e,t){const r=Td("node:fs"),i=Td("node:path");r.mkdirSync(i.dirname(e),{recursive:!0}),r.writeFileSync(e,t),console.log(`# Write file: ${e}`)}function Od(e,t){Bd(e,JSON.stringify(t,null,2))}function Cd(e){const t=Td("node:fs");return JSON.parse(t.readFileSync(e,"utf8"))}function Dd(e){if(Array.isArray(e))return e.map(Dd);if(null!==e&&"object"==typeof e){const t={};for(const r of Object.keys(e).sort())t[r]=Dd(e[r]);return t}return e}function jd(e,t){return t||(Dh[e]?Dh[e]:Dh[`${e}.owner`]?Dh[`${e}.owner`]:(console.log(`Warning: Key pair for user ${e} not found, using devtest key pair`),Rh("devtest")))}function Pd(e,t,r){return r||Rh(`${e}.${t}`)}function Rd(e){const t=Td("node:path");return new Gp(t.join(e,"local","identity"),t.join(e,"security"))}class Ud{constructor(e){Id(),this.dbPath=e}connect(){const{DatabaseSync:e}=Td("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 $d(){var e;const t=(null==(e=globalThis.process)?void 0:e.arch)??"";return"x64"===t?"amd64":"arm64"===t?"aarch64":t}function Md(){var e;const t=(null==(e=globalThis.process)?void 0:e.platform)??"";return"darwin"===t?"apple":"win32"===t?"windows":t}function Ld(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}class Vd{constructor(e){Id(),this.dbPath=e}connect(){const{DatabaseSync:e}=Td("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=Ld(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.calcPkgMetaObjId=i.calcPkgMetaObjId,exports.normalizePackageMetaForObjId=i.normalizePackageMetaForObjId,exports.ACTIVATION_DEFAULT_RTCP_PORT=2980,exports.ACTIVATION_DEVICE_NAME=Uh,exports.ACTIVATION_DOCUMENT_VALIDITY_SECONDS=Mh,exports.ACTIVATION_LOCK_FILE_NAME=Lh,exports.ACTIVATION_MIN_PASSWORD_LENGTH=8,exports.ACTIVATION_NET_ID=$h,exports.ActivationError=Kh,exports.DEVICE_DOC_JWT_FILE_NAME=a,exports.DEVICE_MINI_DOC_JWT_FILE_NAME=c,exports.DEV_TEST_EVM_ACCOUNTS=jh,exports.DEV_TEST_EVM_SEED_SENDER=Ph,exports.DEV_TEST_EVM_SEED_SENDER_INDEX=0,exports.DEV_TEST_EVM_USER_INDEXES=Ch,exports.DEV_TEST_KEYS=Dh,exports.DEV_TEST_KEY_INDEXES=Oh,exports.DEV_TEST_MNEMONIC=sh,exports.DevSnDb=Ud,exports.IDENTITY_MATERIALS=Rp,exports.IDENTITY_USAGES=Pp,exports.IdentityRoots=Gp,exports.KERNEL_SERVICE_DOC_VERSION=Kd,exports.MetaIndexDb=Vd,exports.NODE_GATEWAY_PARAMS_FILE_NAME=u,exports.PROVISION_BASE_TIME=xd,exports.PROVISION_DEFAULT_EXP=_d,exports.ZONE_DNS_RECORDS_FILE_NAME=Vh,exports.ZONE_DOCUMENT_JWT_FILE_NAME=Hh,exports.activateOfflineZone=async function(e){const t=Fh("node:fs"),r=ld(e),n=sd(e.adminPassword),o=await bd(e);if(!o.ready)throw Sd(o);const s=e.ownerKeyPair??ud(),a=e.deviceKeyPair??ud(),c=await Ad(r,n,s,a),u=hd(r.rootDir,r.zoneDid,r.deviceDid),l=dd(r.rootDir,u),p=[],h={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=Fh("node:fs");try{r.writeFileSync(e,ed(t),{mode:384,flag:"wx"})}catch(i){if("EEXIST"===i.code)throw new Kh("ACTIVATION_IN_PROGRESS",`another activation holds the lock ${e}; inspect it with provision status`,{lock_file:e,lock:yd(e)});throw i}}(u.lockPath,h);const d=()=>{try{t.rmSync(u.lockPath,{force:!0})}catch{}};let f;try{f=await bd(e)}catch(v){throw d(),v}const y=f.problems.filter((e=>"ACTIVATION_IN_PROGRESS"!==e.code));if(y.length>0)throw d(),Sd({...f,problems:y});for(const i of l)if(Gh(i.absolutePath))throw d(),new Kh("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=Fh("node:fs");r.writeFileSync(e,t,{mode:384,flag:"wx"}),zh()||r.chmodSync(e,384)}(r.ownerKeyBackupPath,s.privateKeyPem)}catch(v){d();const e=v.code;throw new Kh("EEXIST"===e?"OWNER_KEY_BACKUP_EXISTS":"OWNER_KEY_BACKUP_FAILED",`owner key backup could not be saved: ${v instanceof Error?v.message:String(v)}`,{owner_key_backup:{path:r.ownerKeyBackupPath,saved:!1},committed_files:[]})}h.stage="backup_saved";const g=[],m=(e,t)=>{throw new Kh("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:g,lock_file:u.lockPath,recovery:kd(u.lockPath,r.ownerKeyBackupPath,g.map((e=>e.path)))})};try{gd(u.lockPath,h)}catch(v){m(v,"lock:backup_saved")}h.stage="committing";for(const i of l){const e=Ed(i,c,a,r.domain);try{td(i.absolutePath,e,i.mode,i.dirMode)}catch(v){m(v,i.path)}g.push({...fd(i),sha256:i.secret?null:Jh(e)}),h.committed=g.map((e=>e.path));try{gd(u.lockPath,h)}catch(v){m(v,`lock:${i.path}`)}}h.stage="committed";try{gd(u.lockPath,h),t.rmSync(u.lockPath,{force:!0})}catch(v){p.push(`activation completed but the lock ${u.lockPath} could not be removed: ${v instanceof Error?v.message:String(v)}`)}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:Uh,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:g,warnings:p}},exports.assertProvisionRuntime=Id,exports.bindDeviceDocumentDid=m,exports.buildActivationDnsRecords=cd,exports.buildDeviceDid=g,exports.buildDidDocs=function(e,t){Id();const r=Td("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=Dd({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`);Od(c,a),s.push(c)}return s},exports.checkOfflineActivation=bd,exports.createCa=Qp,exports.createCertFromCa=async function(e,t,r,i){const n=Op("node:fs"),o=Op("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 eh(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=Op("node:fs"),o=function(e){return e instanceof Gp?e:Gp.fromEnvOrBuckyosRoot(e)}(r),s=i.usage??"server",a=Hp(t),c=a.toRawHostUri(),u=Vp(c),l=o.publicDir(a.toString()),p=o.securityDir(a.toString()),h=qp(l,p,s),d=i.hostnames&&i.hostnames.length>0?i.hostnames:[ih(a)],f=i.uriSans??[a.toString()];n.mkdirSync(l,{recursive:!0,mode:493}),n.mkdirSync(p,{recursive:!0,mode:448});const y=await eh(e,d,f,s),g=th(y.certPem),m=th(y.caCertPem),v=m,w=`${g}${v}`;var b,S,A;return rh(h.privateKey,y.privateKeyPem,384),rh(h.cert,g,420),rh(h.chain,v,420),rh(h.fullchain,w,420),rh(h.ca,m,420),b=h.metadata,S=await oh(a,s,c,u,y),A=420,rh(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){Id();const t=Td("node:path"),r=e.envDir,n=Cd(t.join(r,"user_config.json")).name;if("string"!=typeof n||!n)throw new Error("user_config.json missing name field");const o=Cd(t.join(r,"zone_config.json")),s=i.DID.fromStr(o.id),a=jd(n,e.ownerKeyPair),c=Pd(n,e.deviceName,e.deviceKeyPair),u=t.join(r,e.deviceName),l=new i.DID("bns",n),p=g(e.deviceName,s),h=v(e.deviceName,i.createJwkByX(c.publicKeyX),p,e.now);h.support_container=!0,delete h.support_container,void 0!==e.netId&&(h.net_id=e.netId),h.owner=l.toString(),h.zone_did=s.toString(),console.log(`input net_id: ${e.netId}, device_config.net_id: ${h.net_id}`);const f=await i.encodeDeviceDocument(h,a.privateKeyPem);console.log(`${e.deviceName} device jwt: ${f}`);const y=i.newDeviceMiniDocumentByDeviceDocument(h),m=await i.deviceMiniDocumentToJwt(y,a.privateKeyPem);Bd(t.join(u,"device_mini_config.jwt"),m);const w=d({zoneDid:s,ownerDid:l,ownerPublicKey:i.createJwkByX(a.publicKeyX),deviceName:e.deviceName,deviceDid:p,zoneIat:xd});if(S(u,Rd(u),w,h,f,m,c.privateKeyPem),e.deviceName.startsWith("ood")){const e=Dd({admin_password_hash:ad(n,"bucky2025"),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"});Od(t.join(u,"start_config.json"),e)}return console.log(`Successfully created node configuration: ${n}.${e.deviceName}`),i.encodeDeviceDocument(h,c.privateKeyPem)},exports.createSnConfigs=async function(e){Id();const t=Td("node:path"),r=t.join(e.outputDir,"sn_server"),n=Rh("sn_owner"),o=Rh("sn_server"),s=_d;Bd(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)});Od(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",Od(t.join(r,"sn_device_config.json"),i.deviceDocumentToOrderedJson(l)),Bd(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=Dd({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"}});Od(t.join(r,"params.json"),h),console.log("- Created params.json.");const d=new Ud(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){Id();const t=Td("node:path"),r=e.rtcpPort??2980,n=e.outputDir,o=_d,s=jd(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}`}Bd(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});Od(t.join(n,"user_config.json"),i.ownerDocumentToOrderedJson(p)),console.log(`Created owner config for ${e.username}`);const h=i.parseOODDescription(e.oodName),d=Pd(e.username,h.name,e.deviceKeyPair);let f,y=c;h.netId&&(h.netId.startsWith("wan")&&(y=void 0),h.netId.startsWith("wan_dyn")&&c&&(f=`https://${c}/kapi/sn`));const m=i.oodDescriptionToString(h),w=i.newZoneBootDocument({oods:[m],sn:y,exp:o}),b=u.toRawHostName();Od(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),Od(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=g(h.name,u),I=v(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 Od(t.join(n,"zone_txt_record.json"),T),console.log(`Successfully created user environment configuration: ${e.username}`),T},exports.decodeDeviceDocumentWithoutVerify=A,exports.deriveDevTestEvmAccount=Bh,exports.deriveDevTestEvmAccountFromMnemonic=Th,exports.deriveDevTestKeyPair=wh,exports.deriveDevTestKeyPairFromMnemonic=vh,exports.devTestKeccak256=Nh,exports.deviceIdentityPathsForRoots=y,exports.didWebDocumentUrl=zp,exports.encodeIdentityDirName=Vp,exports.ensureCa=async function(e,t="devtest"){const r=Op("node:fs"),i=Op("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 Zp(new Tp(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`),Qp(e,t)):(console.log(`Use existing CA at: ${n}`),{caCertPath:n,caKeyPath:o})}return Qp(e,t)},exports.generateProvisionKeyPair=ud,exports.getDevTestEvmAccountByIndex=function(e){return Bh(e)},exports.getDevTestEvmAccountByUsername=function(e){const t=jh[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=Rh,exports.getDevTestKeyPairByIndex=function(e){return wh(e)},exports.hashAdminPassword=ad,exports.identityDirName=Fp,exports.identityFileName=Wp,exports.identityRawHostUri=Kp,exports.inspectActivationRoot=wd,exports.loadDeviceDocJwtForRoots=w,exports.loadDeviceMiniDocJwtForRoots=function(e,t){return l("node:fs").readFileSync(y(e,t).deviceMiniDocJwt,"utf8")},exports.loadLocalDeviceDocumentForRoots=async function(e,t,r){const n=w(e,t.device_did),o=r?await i.verifyJwtEdDSA(n,t.owner_public_key):A(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=d,exports.nodeTestIdentityRoots=Rd,exports.registerDeviceToSn=async function(e,t,r,n){Id();const o=Td("node:path"),s=Td("node:fs"),a=Td("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),p=i.DID.fromStr(l.owner_did).id,h=y(Rd(c),l.device_did),d=s.readFileSync(h.deviceDocJwt,"utf8"),g=s.readFileSync(h.deviceMiniDocJwt,"utf8"),m=await i.verifyJwtEdDSA(d,l.owner_public_key),v=m.id;let w;try{w=i.parseOODDescription(r)}catch{w={name:r,nodeType:"Device"}}try{const n=Cd(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=Td("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:$d(),os:Md(),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 Ud(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){Id();const n=Td("node:path"),o=Cd(n.join(e,t,"user_config.json")).name;if("string"!=typeof o||!o)throw new Error("user_config.json missing name field");const s=Cd(n.join(e,t,"zone_config.json")),a=i.DID.fromStr(s.id);let c;"bns"!==a.method&&(c=a.toHostName());const u=Cd(n.join(e,t,"zone_txt_record.json")),l=new Ud(r),p=JSON.stringify(Dd({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=S,exports.saveNodeGatewayParams=b,exports.setPkgMeta=async function(e,t){Id();const r=Td("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=i.calcPkgMetaObjId(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=sd,exports.validateOwnerName=id,exports.validatePublicIp=od,exports.validateRtcpPort=nd,exports.validateZoneDomain=rd,exports.versionToInt=Ld;
|
|
92
92
|
//# sourceMappingURL=provision.cjs.map
|