module-develop-kit 1.4.1 → 1.4.2

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 (33) hide show
  1. package/dist/commonjs-virtual-dir/index2.js +2 -5
  2. package/dist/commonjs-virtual-dir/index3.js +4 -2
  3. package/dist/commonjs-virtual-dir/index4.js +2 -2
  4. package/dist/main.d.ts +60 -14
  5. package/dist/main.js +19 -19
  6. package/dist/src/shield/gcm-crypto/axios-adapter.js +82 -0
  7. package/dist/src/shield/gcm-crypto/constants.js +4 -0
  8. package/dist/src/shield/gcm-crypto/gcm.config.js +60 -0
  9. package/dist/src/shield/gcm-crypto/index.js +22 -19
  10. package/dist/src/shield/gcm-crypto/utils.js +40 -0
  11. package/dist/types/axios.d.ts +10 -8
  12. package/dist/vendor/ieee754/index.js +1 -1
  13. package/dist/vendor/sdp-transform/lib/index.js +1 -1
  14. package/dist/vendor/token-types/lib/index.js +1 -1
  15. package/package.json +1 -1
  16. package/dist/commonjs-virtual-dir/index5.js +0 -4
  17. package/dist/commonjs-virtual-dir/index6.js +0 -4
  18. package/dist/src/shield/crypto/const.js +0 -4
  19. package/dist/src/shield/crypto/sm2.js +0 -7
  20. package/dist/src/shield/crypto/util.js +0 -17
  21. package/dist/src/shield/gcm-crypto/gcm.service.js +0 -29
  22. package/dist/src/shield/gcm-crypto/hex.js +0 -18
  23. package/dist/src/shield/gcm-crypto/init.js +0 -61
  24. package/dist/src/shield/gcm-crypto/string.js +0 -10
  25. package/dist/vendor/jsbn/index.js +0 -714
  26. package/dist/vendor/sm-crypto/src/index.js +0 -14
  27. package/dist/vendor/sm-crypto/src/sm2/asn1.js +0 -86
  28. package/dist/vendor/sm-crypto/src/sm2/ec.js +0 -205
  29. package/dist/vendor/sm-crypto/src/sm2/index.js +0 -114
  30. package/dist/vendor/sm-crypto/src/sm2/sm3.js +0 -71
  31. package/dist/vendor/sm-crypto/src/sm2/utils.js +0 -95
  32. package/dist/vendor/sm-crypto/src/sm3/index.js +0 -50
  33. package/dist/vendor/sm-crypto/src/sm4/index.js +0 -408
