@certd/plus-core 1.25.4 → 1.25.6

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/build.md CHANGED
@@ -1 +1 @@
1
- 09:51
1
+ 02:32
@@ -0,0 +1 @@
1
+ "use strict";var e=require("node:crypto"),t=require("dayjs");function s(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(s){if("default"!==s){var r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:function(){return e[s]}})}})),t.default=e,Object.freeze(t)}var r=s(e);const i={logger:{info(...e){console.log(...e)},warn(...e){console.warn(...e)},error(...e){console.error(...e)},debug(...e){console.log(...e)}}};function n(){return i.logger}let c="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQW9VWE1EWUhjdi82WFROWEZFSUI2RlpuR2FER0cwZnR5bTV1dVhPck9NaVl0UkxSb1lvSGMKNVZxenE0N00rdEFqRFBhaTBlOFhWS1c3aytUQUw3MUs0N2JCQVEyWTBxNU5Ya3lYcE5PTVdueVFMYXBwb0tWNgpPMkFJMnpFVURWMVJVa0ZtMFZTVjU0VXNzMDcrdjI2aW5aQU1CWitDMU42eWFDc2tZL3grNnVlNkVRNVcyZXdFCjZOWEhJcUU1bHdEUmU2SXJtdEpnU2doSnlHTS91azIyejN6NGEraFVPVUlWMy9DbEhYV0VhRHBBRFFsakt3NSsKeHR0dURiTHZyUmdzdWp6czB0dEI2OE1SbXE0R0FJL0JtNWVPWkhlNGxFQjBFVVhFUXdVWE1jV1N1VFZSMUE2cApUM21LRGo5MGcwVDFZUlNOdE5TMm9aRzgvRWIwOVlxK3Z3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K",a="kQth6FHM71IPV3qdWc";"false"===process.env.plus_use_prod&&(c="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQXY3TGtMaUp1dGM0NzhTU3RaTExjajVGZXh1YjJwR2NLMGxwa0hwVnlZWjhMY29rRFhuUlAKUGQ5UlJSTVRTaGJsbFl2Mzd4QUhOV1ZIQ0ZsWHkrQklVU001bUlBU1NDQTV0azlJNmpZZ2F4bEFDQm1BY0lGMwozKzBjeGZIYVkrVW9YdVluMkZ6YUt2Ym5GdFZIZ0lkMDg4a3d4clZTZzlCT3BDRVZIR1pxR2I5TWN5MXVHVXhUClFTVENCbmpoTWZlZ0p6cXVPYWVOY0ZPSE5tbmtWRWpLTythbTBPeEhNS1lyS3ZnQnVEbzdoVnFENlBFMUd6V3AKZHdwZUV4QXZDSVJxL2pWTkdRK3FtMkRWOVNJZ3U5bmF4MktmSUtFeU50dUFFS1VpekdqL0VmRFhDM1cxMExhegpKaGNYNGw1SUFZU1o3L3JWVmpGbExWSVl0WDU1T054L1Z3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K",a="z4nXOeTeSnnpUpnmsV"),"true"===process.env.plus_off&&(a="12132");const o=a;const l=new class{isPlus=!1;expireTime=0;vipType="";message=void 0;secret=void 0};l.isPlus=!1;const u=new class{checked=!1;licenseReq=void 0;async reVerify(e){return this.checked=!1,await this.verify(e)}setPlus(e,t={}){return e&&t?(l.isPlus=!0,l.expireTime=t.expireTime,l.secret=t.secret,l.vipType=t.vipType):(l.isPlus=!1,l.expireTime=0,l.vipType="",l.message=t.message,l.secret=void 0),{...l}}async verify(e){if(!e.plusRequestService)return console.error("plusRequestService is not set"),this.setPlus(!1);if(this.licenseReq=e,this.checked)return this.setPlus(!1);const s=e?.license;if(!s)return this.checked=!0,this.setPlus(!1);const r=Buffer.from(s,"base64").toString(),i=JSON.parse(r),o=n();if(i.expireTime<Date.now())return o.warn("授权已过期"),this.setPlus(!1,{message:"授权已过期"});const l=`${a},${this.licenseReq.subjectId},${i.code},${i.secret},${i.vipType},${i.activeTime},${i.duration},${i.expireTime},${i.version}`;o.debug("content:",l);const u=Buffer.from(c,"base64").toString(),p=this.verifySignature(l,i.signature,u);return this.checked=!0,p?(o.info(`授权校验成功,到期时间:${t(i.expireTime).format("YYYY-MM-DD HH:mm:ss")}`),this.setPlus(!0,{expireTime:i.expireTime,vipType:i.vipType||"plus",secret:i.secret})):(o.warn("授权校验失败"),this.setPlus(!1,{message:"授权校验失败"}))}verifySignature(t,s,r){const i=e.createVerify("RSA-SHA256");return i.update(t),i.verify(r,s,"base64")}async verifyFromRemote(){if(this.licenseReq?.plusRequestService)try{const e=await this.licenseReq.plusRequestService.request({url:"/activation/subject/vip/check",data:{url:this.licenseReq.bindUrl}});if(!e.data?.ok){const t=e.data?.message||e.message;return console.log("vip校验失败,退回免费版:",t),this.setPlus(!1,{message:t})}p()||await this.reVerify(this.licenseReq)}catch(e){console.error(e.message)}}};function p(){return l.isPlus&&l.expireTime>Date.now()}function h(){return{isPlus:l.isPlus,vipType:l.vipType,expireTime:l.expireTime,secret:l.secret}}!function(){async function e(){if(!p())return;const e=n();if(e.info("check license"),p()&&!l.secret)return e.info("license 校验失败!!!"),function(){const e=Math.floor(1e3*Math.random()*60*60);setTimeout((()=>{console.log("11111"),process.exit(0)}),e)}();await u.verifyFromRemote()}setInterval((async()=>{await e()}),864e5),setTimeout((async()=>{await e()}),6e4)}();exports.AppKey=o,exports.PlusRequestService=class{plusServerBaseUrls;_validPlusServerBaseUrl;_lastCheckTime=0;http;logger;subjectId;constructor(e){this.plusServerBaseUrls=e.plusServerBaseUrls,this.http=e.http,this.logger=e.logger,this.subjectId=e.subjectId}async checkServer(){if(this._validPlusServerBaseUrl&&Date.now()<this._lastCheckTime+828e5)return!0;for(const e of this.plusServerBaseUrls)try{const t=await this.sendCheckRequest(e);return this._validPlusServerBaseUrl=e,t}catch(t){this.logger.error(`server [${e}] is invalid:`,t)}this._lastCheckTime=Date.now()}async sendCheckRequest(e){const t={appKey:o};return await this.http.request({url:"/activation/app/get",method:"POST",data:t,baseURL:e},!0)}async requestWithoutSign(e,t=!1){return!0!==t&&await this.checkServer(),e.baseURL=this._validPlusServerBaseUrl||this.plusServerBaseUrls[0],e.method=e.method||"POST",await this.http.request(e)}async request(e){if(!p())throw new Error("您还不是专业版,请先激活专业版");const{url:t,data:s}=e,r=Date.now(),i=await this.sign(s,r),n={subjectId:this.subjectId,appKey:o,sign:i,timestamps:r};let c=JSON.stringify(n);c=Buffer.from(c).toString("base64");const a={"Content-Type":"application/json","X-Plus-Subject":c};return await this.requestWithoutSign({url:t,method:"POST",data:s,headers:a})}async sign(e,t){const s=JSON.stringify(e),i=h().secret;if(!i)throw new Error("secret is not set");const n=`${s}.${t}.${i}`,c=r.createHash("sha256").update(n).digest("base64");return this.logger.info("content:",n,"sign:",c),c}},exports.getLogger=n,exports.getPlusInfo=h,exports.isCommercial=function(){return l.isPlus&&"comm"===l.vipType&&l.expireTime>Date.now()},exports.isPlus=p,exports.setLogger=function(e){i.logger=e},exports.verify=async function(e){try{const t=await u.reVerify(e);return p()&&setTimeout((()=>{u.verifyFromRemote()}),1e3),t}catch(e){return n().error(e),u.setPlus(!1,{message:"授权校验失败"})}};
@@ -0,0 +1 @@
1
+ import*as e from"node:crypto";import{createVerify as t}from"node:crypto";import s from"dayjs";const r={logger:{info(...e){console.log(...e)},warn(...e){console.warn(...e)},error(...e){console.error(...e)},debug(...e){console.log(...e)}}};function i(e){r.logger=e}function n(){return r.logger}let a="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQW9VWE1EWUhjdi82WFROWEZFSUI2RlpuR2FER0cwZnR5bTV1dVhPck9NaVl0UkxSb1lvSGMKNVZxenE0N00rdEFqRFBhaTBlOFhWS1c3aytUQUw3MUs0N2JCQVEyWTBxNU5Ya3lYcE5PTVdueVFMYXBwb0tWNgpPMkFJMnpFVURWMVJVa0ZtMFZTVjU0VXNzMDcrdjI2aW5aQU1CWitDMU42eWFDc2tZL3grNnVlNkVRNVcyZXdFCjZOWEhJcUU1bHdEUmU2SXJtdEpnU2doSnlHTS91azIyejN6NGEraFVPVUlWMy9DbEhYV0VhRHBBRFFsakt3NSsKeHR0dURiTHZyUmdzdWp6czB0dEI2OE1SbXE0R0FJL0JtNWVPWkhlNGxFQjBFVVhFUXdVWE1jV1N1VFZSMUE2cApUM21LRGo5MGcwVDFZUlNOdE5TMm9aRzgvRWIwOVlxK3Z3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K",o="kQth6FHM71IPV3qdWc";"false"===process.env.plus_use_prod&&(a="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQXY3TGtMaUp1dGM0NzhTU3RaTExjajVGZXh1YjJwR2NLMGxwa0hwVnlZWjhMY29rRFhuUlAKUGQ5UlJSTVRTaGJsbFl2Mzd4QUhOV1ZIQ0ZsWHkrQklVU001bUlBU1NDQTV0azlJNmpZZ2F4bEFDQm1BY0lGMwozKzBjeGZIYVkrVW9YdVluMkZ6YUt2Ym5GdFZIZ0lkMDg4a3d4clZTZzlCT3BDRVZIR1pxR2I5TWN5MXVHVXhUClFTVENCbmpoTWZlZ0p6cXVPYWVOY0ZPSE5tbmtWRWpLTythbTBPeEhNS1lyS3ZnQnVEbzdoVnFENlBFMUd6V3AKZHdwZUV4QXZDSVJxL2pWTkdRK3FtMkRWOVNJZ3U5bmF4MktmSUtFeU50dUFFS1VpekdqL0VmRFhDM1cxMExhegpKaGNYNGw1SUFZU1o3L3JWVmpGbExWSVl0WDU1T054L1Z3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K",o="z4nXOeTeSnnpUpnmsV"),"true"===process.env.plus_off&&(o="12132");const c=o;const l=new class{isPlus=!1;expireTime=0;vipType="";message=void 0;secret=void 0};l.isPlus=!1;const u=new class{checked=!1;licenseReq=void 0;async reVerify(e){return this.checked=!1,await this.verify(e)}setPlus(e,t={}){return e&&t?(l.isPlus=!0,l.expireTime=t.expireTime,l.secret=t.secret,l.vipType=t.vipType):(l.isPlus=!1,l.expireTime=0,l.vipType="",l.message=t.message,l.secret=void 0),{...l}}async verify(e){if(!e.plusRequestService)return console.error("plusRequestService is not set"),this.setPlus(!1);if(this.licenseReq=e,this.checked)return this.setPlus(!1);const t=e?.license;if(!t)return this.checked=!0,this.setPlus(!1);const r=Buffer.from(t,"base64").toString(),i=JSON.parse(r),c=n();if(i.expireTime<Date.now())return c.warn("授权已过期"),this.setPlus(!1,{message:"授权已过期"});const l=`${o},${this.licenseReq.subjectId},${i.code},${i.secret},${i.vipType},${i.activeTime},${i.duration},${i.expireTime},${i.version}`;c.debug("content:",l);const u=Buffer.from(a,"base64").toString(),h=this.verifySignature(l,i.signature,u);return this.checked=!0,h?(c.info(`授权校验成功,到期时间:${s(i.expireTime).format("YYYY-MM-DD HH:mm:ss")}`),this.setPlus(!0,{expireTime:i.expireTime,vipType:i.vipType||"plus",secret:i.secret})):(c.warn("授权校验失败"),this.setPlus(!1,{message:"授权校验失败"}))}verifySignature(e,s,r){const i=t("RSA-SHA256");return i.update(e),i.verify(r,s,"base64")}async verifyFromRemote(){if(this.licenseReq?.plusRequestService)try{const e=await this.licenseReq.plusRequestService.request({url:"/activation/subject/vip/check",data:{url:this.licenseReq.bindUrl}});if(!e.data?.ok){const t=e.data?.message||e.message;return console.log("vip校验失败,退回免费版:",t),this.setPlus(!1,{message:t})}h()||await this.reVerify(this.licenseReq)}catch(e){console.error(e.message)}}};function h(){return l.isPlus&&l.expireTime>Date.now()}function p(){return l.isPlus&&"comm"===l.vipType&&l.expireTime>Date.now()}function S(){return{isPlus:l.isPlus,vipType:l.vipType,expireTime:l.expireTime,secret:l.secret}}async function U(e){try{const t=await u.reVerify(e);return h()&&setTimeout((()=>{u.verifyFromRemote()}),1e3),t}catch(e){return n().error(e),u.setPlus(!1,{message:"授权校验失败"})}}!function(){async function e(){if(!h())return;const e=n();if(e.info("check license"),h()&&!l.secret)return e.info("license 校验失败!!!"),function(){const e=Math.floor(1e3*Math.random()*60*60);setTimeout((()=>{console.log("11111"),process.exit(0)}),e)}();await u.verifyFromRemote()}setInterval((async()=>{await e()}),864e5),setTimeout((async()=>{await e()}),6e4)}();class d{plusServerBaseUrls;_validPlusServerBaseUrl;_lastCheckTime=0;http;logger;subjectId;constructor(e){this.plusServerBaseUrls=e.plusServerBaseUrls,this.http=e.http,this.logger=e.logger,this.subjectId=e.subjectId}async checkServer(){if(this._validPlusServerBaseUrl&&Date.now()<this._lastCheckTime+828e5)return!0;for(const e of this.plusServerBaseUrls)try{const t=await this.sendCheckRequest(e);return this._validPlusServerBaseUrl=e,t}catch(t){this.logger.error(`server [${e}] is invalid:`,t)}this._lastCheckTime=Date.now()}async sendCheckRequest(e){const t={appKey:c};return await this.http.request({url:"/activation/app/get",method:"POST",data:t,baseURL:e},!0)}async requestWithoutSign(e,t=!1){return!0!==t&&await this.checkServer(),e.baseURL=this._validPlusServerBaseUrl||this.plusServerBaseUrls[0],e.method=e.method||"POST",await this.http.request(e)}async request(e){if(!h())throw new Error("您还不是专业版,请先激活专业版");const{url:t,data:s}=e,r=Date.now(),i=await this.sign(s,r),n={subjectId:this.subjectId,appKey:c,sign:i,timestamps:r};let a=JSON.stringify(n);a=Buffer.from(a).toString("base64");const o={"Content-Type":"application/json","X-Plus-Subject":a};return await this.requestWithoutSign({url:t,method:"POST",data:s,headers:o})}async sign(t,s){const r=JSON.stringify(t),i=S().secret;if(!i)throw new Error("secret is not set");const n=`${r}.${s}.${i}`,a=e.createHash("sha256").update(n).digest("base64");return this.logger.info("content:",n,"sign:",a),a}}export{c as AppKey,d as PlusRequestService,n as getLogger,S as getPlusInfo,p as isCommercial,h as isPlus,i as setLogger,U as verify};
@@ -1,15 +1,19 @@
1
1
  export declare class PlusRequestService {
2
- plusServerBaseUrl: string;
2
+ plusServerBaseUrls: string[];
3
+ _validPlusServerBaseUrl: string;
4
+ _lastCheckTime: number;
3
5
  http: any;
4
6
  logger: any;
5
7
  subjectId: string;
6
8
  constructor(opts: {
7
- plusServerBaseUrl: string;
9
+ plusServerBaseUrls: string[];
8
10
  http: any;
9
11
  logger: any;
10
12
  subjectId: string;
11
13
  });
12
- requestWithoutSign(config: any): Promise<any>;
14
+ checkServer(): Promise<any>;
15
+ sendCheckRequest(baseServerUrl: string): Promise<any>;
16
+ requestWithoutSign(config: any, checkOff?: boolean): Promise<any>;
13
17
  request(config: any): Promise<any>;
14
18
  sign(body: any, timestamps: number): Promise<string>;
15
19
  }
