@lingxiteam/assets 3.5.1-alpha.6 → 3.5.1-alpha.8

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.
@@ -1,42 +1,2 @@
1
- declare const _default: {
2
- httpEncryption: {
3
- start: ({ mode, signKeyOptions, aesOptions, desOptions, rsaOptions }: {
4
- mode?: import("./const").MODE | undefined;
5
- signKeyOptions?: {} | undefined;
6
- aesOptions?: {} | undefined;
7
- desOptions?: {} | undefined;
8
- rsaOptions?: {} | undefined;
9
- }) => boolean;
10
- stop: () => void;
11
- fetch: (url: any, fetchOptions?: any, config?: {
12
- mode?: string | undefined;
13
- signKeyOptions?: any;
14
- aesOptions?: any;
15
- desOptions?: any;
16
- rsaOptions?: any;
17
- debug?: boolean | undefined;
18
- }) => Promise<Response>;
19
- createHttpSignStr: (url: string, options: any, version?: (import("./const").MODE.SIGN_KEY | import("./const").MODE.SIGN | import("./const").MODE.SIGN_WITH_TIME | import("./const").MODE.SIGN_WITHOUT_USER | import("./const").MODE.SIGN_UUID | import("./const").MODE.SIGN_UUID_WITHOUT_USER) | undefined) => string;
20
- buildXSignUrl: (url: string, options?: any, version?: (import("./const").MODE.SIGN_KEY | import("./const").MODE.SIGN | import("./const").MODE.SIGN_WITH_TIME | import("./const").MODE.SIGN_WITHOUT_USER | import("./const").MODE.SIGN_UUID | import("./const").MODE.SIGN_UUID_WITHOUT_USER) | undefined) => string;
21
- };
22
- sign: {
23
- createHttpSignStr: (url: string, options: any, version?: (import("./const").MODE.SIGN_KEY | import("./const").MODE.SIGN | import("./const").MODE.SIGN_WITH_TIME | import("./const").MODE.SIGN_WITHOUT_USER | import("./const").MODE.SIGN_UUID | import("./const").MODE.SIGN_UUID_WITHOUT_USER) | undefined) => string;
24
- getApiPath: (url: string) => string | undefined;
25
- };
26
- RSAEncrypt: (value: string, publicKey: string, handle?: any) => any;
27
- RSADecrypt: (value: string, privKey: string, handle?: any) => any;
28
- AESEncrypt: (value: any, aesKey: string, handle?: any) => any;
29
- AESDecrypt: (value: string, aesKey: string, handle?: any) => any;
30
- DESEncrypt: (value: string, aesKey: string, handle?: any) => any;
31
- DESDecrypt: (value: string, aesKey: string, handle?: any) => any;
32
- KEYS: {
33
- signKey: string;
34
- rsaPublicKey: string | undefined;
35
- rsaPrivKey: string | undefined;
36
- aesKey: string;
37
- desKey: string;
38
- };
39
- checkToken: (arg0: string, arg1: string) => boolean;
40
- generateToken: (pageId: any) => string;
41
- };
42
- export default _default;
1
+ import security from '@lingxiteam/security';
2
+ export default security;
@@ -1,24 +1,9 @@
1
- import httpEncryption from './httpEncryption';
2
- import sign from './encipher/sign';
3
- import { RSAEncrypt, RSADecrypt } from './encipher/rsa';
4
- import { AESEncrypt, AESDecrypt } from './encipher/aes';
5
- import { DESEncrypt, DESDecrypt } from './encipher/des';
6
- import { checkToken, generateToken } from './encipher/token';
7
- import KEYS from './const';
1
+ import security from '@lingxiteam/security';
8
2
  window.lingxiSecurity = {
9
- httpEncryption: httpEncryption,
10
- sign: sign
3
+ httpEncryption: security.httpEncryption
11
4
  };
