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
@@ -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 m, hexToBase64 as f, sm2Encrypt as E, base64ToHex as i, utf8BytesToString as S } from "./utils.js";
4
+ const v = (s, c, n) => {
5
+ const t = y(12), e = y(16), { output: o, tag: a } = d.encrypt(T(c), e, {
9
6
  mode: "gcm",
10
7
  iv: t,
11
- associatedData: u(`uri=${p}`),
8
+ associatedData: u(`uri=${n}`),
12
9
  output: "array",
13
10
  outputTag: !0
14
11
  });
@@ -18,23 +15,29 @@ const H = (s, n, p) => {
18
15
  headers: {
19
16
  [r.encryptIv]: t,
20
17
  [r.encryptTag]: m(a),
21
- [r.encryptKey]: g(d(s, e))
18
+ [r.encryptKey]: f(E(s, e))
22
19
  },
23
20
  data: {
24
21
  body: m(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, c, n, t) => {
25
+ const e = t[r.encryptIv], o = i(t[r.encryptTag]), a = d.decrypt(i(c), s, {
29
26
  mode: "gcm",
30
27
  iv: e,
31
- associatedData: u(`uri=${p}`),
28
+ associatedData: u(`uri=${n}`),
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 requestDataGcmEncryption,
42
+ w as responseDataGcmDecryption
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,5 +1,5 @@
1
1
  import { UINT32_LE as h, StringType as k } from "../../../token-types/lib/index.js";
2
- import D from "../../../../commonjs-virtual-dir/browser2.js";
2
+ import D from "../../../../commonjs-virtual-dir/browser.js";
3
3
  import { Signature as c, EndOfCentralDirectoryRecordToken as L, FileHeader as E, DataDescriptor as y, LocalFileHeaderToken as S } from "./ZipToken.js";
4
4
  function m(s) {
5
5
  const t = new Uint8Array(h.len);
@@ -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
+ };
@@ -1,4 +1,4 @@
1
- import { __module as C } from "../../../commonjs-virtual-dir/browser.js";
1
+ import { __module as C } from "../../../commonjs-virtual-dir/browser2.js";
2
2
  import { __require as g } from "./common.js";
3
3
  var F;
4
4
  function p() {
@@ -0,0 +1,10 @@
1
+ import { __require as t } from "./src/sm4.js";
2
+ var r, e;
3
+ function m() {
4
+ return e || (e = 1, r = {
5
+ sm4: t()
6
+ }), r;
7
+ }
8
+ export {
9
+ m as __require
10
+ };
@@ -0,0 +1,60 @@
1
+ import { __require as a } from "../../base64-js/index.js";
2
+ import n from "util";
3
+ var t, d;
4
+ function y() {
5
+ if (d) return t;
6
+ d = 1;
7
+ const o = a();
8
+ class c {
9
+ /**
10
+ * Converts a JS string to an UTF-8 uint8array.
11
+ *
12
+ * @static
13
+ * @param {String} str 16-bit unicode string.
14
+ * @return {Uint8Array} UTF-8 Uint8Array.
15
+ * @memberof Crypt
16
+ */
17
+ static stringToArrayBufferInUtf8(e) {
18
+ const r = typeof window > "u" ? n.TextEncoder : window.TextEncoder;
19
+ return new r().encode(e);
20
+ }
21
+ /**
22
+ * Converts an UTF-8 uint8array to a JS string.
23
+ *
24
+ * @static
25
+ * @param {Uint8Array} strBuffer UTF-8 Uint8Array.
26
+ * @return {String} 16-bit unicode string.
27
+ * @memberof Crypt
28
+ */
29
+ static utf8ArrayBufferToString(e) {
30
+ const r = typeof window > "u" ? n.TextDecoder : window.TextDecoder;
31
+ return new r("utf-8").decode(e);
32
+ }
33
+ /**
34
+ * crypt a utf8 byteArray to base64 string
35
+ *
36
+ * @static
37
+ * @param {Uint8Array} strBuffer UTF-8 Uint8Array.
38
+ * @returns {String} base64 str
39
+ * @memberof Crypt
40
+ */
41
+ static arrayBufferToBase64(e) {
42
+ return o.fromByteArray(e);
43
+ }
44
+ /**
45
+ * crypt base64 stringa to utf8 byteArray
46
+ *
47
+ * @static
48
+ * @param {String} base64 str
49
+ * @returns {Uint8Array} strBuffer UTF-8 Uint8Array.
50
+ * @memberof Crypt
51
+ */
52
+ static base64ToArrayBuffer(e) {
53
+ return o.toByteArray(e);
54
+ }
55
+ }
56
+ return t = c, t;
57
+ }
58
+ export {
59
+ y as __require
60
+ };