package/package.json CHANGED
@@ -1,24 +1,29 @@
1
1
  {
2
2
  "name": "@certd/plus-core",
3
3
  "private": false,
4
- "version": "1.25.4",
5
- "main": "./dist/bundle.js",
6
- "module": "./dist/bundle.js",
4
+ "version": "1.25.6",
5
+ "main": "./dist/bundle.mjs",
6
+ "module": "./dist/bundle.mjs",
7
7
  "types": "./dist/d/index.d.ts",
8
+ "type": "module",
8
9
  "scripts": {
9
10
  "dev": "vite",
10
- "build": "rollup -c ",
11
+ "before-build": "rimraf dist && rimraf tsconfig.tsbuildinfo && rimraf .rollup.cache",
12
+ "build": "npm run before-build && rollup -c ",
11
13
  "build2": "vue-tsc --noEmit && vite build",
12
14
  "preview": "vite preview"
13
15
  },
16
+ "dependencies": {
17
+ "dayjs": "^1.11.7"
18
+ },
14
19
  "devDependencies": {
20
+ "rimraf": "^5.0.5",
15
21
  "@rollup/plugin-json": "^6.0.0",
16
22
  "@rollup/plugin-terser": "^0.4.3",
17
23
  "@rollup/plugin-typescript": "^11.0.0",
18
24
  "@types/mocha": "^10.0.7",
19
25
  "@types/node": "^18",
20
26
  "chai": "4.3.10",
21
- "dayjs": "^1.11.7",
22
27
  "eslint": "^8.41.0",
23
28
  "eslint-config-prettier": "^8.8.0",
24
29
  "eslint-plugin-import": "^2.27.5",
@@ -27,7 +32,7 @@
27
32
  "mocha": "^10.2.0",
28
33
  "rollup": "^3.7.4",
29
34
  "ts-node": "^10.9.1",
30
- "typescript": "^5.0.4",
35
+ "typescript": "^5.4.2",
31
36
  "@types/chai": "^4.3.10"
32
37
  },
33
38
  "gitHead": "47fe3d5826661f678d081ab53e67c847a3239d88"
package/rollup.config.js CHANGED
@@ -1,15 +1,21 @@
1
1
  // const resolve = require("@rollup/plugin-node-resolve");
2
2
  // const commonjs = require("@rollup/plugin-commonjs");
3
3
  //const Typescript = require("rollup-plugin-typescript2");
4
- const typescript = require("@rollup/plugin-typescript");
5
- const json = require("@rollup/plugin-json");
6
- const terser = require("@rollup/plugin-terser");
7
- module.exports = {
4
+ import typescript from "@rollup/plugin-typescript";
5
+ import json from "@rollup/plugin-json";
6
+ import terser from "@rollup/plugin-terser";
7
+ export default {
8
8
  input: "src/index.ts",
9
- output: {
10
- file: "dist/bundle.js",
11
- format: "cjs",
12
- },
9
+ output: [
10
+ {
11
+ file: "dist/bundle.mjs",
12
+ format: "es",
13
+ },
14
+ {
15
+ file: "dist/bundle.cjs",
16
+ format: "cjs",
17
+ },
18
+ ],
13
19
  plugins: [
14
20
  typescript({
15
21
  target: "esnext",
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compileOnSave": false,
3
3
  "compilerOptions": {
4
+ "importHelpers": true,
4
5
  "target": "ESNext",
5
6
  "module": "ESNext",
6
7
  "moduleResolution": "node",
package/dist/bundle.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var e=require("node:crypto"),t=require("dayjs");function s(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(s){if("default"!==s){var r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:function(){return e[s]}})}})),t.default=e,Object.freeze(t)}var r=s(e);const i={logger:{info(...e){console.log(...e)},warn(...e){console.warn(...e)},error(...e){console.error(...e)},debug(...e){console.log(...e)}}};function n(){return i.logger}let o="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQW9VWE1EWUhjdi82WFROWEZFSUI2RlpuR2FER0cwZnR5bTV1dVhPck9NaVl0UkxSb1lvSGMKNVZxenE0N00rdEFqRFBhaTBlOFhWS1c3aytUQUw3MUs0N2JCQVEyWTBxNU5Ya3lYcE5PTVdueVFMYXBwb0tWNgpPMkFJMnpFVURWMVJVa0ZtMFZTVjU0VXNzMDcrdjI2aW5aQU1CWitDMU42eWFDc2tZL3grNnVlNkVRNVcyZXdFCjZOWEhJcUU1bHdEUmU2SXJtdEpnU2doSnlHTS91azIyejN6NGEraFVPVUlWMy9DbEhYV0VhRHBBRFFsakt3NSsKeHR0dURiTHZyUmdzdWp6czB0dEI2OE1SbXE0R0FJL0JtNWVPWkhlNGxFQjBFVVhFUXdVWE1jV1N1VFZSMUE2cApUM21LRGo5MGcwVDFZUlNOdE5TMm9aRzgvRWIwOVlxK3Z3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K",c="kQth6FHM71IPV3qdWc";"false"===process.env.plus_use_prod&&(o="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQXY3TGtMaUp1dGM0NzhTU3RaTExjajVGZXh1YjJwR2NLMGxwa0hwVnlZWjhMY29rRFhuUlAKUGQ5UlJSTVRTaGJsbFl2Mzd4QUhOV1ZIQ0ZsWHkrQklVU001bUlBU1NDQTV0azlJNmpZZ2F4bEFDQm1BY0lGMwozKzBjeGZIYVkrVW9YdVluMkZ6YUt2Ym5GdFZIZ0lkMDg4a3d4clZTZzlCT3BDRVZIR1pxR2I5TWN5MXVHVXhUClFTVENCbmpoTWZlZ0p6cXVPYWVOY0ZPSE5tbmtWRWpLTythbTBPeEhNS1lyS3ZnQnVEbzdoVnFENlBFMUd6V3AKZHdwZUV4QXZDSVJxL2pWTkdRK3FtMkRWOVNJZ3U5bmF4MktmSUtFeU50dUFFS1VpekdqL0VmRFhDM1cxMExhegpKaGNYNGw1SUFZU1o3L3JWVmpGbExWSVl0WDU1T054L1Z3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K",c="z4nXOeTeSnnpUpnmsV"),"true"===process.env.plus_off&&(c="12132");const a=c;const u=new class{isPlus=!1;expireTime=0;vipType="";message=void 0;secret=void 0};u.isPlus=!1;const l=new class{checked=!1;licenseReq=void 0;async reVerify(e){return this.checked=!1,await this.verify(e)}setPlus(e,t={}){return e&&t?(u.isPlus=!0,u.expireTime=t.expireTime,u.secret=t.secret,u.vipType=t.vipType):(u.isPlus=!1,u.expireTime=0,u.vipType="",u.message=t.message,u.secret=void 0),{...u}}async verify(e){if(!e.plusRequestService)return console.error("plusRequestService is not set"),this.setPlus(!1);if(this.licenseReq=e,this.checked)return this.setPlus(!1);const s=e?.license;if(!s)return this.checked=!0,this.setPlus(!1);const r=Buffer.from(s,"base64").toString(),i=JSON.parse(r),a=n();if(i.expireTime<Date.now())return a.warn("授权已过期"),this.setPlus(!1,{message:"授权已过期"});const u=`${c},${this.licenseReq.subjectId},${i.code},${i.secret},${i.vipType},${i.activeTime},${i.duration},${i.expireTime},${i.version}`;a.debug("content:",u);const l=Buffer.from(o,"base64").toString(),p=this.verifySignature(u,i.signature,l);return this.checked=!0,p?(a.info(`授权校验成功,到期时间:${t(i.expireTime).format("YYYY-MM-DD HH:mm:ss")}`),this.setPlus(!0,{expireTime:i.expireTime,vipType:i.vipType||"plus",secret:i.secret})):(a.warn("授权校验失败"),this.setPlus(!1,{message:"授权校验失败"}))}verifySignature(t,s,r){const i=e.createVerify("RSA-SHA256");return i.update(t),i.verify(r,s,"base64")}async verifyFromRemote(){if(this.licenseReq?.plusRequestService)try{const e=await this.licenseReq.plusRequestService.request({url:"/activation/subject/vip/check",data:{url:this.licenseReq.bindUrl}});if(!e.data?.ok){const t=e.data?.message||e.message;return console.log("vip校验失败,退回免费版:",t),this.setPlus(!1,{message:t})}p()||await this.reVerify(this.licenseReq)}catch(e){console.error(e.message)}}};function p(){return u.isPlus&&u.expireTime>Date.now()}function h(){return{isPlus:u.isPlus,vipType:u.vipType,expireTime:u.expireTime,secret:u.secret}}!function(){async function e(){if(!p())return;const e=n();if(e.info("check license"),p()&&!u.secret)return e.info("license 校验失败!!!"),function(){const e=Math.floor(1e3*Math.random()*60*60);setTimeout((()=>{console.log("11111"),process.exit(0)}),e)}();await l.verifyFromRemote()}setInterval((async()=>{await e()}),864e5),setTimeout((async()=>{await e()}),6e4)}();exports.AppKey=a,exports.PlusRequestService=class{plusServerBaseUrl;http;logger;subjectId;constructor(e){this.plusServerBaseUrl=e.plusServerBaseUrl,this.http=e.http,this.logger=e.logger,this.subjectId=e.subjectId}async requestWithoutSign(e){return e.baseURL=this.plusServerBaseUrl,e.method=e.method||"POST",await this.http.request(e)}async request(e){if(!p())throw new Error("您还不是专业版,请先激活专业版");const{url:t,data:s}=e,r=Date.now(),i=await this.sign(s,r),n={subjectId:this.subjectId,appKey:a,sign:i,timestamps:r};let o=JSON.stringify(n);o=Buffer.from(o).toString("base64");const c={"Content-Type":"application/json","X-Plus-Subject":o};return await this.http.request({url:t,baseURL:this.plusServerBaseUrl,method:"POST",data:s,headers:c})}async sign(e,t){const s=JSON.stringify(e),i=h().secret;if(!i)throw new Error("secret is not set");const n=`${s}.${t}.${i}`,o=r.createHash("sha256").update(n).digest("base64");return this.logger.info("content:",n,"sign:",o),o}},exports.getLogger=n,exports.getPlusInfo=h,exports.isCommercial=function(){return u.isPlus&&"comm"===u.vipType&&u.expireTime>Date.now()},exports.isPlus=p,exports.setLogger=function(e){i.logger=e},exports.verify=async function(e){try{const t=await l.reVerify(e);return p()&&setTimeout((()=>{l.verifyFromRemote()}),1e3),t}catch(e){return n().error(e),l.setPlus(!1,{message:"授权校验失败"})}};