module-develop-kit 1.4.1 → 1.4.3

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 (36) 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 +3 -5
  4. package/dist/commonjs-virtual-dir/index2.js +5 -3
  5. package/dist/commonjs-virtual-dir/index3.js +5 -2
  6. package/dist/commonjs-virtual-dir/index4.js +2 -4
  7. package/dist/commonjs-virtual-dir/index5.js +2 -2
  8. package/dist/commonjs-virtual-dir/index7.js +4 -0
  9. package/dist/commonjs-virtual-dir/index8.js +4 -0
  10. package/dist/main.d.ts +107 -21
  11. package/dist/main.js +44 -40
  12. package/dist/src/outside-call/utils.js +1 -1
  13. package/dist/src/shield/crypto/index.js +53 -0
  14. package/dist/src/shield/crypto/sm2.js +4 -4
  15. package/dist/src/shield/crypto/sm4.js +15 -0
  16. package/dist/src/shield/crypto/util.js +23 -11
  17. package/dist/src/shield/gcm-crypto/axios-adapter.js +82 -0
  18. package/dist/src/shield/gcm-crypto/constants.js +4 -0
  19. package/dist/src/shield/gcm-crypto/gcm.config.js +60 -0
  20. package/dist/src/shield/gcm-crypto/index.js +20 -17
  21. package/dist/src/shield/gcm-crypto/utils.js +40 -0
  22. package/dist/types/axios.d.ts +10 -8
  23. package/dist/vendor/@tokenizer/inflate/lib/ZipHandler.js +1 -1
  24. package/dist/vendor/base64-js/index.js +52 -0
  25. package/dist/vendor/debug/src/browser.js +1 -1
  26. package/dist/vendor/gm-crypt/index.js +10 -0
  27. package/dist/vendor/gm-crypt/src/crypt.js +60 -0
  28. package/dist/vendor/gm-crypt/src/sm4.js +513 -0
  29. package/dist/vendor/ieee754/index.js +1 -1
  30. package/dist/vendor/sdp-transform/lib/index.js +1 -1
  31. package/dist/vendor/token-types/lib/index.js +1 -1
  32. package/package.json +1 -1
  33. package/dist/src/shield/gcm-crypto/gcm.service.js +0 -29
  34. package/dist/src/shield/gcm-crypto/hex.js +0 -18
  35. package/dist/src/shield/gcm-crypto/init.js +0 -61
  36. package/dist/src/shield/gcm-crypto/string.js +0 -10
@@ -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,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,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,2 +1,5 @@
1
- import { __require as e } from "../vendor/ieee754/index.js";
2
- e();
1
+ import { __require as r } from "../vendor/gm-crypt/index.js";
2
+ var p = r();
3
+ export {
4
+ p as g
5
+ };
@@ -1,4 +1,2 @@
1
- var r = {};
2
- export {
3
- r as __exports
4
- };
1
+ import { __require as e } from "../vendor/ieee754/index.js";
2
+ e();
@@ -1,4 +1,4 @@
1
- var e = {};
1
+ var r = {};
2
2
  export {
3
- e as __exports
3
+ r as __exports
4
4
  };
@@ -0,0 +1,4 @@
1
+ var e = {};
2
+ export {
3
+ e as __exports
4
+ };
@@ -0,0 +1,4 @@
1
+ var s = {};
2
+ export {
3
+ s as __exports
4
+ };
package/dist/main.d.ts CHANGED
@@ -27,6 +27,21 @@ export declare const ALLOWED_FILE_TYPES: {
27
27
  readonly model: Set<string>;
28
28
  };
29
29
 
30
+ /**
31
+ * 防重放攻击策略
32
+ * @param uid
33
+ * @param salt
34
+ * @param ts
35
+ * @param data
36
+ * @param headers
37
+ * @deprecated 已废弃,请使用新的 gcm 方式进行加解密
38
+ */
39
+ export declare function antiReplyAttackStrategy({ uid, salt, ts, data, ...headers }: IAntiReplyAttackStrategy): {
40
+ "X-Sign-Timestamp": string;
41
+ "X-Sign-Nonce": string;
42
+ "X-Sign-Client": string;
43
+ };
44
+
30
45
  /**
31
46
  * 用于格式化输出会话过程中的日志信息
32
47
  */
