module-develop-kit 1.4.2 → 1.5.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 (39) hide show
  1. package/dist/commonjs-virtual-dir/index.js +3 -5
  2. package/dist/commonjs-virtual-dir/index2.js +5 -2
  3. package/dist/commonjs-virtual-dir/index3.js +5 -2
  4. package/dist/commonjs-virtual-dir/index4.js +2 -4
  5. package/dist/commonjs-virtual-dir/index5.js +4 -0
  6. package/dist/commonjs-virtual-dir/index6.js +4 -0
  7. package/dist/commonjs-virtual-dir/index7.js +4 -0
  8. package/dist/commonjs-virtual-dir/index8.js +4 -0
  9. package/dist/main.d.ts +92 -10
  10. package/dist/main.js +44 -40
  11. package/dist/src/outside-call/utils.js +1 -1
  12. package/dist/src/shield/crypto/const.js +4 -0
  13. package/dist/src/shield/crypto/index.js +53 -0
  14. package/dist/src/shield/crypto/sm2.js +7 -0
  15. package/dist/src/shield/crypto/sm4.js +15 -0
  16. package/dist/src/shield/crypto/util.js +29 -0
  17. package/dist/src/shield/gcm-crypto/axios-adapter.js +25 -23
  18. package/dist/src/shield/gcm-crypto/index.js +16 -15
  19. package/dist/vendor/base64-js/index.js +52 -0
  20. package/dist/vendor/file-type/source/detectors/zip.js +64 -60
  21. package/dist/vendor/file-type/source/index.js +146 -130
  22. package/dist/vendor/file-type/source/supported.js +4 -2
  23. package/dist/vendor/gm-crypt/index.js +10 -0
  24. package/dist/vendor/gm-crypt/src/crypt.js +60 -0
  25. package/dist/vendor/gm-crypt/src/sm4.js +513 -0
  26. package/dist/vendor/ieee754/index.js +1 -1
  27. package/dist/vendor/jsbn/index.js +714 -0
  28. package/dist/vendor/sdp-transform/lib/index.js +1 -1
  29. package/dist/vendor/sm-crypto/src/index.js +14 -0
  30. package/dist/vendor/sm-crypto/src/sm2/asn1.js +86 -0
  31. package/dist/vendor/sm-crypto/src/sm2/ec.js +205 -0
  32. package/dist/vendor/sm-crypto/src/sm2/index.js +114 -0
  33. package/dist/vendor/sm-crypto/src/sm2/sm3.js +71 -0
  34. package/dist/vendor/sm-crypto/src/sm2/utils.js +95 -0
  35. package/dist/vendor/sm-crypto/src/sm3/index.js +50 -0
  36. package/dist/vendor/sm-crypto/src/sm4/index.js +408 -0
  37. package/dist/vendor/token-types/lib/index.js +1 -1
  38. package/dist/vite-plugins/index.d.ts +42 -0
  39. package/package.json +13 -13
@@ -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,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,7 @@
1
- var 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);
2
5
  export {
3
- r as __exports
6
+ a as default
4
7
  };