12
- export default {
13
- httpEncryption: httpEncryption,
14
- sign: sign,
15
- RSAEncrypt: RSAEncrypt,
16
- RSADecrypt: RSADecrypt,
17
- AESEncrypt: AESEncrypt,
18
- AESDecrypt: AESDecrypt,
19
- DESEncrypt: DESEncrypt,
20
- DESDecrypt: DESDecrypt,
21
- KEYS: KEYS,
22
- checkToken: checkToken,
23
- generateToken: generateToken
24
- };
5
+ // @ts-ignore
6
+ security.httpEncryption.buildXSignUrl = security.createHttpSignWithUrl;
7
+ // @ts-ignore
8
+ security.httpEncryption.createHttpSignStr = security.createHttpSignStr;
9
+ export default security;
@@ -1,42 +1,2 @@
1
- declare const _default: {
2
- httpEncryption: {
3
- start: ({ mode, signKeyOptions, aesOptions, desOptions, rsaOptions }: {
4
- mode?: import("./const").MODE | undefined;
5
- signKeyOptions?: {} | undefined;
6
- aesOptions?: {} | undefined;
7
- desOptions?: {} | undefined;
8
- rsaOptions?: {} | undefined;
9
- }) => boolean;
10
- stop: () => void;
11
- fetch: (url: any, fetchOptions?: any, config?: {
12
- mode?: string | undefined;
13
- signKeyOptions?: any;
14
- aesOptions?: any;
15
- desOptions?: any;
16
- rsaOptions?: any;
17
- debug?: boolean | undefined;
18
- }) => Promise<Response>;
19
- createHttpSignStr: (url: string, options: any, version?: (import("./const").MODE.SIGN_KEY | import("./const").MODE.SIGN | import("./const").MODE.SIGN_WITH_TIME | import("./const").MODE.SIGN_WITHOUT_USER | import("./const").MODE.SIGN_UUID | import("./const").MODE.SIGN_UUID_WITHOUT_USER) | undefined) => string;
20
- buildXSignUrl: (url: string, options?: any, version?: (import("./const").MODE.SIGN_KEY | import("./const").MODE.SIGN | import("./const").MODE.SIGN_WITH_TIME | import("./const").MODE.SIGN_WITHOUT_USER | import("./const").MODE.SIGN_UUID | import("./const").MODE.SIGN_UUID_WITHOUT_USER) | undefined) => string;
21
- };
22
- sign: {
23
- createHttpSignStr: (url: string, options: any, version?: (import("./const").MODE.SIGN_KEY | import("./const").MODE.SIGN | import("./const").MODE.SIGN_WITH_TIME | import("./const").MODE.SIGN_WITHOUT_USER | import("./const").MODE.SIGN_UUID | import("./const").MODE.SIGN_UUID_WITHOUT_USER) | undefined) => string;
24
- getApiPath: (url: string) => string | undefined;
25
- };
26
- RSAEncrypt: (value: string, publicKey: string, handle?: any) => any;
27
- RSADecrypt: (value: string, privKey: string, handle?: any) => any;
28
- AESEncrypt: (value: any, aesKey: string, handle?: any) => any;
29
- AESDecrypt: (value: string, aesKey: string, handle?: any) => any;
30
- DESEncrypt: (value: string, aesKey: string, handle?: any) => any;
31
- DESDecrypt: (value: string, aesKey: string, handle?: any) => any;
32
- KEYS: {
33
- signKey: string;
34
- rsaPublicKey: string | undefined;
35
- rsaPrivKey: string | undefined;
36
- aesKey: string;
37
- desKey: string;
38
- };
39
- checkToken: (arg0: string, arg1: string) => boolean;
40
- generateToken: (pageId: any) => string;
41
- };
42
- export default _default;
1
+ import security from '@lingxiteam/security';
2
+ export default security;
@@ -4,29 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _httpEncryption = _interopRequireDefault(require("./httpEncryption"));
8
- var _sign = _interopRequireDefault(require("./encipher/sign"));
9
- var _rsa = require("./encipher/rsa");
10
- var _aes = require("./encipher/aes");
11
- var _des = require("./encipher/des");
12
- var _token = require("./encipher/token");
13
- var _const = _interopRequireDefault(require("./const"));
7
+ var _security = _interopRequireDefault(require("@lingxiteam/security"));
14
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
9
  window.lingxiSecurity = {
16
- httpEncryption: _httpEncryption.default,
17
- sign: _sign.default
18
- };
19
- var _default = {
20
- httpEncryption: _httpEncryption.default,
21
- sign: _sign.default,
22
- RSAEncrypt: _rsa.RSAEncrypt,
23
- RSADecrypt: _rsa.RSADecrypt,
24
- AESEncrypt: _aes.AESEncrypt,
25
- AESDecrypt: _aes.AESDecrypt,
26
- DESEncrypt: _des.DESEncrypt,
27
- DESDecrypt: _des.DESDecrypt,
28
- KEYS: _const.default,
29
- checkToken: _token.checkToken,
30
- generateToken: _token.generateToken
10
+ httpEncryption: _security.default.httpEncryption
31
11
  };