@@ -111,6 +126,16 @@ export declare enum ECallStatus {
111
126
  RECONNECT = "reconnect"
112
127
  }
113
128
 
129
+ declare enum EGcmHeaderKey {
130
+ publicKey = "X-Public-Key",
131
+ gcmPublicKey = "X-Client-SM2-Public-Key",
132
+ encryptIv = "X-Encrypted-Iv",
133
+ encryptKey = "X-Encrypted-Key",
134
+ encryptIvLow = "x-encrypted-iv",
135
+ encryptTag = "X-Encrypted-Tag",
136
+ encryptKeyLow = "x-encrypted-key"
137
+ }
138
+
114
139
  declare enum EHeaderKey {
115
140
  publicKey = "X-Public-Key",
116
141
  gcmPublicKey = "X-Client-SM2-Public-Key",
@@ -168,7 +193,7 @@ declare type EventFnc = (...args: any) => void;
168
193
  /**
169
194
  * gcm-crypto
170
195
  */
171
- export declare const gcmCrypto: Plugin_2<IGcmCryptoOptions>;
196
+ export declare const gcmCryptoPlugin: Plugin_2<IGcmCryptoOptions>;
172
197
 
173
198
  /**
174
199
  * 安全的解析html内容 防止xss攻击
@@ -313,30 +338,41 @@ export declare interface IFileDetectionResult {
313
338
  mimeMatches?: boolean;
314
339
  }
315
340
 
316
- export declare interface IGcmCryptoOptions {
341
+ declare interface IGcmCryptoConfig {
317
342
  /**
318
- * 获取公钥 API
343
+ * 是否启用请求加密
344
+ * @default false
319
345
  */
320
- getPublicKeyApi: () => Promise<string>;
346
+ enableRequestCrypto?: boolean;
321
347
  /**
322
- * 是否加密
348
+ * 是否启用响应加密
349
+ * @default false
323
350
  */
324
- isEncrypt: boolean;
351
+ enableResponseCrypto?: boolean;
325
352
  }
326
353
 
327
354
  /**
328
- * 初始化公钥
355
+ * GCM 加密插件配置选项
329
356
  */
330
- export declare const initPublicKey: () => Promise<void>;
357
+ declare interface IGcmCryptoOptions extends IGcmCryptoConfig {
358
+ /**
359
+ * 获取后端公钥的 API 函数
360
+ */
361
+ getPublicKeyApi: () => Promise<string>;
362
+ /**
363
+ * Vue Router 实例或兼容接口
364
+ */
365
+ router: TRouterLike;
366
+ }
331
367
 