@@ -1,5 +1,2 @@
1
- import { __require as r } from "../vendor/sm-crypto/src/index.js";
2
- var s = r();
3
- export {
4
- s
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
@@ -111,6 +111,16 @@ export declare enum ECallStatus {
111
111
  RECONNECT = "reconnect"
112
112
  }
113
113
 
114
+ declare enum EGcmHeaderKey {
115
+ publicKey = "X-Public-Key",
116
+ gcmPublicKey = "X-Client-SM2-Public-Key",
117
+ encryptIv = "X-Encrypted-Iv",
118
+ encryptKey = "X-Encrypted-Key",
119
+ encryptIvLow = "x-encrypted-iv",
120
+ encryptTag = "X-Encrypted-Tag",
121
+ encryptKeyLow = "x-encrypted-key"
122
+ }
123
+
114
124
  declare enum EHeaderKey {
115
125
  publicKey = "X-Public-Key",
116
126
  gcmPublicKey = "X-Client-SM2-Public-Key",
@@ -168,7 +178,7 @@ declare type EventFnc = (...args: any) => void;
168
178
  /**
169
179
  * gcm-crypto
170
180
  */
171
- export declare const gcmCrypto: Plugin_2<IGcmCryptoOptions>;
181
+ export declare const gcmCryptoPlugin: Plugin_2<IGcmCryptoOptions>;
172
182
 
173
183
  /**
174
184
  * 安全的解析html内容 防止xss攻击
@@ -313,30 +323,41 @@ export declare interface IFileDetectionResult {
313
323
  mimeMatches?: boolean;
314
324
  }
315
325
 
316
- export declare interface IGcmCryptoOptions {
326
+ declare interface IGcmCryptoConfig {
317
327
  /**
318
- * 获取公钥 API
328
+ * 是否启用请求加密
329
+ * @default false
319
330
  */
320
- getPublicKeyApi: () => Promise<string>;
331
+ enableRequestCrypto?: boolean;
321
332
  /**
322
- * 是否加密
333
+ * 是否启用响应加密
334
+ * @default false
323
335
  */
324
- isEncrypt: boolean;
336
+ enableResponseCrypto?: boolean;
325
337
  }
326
338
 
327
339
  /**
328
- * 初始化公钥
340
+ * GCM 加密插件配置选项
329
341
  */
330
- export declare const initPublicKey: () => Promise<void>;
342
+ declare interface IGcmCryptoOptions extends IGcmCryptoConfig {
343
+ /**
344
+ * 获取后端公钥的 API 函数
345
+ */
346
+ getPublicKeyApi: () => Promise<string>;
347
+ /**
348
+ * Vue Router 实例或兼容接口
349
+ */
350
+ router: TRouterLike;
351
+ }
331
352
 
332
353
  export declare interface IResponseDataEncryptionReturn {
333
354
  /**
334
355
  * 响应头
335
356
  */
336
357
  headers: {
337
- [EHeaderKey.encryptIv]: string;
338
- [EHeaderKey.encryptTag]: string;
339
- [EHeaderKey.encryptKey]: string;
358
+ [EGcmHeaderKey.encryptIv]: string;
359
+ [EGcmHeaderKey.encryptTag]: string;
360
+ [EGcmHeaderKey.encryptKey]: string;
340
361
  };
341
362
  /**
342
363
  * 加密后的数据
@@ -422,7 +443,7 @@ export declare interface IUrlSanitizeOptions {
422
443
  * 添加请求前加密回调
423
444
  * @param callback
424
445
  */
425
- export declare const requestDataBeforeGcmCrypto: (callback: TRequestBeforeCryptoCallBack) => void;
446
+ export declare const requestDataBeforeGcmCrypto: (callback: TRequestBeforeCryptoCallBack<InternalAxiosRequestConfig>) => void;
426
447
 
427
448
  /**
428
449
  * 请求数据加密
@@ -435,7 +456,13 @@ export declare const requestDataEncryption: <T>(publicKey: string, data: T, uri:
435
456
  /**
436
457
  * gcm 加密请求拦截器
437
458
  */
438
- export declare const requestDataGcmCryptoInterceptor: <T>(config: InternalAxiosRequestConfig<T>) => InternalAxiosRequestConfig<T>;
459
+ export declare const requestDataGcmCryptoInterceptor: <T>(config: InternalAxiosRequestConfig<T>) => Promise<InternalAxiosRequestConfig<T>>;
460
+
461
+ /**
462
+ * 添加响应前解密回调
463
+ * @param callback
464
+ */
465
+ export declare const responseDataBeforeGcmCrypto: <T = TAny>(callback: TRequestBeforeCryptoCallBack<AxiosResponse<T>>) => void;
439
466
 
440
467
  /**
441
468
  * 响应数据解密
@@ -534,17 +561,36 @@ export { supportedExtensions }
534
561
 
535
562
  export { supportedMimeTypes }
536
563
 
564
+ declare type TAny = any;
565
+
537
566
  export declare type TData = _TData | _TData[];
538
567
 
539
568
  declare type _TData = null | undefined | number | string | Record<string, any>;
540
569
 
541
570
  export declare type TMaybeArray<T> = T[] | T;
542
571
 
572
+ /**
573
+ * 路由守卫函数
574
+ */
575
+ declare type TNavigationGuard = (to: TAny, from: TAny, next: TNavigationGuardNext) => TAny | Promise<TAny>;
576
+
577
+ /**
578
+ * 路由守卫的 next 函数
579
+ */
580
+ declare type TNavigationGuardNext = (to?: TAny) => void;
581
+
543
582
  export declare type TNullable<T> = T | null;
544
583
 
545
584
  export declare type TObj<K extends keyof any = string, T = any> = Record<K, T>;
546
585
 
547
- declare type TRequestBeforeCryptoCallBack = (config: InternalAxiosRequestConfig) => void;
586
+ declare type TRequestBeforeCryptoCallBack<T> = (config: T) => void;
587
+
588
+ /**
589
+ * 类 Router 接口,兼容 Vue Router 2/3/4
590
+ */
591
+ declare interface TRouterLike {
592
+ beforeEach: (guard: TNavigationGuard) => () => void;
593
+ }
548
594
 
549
595
  export declare type TUndefinable<T> = T | undefined;
550
596
 
package/dist/main.js CHANGED
@@ -1,15 +1,15 @@
1
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 { 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";
3
+ import { ALLOWED_FILE_MIMES as p, ALLOWED_FILE_TYPES as a, detectFileByExtension as m, detectFileByMime as n, detectionFilesByExtension as l, detectionFilesByMime as E, isValidDocument as c, isValidFile as f, isValidImage as x, isValidVideo as y } from "./src/shield/file-detection.js";
4
+ import { requestDataEncryption as d, responseDataDecryption as u } from "./src/shield/gcm-crypto/index.js";
5
+ import { htmlSanitize as S } from "./src/shield/html-sanitize.js";
6
6
  import { startNoDebugger as I } from "./src/shield/no-debugger.js";
7
- import { isUrlSafe as M, sanitizeUrl as L, sanitizeUrls as g } from "./src/shield/url-sanitize.js";
7
+ import { isUrlSafe as M, sanitizeUrl as g, sanitizeUrls as B } from "./src/shield/url-sanitize.js";
8
8
  import { EventBus as V } from "./src/utils/eventBus.js";
9
9
  import { CallLogger as G } from "./src/outside-call/utils.js";
10
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
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
+ import { gcmCryptoPlugin as b, requestDataBeforeGcmCrypto as h, requestDataGcmCryptoInterceptor as v, responseDataBeforeGcmCrypto as Y, responseDataGcmCryptoInterceptor as j } from "./src/shield/gcm-crypto/axios-adapter.js";
13
13
  export {
14
14
  p as ALLOWED_FILE_MIMES,
15
15
  a as ALLOWED_FILE_TYPES,
@@ -21,24 +21,24 @@ export {
21
21
  U as SIP_ERROR_CAUSES,
22
22
  i as createCosFileName,
23
23
  m as detectFileByExtension,
24
- l as detectFileByMime,
25
- n as detectionFilesByExtension,
24
+ n as detectFileByMime,
25
+ l as detectionFilesByExtension,
26
26
  E as detectionFilesByMime,
27
- W as gcmCrypto,
28
- C as htmlSanitize,
29
- h as initPublicKey,
27
+ b as gcmCryptoPlugin,
28
+ S as htmlSanitize,
30
29
  M as isUrlSafe,
31
30
  c as isValidDocument,
32
- x as isValidFile,
33
- f as isValidImage,
31
+ f as isValidFile,
32
+ x as isValidImage,
34
33
  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,
34
+ h as requestDataBeforeGcmCrypto,
35
+ d as requestDataEncryption,
36
+ v as requestDataGcmCryptoInterceptor,
37
+ Y as responseDataBeforeGcmCrypto,
38
+ u as responseDataDecryption,
39
+ j as responseDataGcmCryptoInterceptor,
40
+ g as sanitizeUrl,
41
+ B as sanitizeUrls,
42
42
  I as startNoDebugger,
43
43
  z as supportedExtensions,
44
44
  R as supportedMimeTypes,
@@ -0,0 +1,82 @@
1
+ import { sm2 as K } from "../../../vendor/sm-crypto-v2/dist/index.js";
2
+ import { EGcmHeaderKey as a } from "./constants.js";
3
+ import { gcmConfig as r } from "./gcm.config.js";
4
+ import { requestDataEncryption as h, responseDataDecryption as E } from "./index.js";
5
+ import { formatUrlToGcmCryptoUri as d, sm2Decrypt as w, base64ToHex as D } from "./utils.js";
6
+ import { isNullOrUndefined as f } from "../../utils/is.js";
7
+ import "vue";
8
+ const x = {
9
+ install: (e, t) => {
10
+ r.init(t), t.router.beforeEach(async (o, n, c) => {
11
+ await r.initPublicKey(), c();
12
+ });
13
+ }
14
+ }, G = (e) => {
15
+ r.addRequestBeforeCryptoCallback(e);
16
+ }, y = /* @__PURE__ */ new Map(), v = 10 * 60 * 1e3, m = setInterval(
17
+ () => {
18
+ const e = Date.now();
19
+ for (const [t, o] of y.entries())
20
+ e - o.timestamp > v && y.delete(t);
21
+ },
22
+ 5 * 60 * 1e3
23
+ );
24
+ typeof m.unref == "function" && m.unref();
25
+ const i = (e, t) => e && (e[t] || e.get(t)) || "", R = async (e) => {
26
+ if (i(e.headers, "Content-Type") === "multipart/form-data" || !r.isEnableRequestCrypto(e) || !e.url || (r.publicKey || await r.initPublicKey(), !r.publicKey))
27
+ return e;
28
+ r.requestBeforeCryptoCallBacks.forEach((n) => {
29
+ n(e);
30
+ });
31
+ const { headers: t, data: o } = h(
32
+ r.publicKey,
33
+ e.data,
34
+ d(e.url)
35
+ );
36
+ if (e.data = f(e.data) ? e.data : o, r.isEnableResponseCrypto(e)) {
37
+ const { publicKey: n, privateKey: c } = K.generateKeyPairHex();
38
+ y.set(n, { privateKey: c, timestamp: Date.now() }), e.headers.set(a.gcmPublicKey, n);
39
+ }
40
+ return e.headers.set(t), e;
41
+ }, H = (e) => {
42
+ r.addResponseBeforeCryptoCallback(e);
43
+ }, _ = (e) => {
44
+ if (!r.isEnableResponseCrypto(e.config))
45
+ return e;
46
+ const t = i(e.headers, a.gcmPublicKey);
47
+ if (!t)
48
+ return e;
49
+ const o = y.get(t);
50
+ if (y.delete(t), !o)
51
+ throw new Error("[gcm-crypto] Private key not found, possible security issue or expired request");
52
+ const { privateKey: n } = o, { data: c, ...C } = e.data;
53
+ if (f(c))
54
+ return e;
55
+ const p = i(e.headers, a.encryptIv), u = i(e.headers, a.encryptKey), l = i(e.headers, a.encryptTag);
56
+ if (!p || !u || !l)
57
+ throw new Error("[gcm-crypto] Missing required encryption headers");
58
+ try {
59
+ r.responseBeforeCryptoCallBacks.forEach((b) => {
60
+ b(e);
61
+ });
62
+ const s = w(n, D(u));
63
+ e.data = {
64
+ ...C,
65
+ data: E(s, c, d(e.config.url), {
66
+ [a.encryptIv]: p,
67
+ [a.encryptKey]: s,
68
+ [a.encryptTag]: l
69
+ })
70
+ };
71
+ } catch (s) {
72
+ throw new Error(`[gcm-crypto] Decryption failed: ${s instanceof Error ? s.message : String(s)}`);
73
+ }
74
+ return e;
75
+ };
76
+ export {
77
+ x as gcmCryptoPlugin,
78
+ G as requestDataBeforeGcmCrypto,
79
+ R as requestDataGcmCryptoInterceptor,
80
+ H as responseDataBeforeGcmCrypto,
81
+ _ as responseDataGcmCryptoInterceptor
82
+ };
@@ -0,0 +1,4 @@
1
+ var n = /* @__PURE__ */ ((t) => (t.publicKey = "X-Public-Key", t.gcmPublicKey = "X-Client-SM2-Public-Key", t.encryptIv = "X-Encrypted-Iv", t.encryptKey = "X-Encrypted-Key", t.encryptIvLow = "x-encrypted-iv", t.encryptTag = "X-Encrypted-Tag", t.encryptKeyLow = "x-encrypted-key", t))(n || {});
2
+ export {
3
+ n as EGcmHeaderKey
4
+ };
@@ -0,0 +1,60 @@
1
+ class t {
2
+ /**
3
+ * 是否启用请求加密
4
+ */
5
+ enableRequestCrypto = !1;
6
+ /**
7
+ * 获取是否启用请求加密
8
+ * @param config
9
+ */
10
+ isEnableRequestCrypto(e) {
11
+ const s = e.enableRequestCrypto;
12
+ return typeof s < "u" ? s : this.enableRequestCrypto;
13
+ }
14
+ /**
15
+ * 是否启用响应加密
16
+ */
17
+ enableResponseCrypto = !1;
18
+ /**
19
+ * 获取是否启用响应加密
20
+ * @param config
21
+ */
22
+ isEnableResponseCrypto(e) {
23
+ const s = e.enableResponseCrypto;
24
+ return typeof s < "u" ? s : this.enableResponseCrypto;
25
+ }
26
+ /**
27
+ * 公钥
28
+ */
29
+ publicKey = "";
30
+ /**
31
+ * 获取公钥
32
+ */
33
+ // eslint-disable-next-line
34
+ getPublicKeyApi = () => Promise.resolve("");
35
+ /**
36
+ * 公钥初始化 Promise(防止重复请求)
37
+ */
38
+ publicKeyPromise;
39
+ requestBeforeCryptoCallBacks = [];
40
+ responseBeforeCryptoCallBacks = [];
41
+ init(e) {
42
+ this.getPublicKeyApi = e.getPublicKeyApi, this.enableRequestCrypto = e.enableRequestCrypto ?? !1, this.enableResponseCrypto = e.enableResponseCrypto ?? !1;
43
+ }
44
+ initPublicKey() {
45
+ if (!(!this.enableRequestCrypto && !this.enableResponseCrypto) && !this.publicKey)
46
+ return this.publicKeyPromise ? this.publicKeyPromise : (this.publicKeyPromise = this.getPublicKeyApi().then((e) => (this.publicKey = e, e)).finally(() => {
47
+ this.publicKeyPromise = void 0;
48
+ }), this.publicKeyPromise);
49
+ }
50
+ addRequestBeforeCryptoCallback(e) {
51
+ this.requestBeforeCryptoCallBacks.push(e);
52
+ }
53
+ addResponseBeforeCryptoCallback(e) {
54
+ this.responseBeforeCryptoCallBacks.push(e);
55
+ }
56
+ }
57
+ const r = new t();
58
+ export {
59
+ r as gcmConfig
60
+ };
@@ -1,14 +1,11 @@
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, {
1
+ import { sm4 as d } from "../../../vendor/sm-crypto-v2/dist/index.js";
2
+ import { EGcmHeaderKey as r } from "./constants.js";
3
+ import { generateHex as y, dataToStr as T, stringToUtf8Bytes as u, bytesToBase64 as i, hexToBase64 as f, sm2Encrypt as E, base64ToHex as m, utf8BytesToString as S } from "./utils.js";
4
+ const v = (s, n, c) => {
5
+ const t = y(12), e = y(16), { output: o, tag: a } = d.encrypt(T(n), e, {
9
6
  mode: "gcm",
10
7
  iv: t,
11
- associatedData: u(`uri=${p}`),
8
+ associatedData: u(`uri=${c}`),
12
9
  output: "array",
13
10
  outputTag: !0
14
11
  });
@@ -17,24 +14,30 @@ const H = (s, n, p) => {
17
14
  return {
18
15
  headers: {
19
16
  [r.encryptIv]: t,
20
- [r.encryptTag]: m(a),
21
- [r.encryptKey]: g(d(s, e))
17
+ [r.encryptTag]: i(a),
18
+ [r.encryptKey]: f(E(s, e))
22
19
  },
23
20
  data: {
24
- body: m(o)
21
+ body: i(o)
25
22
  }
26
23
  };
27
- }, S = (s, n, p, t) => {
28
- const e = t[r.encryptIv], o = y(t[r.encryptTag]), a = i.decrypt(y(n), s, {
24
+ }, w = (s, n, c, t) => {
25
+ const e = t[r.encryptIv], o = m(t[r.encryptTag]), a = d.decrypt(m(n), s, {
29
26
  mode: "gcm",
30
27
  iv: e,
31
- associatedData: u(`uri=${p}`),
28
+ associatedData: u(`uri=${c}`),
32
29
  output: "array",
33
30
  tag: o
34
- });
35
- return JSON.parse(f(a));
31
+ }), g = S(a);
32
+ try {
33
+ return JSON.parse(g);
34
+ } catch (p) {
35
+ throw new Error(
36
+ `[gcm-crypto] Failed to parse decrypted data as JSON: ${p instanceof Error ? p.message : String(p)}`
37
+ );
38
+ }
36
39
  };
37
40
  export {
38
- H as requestDataEncryption,
39
- S as responseDataDecryption
41
+ v as requestDataEncryption,
42
+ w as responseDataDecryption
40
43
  };
@@ -0,0 +1,40 @@
1
+ import { sm2 as o } from "../../../vendor/sm-crypto-v2/dist/index.js";
2
+ const a = (t) => Array.from(crypto.getRandomValues(new Uint8Array(t))).map((r) => r.toString(16).padStart(2, "0")).join(""), i = (t) => {
3
+ let r = "";
4
+ for (let e = 0; e < t.length; e += 32768)
5
+ r += String.fromCharCode(...t.subarray(e, e + 32768));
6
+ return btoa(r);
7
+ }, f = (t) => new TextEncoder().encode(t), l = (t) => new TextDecoder().decode(t), c = (t) => {
8
+ if (t.length % 2 !== 0)
9
+ throw new Error("Invalid hex string");
10
+ const r = new Uint8Array(t.length / 2);
11
+ for (let n = 0; n < t.length; n += 2)
12
+ r[n / 2] = parseInt(t.slice(n, n + 2), 16);
13
+ return r;
14
+ }, g = (t) => {
15
+ const r = atob(t), n = new Uint8Array(r.length);
16
+ for (let e = 0; e < r.length; e++)
17
+ n[e] = r.charCodeAt(e);
18
+ return Array.from(n, (e) => e.toString(16).padStart(2, "0")).join("");
19
+ }, p = (t) => {
20
+ const r = c(t);
21
+ return i(r);
22
+ }, u = (t) => t == null || typeof t == "object" ? JSON.stringify(t) : typeof t == "number" ? String(t) : t, h = (t) => {
23
+ if (!t)
24
+ return "";
25
+ const r = t.split("/").filter(Boolean);
26
+ return r.shift(), `/${r.join("/")}`;
27
+ }, s = 1, m = (t, r) => `04${o.doEncrypt(r, t.toLowerCase(), s)}`, S = (t, r) => o.doDecrypt(r.toLowerCase().replace(/^04/, ""), t.toLowerCase(), s);
28
+ export {
29
+ g as base64ToHex,
30
+ i as bytesToBase64,
31
+ u as dataToStr,
32
+ h as formatUrlToGcmCryptoUri,
33
+ a as generateHex,
34
+ p as hexToBase64,
35
+ c as hexToBytes,
36
+ S as sm2Decrypt,
37
+ m as sm2Encrypt,
38
+ f as stringToUtf8Bytes,
39
+ l as utf8BytesToString
40
+ };
@@ -3,28 +3,30 @@ import "axios";
3
3
  declare module "axios" {
4
4
  export interface InternalAxiosRequestConfig {
5
5
  /**
6
- * 接口是否不需要自动加密
6
+ * 是否启用请求加密
7
7
  * @default false
8
8
  */
9
- isNotAutoEncryption?: boolean;
9
+ enableRequestCrypto?: boolean;
10
+
10
11
  /**
11
- * 响应是否需要自动解密
12
+ * 是否启用响应加密
12
13
  * @default false
13
14
  */
14
- isAutoDecryptionResponse?: boolean;
15
+ enableResponseCrypto?: boolean;
15
16
  }
16
17
 
17
18
  // eslint-disable-next-line
18
19
  export interface AxiosRequestConfig<D = any> {
19
20
  /**
20
- * 接口是否不需要自动加密
21
+ * 是否启用请求加密
21
22
  * @default false
22
23
  */
23
- isNotAutoEncryption?: boolean;
24
+ enableRequestCrypto?: boolean;
25
+
24
26
  /**
25
- * 响应是否需要自动解密
27
+ * 是否启用响应加密
26
28
  * @default false
27
29
  */
28
- isAutoDecryptionResponse?: boolean;
30
+ enableResponseCrypto?: boolean;
29
31
  }
30
32
  }
@@ -1,4 +1,4 @@
1
- import { __exports as n } from "../../commonjs-virtual-dir/index5.js";
1
+ import { __exports as n } from "../../commonjs-virtual-dir/index4.js";
2
2
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
3
3
  var d;
4
4
  function q() {
@@ -1,4 +1,4 @@
1
- import { __exports as r } from "../../../commonjs-virtual-dir/index4.js";
1
+ import { __exports as r } from "../../../commonjs-virtual-dir/index3.js";
2
2
  import { __require as t } from "./parser.js";
3
3
  import { __require as m } from "./writer.js";
4
4
  import { __require as p } from "./grammar.js";
@@ -1,4 +1,4 @@
1
- import "../../../commonjs-virtual-dir/index3.js";
1
+ import "../../../commonjs-virtual-dir/index2.js";
2
2
  import { textDecode as i } from "../../@borewit/text-codec/lib/index.js";
3
3
  function r(e) {
4
4
  return new DataView(e.buffer, e.byteOffset);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "module-develop-kit",
3
3
  "author": "Front-End team",
4
- "version": "1.4.1",
4
+ "version": "1.4.2",
5
5
  "type": "module",
6
6
  "description": "前端项目通用工具包",
7
7
  "module": "dist/main.js",
@@ -1,4 +0,0 @@
1
- var e = {};
2
- export {
3
- e as __exports
4
- };
@@ -1,4 +0,0 @@
1
- var e = { exports: {} };
2
- export {
3
- e as __module
4
- };
@@ -1,4 +0,0 @@
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
- export {
3
- t as EHeaderKey
4
- };
@@ -1,7 +0,0 @@
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);
4
- export {
5
- p as sm2Decrypt,
6
- c as sm2Encrypt
7
- };
@@ -1,17 +0,0 @@
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);
6
- return btoa(e);
7
- }
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);
12
- return Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
13
- }
14
- export {
15
- i as base64ToHex,
16
- o as hexToBase64
17
- };
@@ -1,29 +0,0 @@
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
- };
@@ -1,18 +0,0 @@
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
- };