@polyv/utils-encrypt 3.0.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/index.cjs +1 -0
- package/index.d.ts +12 -0
- package/index.js +12 -0
- package/package.json +22 -0
package/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("md5");c=s(c);let l=require("sha256");l=s(l);function u(e,t,n){let r=Object.keys(e).filter(e=>e!==`sign`).sort(),i=``;return r.forEach(t=>{let n=e[t];typeof n==`object`&&(n=JSON.stringify(n)),i+=t+n}),n||=String(e.signatureMethod).toLowerCase()===`sha256`?`sha256`:`md5`,(n===`sha256`?l.default:c.default)(t+i+t).toString().toUpperCase()}exports.genAPISign=u;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本模块提供加密处理相关方法。
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 生成保利威 API 签名(https://help.polyv.net/index.html#/live/api/buildSign)。
|
|
7
|
+
* @param obj 需要签名的对象。
|
|
8
|
+
* @param appSecret 应用密钥。
|
|
9
|
+
* @param method 签名方法。当 obj.signatureMethod 为 SHA256 时,默认为 sha256,否则默认为 md5。
|
|
10
|
+
* @returns 签名字符串。
|
|
11
|
+
*/
|
|
12
|
+
export declare function genAPISign(obj: Record<string, unknown>, appSecret: string, method?: 'md5' | 'sha256'): string;
|
package/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import e from "md5";
|
|
2
|
+
import t from "sha256";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
function n(n, r, i) {
|
|
5
|
+
let a = Object.keys(n).filter((e) => e !== "sign").sort(), o = "";
|
|
6
|
+
return a.forEach((e) => {
|
|
7
|
+
let t = n[e];
|
|
8
|
+
typeof t == "object" && (t = JSON.stringify(t)), o += e + t;
|
|
9
|
+
}), i ||= String(n.signatureMethod).toLowerCase() === "sha256" ? "sha256" : "md5", (i === "sha256" ? t : e)(r + o + r).toString().toUpperCase();
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { n as genAPISign };
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@polyv/utils-encrypt",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Encryption utilities for Polyv frontend development.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"module": "./index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"miniprogram": "./",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"import": "./index.js",
|
|
14
|
+
"require": "./index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"md5": "^2.3.0",
|
|
20
|
+
"sha256": "^0.2.0"
|
|
21
|
+
}
|
|
22
|
+
}
|