332
368
  export declare interface IResponseDataEncryptionReturn {
333
369
  /**
334
370
  * 响应头
335
371
  */
336
372
  headers: {
337
- [EHeaderKey.encryptIv]: string;
338
- [EHeaderKey.encryptTag]: string;
339
- [EHeaderKey.encryptKey]: string;
373
+ [EGcmHeaderKey.encryptIv]: string;
374
+ [EGcmHeaderKey.encryptTag]: string;
375
+ [EGcmHeaderKey.encryptKey]: string;
340
376
  };
341
377
  /**
342
378
  * 加密后的数据
@@ -422,29 +458,51 @@ export declare interface IUrlSanitizeOptions {
422
458
  * 添加请求前加密回调
423
459
  * @param callback
424
460
  */
425
- export declare const requestDataBeforeGcmCrypto: (callback: TRequestBeforeCryptoCallBack) => void;
461
+ export declare const requestDataBeforeGcmCrypto: (callback: TRequestBeforeCryptoCallBack<InternalAxiosRequestConfig>) => void;
426
462
 
427
463
  /**
428
464
  * 请求数据加密
429
465
  * @param publicKey 公钥
466
+ * @param _data 数据
467
+ * @deprecated 已废弃,请使用新的 gcm 方式进行加解密
468
+ */
469
+ export declare function requestDataEncryption(publicKey: string, _data?: TData): {
470
+ headers: {
471
+ "X-Encrypted-Iv": string;
472
+ "X-Encrypted-Key": string;
473
+ };
474
+ data: {
475
+ body: string;
476
+ };
477
+ };
478
+
479
+ /**
480
+ * gcm 加密请求拦截器
481
+ */
482
+ export declare const requestDataGcmCryptoInterceptor: <T>(config: InternalAxiosRequestConfig<T>) => Promise<InternalAxiosRequestConfig<T>>;
483
+
484
+ /**
485
+ * 请求数据通过gcm模式加密
486
+ * @param publicKey 公钥
430
487
  * @param data 原始数据
431
488
  * @param uri 当前请求的路径
432
489
  */
433
- export declare const requestDataEncryption: <T>(publicKey: string, data: T, uri: string) => IResponseDataEncryptionReturn;
490
+ export declare const requestDataGcmEncryption: <T>(publicKey: string, data: T, uri: string) => IResponseDataEncryptionReturn;
434
491
 
435
492
  /**
436
- * gcm 加密请求拦截器
493
+ * 添加响应前解密回调
494
+ * @param callback
437
495
  */
438
- export declare const requestDataGcmCryptoInterceptor: <T>(config: InternalAxiosRequestConfig<T>) => InternalAxiosRequestConfig<T>;
496
+ export declare const responseDataBeforeGcmCrypto: <T = TAny>(callback: TRequestBeforeCryptoCallBack<AxiosResponse<T>>) => void;
439
497
 
440
498
  /**
441
499
  * 响应数据解密
442
- * @param sm4Key 解密后的 SM4 密钥
443
- * @param data
444
- * @param uri
445
- * @param headers
500
+ * @param stepCb
501
+ * @deprecated 已废弃,请使用新的 gcm 方式进行加解密
446
502
  */
447
- export declare const responseDataDecryption: (sm4Key: string, data: string, uri: string, headers: IResponseDataEncryptionReturn["headers"]) => any;
503
+ export declare function responseDataEncryption<T>(stepCb: (_headers: {
504
+ [EHeaderKey.publicKey]: string;
505
+ }) => Promise<IResponseDataEncryptionStep>): Promise<T>;
448
506
 
449
507
  /**
450
508
  * gcm 解密响应
@@ -454,6 +512,15 @@ export declare const responseDataGcmCryptoInterceptor: <T extends {
454
512
  data: unknown;
455
513
  }>(response: AxiosResponse<T>) => AxiosResponse<T, any, {}>;
456
514
 
515
+ /**
516
+ * 响应数据通过gcm模式解密
517
+ * @param sm4Key 解密后的 SM4 密钥
518
+ * @param data
519
+ * @param uri
520
+ * @param headers
521
+ */
522
+ export declare const responseDataGcmDecryption: (sm4Key: string, data: string, uri: string, headers: IResponseDataEncryptionReturn["headers"]) => any;
523
+
457
524
  /**
458
525
  * 消毒 URL,返回安全的 URL 或替代 URL
459
526
  * @param url - 需要消毒的 URL
@@ -534,17 +601,36 @@ export { supportedExtensions }
534
601
 
535
602
  export { supportedMimeTypes }
536
603
 
604
+ declare type TAny = any;
605
+
537
606
  export declare type TData = _TData | _TData[];
538
607
 
539
608
  declare type _TData = null | undefined | number | string | Record<string, any>;
540
609
 
541
610
  export declare type TMaybeArray<T> = T[] | T;
542
611
 
612
+ /**
613
+ * 路由守卫函数
614
+ */
615
+ declare type TNavigationGuard = (to: TAny, from: TAny, next: TNavigationGuardNext) => TAny | Promise<TAny>;
616
+
617
+ /**
618
+ * 路由守卫的 next 函数
619
+ */
620
+ declare type TNavigationGuardNext = (to?: TAny) => void;
621
+
543
622
  export declare type TNullable<T> = T | null;
544
623
 
545
624
  export declare type TObj<K extends keyof any = string, T = any> = Record<K, T>;
546
625
 
547
- declare type TRequestBeforeCryptoCallBack = (config: InternalAxiosRequestConfig) => void;
626
+ declare type TRequestBeforeCryptoCallBack<T> = (config: T) => void;
627
+
628
+ /**
629
+ * 类 Router 接口,兼容 Vue Router 2/3/4
630
+ */
631
+ declare interface TRouterLike {
632
+ beforeEach: (guard: TNavigationGuard) => () => void;
633
+ }
548
634
 
549
635
  export declare type TUndefinable<T> = T | undefined;
550
636
 
package/dist/main.js CHANGED
@@ -1,46 +1,50 @@
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";
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";
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";
3
+ import { antiReplyAttackStrategy as p, requestDataEncryption as s, responseDataEncryption as n } from "./src/shield/crypto/index.js";
4
+ import { ALLOWED_FILE_MIMES as E, ALLOWED_FILE_TYPES as l, detectFileByExtension as c, detectFileByMime as f, detectionFilesByExtension as x, detectionFilesByMime as y, isValidDocument as D, isValidFile as u, isValidImage as S, isValidVideo as d } from "./src/shield/file-detection.js";
5
+ import { requestDataGcmEncryption as _, responseDataGcmDecryption as I } from "./src/shield/gcm-crypto/index.js";
6
+ import { htmlSanitize as F } from "./src/shield/html-sanitize.js";
7
+ import { startNoDebugger as B } from "./src/shield/no-debugger.js";
8
+ import { isUrlSafe as L, sanitizeUrl as A, sanitizeUrls as V } from "./src/shield/url-sanitize.js";
9
+ import { EventBus as N } from "./src/utils/eventBus.js";
10
+ import { CallLogger as P } from "./src/outside-call/utils.js";
11
+ import { ECallStatus as T, EMIT_EVENT_NAME as U, SIP_CODE_MESSAGE as z, SIP_ERROR_CAUSES as W } from "./src/outside-call/constants.js";
12
+ import { supportedExtensions as h, supportedMimeTypes as k } from "./vendor/file-type/source/index.js";
13
+ import { gcmCryptoPlugin as Y, requestDataBeforeGcmCrypto as j, requestDataGcmCryptoInterceptor as w, responseDataBeforeGcmCrypto as H, responseDataGcmCryptoInterceptor as J } from "./src/shield/gcm-crypto/axios-adapter.js";
13
14
  export {
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,
15
+ E as ALLOWED_FILE_MIMES,
16
+ l as ALLOWED_FILE_TYPES,
17
+ P as CallLogger,
18
+ T as ECallStatus,
19
+ U as EMIT_EVENT_NAME,
20
+ N as EventBus,
21
+ z as SIP_CODE_MESSAGE,
22
+ W as SIP_ERROR_CAUSES,
23
+ p as antiReplyAttackStrategy,
22
24
  i as createCosFileName,
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,
42
- I as startNoDebugger,
43
- z as supportedExtensions,
44
- R as supportedMimeTypes,
25
+ c as detectFileByExtension,
26
+ f as detectFileByMime,
27
+ x as detectionFilesByExtension,
28
+ y as detectionFilesByMime,
29
+ Y as gcmCryptoPlugin,
30
+ F as htmlSanitize,
31
+ L as isUrlSafe,
32
+ D as isValidDocument,
33
+ u as isValidFile,
34
+ S as isValidImage,
35
+ d as isValidVideo,
36
+ j as requestDataBeforeGcmCrypto,
37
+ s as requestDataEncryption,
38
+ w as requestDataGcmCryptoInterceptor,
39
+ _ as requestDataGcmEncryption,
40
+ H as responseDataBeforeGcmCrypto,
41
+ n as responseDataEncryption,
42
+ J as responseDataGcmCryptoInterceptor,
43
+ I as responseDataGcmDecryption,
44
+ A as sanitizeUrl,
45
+ V as sanitizeUrls,
46
+ B as startNoDebugger,
47
+ h as supportedExtensions,
48
+ k as supportedMimeTypes,
45
49
  r as useCall
46
50
  };
@@ -1,4 +1,4 @@
1
- import c from "../../commonjs-virtual-dir/index.js";
1
+ import c from "../../commonjs-virtual-dir/index2.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);
@@ -0,0 +1,53 @@
1
+ import { s as m } from "../../../commonjs-virtual-dir/index.js";
2
+ import { EHeaderKey as a } from "./const.js";
3
+ import { sm2Encrypt as d, generateKeyPairHex as g, sm2Decrypt as u } from "./sm2.js";
4
+ import { sm4Encrypt as K, sm4Decrypt as S } from "./sm4.js";
5
+ import { hexToBase64 as f, generateRandomString as p, base64ToHex as E, dataToStr as v } from "./util.js";
6
+ function $(o, c) {
7
+ const e = p(), n = p(), t = {
8
+ body: K(
9
+ {
10
+ key: e,
11
+ iv: n
12
+ },
13
+ c
14
+ )
15
+ }, r = f(d(o, e));
16
+ return {
17
+ headers: {
18
+ "X-Encrypted-Iv": n,
19
+ "X-Encrypted-Key": r
20
+ },
21
+ data: t
22
+ };
23
+ }
24
+ async function h(o) {
25
+ const { publicKey: c, privateKey: e } = g(), { data: n, headers: t } = await o({ "X-Public-Key": c }), r = t[a.encryptIv] || t[a.encryptIvLow], s = t[a.encryptKey] || t[a.encryptKeyLow], y = u(e, E(s)), i = S(
26
+ {
27
+ iv: r,
28
+ key: y
29
+ },
30
+ n
31
+ );
32
+ return JSON.parse(i);
33
+ }
34
+ function k({
35
+ uid: o = "",
36
+ salt: c = "",
37
+ ts: e = 0,
38
+ data: n = "",
39
+ ...t
40
+ }) {
41
+ const r = Date.now() + e, s = Math.random().toString(36).substring(2, 15), y = `${r}${o}${s}${v(n)}${c}`, i = m.sm3(y);
42
+ return {
43
+ ...t,
44
+ "X-Sign-Timestamp": String(r),
45
+ "X-Sign-Nonce": s,
46
+ "X-Sign-Client": i
47
+ };
48
+ }
49
+ export {
50
+ k as antiReplyAttackStrategy,
51
+ $ as requestDataEncryption,
52
+ h as responseDataEncryption
53
+ };
@@ -1,7 +1,7 @@
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);
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);
4
3
  export {
4
+ c as generateKeyPairHex,
5
5
  p as sm2Decrypt,
6
- c as sm2Encrypt
6
+ a as sm2Encrypt
7
7
  };
