module-develop-kit 0.5.10 → 0.5.11

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 (163) hide show
  1. package/dist/commonjs-virtual-dir/Config.js +4 -0
  2. package/dist/commonjs-virtual-dir/Constants.js +5 -0
  3. package/dist/commonjs-virtual-dir/DTMF.js +4 -0
  4. package/dist/commonjs-virtual-dir/JsSIP.js +5 -0
  5. package/dist/commonjs-virtual-dir/Parser2.js +4 -0
  6. package/dist/commonjs-virtual-dir/Socket.js +4 -0
  7. package/dist/commonjs-virtual-dir/Utils.js +4 -0
  8. package/dist/commonjs-virtual-dir/___vite-browser-external.js +6 -0
  9. package/dist/commonjs-virtual-dir/__vite-browser-external.js +4 -0
  10. package/dist/commonjs-virtual-dir/_commonjs-dynamic-modules.js +6 -0
  11. package/dist/commonjs-virtual-dir/_commonjsHelpers.js +33 -0
  12. package/dist/{vite-plugins/index.es.js → commonjs-virtual-dir/_virtual_mobile-compatibility-detection.js} +2 -31
  13. package/dist/commonjs-virtual-dir/_virtual_pc-compatibility-detection.js +4 -0
  14. package/dist/commonjs-virtual-dir/aes.js +4 -0
  15. package/dist/commonjs-virtual-dir/blowfish.js +4 -0
  16. package/dist/commonjs-virtual-dir/browser.js +4 -0
  17. package/dist/commonjs-virtual-dir/cipher-core.js +4 -0
  18. package/dist/commonjs-virtual-dir/core.js +4 -0
  19. package/dist/commonjs-virtual-dir/enc-base64.js +4 -0
  20. package/dist/commonjs-virtual-dir/enc-base64url.js +4 -0
  21. package/dist/commonjs-virtual-dir/enc-utf16.js +4 -0
  22. package/dist/commonjs-virtual-dir/events.js +4 -0
  23. package/dist/commonjs-virtual-dir/evpkdf.js +4 -0
  24. package/dist/commonjs-virtual-dir/format-hex.js +4 -0
  25. package/dist/commonjs-virtual-dir/grammar.js +4 -0
  26. package/dist/commonjs-virtual-dir/hmac.js +4 -0
  27. package/dist/commonjs-virtual-dir/index.js +5 -0
  28. package/dist/commonjs-virtual-dir/index2.js +5 -0
  29. package/dist/commonjs-virtual-dir/index3.js +7 -0
  30. package/dist/commonjs-virtual-dir/index4.js +4 -0
  31. package/dist/commonjs-virtual-dir/index5.js +7 -0
  32. package/dist/commonjs-virtual-dir/index6.js +4 -0
  33. package/dist/commonjs-virtual-dir/index7.js +4 -0
  34. package/dist/commonjs-virtual-dir/index8.js +4 -0
  35. package/dist/commonjs-virtual-dir/lib-typedarrays.js +4 -0
  36. package/dist/commonjs-virtual-dir/md5.js +4 -0
  37. package/dist/commonjs-virtual-dir/mode-cfb.js +4 -0
  38. package/dist/commonjs-virtual-dir/mode-ctr-gladman.js +4 -0
  39. package/dist/commonjs-virtual-dir/mode-ctr.js +4 -0
  40. package/dist/commonjs-virtual-dir/mode-ecb.js +4 -0
  41. package/dist/commonjs-virtual-dir/mode-ofb.js +4 -0
  42. package/dist/commonjs-virtual-dir/pad-ansix923.js +4 -0
  43. package/dist/commonjs-virtual-dir/pad-iso10126.js +4 -0
  44. package/dist/commonjs-virtual-dir/pad-iso97971.js +4 -0
  45. package/dist/commonjs-virtual-dir/pad-nopadding.js +4 -0
  46. package/dist/commonjs-virtual-dir/pad-zeropadding.js +4 -0
  47. package/dist/commonjs-virtual-dir/parser.js +4 -0
  48. package/dist/commonjs-virtual-dir/pbkdf2.js +4 -0
  49. package/dist/commonjs-virtual-dir/rabbit-legacy.js +4 -0
  50. package/dist/commonjs-virtual-dir/rabbit.js +4 -0
  51. package/dist/commonjs-virtual-dir/rc4.js +4 -0
  52. package/dist/commonjs-virtual-dir/ripemd160.js +4 -0
  53. package/dist/commonjs-virtual-dir/sha1.js +4 -0
  54. package/dist/commonjs-virtual-dir/sha224.js +4 -0
  55. package/dist/commonjs-virtual-dir/sha256.js +4 -0
  56. package/dist/commonjs-virtual-dir/sha3.js +4 -0
  57. package/dist/commonjs-virtual-dir/sha384.js +4 -0
  58. package/dist/commonjs-virtual-dir/sha512.js +4 -0
  59. package/dist/commonjs-virtual-dir/tripledes.js +4 -0
  60. package/dist/commonjs-virtual-dir/x64-core.js +4 -0
  61. package/dist/main.js +25 -0
  62. package/dist/src/outside-call/CallManagement.js +249 -0
  63. package/dist/src/outside-call/constants.js +42 -0
  64. package/dist/src/outside-call/index.js +74 -0
  65. package/dist/src/outside-call/utils.js +50 -0
  66. package/dist/src/shield/crypto.js +28 -0
  67. package/dist/src/shield/index.js +59 -0
  68. package/dist/src/shield/no-debugger.js +26 -0
  69. package/dist/src/utils/eventBus.js +59 -0
  70. package/dist/src/vite-plugins/getCompatibilityPlugins.js +13 -0
  71. package/dist/src/vite-plugins/vitePluginCompatibilityDetection.js +26 -0
  72. package/dist/vendor/base64-js/index.js +52 -0
  73. package/dist/vendor/crypto-js/aes.js +69 -0
  74. package/dist/vendor/crypto-js/blowfish.js +1131 -0
  75. package/dist/vendor/crypto-js/cipher-core.js +544 -0
  76. package/dist/vendor/crypto-js/core.js +508 -0
  77. package/dist/vendor/crypto-js/enc-base64.js +80 -0
  78. package/dist/vendor/crypto-js/enc-base64url.js +87 -0
  79. package/dist/vendor/crypto-js/enc-utf16.js +99 -0
  80. package/dist/vendor/crypto-js/evpkdf.js +70 -0
  81. package/dist/vendor/crypto-js/format-hex.js +53 -0
  82. package/dist/vendor/crypto-js/hmac.js +83 -0
  83. package/dist/vendor/crypto-js/index.js +49 -0
  84. package/dist/vendor/crypto-js/lib-typedarrays.js +27 -0
  85. package/dist/vendor/crypto-js/md5.js +71 -0
  86. package/dist/vendor/crypto-js/mode-cfb.js +36 -0
  87. package/dist/vendor/crypto-js/mode-ctr-gladman.js +45 -0
  88. package/dist/vendor/crypto-js/mode-ctr.js +28 -0
  89. package/dist/vendor/crypto-js/mode-ecb.js +27 -0
  90. package/dist/vendor/crypto-js/mode-ofb.js +26 -0
  91. package/dist/vendor/crypto-js/pad-ansix923.js +25 -0
  92. package/dist/vendor/crypto-js/pad-iso10126.js +25 -0
  93. package/dist/vendor/crypto-js/pad-iso97971.js +23 -0
  94. package/dist/vendor/crypto-js/pad-nopadding.js +21 -0
  95. package/dist/vendor/crypto-js/pad-zeropadding.js +28 -0
  96. package/dist/vendor/crypto-js/pbkdf2.js +74 -0
  97. package/dist/vendor/crypto-js/rabbit-legacy.js +73 -0
  98. package/dist/vendor/crypto-js/rabbit.js +75 -0
  99. package/dist/vendor/crypto-js/rc4.js +63 -0
  100. package/dist/vendor/crypto-js/ripemd160.js +398 -0
  101. package/dist/vendor/crypto-js/sha1.js +49 -0
  102. package/dist/vendor/crypto-js/sha224.js +36 -0
  103. package/dist/vendor/crypto-js/sha256.js +57 -0
  104. package/dist/vendor/crypto-js/sha3.js +116 -0
  105. package/dist/vendor/crypto-js/sha384.js +37 -0
  106. package/dist/vendor/crypto-js/sha512.js +147 -0
  107. package/dist/vendor/crypto-js/tripledes.js +729 -0
  108. package/dist/vendor/crypto-js/x64-core.js +235 -0
  109. package/dist/vendor/debug/src/browser.js +146 -0
  110. package/dist/vendor/debug/src/common.js +97 -0
  111. package/dist/vendor/events/events.js +216 -0
  112. package/dist/vendor/gm-crypt/index.js +10 -0
  113. package/dist/vendor/gm-crypt/src/crypt.js +60 -0
  114. package/dist/vendor/gm-crypt/src/sm4.js +513 -0
  115. package/dist/vendor/jsbn/index.js +714 -0
  116. package/dist/vendor/jssip/lib/Constants.js +180 -0
  117. package/dist/vendor/jssip/lib-es5/Config.js +263 -0
  118. package/dist/vendor/jssip/lib-es5/Constants.js +180 -0
  119. package/dist/vendor/jssip/lib-es5/Dialog/RequestSender.js +84 -0
  120. package/dist/vendor/jssip/lib-es5/Dialog.js +179 -0
  121. package/dist/vendor/jssip/lib-es5/DigestAuthentication.js +93 -0
  122. package/dist/vendor/jssip/lib-es5/Exceptions.js +131 -0
  123. package/dist/vendor/jssip/lib-es5/Grammar.js +1937 -0
  124. package/dist/vendor/jssip/lib-es5/JsSIP.js +37 -0
  125. package/dist/vendor/jssip/lib-es5/Logger.js +44 -0
  126. package/dist/vendor/jssip/lib-es5/Message.js +229 -0
  127. package/dist/vendor/jssip/lib-es5/NameAddrHeader.js +107 -0
  128. package/dist/vendor/jssip/lib-es5/Options.js +227 -0
  129. package/dist/vendor/jssip/lib-es5/Parser.js +202 -0
  130. package/dist/vendor/jssip/lib-es5/RTCSession/DTMF.js +175 -0
  131. package/dist/vendor/jssip/lib-es5/RTCSession/Info.js +149 -0
  132. package/dist/vendor/jssip/lib-es5/RTCSession/ReferNotifier.js +52 -0
  133. package/dist/vendor/jssip/lib-es5/RTCSession/ReferSubscriber.js +187 -0
  134. package/dist/vendor/jssip/lib-es5/RTCSession.js +1799 -0
  135. package/dist/vendor/jssip/lib-es5/Registrator.js +194 -0
  136. package/dist/vendor/jssip/lib-es5/RequestSender.js +99 -0
  137. package/dist/vendor/jssip/lib-es5/SIPMessage.js +623 -0
  138. package/dist/vendor/jssip/lib-es5/Socket.js +38 -0
  139. package/dist/vendor/jssip/lib-es5/Timers.js +25 -0
  140. package/dist/vendor/jssip/lib-es5/Transactions.js +481 -0
  141. package/dist/vendor/jssip/lib-es5/Transport.js +220 -0
  142. package/dist/vendor/jssip/lib-es5/UA.js +663 -0
  143. package/dist/vendor/jssip/lib-es5/URI.js +221 -0
  144. package/dist/vendor/jssip/lib-es5/Utils.js +263 -0
  145. package/dist/vendor/jssip/lib-es5/WebSocketInterface.js +120 -0
  146. package/dist/vendor/jssip/lib-es5/sanityCheck.js +170 -0
  147. package/dist/vendor/jssip/package.json.js +9 -0
  148. package/dist/vendor/ms/index.js +85 -0
  149. package/dist/vendor/sdp-transform/lib/grammar.js +449 -0
  150. package/dist/vendor/sdp-transform/lib/index.js +14 -0
  151. package/dist/vendor/sdp-transform/lib/parser.js +70 -0
  152. package/dist/vendor/sdp-transform/lib/writer.js +74 -0
  153. package/dist/vendor/sm-crypto/src/index.js +14 -0
  154. package/dist/vendor/sm-crypto/src/sm2/asn1.js +86 -0
  155. package/dist/vendor/sm-crypto/src/sm2/ec.js +205 -0
  156. package/dist/vendor/sm-crypto/src/sm2/index.js +114 -0
  157. package/dist/vendor/sm-crypto/src/sm2/sm3.js +71 -0
  158. package/dist/vendor/sm-crypto/src/sm2/utils.js +95 -0
  159. package/dist/vendor/sm-crypto/src/sm3/index.js +50 -0
  160. package/dist/vendor/sm-crypto/src/sm4/index.js +408 -0
  161. package/dist/vite-plugins/index.js +6 -0
  162. package/package.json +6 -5
  163. package/dist/index.es.js +0 -18159
