module-develop-kit 1.3.1 → 1.4.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.
Files changed (45) hide show
  1. package/dist/commonjs-virtual-dir/browser.js +5 -2
  2. package/dist/commonjs-virtual-dir/browser2.js +2 -5
  3. package/dist/commonjs-virtual-dir/index.js +5 -3
  4. package/dist/commonjs-virtual-dir/index2.js +3 -5
  5. package/dist/commonjs-virtual-dir/index3.js +2 -5
  6. package/dist/commonjs-virtual-dir/index4.js +4 -2
  7. package/dist/commonjs-virtual-dir/index5.js +2 -2
  8. package/dist/main.d.ts +74 -28
  9. package/dist/main.js +40 -35
  10. package/dist/src/outside-call/utils.js +1 -1
  11. package/dist/src/shield/crypto/const.js +2 -2
  12. package/dist/src/shield/crypto/sm2.js +4 -4
  13. package/dist/src/shield/crypto/util.js +11 -23
  14. package/dist/src/shield/gcm-crypto/gcm.service.js +29 -0
  15. package/dist/src/shield/gcm-crypto/hex.js +18 -0
  16. package/dist/src/shield/gcm-crypto/index.js +40 -0
  17. package/dist/src/shield/gcm-crypto/init.js +61 -0
  18. package/dist/src/shield/gcm-crypto/string.js +10 -0
  19. package/dist/src/utils/is.js +4 -0
  20. package/dist/types/axios.d.ts +16 -0
  21. package/dist/vendor/@noble/ciphers/esm/_polyval.js +116 -0
  22. package/dist/vendor/@noble/ciphers/esm/utils.js +68 -0
  23. package/dist/vendor/@noble/curves/esm/abstract/curve.js +203 -0
  24. package/dist/vendor/@noble/curves/esm/abstract/modular.js +240 -0
  25. package/dist/vendor/@noble/curves/esm/abstract/utils.js +10 -0
  26. package/dist/vendor/@noble/curves/esm/abstract/weierstrass.js +791 -0
  27. package/dist/vendor/@noble/curves/esm/utils.js +154 -0
  28. package/dist/vendor/@noble/hashes/esm/crypto.js +4 -0
  29. package/dist/vendor/@noble/hashes/esm/hmac.js +45 -0
  30. package/dist/vendor/@noble/hashes/esm/utils.js +112 -0
  31. package/dist/vendor/@tokenizer/inflate/lib/ZipHandler.js +1 -1
  32. package/dist/vendor/debug/src/browser.js +1 -1
  33. package/dist/vendor/ieee754/index.js +1 -1
  34. package/dist/vendor/sdp-transform/lib/index.js +1 -1
  35. package/dist/vendor/sm-crypto-v2/dist/index.js +1004 -0
  36. package/dist/vendor/token-types/lib/index.js +1 -1
  37. package/package.json +3 -2
  38. package/dist/commonjs-virtual-dir/index7.js +0 -4
  39. package/dist/commonjs-virtual-dir/index8.js +0 -4
  40. package/dist/src/shield/crypto/index.js +0 -53
  41. package/dist/src/shield/crypto/sm4.js +0 -15
  42. package/dist/vendor/base64-js/index.js +0 -52
  43. package/dist/vendor/gm-crypt/index.js +0 -10
  44. package/dist/vendor/gm-crypt/src/crypt.js +0 -60
  45. package/dist/vendor/gm-crypt/src/sm4.js +0 -513
@@ -1,4 +1,7 @@
1
- var r = { exports: {} };
1
+ import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
2
+ import { __require as e } from "../vendor/debug/src/browser.js";
3
+ var o = e();
4
+ const i = /* @__PURE__ */ r(o);
2
5
  export {
3
- r as __module
6
+ i as default
4
7
  };
@@ -1,7 +1,4 @@
1
- import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
2
- import { __require as e } from "../vendor/debug/src/browser.js";
3
- var o = e();
4
- const i = /* @__PURE__ */ r(o);
1
+ var r = { exports: {} };
5
2
  export {
6
- i as default
3
+ r as __module
7
4
  };