@@ -0,0 +1,15 @@
1
+ import { g as o } from "../../../commonjs-virtual-dir/index3.js";
2
+ import { dataToStr as r } from "./util.js";
3
+ const c = "cbc", n = (t, e) => new o.sm4({
4
+ key: t.key,
5
+ iv: t.iv,
6
+ mode: c
7
+ }).decrypt(r(e)), p = (t, e) => new o.sm4({
8
+ key: t.key,
9
+ iv: t.iv,
10
+ mode: c
11
+ }).encrypt(r(e));
12
+ export {
13
+ n as sm4Decrypt,
14
+ p as sm4Encrypt
15
+ };
@@ -1,17 +1,29 @@
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);
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);
6
16
  return btoa(e);
7
17
  }
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);
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);
12
22
  return Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
13
23
  }
14
24
  export {
15
- i as base64ToHex,
16
- o as hexToBase64
25
+ g as base64ToHex,
26
+ o as dataToStr,
27
+ i as generateRandomString,
28
+ a as hexToBase64
17
29
  };
@@ -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 { requestDataGcmEncryption as h, responseDataGcmDecryption 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 g = {
9
+ install: (e, t) => {
10
+ r.init(t), t.router.beforeEach(async (o, c, n) => {
11
+ await r.initPublicKey(), n();
12
+ });
13
+ }
14
+ }, x = (e) => {
15
+ r.addRequestBeforeCryptoCallback(e);
16
+ }, y = /* @__PURE__ */ new Map(), v = 10 * 60 * 1e3, l = 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 l.unref == "function" && l.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((c) => {
29
+ c(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: c, privateKey: n } = K.generateKeyPairHex();
38
+ y.set(c, { privateKey: n, timestamp: Date.now() }), e.headers.set(a.gcmPublicKey, c);
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: c } = o, { data: n, ...C } = e.data;
53
+ if (f(n))
54
+ return e;
55
+ const p = i(e.headers, a.encryptIv), u = i(e.headers, a.encryptKey), m = i(e.headers, a.encryptTag);
56
+ if (!p || !u || !m)
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(c, D(u));
63
+ e.data = {
64
+ ...C,
65
+ data: E(s, n, d(e.config.url), {
66
+ [a.encryptIv]: p,
67
+ [a.encryptKey]: s,
68
+ [a.encryptTag]: m
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
+ g as gcmCryptoPlugin,
78
+ x 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
+ };