@@ -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 "../../../commonjs-virtual-dir/___vite-browser-external.js";
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
+ };
@@ -0,0 +1,513 @@
1
+ import { __require as B } from "./crypt.js";
2
+ var b, k;
3
+ function w() {
4
+ if (k) return b;
5
+ k = 1;
6
+ const h = B(), l = 16, y = Uint8Array.from([
7
+ 214,
8
+ 144,
9
+ 233,
10
+ 254,
11
+ 204,
12
+ 225,
13
+ 61,
14
+ 183,
15
+ 22,
16
+ 182,
17
+ 20,
18
+ 194,
19
+ 40,
20
+ 251,
21
+ 44,
22
+ 5,
23
+ 43,
24
+ 103,
25
+ 154,
26
+ 118,
27
+ 42,
28
+ 190,
29
+ 4,
30
+ 195,
31
+ 170,
32
+ 68,
33
+ 19,
34
+ 38,
35
+ 73,
36
+ 134,
37
+ 6,
38
+ 153,
39
+ 156,
40
+ 66,
41
+ 80,
42
+ 244,
43
+ 145,
44
+ 239,
45
+ 152,
46
+ 122,
47
+ 51,
48
+ 84,
49
+ 11,
50
+ 67,
51
+ 237,
52
+ 207,
53
+ 172,
54
+ 98,
55
+ 228,
56
+ 179,
57
+ 28,
58
+ 169,
59
+ 201,
60
+ 8,
61
+ 232,
62
+ 149,
63
+ 128,
64
+ 223,
65
+ 148,
66
+ 250,
67
+ 117,
68
+ 143,
69
+ 63,
70
+ 166,
71
+ 71,
72
+ 7,
73
+ 167,
74
+ 252,
75
+ 243,
76
+ 115,
77
+ 23,
78
+ 186,
79
+ 131,
80
+ 89,
81
+ 60,
82
+ 25,
83
+ 230,
84
+ 133,
85
+ 79,
86
+ 168,
87
+ 104,
88
+ 107,
89
+ 129,
90
+ 178,
91
+ 113,
92
+ 100,
93
+ 218,
94
+ 139,
95
+ 248,
96
+ 235,
97
+ 15,
98
+ 75,
99
+ 112,
100
+ 86,
101
+ 157,
102
+ 53,
103
+ 30,
104
+ 36,
105
+ 14,
106
+ 94,
107
+ 99,
108
+ 88,
109
+ 209,
110
+ 162,
111
+ 37,
112
+ 34,
113
+ 124,
114
+ 59,
115
+ 1,
116
+ 33,
117
+ 120,
118
+ 135,
119
+ 212,
120
+ 0,
121
+ 70,
122
+ 87,
123
+ 159,
124
+ 211,
125
+ 39,
126
+ 82,
127
+ 76,
128
+ 54,
129
+ 2,
130
+ 231,
131
+ 160,
132
+ 196,
133
+ 200,
134
+ 158,
135
+ 234,
136
+ 191,
137
+ 138,
138
+ 210,
139
+ 64,
140
+ 199,
141
+ 56,
142
+ 181,
143
+ 163,
144
+ 247,
145
+ 242,
146
+ 206,
147
+ 249,
148
+ 97,
149
+ 21,
150
+ 161,
151
+ 224,
152
+ 174,
153
+ 93,
154
+ 164,
155
+ 155,
156
+ 52,
157
+ 26,
158
+ 85,
159
+ 173,
160
+ 147,
161
+ 50,
162
+ 48,
163
+ 245,
164
+ 140,
165
+ 177,
166
+ 227,
167
+ 29,
168
+ 246,
169
+ 226,
170
+ 46,
171
+ 130,
172
+ 102,
173
+ 202,
174
+ 96,
175
+ 192,
176
+ 41,
177
+ 35,
178
+ 171,
179
+ 13,
180
+ 83,
181
+ 78,
182
+ 111,
183
+ 213,
184
+ 219,
185
+ 55,
186
+ 69,
187
+ 222,
188
+ 253,
189
+ 142,
190
+ 47,
191
+ 3,
192
+ 255,
193
+ 106,
194
+ 114,
195
+ 109,
196
+ 108,
197
+ 91,
198
+ 81,
199
+ 141,
200
+ 27,
201
+ 175,
202
+ 146,
203
+ 187,
204
+ 221,
205
+ 188,
206
+ 127,
207
+ 17,
208
+ 217,
209
+ 92,
210
+ 65,
211
+ 31,
212
+ 16,
213
+ 90,
214
+ 216,
215
+ 10,
216
+ 193,
217
+ 49,
218
+ 136,
219
+ 165,
220
+ 205,
221
+ 123,
222
+ 189,
223
+ 45,
224
+ 116,
225
+ 208,
226
+ 18,
227
+ 184,
228
+ 229,
229
+ 180,
230
+ 176,
231
+ 137,
232
+ 105,
233
+ 151,
234
+ 74,
235
+ 12,
236
+ 150,
237
+ 119,
238
+ 126,
239
+ 101,
240
+ 185,
241
+ 241,
242
+ 9,
243
+ 197,
244
+ 110,
245
+ 198,
246
+ 132,
247
+ 24,
248
+ 240,
249
+ 125,
250
+ 236,
251
+ 58,
252
+ 220,
253
+ 77,
254
+ 32,
255
+ 121,
256
+ 238,
257
+ 95,
258
+ 62,
259
+ 215,
260
+ 203,
261
+ 57,
262
+ 72
263
+ ]), p = Uint32Array.from([
264
+ 462357,
265
+ 472066609,
266
+ 943670861,
267
+ 1415275113,
268
+ 1886879365,
269
+ 2358483617,
270
+ 2830087869,
271
+ 3301692121,
272
+ 3773296373,
273
+ 4228057617,
274
+ 404694573,
275
+ 876298825,
276
+ 1347903077,
277
+ 1819507329,
278
+ 2291111581,
279
+ 2762715833,
280
+ 3234320085,
281
+ 3705924337,
282
+ 4177462797,
283
+ 337322537,
284
+ 808926789,
285
+ 1280531041,
286
+ 1752135293,
287
+ 2223739545,
288
+ 2695343797,
289
+ 3166948049,
290
+ 3638552301,
291
+ 4110090761,
292
+ 269950501,
293
+ 741554753,
294
+ 1213159005,
295
+ 1684763257
296
+ ]), u = Uint32Array.from([
297
+ 2746333894,
298
+ 1453994832,
299
+ 1736282519,
300
+ 2993693404
301
+ ]);
302
+ class T {
303
+ /**
304
+ * Creates an instance of SM4.
305
+ * @param {Object} config
306
+ * @memberof SM4
307
+ */
308
+ constructor(x) {
309
+ let e = h.stringToArrayBufferInUtf8(x.key);
310
+ if (e.length !== 16)
311
+ throw new Error("key should be a 16 bytes string");
312
+ this.key = e;
313
+ let t = new Uint8Array(0);
314
+ if (x.iv !== void 0 && x.iv !== null && (t = h.stringToArrayBufferInUtf8(x.iv), t.length !== 16))
315
+ throw new Error("iv should be a 16 bytes string");
316
+ this.iv = t, this.mode = "cbc", ["cbc", "ecb"].indexOf(x.mode) >= 0 && (this.mode = x.mode), this.cipherType = "base64", ["base64", "text"].indexOf(x.outType) >= 0 && (this.cipherType = x.outType), this.encryptRoundKeys = new Uint32Array(32), this.spawnEncryptRoundKeys(), this.decryptRoundKeys = Uint32Array.from(this.encryptRoundKeys), this.decryptRoundKeys.reverse();
317
+ }
318
+ /**
319
+ * general sm4 encrypt/decrypt algorithm for a 16 bytes block using roundKey
320
+ *
321
+ * @param {Uint32Array} blockData
322
+ * @param {Uint32Array} roundKeys
323
+ * @return {Uint32Array} return a 16 bytes cipher block
324
+ * @memberof SM4
325
+ */
326
+ doBlockCrypt(x, e) {
327
+ let t = new Uint32Array(36);
328
+ t.set(x, 0);
329
+ for (let n = 0; n < 32; n++)
330
+ t[n + 4] = t[n] ^ this.tTransform1(t[n + 1] ^ t[n + 2] ^ t[n + 3] ^ e[n]);
331
+ let o = new Uint32Array(4);
332
+ return o[0] = t[35], o[1] = t[34], o[2] = t[33], o[3] = t[32], o;
333
+ }
334
+ /**
335
+ * spawn round key array for encrypt. reverse this key array when decrypt.
336
+ * every round key's length is 32 bytes.
337
+ * there are 32 round keys.
338
+ * @return {Uint32Array}
339
+ * @memberof SM4
340
+ */
341
+ spawnEncryptRoundKeys() {
342
+ let x = new Uint32Array(4);
343
+ x[0] = this.key[0] << 24 | this.key[1] << 16 | this.key[2] << 8 | this.key[3], x[1] = this.key[4] << 24 | this.key[5] << 16 | this.key[6] << 8 | this.key[7], x[2] = this.key[8] << 24 | this.key[9] << 16 | this.key[10] << 8 | this.key[11], x[3] = this.key[12] << 24 | this.key[13] << 16 | this.key[14] << 8 | this.key[15];
344
+ let e = new Uint32Array(36);
345
+ e[0] = x[0] ^ u[0], e[1] = x[1] ^ u[1], e[2] = x[2] ^ u[2], e[3] = x[3] ^ u[3];
346
+ for (let t = 0; t < 32; t++)
347
+ e[t + 4] = e[t] ^ this.tTransform2(e[t + 1] ^ e[t + 2] ^ e[t + 3] ^ p[t]), this.encryptRoundKeys[t] = e[t + 4];
348
+ }
349
+ /**
350
+ * left rotate x by y bits
351
+ *
352
+ * @param {*} x
353
+ * @param {Number} y
354
+ * @returns
355
+ * @memberof SM4
356
+ */
357
+ rotateLeft(x, e) {
358
+ return x << e | x >>> 32 - e;
359
+ }
360
+ /**
361
+ * L transform function for encrypt
362
+ *
363
+ * @param {Uint32Number} b
364
+ * @returns {Uint32Number}
365
+ * @memberof SM4
366
+ */
367
+ linearTransform1(x) {
368
+ return x ^ this.rotateLeft(x, 2) ^ this.rotateLeft(x, 10) ^ this.rotateLeft(x, 18) ^ this.rotateLeft(x, 24);
369
+ }
370
+ /**
371
+ * L' transform function for key expand
372
+ *
373
+ * @param {Uint32Number} b
374
+ * @returns {Uint32Number}
375
+ * @memberof SM4
376
+ */
377
+ linearTransform2(x) {
378
+ return x ^ this.rotateLeft(x, 13) ^ this.rotateLeft(x, 23);
379
+ }
380
+ /**
381
+ * τ transform function
382
+ *
383
+ * @param {Uint32Number} a
384
+ * @returns {Uint32Number}
385
+ * @memberof SM4
386
+ */
387
+ tauTransform(x) {
388
+ return y[x >>> 24 & 255] << 24 | y[x >>> 16 & 255] << 16 | y[x >>> 8 & 255] << 8 | y[x & 255];
389
+ }
390
+ /**
391
+ * mix replacement T transform for encrypt
392
+ *
393
+ * @param {Uint32Number} z
394
+ * @returns {Uint32Number}
395
+ * @memberof SM4
396
+ */
397
+ tTransform1(x) {
398
+ let e = this.tauTransform(x);
399
+ return this.linearTransform1(e);
400
+ }
401
+ /**
402
+ * mix replacement T transform for key expand
403
+ *
404
+ * @param {Uint32Number} z
405
+ * @returns {Uint32Number}
406
+ * @memberof SM4
407
+ */
408
+ tTransform2(x) {
409
+ let e = this.tauTransform(x);
410
+ return this.linearTransform2(e);
411
+ }
412
+ /**
413
+ * padding the array length to multiple of BLOCK
414
+ *
415
+ * @param {ByteArray} originalBuffer
416
+ * @returns {ByteArray}
417
+ * @memberof SM4
418
+ */
419
+ padding(x) {
420
+ if (x === null)
421
+ return null;
422
+ let e = l - x.length % l, t = new Uint8Array(x.length + e);
423
+ return t.set(x, 0), t.fill(e, x.length), t;
424
+ }
425
+ /**
426
+ * depadding the byte array to its original length
427
+ *
428
+ * @param {ByteArray} paddedBuffer
429
+ * @returns {ByteArray}
430
+ * @memberof SM4
431
+ */
432
+ dePadding(x) {
433
+ if (x === null)
434
+ return null;
435
+ let e = x[x.length - 1];
436
+ return x.slice(0, x.length - e);
437
+ }
438
+ /**
439
+ * exctract uint32 array block from uint8 array
440
+ *
441
+ * @param {Uint8Array} uint8Array
442
+ * @param {Number} baseIndex
443
+ * @returns {Uint32Array}
444
+ * @memberof SM4
445
+ */
446
+ uint8ToUint32Block(x, e = 0) {
447
+ let t = new Uint32Array(4);
448
+ return t[0] = x[e] << 24 | x[e + 1] << 16 | x[e + 2] << 8 | x[e + 3], t[1] = x[e + 4] << 24 | x[e + 5] << 16 | x[e + 6] << 8 | x[e + 7], t[2] = x[e + 8] << 24 | x[e + 9] << 16 | x[e + 10] << 8 | x[e + 11], t[3] = x[e + 12] << 24 | x[e + 13] << 16 | x[e + 14] << 8 | x[e + 15], t;
449
+ }
450
+ /**
451
+ * encrypt the string plaintext
452
+ *
453
+ * @param {String} plaintext
454
+ * @memberof SM4
455
+ * @return {String} ciphertext
456
+ */
457
+ encrypt(x) {
458
+ let e = h.stringToArrayBufferInUtf8(x), t = this.padding(e), o = t.length / l, n = new Uint8Array(t.length);
459
+ if (this.mode === "cbc") {
460
+ if (this.iv === null || this.iv.length !== 16)
461
+ throw new Error("iv error");
462
+ let r = this.uint8ToUint32Block(this.iv);
463
+ for (let f = 0; f < o; f++) {
464
+ let a = f * l, s = this.uint8ToUint32Block(t, a);
465
+ r[0] = r[0] ^ s[0], r[1] = r[1] ^ s[1], r[2] = r[2] ^ s[2], r[3] = r[3] ^ s[3];
466
+ let i = this.doBlockCrypt(r, this.encryptRoundKeys);
467
+ r = i;
468
+ for (let c = 0; c < l; c++)
469
+ n[a + c] = i[parseInt(c / 4)] >> (3 - c) % 4 * 8 & 255;
470
+ }
471
+ } else
472
+ for (let r = 0; r < o; r++) {
473
+ let f = r * l, a = this.uint8ToUint32Block(t, f), s = this.doBlockCrypt(a, this.encryptRoundKeys);
474
+ for (let i = 0; i < l; i++)
475
+ n[f + i] = s[parseInt(i / 4)] >> (3 - i) % 4 * 8 & 255;
476
+ }
477
+ return this.cipherType === "base64" ? h.arrayBufferToBase64(n) : h.utf8ArrayBufferToString(n);
478
+ }
479
+ /**
480
+ * decrypt the string ciphertext
481
+ *
482
+ * @param {String} ciphertext
483
+ * @memberof SM4
484
+ */
485
+ decrypt(x) {
486
+ let e = new Uint8Array();
487
+ this.cipherType === "base64" ? e = h.base64ToArrayBuffer(x) : e = h.stringToArrayBufferInUtf8(x);
488
+ let t = e.length / l, o = new Uint8Array(e.length);
489
+ if (this.mode === "cbc") {
490
+ if (this.iv === null || this.iv.length !== 16)
491
+ throw new Error("iv error");
492
+ let r = this.uint8ToUint32Block(this.iv);
493
+ for (let f = 0; f < t; f++) {
494
+ let a = f * l, s = this.uint8ToUint32Block(e, a), i = this.doBlockCrypt(s, this.decryptRoundKeys), c = new Uint32Array(4);
495
+ c[0] = r[0] ^ i[0], c[1] = r[1] ^ i[1], c[2] = r[2] ^ i[2], c[3] = r[3] ^ i[3], r = s;
496
+ for (let d = 0; d < l; d++)
497
+ o[a + d] = c[parseInt(d / 4)] >> (3 - d) % 4 * 8 & 255;
498
+ }
499
+ } else
500
+ for (let r = 0; r < t; r++) {
501
+ let f = r * l, a = this.uint8ToUint32Block(e, f), s = this.doBlockCrypt(a, this.decryptRoundKeys);
502
+ for (let i = 0; i < l; i++)
503
+ o[f + i] = s[parseInt(i / 4)] >> (3 - i) % 4 * 8 & 255;
504
+ }
505
+ let n = this.dePadding(o);
506
+ return h.utf8ArrayBufferToString(n);
507
+ }
508
+ }
509
+ return b = T, b;
510
+ }
511
+ export {
512
+ w as __require
513
+ };