@@ -1,5 +1,7 @@
1
- import { __require as r } from "../vendor/sm-crypto/src/index.js";
2
- var s = r();
1
+ import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
2
+ import { __require as o } from "../vendor/sdp-transform/lib/index.js";
3
+ var t = o();
4
+ const a = /* @__PURE__ */ r(t);
3
5
  export {
4
- s
6
+ a as default
5
7
  };
@@ -1,7 +1,5 @@
1
- import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
2
- import { __require as o } from "../vendor/sdp-transform/lib/index.js";
3
- var t = o();
4
- const a = /* @__PURE__ */ r(t);
1
+ import { __require as r } from "../vendor/sm-crypto/src/index.js";
2
+ var s = r();
5
3
  export {
6
- a as default
4
+ s
7
5
  };
@@ -1,5 +1,2 @@
1
- import { __require as r } from "../vendor/gm-crypt/index.js";
2
- var p = r();
3
- export {
4
- p as g
5
- };
1
+ import { __require as e } from "../vendor/ieee754/index.js";
2
+ e();
@@ -1,2 +1,4 @@
1
- import { __require as e } from "../vendor/ieee754/index.js";
2
- e();
1
+ var r = {};
2
+ export {
3
+ r as __exports
4
+ };
@@ -1,4 +1,4 @@
1
- var r = {};
1
+ var e = {};
2
2
  export {
3
- r as __exports
3
+ e as __exports
4
4
  };
package/dist/main.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /// <reference path="./types/axios.d.ts" />
2
+
3
+ import { AxiosResponse } from 'axios';
4
+ import { InternalAxiosRequestConfig } from 'axios';
5
+ import { Plugin as Plugin_2 } from 'vue';
1
6
  import { Ref } from 'vue';
2
7
  import { supportedExtensions } from 'file-type';
3
8
  import { supportedMimeTypes } from 'file-type';
@@ -22,20 +27,6 @@ export declare const ALLOWED_FILE_TYPES: {
22
27
  readonly model: Set<string>;
23
28
  };
24
29
 
25
- /**
26
- * 防重放攻击策略
27
- * @param uid
28
- * @param salt
29
- * @param ts
30
- * @param data
31
- * @param headers
32
- */
33
- export declare function antiReplyAttackStrategy({ uid, salt, ts, data, ...headers }: IAntiReplyAttackStrategy): {
34
- "X-Sign-Timestamp": string;
35
- "X-Sign-Nonce": string;
36
- "X-Sign-Client": string;
37
- };
38
-
39
30
  /**
40
31
  * 用于格式化输出会话过程中的日志信息
41
32
  */