@@ -1,4 +1,2 @@
1
- var e = {};
2
- export {
3
- e as __exports
4
- };
1
+ import { __require as e } from "../vendor/ieee754/index.js";
2
+ e();
@@ -0,0 +1,4 @@
1
+ var r = {};
2
+ export {
3
+ r as __exports
4
+ };
@@ -0,0 +1,4 @@
1
+ var e = { exports: {} };
2
+ export {
3
+ e as __module
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
  */
@@ -448,15 +463,31 @@ export declare const requestDataBeforeGcmCrypto: (callback: TRequestBeforeCrypto
448
463
  /**
449
464
  * 请求数据加密
450
465
  * @param publicKey 公钥
451
- * @param data 原始数据
452
- * @param uri 当前请求的路径
466
+ * @param _data 数据
467
+ * @deprecated 已废弃,请使用新的 gcm 方式进行加解密
453
468
  */
454
- export declare const requestDataEncryption: <T>(publicKey: string, data: T, uri: string) => IResponseDataEncryptionReturn;
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
+ };
455
478
 
456
479
  /**
457
480
  * gcm 加密请求拦截器
458
481
  */
459
- export declare const requestDataGcmCryptoInterceptor: <T>(config: InternalAxiosRequestConfig<T>) => Promise<InternalAxiosRequestConfig<T>>;
482
+ export declare const requestDataGcmCryptoInterceptor: <T>(config: InternalAxiosRequestConfig<T>) => Promise<InternalAxiosRequestConfig<T, any>>;
483
+
484
+ /**
485
+ * 请求数据通过gcm模式加密
486
+ * @param publicKey 公钥
487
+ * @param data 原始数据
488
+ * @param uri 当前请求的路径
489
+ */
490
+ export declare const requestDataGcmEncryption: <T>(publicKey: string, data: T, uri: string) => IResponseDataEncryptionReturn;
460
491
 
461
492
  /**
462
493
  * 添加响应前解密回调
@@ -466,12 +497,12 @@ export declare const responseDataBeforeGcmCrypto: <T = TAny>(callback: TRequestB
466
497
 
467
498
  /**
468
499
  * 响应数据解密
469
- * @param sm4Key 解密后的 SM4 密钥
470
- * @param data
471
- * @param uri
472
- * @param headers
500
+ * @param stepCb
501
+ * @deprecated 已废弃,请使用新的 gcm 方式进行加解密
473
502
  */
474
- 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>;
475
506
 
476
507
  /**
477
508
  * gcm 解密响应
@@ -479,7 +510,16 @@ export declare const responseDataDecryption: (sm4Key: string, data: string, uri:
479
510
  */
480
511
  export declare const responseDataGcmCryptoInterceptor: <T extends {
481
512
  data: unknown;
482
- }>(response: AxiosResponse<T>) => AxiosResponse<T, any, {}>;
513
+ }>(response: AxiosResponse<T>) => AxiosResponse<T, any, {}, any>;
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;
483
523
 
484
524
  /**
485
525
  * 消毒 URL,返回安全的 URL 或替代 URL
@@ -612,3 +652,45 @@ export declare const useCall: (callBack?: (status: ECallStatus, callStatusText:
612
652
  };
613
653
 
614
654
  export { }
655
+
656
+
657
+
658
+ declare module "axios" {
659
+ export interface InternalAxiosRequestConfig {
660
+ /**
661
+ * 是否启用请求加密
662
+ * @default false
663
+ */
664
+ enableRequestCrypto?: boolean;
665
+
666
+ /**
667
+ * 是否启用响应加密
668
+ * @default false
669
+ */
670
+ enableResponseCrypto?: boolean;
671
+ }
672
+
673
+ // eslint-disable-next-line
674
+ export interface AxiosRequestConfig<D = any> {
675
+ /**
676
+ * 是否启用请求加密
677
+ * @default false
678
+ */
679
+ enableRequestCrypto?: boolean;
680
+
681
+ /**
682
+ * 是否启用响应加密
683
+ * @default false
684
+ */
685
+ enableResponseCrypto?: boolean;
686
+ }
687
+ }
688
+
689
+ declare module "gm-crypt" {
690
+ export class sm4 {
691
+ // eslint-disable-next-line
692
+ public constructor(options: { key: string; iv: string; mode?: "cbc" | "ecb"; cipherType?: "base64" | "text" }) {}
693
+ public encrypt(data: string): string;
694
+ public decrypt(encryptedData: string): string;
695
+ }
696
+ }
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 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
- import { startNoDebugger as I } from "./src/shield/no-debugger.js";
7
- import { isUrlSafe as M, sanitizeUrl as g, sanitizeUrls as B } 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 { gcmCryptoPlugin as b, requestDataBeforeGcmCrypto as h, requestDataGcmCryptoInterceptor as v, responseDataBeforeGcmCrypto as Y, responseDataGcmCryptoInterceptor as j } from "./src/shield/gcm-crypto/axios-adapter.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
- n as detectFileByMime,
25
- l as detectionFilesByExtension,
26
- E as detectionFilesByMime,
27
- b as gcmCryptoPlugin,
28
- S as htmlSanitize,
29
- M as isUrlSafe,
30
- c as isValidDocument,
31
- f as isValidFile,
32
- x as isValidImage,
33
- y as isValidVideo,
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
- 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/index3.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,4 @@
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
+ };
@@ -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
+ };
@@ -0,0 +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);
3
+ export {
4
+ c as generateKeyPairHex,
5
+ p as sm2Decrypt,
6
+ a as sm2Encrypt
7
+ };
@@ -0,0 +1,15 @@
1
+ import { g as o } from "../../../commonjs-virtual-dir/index2.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
+ };
@@ -0,0 +1,29 @@
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);
16
+ return btoa(e);
17
+ }
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);
22
+ return Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
23
+ }
24
+ export {
25
+ g as base64ToHex,
26
+ o as dataToStr,
27
+ i as generateRandomString,
28
+ a as hexToBase64
29
+ };
@@ -1,19 +1,19 @@
1
1
  import { sm2 as K } from "../../../vendor/sm-crypto-v2/dist/index.js";