12
+ // @ts-ignore
13
+ _security.default.httpEncryption.buildXSignUrl = _security.default.createHttpSignWithUrl;
14
+ // @ts-ignore
15
+ _security.default.httpEncryption.createHttpSignStr = _security.default.createHttpSignStr;
16
+ var _default = _security.default;
32
17
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingxiteam/assets",
3
- "version": "3.5.1-alpha.6",
3
+ "version": "3.5.1-alpha.8",
4
4
  "description": "灵犀低代码平台移动端 - 工具类",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -38,6 +38,7 @@
38
38
  },
39
39
  "gitHead": "bcd338198e2c14459538542d10600ab03abc92f2",
40
40
  "dependencies": {
41
+ "@lingxiteam/security": "1.2.9-rc.1",
41
42
  "crypto-js": "^4.2.0",
42
43
  "jsencrypt": "^3.1.0",
43
44
  "tinycolor2": "^1.6.0",
@@ -1,27 +0,0 @@
1
- export declare const securityHeaderKey = "XA-TYPE";
2
- export declare const defaultSignKey = "X-SIGN";
3
- export declare enum MODE {
4
- SIGN_KEY = "signKey",
5
- SIGN = "1.0",
6
- SIGN_WITH_TIME = "1.1",
7
- SIGN_WITHOUT_USER = "1.1.1",
8
- SIGN_UUID = "1.2",
9
- SIGN_UUID_WITHOUT_USER = "1.2.1",
10
- RSA = "2.0",
11
- AES = "3.0",
12
- DES = "4.0"
13
- }
14
- export declare const SIGN_MODE: MODE[];
15
- export declare const signKey: string;
16
- export declare const rsaPublicKey: string | undefined;
17
- export declare const rsaPrivKey: string | undefined;
18
- export declare const aesKey: string;
19
- export declare const desKey: string;
20
- declare const _default: {
21
- signKey: string;
22
- rsaPublicKey: string | undefined;
23
- rsaPrivKey: string | undefined;
24
- aesKey: string;
25
- desKey: string;
26
- };
27
- export default _default;
@@ -1,29 +0,0 @@
1
- var defaultAESKey = 'd86d7bab3d6ac01a';
2
- var defaultDESKey = '91THRABY';
3
- export var securityHeaderKey = 'XA-TYPE';
4
- export var defaultSignKey = 'X-SIGN';
5
- export var MODE;
6
- (function (MODE) {
7
- MODE["SIGN_KEY"] = "signKey";
8
- MODE["SIGN"] = "1.0";
9
- MODE["SIGN_WITH_TIME"] = "1.1";
10
- MODE["SIGN_WITHOUT_USER"] = "1.1.1";
11
- MODE["SIGN_UUID"] = "1.2";
12
- MODE["SIGN_UUID_WITHOUT_USER"] = "1.2.1";
13
- MODE["RSA"] = "2.0";
14
- MODE["AES"] = "3.0";
15
- MODE["DES"] = "4.0"; // DES参数加密
16
- })(MODE || (MODE = {}));
17
- export var SIGN_MODE = [MODE.SIGN_KEY, MODE.SIGN, MODE.SIGN_WITH_TIME, MODE.SIGN_WITHOUT_USER, MODE.SIGN_UUID, MODE.SIGN_UUID_WITHOUT_USER];
18
- export var signKey = process.env.LINGXI_HTTP_SIGN_HEADER_KEY || process.env.REACT_APP_HTTP_SIGN_HEADER_KEY || process.env.UMI_APP_HTTP_SIGN_HEADER_KEY || process.env.FISHX_APP_HTTP_SIGN_HEADER_KEY || defaultSignKey;
19
- export var rsaPublicKey = process.env.LINGXI_HTTP_RSA_PUBLIC_KEY || process.env.REACT_APP_HTTP_RSA_PUBLIC_KEY || process.env.UMI_APP_HTTP_RSA_PUBLIC_KEY || process.env.FISHX_APP_HTTP_RSA_PUBLIC_KEY;
20
- export var rsaPrivKey = process.env.LINGXI_HTTP_RSA_PRIV_KEY || process.env.REACT_APP_HTTP_RSA_PRIV_KEY || process.env.UMI_APP_HTTP_RSA_PRIV_KEY || process.env.FISHX_APP_HTTP_RSA_PRIV_KEY;
21
- export var aesKey = process.env.LINGXI_HTTP_AES_KEY || process.env.REACT_APP_HTTP_AES_KEY || process.env.UMI_APP_HTTP_AES_KEY || process.env.FISHX_APP_HTTP_AES_KEY || defaultAESKey;
22
- export var desKey = process.env.LINGXI_HTTP_DES_KEY || process.env.REACT_APP_HTTP_DES_KEY || process.env.UMI_APP_HTTP_DES_KEY || process.env.FISHX_APP_HTTP_DES_KEY || defaultDESKey;
23
- export default {
24
- signKey: signKey,
25
- rsaPublicKey: rsaPublicKey,
26
- rsaPrivKey: rsaPrivKey,
27
- aesKey: aesKey,
28
- desKey: desKey
29
- };
@@ -1,2 +0,0 @@
1
- export declare const AESEncrypt: (value: any, aesKey: string, handle?: any) => any;
2
- export declare const AESDecrypt: (value: string, aesKey: string, handle?: any) => any;
@@ -1,26 +0,0 @@
1
- import CryptoJS from 'crypto-js';
2
- export var AESEncrypt = function AESEncrypt(value, aesKey, handle) {
3
- if (typeof handle === 'function') {
4
- return handle(value, aesKey, CryptoJS);
5
- }
6
- var key = CryptoJS.enc.Utf8.parse(aesKey);
7
- var ciphertext = CryptoJS.enc.Utf8.parse(value);
8
- var encrypted = CryptoJS.AES.encrypt(ciphertext, key, {
9
- mode: CryptoJS.mode.ECB,
10
- padding: CryptoJS.pad.Pkcs7
11
- });
12
- return encrypted.toString();
13
- };
14
- export var AESDecrypt = function AESDecrypt(value, aesKey, handle) {
15
- if (typeof handle === 'function') {
16
- return handle(value, aesKey, CryptoJS);
17
- }
18
- var key = CryptoJS.enc.Utf8.parse(aesKey);
19
- var ciphertext = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Base64.parse(value));
20
- // const ciphertext = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Base64.parse(CryptoJS.enc.Utf8.parse(value).toString(CryptoJS.enc.Utf8)));
21
- var encrypted = CryptoJS.AES.decrypt(ciphertext, key, {
22
- mode: CryptoJS.mode.ECB,
23
- padding: CryptoJS.pad.Pkcs7
24
- });
25
- return encrypted.toString(CryptoJS.enc.Utf8);
26
- };
@@ -1,2 +0,0 @@
1
- export declare const DESEncrypt: (value: string, aesKey: string, handle?: any) => any;
2
- export declare const DESDecrypt: (value: string, aesKey: string, handle?: any) => any;
@@ -1,25 +0,0 @@
1
- import CryptoJS from 'crypto-js';
2
- export var DESEncrypt = function DESEncrypt(value, aesKey, handle) {
3
- if (typeof handle === 'function') {
4
- return handle(value, aesKey, CryptoJS);
5
- }
6
- var key = CryptoJS.enc.Utf8.parse(aesKey);
7
- var ciphertext = CryptoJS.enc.Utf8.parse(value);
8
- var encrypted = CryptoJS.DES.encrypt(ciphertext, key, {
9
- mode: CryptoJS.mode.ECB,
10
- padding: CryptoJS.pad.Pkcs7
11
- });
12
- return encrypted.toString();
13
- };
14
- export var DESDecrypt = function DESDecrypt(value, aesKey, handle) {
15
- if (typeof handle === 'function') {
16
- return handle(value, aesKey, CryptoJS);
17
- }
18
- var key = CryptoJS.enc.Utf8.parse(aesKey);
19
- var ciphertext = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Base64.parse(value));
20
- var encrypted = CryptoJS.DES.decrypt(ciphertext, key, {
21
- mode: CryptoJS.mode.ECB,
22
- padding: CryptoJS.pad.Pkcs7
23
- });
24
- return encrypted.toString(CryptoJS.enc.Utf8);
25
- };
@@ -1,2 +0,0 @@
1
- export declare const RSAEncrypt: (value: string, publicKey: string, handle?: any) => any;
2
- export declare const RSADecrypt: (value: string, privKey: string, handle?: any) => any;
@@ -1,17 +0,0 @@
1
- import JSEncrypt from 'jsencrypt';
2
- export var RSAEncrypt = function RSAEncrypt(value, publicKey, handle) {
3
- if (typeof handle === 'function') {
4
- return handle(value, publicKey, JSEncrypt);
5
- }
6
- var encryptor = new JSEncrypt();
7
- encryptor.setPublicKey(publicKey);
8
- return encryptor.encrypt(value);
9
- };
10
- export var RSADecrypt = function RSADecrypt(value, privKey, handle) {
11
- if (typeof handle === 'function') {
12
- return handle(value, privKey, JSEncrypt);
13
- }
14
- var decrypt = new JSEncrypt();
15
- decrypt.setPrivateKey(privKey);
16
- return decrypt.decrypt(value);
17
- };
@@ -1,10 +0,0 @@
1
- import { MODE } from '../const';
2
- type signVersionType = MODE.SIGN | MODE.SIGN_KEY | MODE.SIGN_WITHOUT_USER | MODE.SIGN_WITH_TIME | MODE.SIGN_UUID | MODE.SIGN_UUID_WITHOUT_USER;
3
- export declare const getApiPath: (url: string) => string | undefined;
4
- export declare const createHttpSignStr: (url: string, options: any, version?: signVersionType) => string;
5
- export declare const buildXSignUrl: (url: string, options?: any, version?: signVersionType) => string;
6
- declare const _default: {
7
- createHttpSignStr: (url: string, options: any, version?: signVersionType | undefined) => string;
8
- getApiPath: (url: string) => string | undefined;
9
- };
10
- export default _default;
@@ -1,148 +0,0 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
5
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
6
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
7
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
11
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
12
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
- /* eslint-disable no-case-declarations */
14
- import { SHA256 } from 'crypto-js';
15
- import { v4 as uuidv4 } from 'uuid';
16
- import { obj2QueryString, decodeQueryString } from '../../utils/url';
17
- import CookieUtil from '../../utils/cookieUtil';
18
- import { signKey, MODE, aesKey, securityHeaderKey } from '../const';
19
- import { AESEncrypt } from './aes';
20
- var SIGN_KEY = process.env.LING_XI_HTTP_SIGN_KEY || 'zrT5bi2escXilaH1fs653uZiH9RWfzCS';
21
- // 注意:修改此文件请跑测试用例, npm run test
22
- // 1、签名算法:
23
- // 通过对url、参数、秘钥拼接成字符串,然后对字符串使用算法SHA-256得到64个字符串,放到header, X-SIGN=XXXXXXX。
24
- // 2、签名字符串拼接规则:
25
- // a.get 请求:url+"#"+header+"#"+参数+"#"+秘钥
26
- // b.post 请求:url+"#"+header+"#"+body+"#"秘钥
27
- // 参数说明:
28
- // ● 如果其中的变量为空,则为空字符串。
29
- // ● url :不包含参数,(2022.08.08 更改为apiName)
30
- // ● header :取X-开头的header,或者APP-ID,多个则逗号分隔拼接。比如X-AA=a;APP-ID=88888
31
- // ● get 参数:就是url 问号后面的串
32
- // ● body:post 请求体
33
- /**
34
- * 组装X-SIGN请求头
35
- * @param {请求地址} url 接口请求地址
36
- * @param {请求参数} options
37
- * @returns
38
- */
39
- // 由于X-B 的规则可能被业务网关使用,并往请求头增加内容,导致前后端加密不一致
40
- // 2022.08.09 使用以下3个固定值 + X-LX-*匹配 方式
41
- var hKeys = ['X-B-AUTH', 'X-B-TARGET-ID', 'APP-ID'];
42
- var userKeyInCookie = window.lxDataSaltCode || process.env.LING_XI_USER_KEY_IN_COOKIE || 'X-LX-N-ID';
43
- // 配置指定接口前缀,2023-03-16规则调整,不需要使用
44
- // const apiPrefix =
45
- // process.env.LING_XI_HTTP_SIGN_API_PERFIX ||
46
- // process.env.REACT_APP_HTTP_SIGN_API_PERFIX ||
47
- // process.env.UMI_APP_HTTP_SIGN_API_PERFIX ||
48
- // process.env.FISHX_APP_HTTP_SIGN_API_PERFIX ||
49
- // 'portal,asset,rhin,lcdp,ncdp,flow,app';
50
- // 获取接口路径,2023-03-16调整,只取最后一级
51
- export var getApiPath = function getApiPath(url) {
52
- return url.split('/').pop();
53
- };
54
- export var createHttpSignStr = function createHttpSignStr(url, options, version) {
55
- var _window$lxClientTimeD;
56
- if (!url || !options || !options.method) {
57
- return '';
58
- }
59
- var method = options.method,
60
- headers = options.headers,
61
- body = options.body,
62
- search = options.search;
63
- var signVersion = version || window.lxSecurityMode || MODE.SIGN_WITH_TIME;
64
- // 获取参数1: 接口名称
65
- var mixUrl = url;
66
- if (search && search instanceof Object) {
67
- mixUrl += (url.indexOf('?') !== -1 ? '&' : '?') + obj2QueryString(search);
68
- }
69
- var _mixUrl$split = mixUrl.split('?'),
70
- _mixUrl$split2 = _slicedToArray(_mixUrl$split, 2),
71
- urlPath = _mixUrl$split2[0],
72
- _mixUrl$split2$ = _mixUrl$split2[1],
73
- urlSearch = _mixUrl$split2$ === void 0 ? '' : _mixUrl$split2$;
74
- var apiPath = getApiPath(urlPath);
75
- // 获取参数2: 请求头部参数
76
- var headerParams = '';
77
- var headersKeyArr = [];
78
- if (headers) {
79
- Object.keys(headers).forEach(function (key) {
80
- if (key.startsWith('X-LX-') || hKeys.includes(key)) {
81
- headersKeyArr.push("".concat(key.toLowerCase(), "=").concat(headers[key]));
82
- }
83
- });
84
- }
85
- headerParams = headersKeyArr.sort().join(';');
86
- // 获取参数3: 请求参数
87
- var params = '';
88
- if (method.toLowerCase() === 'get') {
89
- // 为保证与后端值一致此处需要将数据进行解码
90
- params = decodeQueryString(urlSearch);
91
- } else {
92
- params = _typeof(body) === 'object' ? JSON.stringify(body) : body;
93
- }
94
- // 获取参数4: 用户id
95
- var userId = CookieUtil.get(userKeyInCookie) || '';
96
- // 签名内容
97
- var content = '';
98
- // 签名结果
99
- var result = '';
100
- switch (signVersion) {
101
- case MODE.SIGN:
102
- case MODE.SIGN_KEY:
103
- content = [apiPath, headerParams, params, userId, SIGN_KEY].join('#');
104
- result = SHA256(content).toString();
105
- break;
106
- case MODE.SIGN_WITH_TIME:
107
- case MODE.SIGN_WITHOUT_USER:
108
- // eslint-disable-next-line no-case-declarations
109
- var deviation = (_window$lxClientTimeD = window.lxClientTimeDeviation) !== null && _window$lxClientTimeD !== void 0 ? _window$lxClientTimeD : 0;
110
- var now = Date.now() - deviation;
111
- content = [apiPath, headerParams, params, signVersion === MODE.SIGN_WITHOUT_USER ? '' : userId, SIGN_KEY, now].join('#');
112
- result = [SHA256(content).toString(), now, deviation].join('.');
113
- break;
114
- case MODE.SIGN_UUID:
115
- case MODE.SIGN_UUID_WITHOUT_USER:
116
- var uuid = uuidv4();
117
- content = [apiPath, headerParams, params, signVersion === MODE.SIGN_UUID_WITHOUT_USER ? '' : userId, SIGN_KEY, uuid].join('#');
118
- result = AESEncrypt([SHA256(content).toString(), uuid].join('.'), aesKey);
119
- break;
120
- default:
121
- break;
122
- }
123
- if (typeof window !== 'undefined' && (window.lxDebug || window.localStorage.getItem('lxDebug'))) {
124
- console.log(" --- signDebug(".concat(signVersion, ") ---"));
125
- console.log('url', url);
126
- console.log('str', content);
127
- console.log('sign', result);
128
- }
129
- // 返回约定签名
130
- return result;
131
- };
132
- // 由于(img、script)无法进行处理请求头,将签名参数x-sign放到url参数里
133
- export var buildXSignUrl = function buildXSignUrl(url) {
134
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
135
- var version = arguments.length > 2 ? arguments[2] : undefined;
136
- if (!url) {
137
- return '';
138
- }
139
- var signVersion = version || window.lxSecurityMode || MODE.SIGN_WITH_TIME;
140
- var signStr = createHttpSignStr(url, _objectSpread({
141
- method: 'GET'
142
- }, options), signVersion);
143
- return "".concat(url).concat(url.includes('?') ? '&' : '?').concat(signKey, "=").concat(signStr, "&").concat(securityHeaderKey, "=").concat(signVersion);
144
- };
145
- export default {
146
- createHttpSignStr: createHttpSignStr,
147
- getApiPath: getApiPath
148
- };
@@ -1,3 +0,0 @@
1
- declare const generateToken: (pageId: any) => string;
2
- declare const checkToken: (arg0: string, arg1: string) => boolean;
3
- export { checkToken, generateToken, };
@@ -1,30 +0,0 @@
1
- import AES from 'crypto-js/aes';
2
- import encUtf8 from 'crypto-js/enc-utf8';
3
- import MD5 from 'crypto-js/md5';
4
- import CryptoJS from 'crypto-js';
5
- var generateToken = function generateToken(pageId) {
6
- var tokenStr = "".concat(MD5(pageId).toString(), ".").concat(new Date().getTime());
7
- return AES.encrypt(tokenStr, 'Lixing666', {
8
- iv: encUtf8.parse('3468546098617269')
9
- }).toString();
10
- };
11
- var checkToken = function checkToken(token, pageId) {
12
- var result = true;
13
- if (token) {
14
- var bytes = CryptoJS.AES.decrypt(token, 'Lixing666', {
15
- iv: '3468546098617269'
16
- });
17
- var decryptedData = bytes.toString(CryptoJS.enc.Utf8);
18
- if (decryptedData) {
19
- // 加密字符串: MD5(pageId) + '.' + Timestamp + '.' + ‘版本(保留)’
20
- var tokenarr = decryptedData.split('.');
21
- var pagemd5 = CryptoJS.MD5(pageId).toString();
22
- // Token验证:第一段相同,且Timestamp和当前时间的差距在1小时(3600秒 = 3600000毫秒)内
23
- if (tokenarr.length >= 2 && tokenarr[0] === pagemd5 && new Date(parseInt(tokenarr[1], 10)).getTime() - new Date().getTime() <= 3600000) {
24
- result = true;
25
- }
26
- }
27
- }
28
- return result;
29
- };
30
- export { checkToken, generateToken };
@@ -1,9 +0,0 @@
1
- declare const fetch: (url: any, fetchOptions?: any, config?: {
2
- mode?: string;
3
- signKeyOptions?: any;
4
- aesOptions?: any;
5
- desOptions?: any;
6
- rsaOptions?: any;
7
- debug?: boolean;
8
- }) => Promise<Response>;
9
- export default fetch;