@certd/plus-core 1.26.16 → 1.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
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.27.1](https://github.com/certd/certd/compare/v1.27.0...v1.27.1) (2024-11-04)
7
+
8
+ **Note:** Version bump only for package @certd/plus-core
9
+
10
+ # [1.27.0](https://github.com/certd/certd/compare/v1.26.16...v1.27.0) (2024-10-31)
11
+
12
+ **Note:** Version bump only for package @certd/plus-core
13
+
6
14
  ## [1.26.16](https://github.com/certd/certd/compare/v1.26.15...v1.26.16) (2024-10-30)
7
15
 
8
16
  **Note:** Version bump only for package @certd/plus-core
@@ -0,0 +1,2 @@
1
+ export declare function checkPlus(): void;
2
+ export declare function checkComm(): void;
package/dist/d/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./license.js";
2
2
  export * from "./logger.js";
3
3
  export * from "./service.js";
4
+ export * from './check.js';
package/dist/index.cjs CHANGED
@@ -1 +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="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQW9VWE1EWUhjdi82WFROWEZFSUI2RlpuR2FER0cwZnR5bTV1dVhPck9NaVl0UkxSb1lvSGMKNVZxenE0N00rdEFqRFBhaTBlOFhWS1c3aytUQUw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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(1004===e.code)return void console.log("请求参数错误:",e.message);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 d(){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=d().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=d,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:"授权校验失败"})}};
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(e){n.logger=e}function c(){return n.logger}let a="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQW9VWE1EWUhjdi82WFROWEZFSUI2RlpuR2FER0cwZnR5bTV1dVhPck9NaVl0UkxSb1lvSGMKNVZxenE0N00rdEFqRFBhaTBlOFhWS1c3aytUQUw3MUs0N2JCQVEyWTBxNU5Ya3lYcE5PTVdueVFMYXBwb0tWNgpPMkFJMnpFVURWMVJVa0ZtMFZTVjU0VXNzMDcrdjI2aW5aQU1CWitDMU42eWFDc2tZL3grNnVlNkVRNVcyZXdFCjZOWEhJcUU1bHdEUmU2SXJtdEpnU2doSnlHTS91azIyejN6NGEraFVPVUlWMy9DbEhYV0VhRHBBRFFsakt3NSsKeHR0dURiTHZyUmdzdWp6czB0dEI2OE1SbXE0R0FJL0JtNWVPWkhlNGxFQjBFVVhFUXdVWE1jV1N1VFZSMUE2cApUM21LRGo5MGcwVDFZUlNOdE5TMm9aRzgvRWIwOVlxK3Z3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K",l="kQth6FHM71IPV3qdWc";"false"===process.env.plus_use_prod&&(a="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQXY3TGtMaUp1dGM0NzhTU3RaTExjajVGZXh1YjJwR2NLMGxwa0hwVnlZWjhMY29rRFhuUlAKUGQ5UlJSTVRTaGJsbFl2Mzd4QUhOV1ZIQ0ZsWHkrQklVU001bUlBU1NDQTV0azlJNmpZZ2F4bEFDQm1BY0lGMwozKzBjeGZIYVkrVW9YdVluMkZ6YUt2Ym5GdFZIZ0lkMDg4a3d4clZTZzlCT3BDRVZIR1pxR2I5TWN5MXVHVXhUClFTVENCbmpoTWZlZ0p6cXVPYWVOY0ZPSE5tbmtWRWpLTythbTBPeEhNS1lyS3ZnQnVEbzdoVnFENlBFMUd6V3AKZHdwZUV4QXZDSVJxL2pWTkdRK3FtMkRWOVNJZ3U5bmF4MktmSUtFeU50dUFFS1VpekdqL0VmRFhDM1cxMExhegpKaGNYNGw1SUFZU1o3L3JWVmpGbExWSVl0WDU1T054L1Z3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K",l="z4nXOeTeSnnpUpnmsV"),"true"===process.env.plus_off&&(l="12132");const u=l;const p=new class{isPlus=!1;isComm=!1;expireTime=0;vipType="";message=void 0;secret=void 0};p.isPlus=!1,p.isComm=!1;const h=new class{checked=!1;licenseReq=void 0;async reVerify(e){return this.checked=!1,await this.verify(e)}setPlus(e,t={}){return e&&t?(p.isPlus=!0,p.expireTime=t.expireTime,p.secret=t.secret,p.vipType=t.vipType,"comm"===t.vipType&&(p.isComm=!0)):(p.isPlus=!1,p.isComm=!1,p.expireTime=0,p.vipType="",p.message=t.message,p.secret=void 0),{...p}}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=c();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(a,"base64").toString(),p=this.verifySignature(o,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(1004===e.code)return void console.log("请求参数错误:",e.message);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 p.isPlus&&p.expireTime>Date.now()}function d(){return p.isComm&&p.expireTime>Date.now()}function S(){return{isPlus:p.isPlus,isComm:p.isComm,vipType:p.vipType,expireTime:p.expireTime,secret:p.secret}}!function(){async function e(){if(!m())return;const e=c();if(e.info("check license"),m()&&!p.secret)return e.info("license 校验失败!!!"),function(){const e=Math.floor(1e3*Math.random()*60*60);setTimeout((()=>{console.log("11111"),process.exit(0)}),e)}();await h.verifyFromRemote()}setInterval((async()=>{await e()}),864e5),setTimeout((async()=>{await e()}),6e4)}();o(s.logger),exports.AppKey=u,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: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 c={"Content-Type":"application/json","X-Plus-Subject":o};return await this.requestWithoutSign({url:t,method:"POST",data:s,headers:c})}async sign(e,t){const s=JSON.stringify(e),r=S().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.checkComm=function(){if(!d())throw new Error("此为商业版功能,请升级到商业版")},exports.checkPlus=function(){if(!m())throw new Error("此为专业版功能,请升级到专业版")},exports.getLogger=c,exports.getPlusInfo=S,exports.isComm=d,exports.isPlus=m,exports.setLogger=o,exports.verify=async function(e){try{const t=await h.reVerify(e);return m()&&setTimeout((()=>{h.verifyFromRemote()}),1e3),t}catch(e){return c().error(e),h.setPlus(!1,{message:"授权校验失败"})}};
package/dist/index.js CHANGED
@@ -1 +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="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQW9VWE1EWUhjdi82WFROWEZFSUI2RlpuR2FER0cwZnR5bTV1d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VUJMSUMgS0VZLS0tLS0K",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(1004===e.code)return void console.log("请求参数错误:",e.message);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};
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(1004===e.code)return void console.log("请求参数错误:",e.message);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}}function f(){if(!m())throw new Error("此为专业版功能,请升级到专业版")}function T(){if(!d())throw new Error("此为商业版功能,请升级到商业版")}o(i);export{u as AppKey,V as PlusRequestService,T as checkComm,f as checkPlus,a as getLogger,S as getPlusInfo,d as isComm,m as isPlus,o as setLogger,U as verify};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@certd/plus-core",
3
3
  "private": false,
4
- "version": "1.26.16",
4
+ "version": "1.27.1",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/d/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "preview": "vite preview"
15
15
  },
16
16
  "dependencies": {
17
- "@certd/basic": "^1.26.16",
17
+ "@certd/basic": "^1.27.1",
18
18
  "dayjs": "^1.11.7"
19
19
  },
20
20
  "devDependencies": {
@@ -31,10 +31,11 @@
31
31
  "eslint-plugin-node": "^11.1.0",
32
32
  "eslint-plugin-prettier": "^4.2.1",
33
33
  "mocha": "^10.2.0",
34
+ "prettier": "^2.8.8",
34
35
  "rimraf": "^5.0.5",
35
36
  "rollup": "^3.7.4",
36
37
  "ts-node": "^10.9.1",
37
38
  "typescript": "^5.4.2"
38
39
  },
39
- "gitHead": "844fd4358c84251c72c5854ea633f238014244ad"
40
+ "gitHead": "1d8515bce0b3ce5ece84db53ca57cfbd0c3f4d5a"
40
41
  }