@certd/plus-core 1.25.9 → 1.26.0
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/CHANGELOG.md +4 -0
- package/dist/d/license.d.ts +3 -1
- package/dist/d/service.d.ts +3 -4
- package/dist/index.cjs +1 -0
- package/dist/index.js +1 -0
- package/package.json +6 -6
- package/rollup.config.js +2 -2
- package/tsconfig.json +2 -2
- package/dist/bundle.cjs +0 -1
- package/dist/bundle.mjs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.26.0](https://github.com/certd/certd/compare/v1.25.9...v1.26.0) (2024-10-10)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @certd/plus-core
|
|
9
|
+
|
|
6
10
|
## [1.25.9](https://github.com/certd/certd/compare/v1.25.8...v1.25.9) (2024-10-01)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @certd/plus-core
|
package/dist/d/license.d.ts
CHANGED
|
@@ -7,15 +7,17 @@ export type LicenseVerifyReq = {
|
|
|
7
7
|
plusRequestService?: PlusRequestService;
|
|
8
8
|
};
|
|
9
9
|
export declare function isPlus(): boolean;
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function isComm(): boolean;
|
|
11
11
|
export declare function getPlusInfo(): {
|
|
12
12
|
isPlus: boolean;
|
|
13
|
+
isComm: boolean;
|
|
13
14
|
vipType: string;
|
|
14
15
|
expireTime: number;
|
|
15
16
|
secret: string;
|
|
16
17
|
};
|
|
17
18
|
export declare function verify(req: LicenseVerifyReq): Promise<{
|
|
18
19
|
isPlus: boolean;
|
|
20
|
+
isComm: boolean;
|
|
19
21
|
expireTime: number;
|
|
20
22
|
vipType: string;
|
|
21
23
|
message?: string;
|
package/dist/d/service.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
+
import { HttpClient, ILogger } from "@certd/basic";
|
|
1
2
|
export declare class PlusRequestService {
|
|
2
3
|
plusServerBaseUrls: string[];
|
|
3
4
|
_validPlusServerBaseUrl: string;
|
|
4
5
|
_lastCheckTime: number;
|
|
5
|
-
http:
|
|
6
|
-
logger:
|
|
6
|
+
http: HttpClient;
|
|
7
|
+
logger: ILogger;
|
|
7
8
|
subjectId: string;
|
|
8
9
|
constructor(opts: {
|
|
9
10
|
plusServerBaseUrls: string[];
|
|
10
|
-
http: any;
|
|
11
|
-
logger: any;
|
|
12
11
|
subjectId: string;
|
|
13
12
|
});
|
|
14
13
|
checkServer(): Promise<any>;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("node:crypto"),t=require("dayjs"),s=require("@certd/basic");function r(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 i=r(e);const n={logger:{info(...e){console.log(...e)},warn(...e){console.warn(...e)},error(...e){console.error(...e)},debug(...e){console.log(...e)}}};function o(){return n.logger}let a="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQW9VWE1EWUhjdi82WFROWEZFSUI2RlpuR2FER0cwZnR5bTV1dVhPck9NaVl0UkxSb1lvSGMKNVZxenE0N00rdEFqRFBhaTBlOFhWS1c3aytUQUw3MUs0N2JCQVEyWTBxNU5Ya3lYcE5PTVdueVFMYXBwb0tWNgpPMkFJMnpFVURWMVJVa0ZtMFZTVjU0VXNzMDcrdjI2aW5aQU1CWitDMU42eWFDc2tZL3grNnVlNkVRNVcyZXdFCjZOWEhJcUU1bHdEUmU2SXJtdEpnU2doSnlHTS91azIyejN6NGEraFVPVUlWMy9DbEhYV0VhRHBBRFFsakt3NSsKeHR0dURiTHZyUmdzdWp6czB0dEI2OE1SbXE0R0FJL0JtNWVPWkhlNGxFQjBFVVhFUXdVWE1jV1N1VFZSMUE2cApUM21LRGo5MGcwVDFZUlNOdE5TMm9aRzgvRWIwOVlxK3Z3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K",c="kQth6FHM71IPV3qdWc";"false"===process.env.plus_use_prod&&(a="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQXY3TGtMaUp1dGM0NzhTU3RaTExjajVGZXh1YjJwR2NLMGxwa0hwVnlZWjhMY29rRFhuUlAKUGQ5UlJSTVRTaGJsbFl2Mzd4QUhOV1ZIQ0ZsWHkrQklVU001bUlBU1NDQTV0azlJNmpZZ2F4bEFDQm1BY0lGMwozKzBjeGZIYVkrVW9YdVluMkZ6YUt2Ym5GdFZIZ0lkMDg4a3d4clZTZzlCT3BDRVZIR1pxR2I5TWN5MXVHVXhUClFTVENCbmpoTWZlZ0p6cXVPYWVOY0ZPSE5tbmtWRWpLTythbTBPeEhNS1lyS3ZnQnVEbzdoVnFENlBFMUd6V3AKZHdwZUV4QXZDSVJxL2pWTkdRK3FtMkRWOVNJZ3U5bmF4MktmSUtFeU50dUFFS1VpekdqL0VmRFhDM1cxMExhegpKaGNYNGw1SUFZU1o3L3JWVmpGbExWSVl0WDU1T054L1Z3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K",c="z4nXOeTeSnnpUpnmsV"),"true"===process.env.plus_off&&(c="12132");const l=c;const u=new class{isPlus=!1;isComm=!1;expireTime=0;vipType="";message=void 0;secret=void 0};u.isPlus=!1,u.isComm=!1;const p=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,"comm"===t.vipType&&(u.isComm=!0)):(u.isPlus=!1,u.isComm=!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),n=o();if(i.expireTime<Date.now())return n.warn("授权已过期"),this.setPlus(!1,{message:"授权已过期"});const l=`${c},${this.licenseReq.subjectId},${i.code},${i.secret},${i.vipType},${i.activeTime},${i.duration},${i.expireTime},${i.version}`;n.debug("content:",l);const u=Buffer.from(a,"base64").toString(),p=this.verifySignature(l,i.signature,u);return this.checked=!0,p?(n.info(`授权校验成功,到期时间:${t(i.expireTime).format("YYYY-MM-DD HH:mm:ss")}`),this.setPlus(!0,{expireTime:i.expireTime,vipType:i.vipType||"plus",secret:i.secret})):(n.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)h()||await this.reVerify(this.licenseReq);else if(!1===e.data?.ok){const t=e.data?.message||e.message;return console.log("vip校验失败,退回免费版:",JSON.stringify(e.data)),this.setPlus(!1,{message:t})}}catch(e){console.error(e.message)}}};function h(){return u.isPlus&&u.expireTime>Date.now()}function m(){return{isPlus:u.isPlus,isComm:u.isComm,vipType:u.vipType,expireTime:u.expireTime,secret:u.secret}}!function(){async function e(){if(!h())return;const e=o();if(e.info("check license"),h()&&!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 p.verifyFromRemote()}setInterval((async()=>{await e()}),864e5),setTimeout((async()=>{await e()}),6e4)}();exports.AppKey=l,exports.PlusRequestService=class{plusServerBaseUrls;_validPlusServerBaseUrl;_lastCheckTime=0;http;logger;subjectId;constructor(e){this.plusServerBaseUrls=e.plusServerBaseUrls,this.http=s.http,this.logger=s.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:l};return await this.http.request({url:"/activation/app/get",method:"POST",data:t,baseURL:e})}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:l,sign:i,timestamps:r};let o=JSON.stringify(n);o=Buffer.from(o).toString("base64");const a={"Content-Type":"application/json","X-Plus-Subject":o};return await this.requestWithoutSign({url:t,method:"POST",data:s,headers:a})}async sign(e,t){const s=JSON.stringify(e),r=m().secret;if(!r)throw new Error("secret is not set");const n=`${s}.${t}.${r}`,o=i.createHash("sha256").update(n).digest("base64");return this.logger.info("content:",n,"sign:",o),o}},exports.getLogger=o,exports.getPlusInfo=m,exports.isComm=function(){return u.isComm&&u.expireTime>Date.now()},exports.isPlus=h,exports.setLogger=function(e){n.logger=e},exports.verify=async function(e){try{const t=await p.reVerify(e);return h()&&setTimeout((()=>{p.verifyFromRemote()}),1e3),t}catch(e){return o().error(e),p.setPlus(!1,{message:"授权校验失败"})}};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as e from"node:crypto";import{createVerify as t}from"node:crypto";import s from"dayjs";import{http as r,logger as i}from"@certd/basic";const n={logger:{info(...e){console.log(...e)},warn(...e){console.warn(...e)},error(...e){console.error(...e)},debug(...e){console.log(...e)}}};function o(e){n.logger=e}function a(){return n.logger}let c="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQW9VWE1EWUhjdi82WFROWEZFSUI2RlpuR2FER0cwZnR5bTV1dVhPck9NaVl0UkxSb1lvSGMKNVZxenE0N00rdEFqRFBhaTBlOFhWS1c3aytUQUw3MUs0N2JCQVEyWTBxNU5Ya3lYcE5PTVdueVFMYXBwb0tWNgpPMkFJMnpFVURWMVJVa0ZtMFZTVjU0VXNzMDcrdjI2aW5aQU1CWitDMU42eWFDc2tZL3grNnVlNkVRNVcyZXdFCjZOWEhJcUU1bHdEUmU2SXJtdEpnU2doSnlHTS91azIyejN6NGEraFVPVUlWMy9DbEhYV0VhRHBBRFFsakt3NSsKeHR0dURiTHZyUmdzdWp6czB0dEI2OE1SbXE0R0FJL0JtNWVPWkhlNGxFQjBFVVhFUXdVWE1jV1N1VFZSMUE2cApUM21LRGo5MGcwVDFZUlNOdE5TMm9aRzgvRWIwOVlxK3Z3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K",l="kQth6FHM71IPV3qdWc";"false"===process.env.plus_use_prod&&(c="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQXY3TGtMaUp1dGM0NzhTU3RaTExjajVGZXh1YjJwR2NLMGxwa0hwVnlZWjhMY29rRFhuUlAKUGQ5UlJSTVRTaGJsbFl2Mzd4QUhOV1ZIQ0ZsWHkrQklVU001bUlBU1NDQTV0azlJNmpZZ2F4bEFDQm1BY0lGMwozKzBjeGZIYVkrVW9YdVluMkZ6YUt2Ym5GdFZIZ0lkMDg4a3d4clZTZzlCT3BDRVZIR1pxR2I5TWN5MXVHVXhUClFTVENCbmpoTWZlZ0p6cXVPYWVOY0ZPSE5tbmtWRWpLTythbTBPeEhNS1lyS3ZnQnVEbzdoVnFENlBFMUd6V3AKZHdwZUV4QXZDSVJxL2pWTkdRK3FtMkRWOVNJZ3U5bmF4MktmSUtFeU50dUFFS1VpekdqL0VmRFhDM1cxMExhegpKaGNYNGw1SUFZU1o3L3JWVmpGbExWSVl0WDU1T054L1Z3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K",l="z4nXOeTeSnnpUpnmsV"),"true"===process.env.plus_off&&(l="12132");const u=l;const h=new class{isPlus=!1;isComm=!1;expireTime=0;vipType="";message=void 0;secret=void 0};h.isPlus=!1,h.isComm=!1;const p=new class{checked=!1;licenseReq=void 0;async reVerify(e){return this.checked=!1,await this.verify(e)}setPlus(e,t={}){return e&&t?(h.isPlus=!0,h.expireTime=t.expireTime,h.secret=t.secret,h.vipType=t.vipType,"comm"===t.vipType&&(h.isComm=!0)):(h.isPlus=!1,h.isComm=!1,h.expireTime=0,h.vipType="",h.message=t.message,h.secret=void 0),{...h}}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),n=a();if(i.expireTime<Date.now())return n.warn("授权已过期"),this.setPlus(!1,{message:"授权已过期"});const o=`${l},${this.licenseReq.subjectId},${i.code},${i.secret},${i.vipType},${i.activeTime},${i.duration},${i.expireTime},${i.version}`;n.debug("content:",o);const u=Buffer.from(c,"base64").toString(),h=this.verifySignature(o,i.signature,u);return this.checked=!0,h?(n.info(`授权校验成功,到期时间:${s(i.expireTime).format("YYYY-MM-DD HH:mm:ss")}`),this.setPlus(!0,{expireTime:i.expireTime,vipType:i.vipType||"plus",secret:i.secret})):(n.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)m()||await this.reVerify(this.licenseReq);else if(!1===e.data?.ok){const t=e.data?.message||e.message;return console.log("vip校验失败,退回免费版:",JSON.stringify(e.data)),this.setPlus(!1,{message:t})}}catch(e){console.error(e.message)}}};function m(){return h.isPlus&&h.expireTime>Date.now()}function d(){return h.isComm&&h.expireTime>Date.now()}function S(){return{isPlus:h.isPlus,isComm:h.isComm,vipType:h.vipType,expireTime:h.expireTime,secret:h.secret}}async function U(e){try{const t=await p.reVerify(e);return m()&&setTimeout((()=>{p.verifyFromRemote()}),1e3),t}catch(e){return a().error(e),p.setPlus(!1,{message:"授权校验失败"})}}!function(){async function e(){if(!m())return;const e=a();if(e.info("check license"),m()&&!h.secret)return e.info("license 校验失败!!!"),function(){const e=Math.floor(1e3*Math.random()*60*60);setTimeout((()=>{console.log("11111"),process.exit(0)}),e)}();await p.verifyFromRemote()}setInterval((async()=>{await e()}),864e5),setTimeout((async()=>{await e()}),6e4)}();class V{plusServerBaseUrls;_validPlusServerBaseUrl;_lastCheckTime=0;http;logger;subjectId;constructor(e){this.plusServerBaseUrls=e.plusServerBaseUrls,this.http=r,this.logger=i,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:u};return await this.http.request({url:"/activation/app/get",method:"POST",data:t,baseURL:e})}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(!m())throw new Error("您还不是专业版,请先激活专业版");const{url:t,data:s}=e,r=Date.now(),i=await this.sign(s,r),n={subjectId:this.subjectId,appKey:u,sign:i,timestamps:r};let o=JSON.stringify(n);o=Buffer.from(o).toString("base64");const a={"Content-Type":"application/json","X-Plus-Subject":o};return await this.requestWithoutSign({url:t,method:"POST",data:s,headers:a})}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}`,o=e.createHash("sha256").update(n).digest("base64");return this.logger.info("content:",n,"sign:",o),o}}export{u as AppKey,V as PlusRequestService,a as getLogger,S as getPlusInfo,d as isComm,m as isPlus,o as setLogger,U as verify};
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@certd/plus-core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.
|
|
5
|
-
"main": "./dist/
|
|
6
|
-
"module": "./dist/
|
|
4
|
+
"version": "1.26.0",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/d/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "vite",
|
|
11
11
|
"before-build": "rimraf dist && rimraf tsconfig.tsbuildinfo && rimraf .rollup.cache",
|
|
12
12
|
"build": "npm run before-build && rollup -c ",
|
|
13
|
-
"
|
|
13
|
+
"dev-build": "npm run before-build &&tsc --skipLibCheck",
|
|
14
14
|
"preview": "vite preview"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@certd/basic": "^1.
|
|
17
|
+
"@certd/basic": "^1.26.0",
|
|
18
18
|
"dayjs": "^1.11.7"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"ts-node": "^10.9.1",
|
|
37
37
|
"typescript": "^5.4.2"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "46b810822986f7144bb4f67ae5c4a239dbb3691b"
|
|
40
40
|
}
|
package/rollup.config.js
CHANGED
package/tsconfig.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"esModuleInterop": true,
|
|
9
9
|
"experimentalDecorators": true,
|
|
10
10
|
"emitDecoratorMetadata": true,
|
|
11
|
-
"inlineSourceMap":true,
|
|
12
11
|
"noImplicitThis": true,
|
|
13
12
|
"noUnusedLocals": true,
|
|
14
13
|
"stripInternal": true,
|
|
15
14
|
"skipLibCheck": true,
|
|
16
15
|
"pretty": true,
|
|
17
16
|
"declaration": true,
|
|
17
|
+
"declarationDir": "dist/d",
|
|
18
18
|
"forceConsistentCasingInFileNames": true,
|
|
19
19
|
"typeRoots": [ "./typings", "./node_modules/@types"],
|
|
20
20
|
"outDir": "dist",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"composite": true,
|
|
23
23
|
"useDefineForClassFields": true,
|
|
24
24
|
"strict": false,
|
|
25
|
-
"sourceMap":
|
|
25
|
+
"sourceMap": false,
|
|
26
26
|
"resolveJsonModule": true,
|
|
27
27
|
"isolatedModules": false,
|
|
28
28
|
"lib": ["ESNext", "DOM"],
|
package/dist/bundle.cjs
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 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:"授权校验失败"})}};
|
package/dist/bundle.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|