2
2
  import { EGcmHeaderKey as a } from "./constants.js";
3
3
  import { gcmConfig as r } from "./gcm.config.js";
4
- import { requestDataEncryption as h, responseDataDecryption as E } from "./index.js";
4
+ import { requestDataGcmEncryption as h, responseDataGcmDecryption as E } from "./index.js";
5
5
  import { formatUrlToGcmCryptoUri as d, sm2Decrypt as w, base64ToHex as D } from "./utils.js";
6
6
  import { isNullOrUndefined as f } from "../../utils/is.js";
7
7
  import "vue";
8
- const x = {
8
+ const g = {
9
9
  install: (e, t) => {
10
- r.init(t), t.router.beforeEach(async (o, n, c) => {
11
- await r.initPublicKey(), c();
10
+ r.init(t), t.router.beforeEach(async (o, c, s) => {
11
+ await r.initPublicKey(), s();
12
12
  });
13
13
  }
14
- }, G = (e) => {
14
+ }, x = (e) => {
15
15
  r.addRequestBeforeCryptoCallback(e);
16
- }, y = /* @__PURE__ */ new Map(), v = 10 * 60 * 1e3, m = setInterval(
16
+ }, y = /* @__PURE__ */ new Map(), v = 10 * 60 * 1e3, l = setInterval(
17
17
  () => {
18
18
  const e = Date.now();
19
19
  for (const [t, o] of y.entries())
@@ -21,12 +21,12 @@ const x = {
21
21
  },
22
22
  5 * 60 * 1e3
23
23
  );
24
- typeof m.unref == "function" && m.unref();
24
+ typeof l.unref == "function" && l.unref();
25
25
  const i = (e, t) => e && (e[t] || e.get(t)) || "", R = async (e) => {
26
26
  if (i(e.headers, "Content-Type") === "multipart/form-data" || !r.isEnableRequestCrypto(e) || !e.url || (r.publicKey || await r.initPublicKey(), !r.publicKey))
27
27
  return e;
28
- r.requestBeforeCryptoCallBacks.forEach((n) => {
29
- n(e);
28
+ r.requestBeforeCryptoCallBacks.forEach((c) => {
29
+ c(e);
30
30
  });
31
31
  const { headers: t, data: o } = h(
32
32
  r.publicKey,
@@ -34,8 +34,8 @@ const i = (e, t) => e && (e[t] || e.get(t)) || "", R = async (e) => {
34
34
  d(e.url)
35
35
  );
36
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);
37
+ const { publicKey: c, privateKey: s } = K.generateKeyPairHex();
38
+ y.set(c, { privateKey: s, timestamp: Date.now() }), e.headers.set(a.gcmPublicKey, c);
39
39
  }
40
40
  return e.headers.set(t), e;
41
41
  }, H = (e) => {
@@ -49,33 +49,35 @@ const i = (e, t) => e && (e[t] || e.get(t)) || "", R = async (e) => {
49
49
  const o = y.get(t);
50
50
  if (y.delete(t), !o)
51
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))
52
+ const { privateKey: c } = o, { data: s, ...C } = e.data;
53
+ if (f(s))
54
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)
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
57
  throw new Error("[gcm-crypto] Missing required encryption headers");
58
58
  try {
59
59
  r.responseBeforeCryptoCallBacks.forEach((b) => {
60
60
  b(e);
61
61
  });
62
- const s = w(n, D(u));
62
+ const n = w(c, D(u));
63
63
  e.data = {
64
64
  ...C,
65
- data: E(s, c, d(e.config.url), {
65
+ data: E(n, s, d(e.config.url), {
66
66
  [a.encryptIv]: p,
67
- [a.encryptKey]: s,
68
- [a.encryptTag]: l
67
+ [a.encryptKey]: n,
68
+ [a.encryptTag]: m
69
69
  })
70
70
  };
71
- } catch (s) {
72
- throw new Error(`[gcm-crypto] Decryption failed: ${s instanceof Error ? s.message : String(s)}`);
71
+ } catch (n) {
72
+ throw new Error(`[gcm-crypto] Decryption failed: ${n instanceof Error ? n.message : String(n)}`, {
73
+ cause: n
74
+ });
73
75
  }
74
76
  return e;
75
77
  };
76
78
  export {
77
- x as gcmCryptoPlugin,
78
- G as requestDataBeforeGcmCrypto,
79
+ g as gcmCryptoPlugin,
80
+ x as requestDataBeforeGcmCrypto,
79
81
  R as requestDataGcmCryptoInterceptor,
80
82
  H as responseDataBeforeGcmCrypto,
81
83
  _ as responseDataGcmCryptoInterceptor
@@ -1,11 +1,11 @@
1
- import { sm4 as d } from "../../../vendor/sm-crypto-v2/dist/index.js";
1
+ import { sm4 as u } from "../../../vendor/sm-crypto-v2/dist/index.js";
2
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, {
3
+ import { generateHex as y, dataToStr as T, stringToUtf8Bytes as d, bytesToBase64 as m, hexToBase64 as f, sm2Encrypt as E, base64ToHex as i, utf8BytesToString as S } from "./utils.js";
4
+ const v = (c, n, p) => {
5
+ const t = y(12), e = y(16), { output: o, tag: a } = u.encrypt(T(n), e, {
6
6
  mode: "gcm",
7
7
  iv: t,
8
- associatedData: u(`uri=${c}`),
8
+ associatedData: d(`uri=${p}`),
9
9
  output: "array",
10
10
  outputTag: !0
11
11
  });
@@ -14,30 +14,31 @@ const v = (s, n, c) => {
14
14
  return {
15
15
  headers: {
16
16
  [r.encryptIv]: t,
17
- [r.encryptTag]: i(a),
18
- [r.encryptKey]: f(E(s, e))
17
+ [r.encryptTag]: m(a),
18
+ [r.encryptKey]: f(E(c, e))
19
19
  },
20
20
  data: {
21
- body: i(o)
21
+ body: m(o)
22
22
  }
23
23
  };
24
- }, w = (s, n, c, t) => {
25
- const e = t[r.encryptIv], o = m(t[r.encryptTag]), a = d.decrypt(m(n), s, {
24
+ }, w = (c, n, p, t) => {
25
+ const e = t[r.encryptIv], o = i(t[r.encryptTag]), a = u.decrypt(i(n), c, {
26
26
  mode: "gcm",
27
27
  iv: e,
28
- associatedData: u(`uri=${c}`),
28
+ associatedData: d(`uri=${p}`),
29
29
  output: "array",
30
30
  tag: o
31
31
  }), g = S(a);
32
32
  try {
33
33
  return JSON.parse(g);
34
- } catch (p) {
34
+ } catch (s) {
35
35
  throw new Error(
36
- `[gcm-crypto] Failed to parse decrypted data as JSON: ${p instanceof Error ? p.message : String(p)}`
36
+ `[gcm-crypto] Failed to parse decrypted data as JSON: ${s instanceof Error ? s.message : String(s)}`,
37
+ { cause: s }
37
38
  );
38
39
  }
39
40
  };
40
41
  export {
41
- v as requestDataEncryption,
42
- w as responseDataDecryption
42
+ v as requestDataGcmEncryption,
43
+ w as responseDataGcmDecryption
43
44
  };
@@ -0,0 +1,52 @@
1
+ import { __exports as F } from "../../commonjs-virtual-dir/index8.js";
2
+ var A;
3
+ function _() {
4
+ if (A) return F;
5
+ A = 1, F.byteLength = y, F.toByteArray = C, F.fromByteArray = B;
6
+ for (var c = [], n = [], l = typeof Uint8Array < "u" ? Uint8Array : Array, d = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", s = 0, p = d.length; s < p; ++s)
7
+ c[s] = d[s], n[d.charCodeAt(s)] = s;
8
+ n[45] = 62, n[95] = 63;
9
+ function x(r) {
10
+ var e = r.length;
11
+ if (e % 4 > 0)
12
+ throw new Error("Invalid string. Length must be a multiple of 4");
13
+ var a = r.indexOf("=");
14
+ a === -1 && (a = e);
15
+ var o = a === e ? 0 : 4 - a % 4;
16
+ return [a, o];
17
+ }
18
+ function y(r) {
19
+ var e = x(r), a = e[0], o = e[1];
20
+ return (a + o) * 3 / 4 - o;
21
+ }
22
+ function i(r, e, a) {
23
+ return (e + a) * 3 / 4 - a;
24
+ }
25
+ function C(r) {
26
+ var e, a = x(r), o = a[0], v = a[1], t = new l(i(r, o, v)), h = 0, u = v > 0 ? o - 4 : o, f;
27
+ for (f = 0; f < u; f += 4)
28
+ e = n[r.charCodeAt(f)] << 18 | n[r.charCodeAt(f + 1)] << 12 | n[r.charCodeAt(f + 2)] << 6 | n[r.charCodeAt(f + 3)], t[h++] = e >> 16 & 255, t[h++] = e >> 8 & 255, t[h++] = e & 255;
29
+ return v === 2 && (e = n[r.charCodeAt(f)] << 2 | n[r.charCodeAt(f + 1)] >> 4, t[h++] = e & 255), v === 1 && (e = n[r.charCodeAt(f)] << 10 | n[r.charCodeAt(f + 1)] << 4 | n[r.charCodeAt(f + 2)] >> 2, t[h++] = e >> 8 & 255, t[h++] = e & 255), t;
30
+ }
31
+ function L(r) {
32
+ return c[r >> 18 & 63] + c[r >> 12 & 63] + c[r >> 6 & 63] + c[r & 63];
33
+ }
34
+ function g(r, e, a) {
35
+ for (var o, v = [], t = e; t < a; t += 3)
36
+ o = (r[t] << 16 & 16711680) + (r[t + 1] << 8 & 65280) + (r[t + 2] & 255), v.push(L(o));
37
+ return v.join("");
38
+ }
39
+ function B(r) {
40
+ for (var e, a = r.length, o = a % 3, v = [], t = 16383, h = 0, u = a - o; h < u; h += t)
41
+ v.push(g(r, h, h + t > u ? u : h + t));
42
+ return o === 1 ? (e = r[a - 1], v.push(
43
+ c[e >> 2] + c[e << 4 & 63] + "=="
44
+ )) : o === 2 && (e = (r[a - 2] << 8) + r[a - 1], v.push(
45
+ c[e >> 10] + c[e >> 4 & 63] + c[e << 2 & 63] + "="
46
+ )), v.join("");
47
+ }
48
+ return F;
49
+ }
50
+ export {
51
+ _ as __require
52
+ };