@@ -122,9 +113,11 @@ export declare enum ECallStatus {
122
113
 
123
114
  declare enum EHeaderKey {
124
115
  publicKey = "X-Public-Key",
116
+ gcmPublicKey = "X-Client-SM2-Public-Key",
125
117
  encryptIv = "X-Encrypted-Iv",
126
118
  encryptKey = "X-Encrypted-Key",
127
119
  encryptIvLow = "x-encrypted-iv",
120
+ encryptTag = "X-Encrypted-Tag",
128
121
  encryptKeyLow = "x-encrypted-key"
129
122
  }
130
123
 
@@ -172,6 +165,11 @@ export declare interface EventBusProps {
172
165
 
173
166
  declare type EventFnc = (...args: any) => void;
174
167
 
168
+ /**
169
+ * gcm-crypto
170
+ */
171
+ export declare const gcmCrypto: Plugin_2<IGcmCryptoOptions>;
172
+
175
173
  /**
176
174
  * 安全的解析html内容 防止xss攻击
177
175
  * @param input 输入的html内容
@@ -315,6 +313,39 @@ export declare interface IFileDetectionResult {
315
313
  mimeMatches?: boolean;
316
314
  }
317
315
 
316
+ export declare interface IGcmCryptoOptions {
317
+ /**
318
+ * 获取公钥 API
319
+ */
320
+ getPublicKeyApi: () => Promise<string>;
321
+ /**
322
+ * 是否加密
323
+ */
324
+ isEncrypt: boolean;
325
+ }
326
+
327
+ /**
328
+ * 初始化公钥
329
+ */
330
+ export declare const initPublicKey: () => Promise<void>;
331
+
332
+ export declare interface IResponseDataEncryptionReturn {
333
+ /**
334
+ * 响应头
335
+ */
336
+ headers: {
337
+ [EHeaderKey.encryptIv]: string;
338
+ [EHeaderKey.encryptTag]: string;
339
+ [EHeaderKey.encryptKey]: string;
340
+ };
341
+ /**
342
+ * 加密后的数据
343
+ */
344
+ data: {
345
+ body: string;
346
+ };
347
+ }
348
+
318
349
  export declare interface IResponseDataEncryptionStep {
319
350
  data: string;
320
351
  headers: Record<EHeaderKey, string>;
@@ -387,28 +418,41 @@ export declare interface IUrlSanitizeOptions {
387
418
  strictMode?: boolean;
388
419
  }
389
420
 
421
+ /**
422
+ * 添加请求前加密回调
423
+ * @param callback
424
+ */
425
+ export declare const requestDataBeforeGcmCrypto: (callback: TRequestBeforeCryptoCallBack) => void;
426
+
390
427
  /**
391
428
  * 请求数据加密
392
429
  * @param publicKey 公钥
393
- * @param _data 数据
430
+ * @param data 原始数据
431
+ * @param uri 当前请求的路径
394
432
  */
395
- export declare function requestDataEncryption(publicKey: string, _data?: TData): {
396
- headers: {
397
- "X-Encrypted-Iv": string;
398
- "X-Encrypted-Key": string;
399
- };
400
- data: {
401
- body: string;
402
- };
403
- };
433
+ export declare const requestDataEncryption: <T>(publicKey: string, data: T, uri: string) => IResponseDataEncryptionReturn;
434
+
435
+ /**
436
+ * gcm 加密请求拦截器
437
+ */
438
+ export declare const requestDataGcmCryptoInterceptor: <T>(config: InternalAxiosRequestConfig<T>) => InternalAxiosRequestConfig<T>;
404
439
 
405
440
  /**
406
441
  * 响应数据解密
407
- * @param stepCb
442
+ * @param sm4Key 解密后的 SM4 密钥
443
+ * @param data
444
+ * @param uri
445
+ * @param headers
408
446
  */
409
- export declare function responseDataEncryption<T>(stepCb: (_headers: {
410
- [EHeaderKey.publicKey]: string;
411
- }) => Promise<IResponseDataEncryptionStep>): Promise<T>;
447
+ export declare const responseDataDecryption: (sm4Key: string, data: string, uri: string, headers: IResponseDataEncryptionReturn["headers"]) => any;
448
+
449
+ /**
450
+ * gcm 解密响应
451
+ * @param response
452
+ */
453
+ export declare const responseDataGcmCryptoInterceptor: <T extends {
454
+ data: unknown;
455
+ }>(response: AxiosResponse<T>) => AxiosResponse<T, any, {}>;
412
456
 
413
457
  /**
414
458
  * 消毒 URL,返回安全的 URL 或替代 URL
@@ -500,6 +544,8 @@ export declare type TNullable<T> = T | null;
500
544
 
501
545
  export declare type TObj<K extends keyof any = string, T = any> = Record<K, T>;
502
546
 
547
+ declare type TRequestBeforeCryptoCallBack = (config: InternalAxiosRequestConfig) => void;
548
+
503
549
  export declare type TUndefinable<T> = T | undefined;
504
550
 
505
551
  /**
package/dist/main.js CHANGED
@@ -1,41 +1,46 @@
1
- import { useCall as o } from "./src/outside-call/index.js";
1
+ import { useCall as r } from "./src/outside-call/index.js";
2
2
  import { createCosFileName as i } from "./src/shield/create-cos-file-name.js";
3
- import { antiReplyAttackStrategy as a, requestDataEncryption as E, responseDataEncryption as l } from "./src/shield/crypto/index.js";
4
- import { ALLOWED_FILE_MIMES as n, ALLOWED_FILE_TYPES as m, detectFileByExtension as x, detectFileByMime as f, detectionFilesByExtension as S, detectionFilesByMime as d, isValidDocument as _, isValidFile as c, isValidImage as y, isValidVideo as u } from "./src/shield/file-detection.js";
5
- import { htmlSanitize as M } from "./src/shield/html-sanitize.js";
3
+ import { ALLOWED_FILE_MIMES as p, ALLOWED_FILE_TYPES as a, detectFileByExtension as m, detectFileByMime as l, detectionFilesByExtension as n, detectionFilesByMime as E, isValidDocument as c, isValidFile as x, isValidImage as f, isValidVideo as y } from "./src/shield/file-detection.js";
4
+ import { requestDataEncryption as u, responseDataDecryption as D } from "./src/shield/gcm-crypto/index.js";
5
+ import { htmlSanitize as C } from "./src/shield/html-sanitize.js";
6
6
  import { startNoDebugger as I } from "./src/shield/no-debugger.js";
7
- import { isUrlSafe as g, sanitizeUrl as A, sanitizeUrls as C } from "./src/shield/url-sanitize.js";
8
- import { EventBus as B } from "./src/utils/eventBus.js";
9
- import { CallLogger as O } from "./src/outside-call/utils.js";
10
- import { ECallStatus as T, EMIT_EVENT_NAME as U, SIP_CODE_MESSAGE as z, SIP_ERROR_CAUSES as P } from "./src/outside-call/constants.js";
11
- import { supportedExtensions as b, supportedMimeTypes as h } from "./vendor/file-type/source/index.js";
7
+ import { isUrlSafe as M, sanitizeUrl as L, sanitizeUrls as g } from "./src/shield/url-sanitize.js";
8
+ import { EventBus as V } from "./src/utils/eventBus.js";
9
+ import { CallLogger as G } from "./src/outside-call/utils.js";
10
+ import { ECallStatus as O, EMIT_EVENT_NAME as P, SIP_CODE_MESSAGE as T, SIP_ERROR_CAUSES as U } from "./src/outside-call/constants.js";
11
+ import { supportedExtensions as z, supportedMimeTypes as R } from "./vendor/file-type/source/index.js";
12
+ import { gcmCrypto as W, initPublicKey as h, requestDataBeforeGcmCrypto as v, requestDataGcmCryptoInterceptor as K, responseDataGcmCryptoInterceptor as Y } from "./src/shield/gcm-crypto/init.js";
12
13
  export {
13
- n as ALLOWED_FILE_MIMES,
14
- m as ALLOWED_FILE_TYPES,
15
- O as CallLogger,
16
- T as ECallStatus,
17
- U as EMIT_EVENT_NAME,
18
- B as EventBus,
19
- z as SIP_CODE_MESSAGE,
20
- P as SIP_ERROR_CAUSES,
21
- a as antiReplyAttackStrategy,
14
+ p as ALLOWED_FILE_MIMES,
15
+ a as ALLOWED_FILE_TYPES,
16
+ G as CallLogger,
17
+ O as ECallStatus,
18
+ P as EMIT_EVENT_NAME,
19
+ V as EventBus,
20
+ T as SIP_CODE_MESSAGE,
21
+ U as SIP_ERROR_CAUSES,
22
22
  i as createCosFileName,
23
- x as detectFileByExtension,
24
- f as detectFileByMime,
25
- S as detectionFilesByExtension,
26
- d as detectionFilesByMime,
27
- M as htmlSanitize,
28
- g as isUrlSafe,
29
- _ as isValidDocument,
30
- c as isValidFile,
31
- y as isValidImage,
32
- u as isValidVideo,
33
- E as requestDataEncryption,
34
- l as responseDataEncryption,
35
- A as sanitizeUrl,
36
- C as sanitizeUrls,
23
+ m as detectFileByExtension,
24
+ l as detectFileByMime,
25
+ n as detectionFilesByExtension,
26
+ E as detectionFilesByMime,
27
+ W as gcmCrypto,
28
+ C as htmlSanitize,
29
+ h as initPublicKey,
30
+ M as isUrlSafe,
31
+ c as isValidDocument,
32
+ x as isValidFile,
33
+ f as isValidImage,
34
+ y as isValidVideo,
35
+ v as requestDataBeforeGcmCrypto,
36
+ u as requestDataEncryption,
37
+ K as requestDataGcmCryptoInterceptor,
38
+ D as responseDataDecryption,
39
+ Y as responseDataGcmCryptoInterceptor,
40
+ L as sanitizeUrl,
41
+ g as sanitizeUrls,
37
42
  I as startNoDebugger,
38
- b as supportedExtensions,
39
- h as supportedMimeTypes,
40
- o as useCall
43
+ z as supportedExtensions,
44
+ R as supportedMimeTypes,
45
+ r as useCall
41
46
  };
@@ -1,4 +1,4 @@
1
- import c from "../../commonjs-virtual-dir/index2.js";
1
+ import c from "../../commonjs-virtual-dir/index.js";
2
2
  const g = {
3
3
  log(e, ...r) {
4
4
  console.log(`%c【${(/* @__PURE__ */ new Date()).toLocaleString()}】`, "color: green; font-weight: bold;", e, ...r);
@@ -1,4 +1,4 @@
1
- var p = /* @__PURE__ */ ((c) => (c.publicKey = "X-Public-Key", c.encryptIv = "X-Encrypted-Iv", c.encryptKey = "X-Encrypted-Key", c.encryptIvLow = "x-encrypted-iv", c.encryptKeyLow = "x-encrypted-key", c))(p || {});
1
+ var t = /* @__PURE__ */ ((c) => (c.publicKey = "X-Public-Key", c.gcmPublicKey = "X-Client-SM2-Public-Key", c.encryptIv = "X-Encrypted-Iv", c.encryptKey = "X-Encrypted-Key", c.encryptIvLow = "x-encrypted-iv", c.encryptTag = "X-Encrypted-Tag", c.encryptKeyLow = "x-encrypted-key", c))(t || {});
2
2
  export {
3
- p as EHeaderKey
3
+ t as EHeaderKey
4
4
  };
@@ -1,7 +1,7 @@
1
- import { s as o } from "../../../commonjs-virtual-dir/index.js";
2
- const c = o.sm2.generateKeyPairHex, s = 1, a = (e, r) => `04${o.sm2.doEncrypt(r, e.toLowerCase(), s)}`, p = (e, r) => o.sm2.doDecrypt(r.toLowerCase().replace(/^04/, ""), e.toLowerCase(), s);
1
+ import { s as r } from "../../../commonjs-virtual-dir/index2.js";
2
+ r.sm2.generateKeyPairHex;
3
+ const s = 1, c = (e, o) => `04${r.sm2.doEncrypt(o, e.toLowerCase(), s)}`, p = (e, o) => r.sm2.doDecrypt(o.toLowerCase().replace(/^04/, ""), e.toLowerCase(), s);
3
4
  export {
4
- c as generateKeyPairHex,
5
5
  p as sm2Decrypt,
6
- a as sm2Encrypt
6
+ c as sm2Encrypt
7
7
  };
@@ -1,29 +1,17 @@
1
- function o(n) {
2
- return typeof n == "object" ? JSON.stringify(n ?? {}) : typeof n == "number" ? String(n) : n ?? "";
3
- }
4
- const i = (n = 16) => {
5
- const r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
6
- let e = "";
7
- for (let t = 0; t < n; t++)
8
- e += r.charAt(Math.floor(Math.random() * r.length));
9
- return e;
10
- };
11
- function a(n) {
12
- const r = new Uint8Array(n.length / 2);
13
- for (let t = 0; t < n.length; t += 2)
14
- r[t / 2] = parseInt(n.slice(t, t + 2), 16);
15
- const e = String.fromCharCode(...r);
1
+ function o(r) {
2
+ const n = new Uint8Array(r.length / 2);
3
+ for (let t = 0; t < r.length; t += 2)
4
+ n[t / 2] = parseInt(r.slice(t, t + 2), 16);
5
+ const e = String.fromCharCode(...n);
16
6
  return btoa(e);
17
7
  }
18
- function g(n) {
19
- const r = atob(n), e = new Uint8Array(r.length);
20
- for (let t = 0; t < r.length; t++)
21
- e[t] = r.charCodeAt(t);
8
+ function i(r) {
9
+ const n = atob(r), e = new Uint8Array(n.length);
10
+ for (let t = 0; t < n.length; t++)
11
+ e[t] = n.charCodeAt(t);
22
12
  return Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
23
13
  }
24
14
  export {
25
- g as base64ToHex,
26
- o as dataToStr,
27
- i as generateRandomString,
28
- a as hexToBase64
15
+ i as base64ToHex,
16
+ o as hexToBase64
29
17
  };
@@ -0,0 +1,29 @@
1
+ class i {
2
+ /**
3
+ * 公钥
4
+ */
5
+ publicKey = "";
6
+ /**
7
+ * 是否加密
8
+ */
9
+ isEncrypt = !1;
10
+ /**
11
+ * 获取公钥
12
+ */
13
+ // eslint-disable-next-line
14
+ getPublicKeyApi = () => Promise.resolve("");
15
+ requestBeforeCryptoCallBacks = [];
16
+ init(e) {
17
+ this.getPublicKeyApi = e.getPublicKeyApi, this.isEncrypt = e.isEncrypt;
18
+ }
19
+ async initPublicKey() {
20
+ this.publicKey || (this.publicKey = await this.getPublicKeyApi());
21
+ }
22
+ addRequestBeforeCryptoCallback(e) {
23
+ this.requestBeforeCryptoCallBacks.push(e);
24
+ }
25
+ }
26
+ const c = new i();
27
+ export {
28
+ c as gcmService
29
+ };
@@ -0,0 +1,18 @@
1
+ const o = (e) => Array.from(crypto.getRandomValues(new Uint8Array(e))).map((n) => n.toString(16).padStart(2, "0")).join(""), a = (e) => {
2
+ let n = "";
3
+ for (let t = 0; t < e.length; t += 32768)
4
+ n += String.fromCharCode(...e.subarray(t, t + 32768));
5
+ return btoa(n);
6
+ }, c = (e) => new TextEncoder().encode(e), i = (e) => new TextDecoder().decode(e), s = (e) => {
7
+ const n = atob(e), r = new Uint8Array(n.length);
8
+ for (let t = 0; t < n.length; t++)
9
+ r[t] = n.charCodeAt(t);
10
+ return Array.from(r, (t) => t.toString(16).padStart(2, "0")).join("");
11
+ };
12
+ export {
13
+ s as base64ToHex,
14
+ a as bytesToBase64,
15
+ o as generateHex,
16
+ c as stringToUtf8Bytes,
17
+ i as utf8BytesToString
18
+ };
@@ -0,0 +1,40 @@
1
+ import { sm4 as i } from "../../../vendor/sm-crypto-v2/dist/index.js";
2
+ import { EHeaderKey as r } from "../crypto/const.js";
3
+ import { sm2Encrypt as d } from "../crypto/sm2.js";
4
+ import { hexToBase64 as g } from "../crypto/util.js";
5
+ import { generateHex as c, stringToUtf8Bytes as u, bytesToBase64 as m, base64ToHex as y, utf8BytesToString as f } from "./hex.js";
6
+ import { dataToStr as T } from "./string.js";
7
+ const H = (s, n, p) => {
8
+ const t = c(12), e = c(16), { output: o, tag: a } = i.encrypt(T(n), e, {
9
+ mode: "gcm",
10
+ iv: t,
11
+ associatedData: u(`uri=${p}`),
12
+ output: "array",
13
+ outputTag: !0
14
+ });
15
+ if (!o || !a)
16
+ throw new Error("sm4 加密失败");
17
+ return {
18
+ headers: {
19
+ [r.encryptIv]: t,
20
+ [r.encryptTag]: m(a),
21
+ [r.encryptKey]: g(d(s, e))
22
+ },
23
+ data: {
24
+ body: m(o)
25
+ }
26
+ };
27
+ }, S = (s, n, p, t) => {
28
+ const e = t[r.encryptIv], o = y(t[r.encryptTag]), a = i.decrypt(y(n), s, {
29
+ mode: "gcm",
30
+ iv: e,
31
+ associatedData: u(`uri=${p}`),
32
+ output: "array",
33
+ tag: o
34
+ });
35
+ return JSON.parse(f(a));
36
+ };
37
+ export {
38
+ H as requestDataEncryption,
39
+ S as responseDataDecryption
40
+ };
@@ -0,0 +1,61 @@
1
+ import { sm2 as K } from "../../../vendor/sm-crypto-v2/dist/index.js";
2
+ import { EHeaderKey as r } from "../crypto/const.js";
3
+ import { sm2Decrypt as b } from "../crypto/sm2.js";
4
+ import { base64ToHex as f } from "../crypto/util.js";
5
+ import { gcmService as o } from "./gcm.service.js";
6
+ import { requestDataEncryption as C, responseDataDecryption as D } from "./index.js";
7
+ import { formatUrlToGcmCryptoUri as s } from "./string.js";
8
+ import { isNullOrUndefined as n } from "../../utils/is.js";
9
+ import "vue";
10
+ const B = {
11
+ install: (t, e) => {
12
+ o.init(e);
13
+ }
14
+ }, G = () => o.initPublicKey(), I = (t) => {
15
+ o.addRequestBeforeCryptoCallback(t);
16
+ }, m = /* @__PURE__ */ new Map(), c = (t, e) => t && (t[e] || t.get(e)) || "", k = (t) => {
17
+ if (!o.isEncrypt || !o.publicKey)
18
+ return t;
19
+ if (!t.isNotAutoEncryption && t.url) {
20
+ o.requestBeforeCryptoCallBacks.forEach((a) => {
21
+ a(t);
22
+ });
23
+ const { headers: e, data: p } = C(
24
+ o.publicKey,
25
+ t.data,
26
+ s(t.url)
27
+ );
28
+ if (c(t.headers, "Content-Type") !== "multipart/form-data" && (t.data = n(t.data) ? t.data : p), t.isAutoDecryptionResponse) {
29
+ const { publicKey: a, privateKey: i } = K.generateKeyPairHex();
30
+ m.set(a, i), t.headers.set(r.gcmPublicKey, a);
31
+ }
32
+ t.headers.set(e);
33
+ }
34
+ return t;
35
+ }, R = (t) => {
36
+ if (t.config.isAutoDecryptionResponse && t.request.responseType !== "blob") {
37
+ const { data: e, ...p } = t.data, a = c(t.headers, r.gcmPublicKey);
38
+ if (!a)
39
+ return t;
40
+ const i = m.get(a);
41
+ if (i && !n(e)) {
42
+ const u = c(t.headers, r.encryptIv), d = c(t.headers, r.encryptKey), l = c(t.headers, r.encryptTag), y = b(i, f(d));
43
+ t.data = {
44
+ ...p,
45
+ data: D(y, e, s(t.config.url), {
46
+ [r.encryptIv]: u,
47
+ [r.encryptKey]: y,
48
+ [r.encryptTag]: l
49
+ })
50
+ };
51
+ }
52
+ }
53
+ return t;
54
+ };
55
+ export {
56
+ B as gcmCrypto,
57
+ G as initPublicKey,
58
+ I as requestDataBeforeGcmCrypto,
59
+ k as requestDataGcmCryptoInterceptor,
60
+ R as responseDataGcmCryptoInterceptor
61
+ };
@@ -0,0 +1,10 @@
1
+ const t = (o) => typeof o == "object" ? JSON.stringify(o ?? {}) : typeof o == "number" ? String(o) : o ?? "", i = (o) => {
2
+ if (!o)
3
+ return "";
4
+ const r = o.split("/").filter(Boolean);
5
+ return r.shift(), `/${r.join("/")}`;
6
+ };
7
+ export {
8
+ t as dataToStr,
9
+ i as formatUrlToGcmCryptoUri
10
+ };
@@ -0,0 +1,4 @@
1
+ const d = (n) => n == null;
2
+ export {
3
+ d as isNullOrUndefined
4
+ };
@@ -0,0 +1,16 @@
1
+ import "axios";
2
+
3
+ declare module "axios" {
4
+ export interface InternalAxiosRequestConfig {
5
+ /**
6
+ * 接口是否不需要自动加密
7
+ * @default false
8
+ */
9
+ isNotAutoEncryption?: boolean;
10
+ /**
11
+ * 响应是否需要自动解密
12
+ * @default false
13
+ */
14
+ isAutoDecryptionResponse?: boolean;
15
+ }
16
+ }