zby-live-sdk 1.0.49-beta-talrtc0922 → 1.0.49-beta-talrtc1014

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 (51) hide show
  1. package/.babelrc +5 -5
  2. package/.editorconfig +13 -13
  3. package/.eslintrc.js +29 -29
  4. package/CHANGELOG.md +381 -370
  5. package/README.md +276 -276
  6. package/dist/zby-live-sdk.cjs.js +4 -3
  7. package/dist/zby-live-sdk.esm.js +4 -3
  8. package/dist/zby-live-sdk.umd.js +4 -3
  9. package/package.json +1 -1
  10. package/src/channel/getSendMsgParams.js +66 -66
  11. package/src/channel/index.js +138 -138
  12. package/src/channel/pomelo/index.js +184 -184
  13. package/src/channel/pomelo/latestQueue.js +151 -151
  14. package/src/channel/pomelo/polemo.js +749 -749
  15. package/src/channel/pomelo/util.js +54 -54
  16. package/src/channel/sdk-cb.js +73 -73
  17. package/src/channel/stream-msg.js +97 -97
  18. package/src/channel/zby/index.js +74 -74
  19. package/src/channel/zby/interactWithChannel.js +4 -4
  20. package/src/channel/zby/interactWithChannelControl.js +1568 -1568
  21. package/src/channel/zby/interactWithChannelEntry.js +318 -318
  22. package/src/config/config.js +153 -153
  23. package/src/default/base.js +70 -70
  24. package/src/default/extend.js +36 -36
  25. package/src/default/index.js +9 -9
  26. package/src/live/base.js +42 -42
  27. package/src/live/call-method.js +9 -9
  28. package/src/live/extend.js +53 -53
  29. package/src/live/index.js +9 -9
  30. package/src/network/api.js +50 -50
  31. package/src/network/commonFetch.js +66 -66
  32. package/src/network/dataReport.js +429 -429
  33. package/src/notice.js +394 -394
  34. package/src/tool/base.js +74 -74
  35. package/src/tool/call-method.js +9 -9
  36. package/src/tool/extend.js +42 -42
  37. package/src/tool/index.js +9 -9
  38. package/src/util/bridge.js +87 -87
  39. package/src/util/bridge1.js +46 -46
  40. package/src/util/dict.js +51 -51
  41. package/src/util/sessionStorage.js +29 -29
  42. package/src/util/sha256.js +482 -482
  43. package/src/util/util.js +308 -308
  44. package/src/zby-av-sdk/agora-sdk.js +711 -711
  45. package/src/zby-av-sdk/device.js +145 -145
  46. package/src/zby-av-sdk/rtc-sdk.js +2839 -2839
  47. package/src/zby-av-sdk/talrtc-sdk.js +2392 -2348
  48. package/src/zby-av-sdk/trtc-sdk.js +1801 -1801
  49. package/src/zby-av-sdk/zby-av-sdk.js +1891 -1891
  50. package/src/zby-av-sdk/zego-sdk.js +2987 -2987
  51. package/src/zby-live-sdk.js +1561 -1557
@@ -1,483 +1,483 @@
1
- /*eslint-disable*/
2
- /*
3
- * @Author: why
4
- * @Date: 2020-05-25 17:07:03
5
- * @LastEditors: why
6
- * @LastEditTime: 2020-05-25 17:41:42
7
- * @Description:
8
- */
9
- /**
10
- * [js-sha256]{@link https://github.com/emn178/js-sha256}
11
- *
12
- * @version 0.9.0
13
- * @author Chen, Yi-Cyuan [emn178@gmail.com]
14
- * @copyright Chen, Yi-Cyuan 2014-2017
15
- * @license MIT
16
- */
17
- /*jslint bitwise: true */
18
-
19
- var ERROR = 'input is invalid type';
20
- var WINDOW = typeof window === 'object';
21
- var root = WINDOW ? window : {};
22
- if (root.JS_SHA256_NO_WINDOW) {
23
- WINDOW = false;
24
- }
25
- var WEB_WORKER = !WINDOW && typeof self === 'object';
26
- var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
27
- if (NODE_JS) {
28
- root = global;
29
- } else if (WEB_WORKER) {
30
- root = self;
31
- }
32
- var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
33
- var HEX_CHARS = '0123456789abcdef'.split('');
34
- var EXTRA = [-2147483648, 8388608, 32768, 128];
35
- var SHIFT = [24, 16, 8, 0];
36
- var K = [
37
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
38
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
39
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
40
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
41
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
42
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
43
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
44
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
45
- ];
46
- var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
47
-
48
- var blocks = [];
49
-
50
- if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
51
- Array.isArray = function (obj) {
52
- return Object.prototype.toString.call(obj) === '[object Array]';
53
- };
54
- }
55
-
56
- if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
57
- ArrayBuffer.isView = function (obj) {
58
- return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
59
- };
60
- }
61
-
62
- var createOutputMethod = function (outputType, is224) {
63
- return function (message) {
64
- return new Sha256(is224, true).update(message)[outputType]();
65
- };
66
- };
67
-
68
- var createMethod = function (is224) {
69
- var method = createOutputMethod('hex', is224);
70
- method.create = function () {
71
- return new Sha256(is224);
72
- };
73
- method.update = function (message) {
74
- return method.create().update(message);
75
- };
76
- for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
77
- var type = OUTPUT_TYPES[i];
78
- method[type] = createOutputMethod(type, is224);
79
- }
80
- return method;
81
- };
82
-
83
- var createHmacOutputMethod = function (outputType, is224) {
84
- return function (key, message) {
85
- return new HmacSha256(key, is224, true).update(message)[outputType]();
86
- };
87
- };
88
-
89
- var createHmacMethod = function (is224) {
90
- var method = createHmacOutputMethod('hex', is224);
91
- method.create = function (key) {
92
- return new HmacSha256(key, is224);
93
- };
94
- method.update = function (key, message) {
95
- return method.create(key).update(message);
96
- };
97
- for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
98
- var type = OUTPUT_TYPES[i];
99
- method[type] = createHmacOutputMethod(type, is224);
100
- }
101
- return method;
102
- };
103
-
104
- function Sha256(is224, sharedMemory) {
105
- if (sharedMemory) {
106
- blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
107
- blocks[4] = blocks[5] = blocks[6] = blocks[7] =
108
- blocks[8] = blocks[9] = blocks[10] = blocks[11] =
109
- blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
110
- this.blocks = blocks;
111
- } else {
112
- this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
113
- }
114
-
115
- if (is224) {
116
- this.h0 = 0xc1059ed8;
117
- this.h1 = 0x367cd507;
118
- this.h2 = 0x3070dd17;
119
- this.h3 = 0xf70e5939;
120
- this.h4 = 0xffc00b31;
121
- this.h5 = 0x68581511;
122
- this.h6 = 0x64f98fa7;
123
- this.h7 = 0xbefa4fa4;
124
- } else { // 256
125
- this.h0 = 0x6a09e667;
126
- this.h1 = 0xbb67ae85;
127
- this.h2 = 0x3c6ef372;
128
- this.h3 = 0xa54ff53a;
129
- this.h4 = 0x510e527f;
130
- this.h5 = 0x9b05688c;
131
- this.h6 = 0x1f83d9ab;
132
- this.h7 = 0x5be0cd19;
133
- }
134
-
135
- this.block = this.start = this.bytes = this.hBytes = 0;
136
- this.finalized = this.hashed = false;
137
- this.first = true;
138
- this.is224 = is224;
139
- }
140
-
141
- Sha256.prototype.update = function (message) {
142
- if (this.finalized) {
143
- return;
144
- }
145
- var notString, type = typeof message;
146
- if (type !== 'string') {
147
- if (type === 'object') {
148
- if (message === null) {
149
- throw new Error(ERROR);
150
- } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
151
- message = new Uint8Array(message);
152
- } else if (!Array.isArray(message)) {
153
- if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
154
- throw new Error(ERROR);
155
- }
156
- }
157
- } else {
158
- throw new Error(ERROR);
159
- }
160
- notString = true;
161
- }
162
- var code, index = 0, i, length = message.length, blocks = this.blocks;
163
-
164
- while (index < length) {
165
- if (this.hashed) {
166
- this.hashed = false;
167
- blocks[0] = this.block;
168
- blocks[16] = blocks[1] = blocks[2] = blocks[3] =
169
- blocks[4] = blocks[5] = blocks[6] = blocks[7] =
170
- blocks[8] = blocks[9] = blocks[10] = blocks[11] =
171
- blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
172
- }
173
-
174
- if (notString) {
175
- for (i = this.start; index < length && i < 64; ++index) {
176
- blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
177
- }
178
- } else {
179
- for (i = this.start; index < length && i < 64; ++index) {
180
- code = message.charCodeAt(index);
181
- if (code < 0x80) {
182
- blocks[i >> 2] |= code << SHIFT[i++ & 3];
183
- } else if (code < 0x800) {
184
- blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
185
- blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
186
- } else if (code < 0xd800 || code >= 0xe000) {
187
- blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
188
- blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
189
- blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
190
- } else {
191
- code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
192
- blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
193
- blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
194
- blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
195
- blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
196
- }
197
- }
198
- }
199
-
200
- this.lastByteIndex = i;
201
- this.bytes += i - this.start;
202
- if (i >= 64) {
203
- this.block = blocks[16];
204
- this.start = i - 64;
205
- this.hash();
206
- this.hashed = true;
207
- } else {
208
- this.start = i;
209
- }
210
- }
211
- if (this.bytes > 4294967295) {
212
- this.hBytes += this.bytes / 4294967296 << 0;
213
- this.bytes = this.bytes % 4294967296;
214
- }
215
- return this;
216
- };
217
-
218
- Sha256.prototype.finalize = function () {
219
- if (this.finalized) {
220
- return;
221
- }
222
- this.finalized = true;
223
- var blocks = this.blocks, i = this.lastByteIndex;
224
- blocks[16] = this.block;
225
- blocks[i >> 2] |= EXTRA[i & 3];
226
- this.block = blocks[16];
227
- if (i >= 56) {
228
- if (!this.hashed) {
229
- this.hash();
230
- }
231
- blocks[0] = this.block;
232
- blocks[16] = blocks[1] = blocks[2] = blocks[3] =
233
- blocks[4] = blocks[5] = blocks[6] = blocks[7] =
234
- blocks[8] = blocks[9] = blocks[10] = blocks[11] =
235
- blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
236
- }
237
- blocks[14] = this.hBytes << 3 | this.bytes >>> 29;
238
- blocks[15] = this.bytes << 3;
239
- this.hash();
240
- };
241
-
242
- Sha256.prototype.hash = function () {
243
- var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6,
244
- h = this.h7, blocks = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
245
-
246
- for (j = 16; j < 64; ++j) {
247
- // rightrotate
248
- t1 = blocks[j - 15];
249
- s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3);
250
- t1 = blocks[j - 2];
251
- s1 = ((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10);
252
- blocks[j] = blocks[j - 16] + s0 + blocks[j - 7] + s1 << 0;
253
- }
254
-
255
- bc = b & c;
256
- for (j = 0; j < 64; j += 4) {
257
- if (this.first) {
258
- if (this.is224) {
259
- ab = 300032;
260
- t1 = blocks[0] - 1413257819;
261
- h = t1 - 150054599 << 0;
262
- d = t1 + 24177077 << 0;
263
- } else {
264
- ab = 704751109;
265
- t1 = blocks[0] - 210244248;
266
- h = t1 - 1521486534 << 0;
267
- d = t1 + 143694565 << 0;
268
- }
269
- this.first = false;
270
- } else {
271
- s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
272
- s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
273
- ab = a & b;
274
- maj = ab ^ (a & c) ^ bc;
275
- ch = (e & f) ^ (~e & g);
276
- t1 = h + s1 + ch + K[j] + blocks[j];
277
- t2 = s0 + maj;
278
- h = d + t1 << 0;
279
- d = t1 + t2 << 0;
280
- }
281
- s0 = ((d >>> 2) | (d << 30)) ^ ((d >>> 13) | (d << 19)) ^ ((d >>> 22) | (d << 10));
282
- s1 = ((h >>> 6) | (h << 26)) ^ ((h >>> 11) | (h << 21)) ^ ((h >>> 25) | (h << 7));
283
- da = d & a;
284
- maj = da ^ (d & b) ^ ab;
285
- ch = (h & e) ^ (~h & f);
286
- t1 = g + s1 + ch + K[j + 1] + blocks[j + 1];
287
- t2 = s0 + maj;
288
- g = c + t1 << 0;
289
- c = t1 + t2 << 0;
290
- s0 = ((c >>> 2) | (c << 30)) ^ ((c >>> 13) | (c << 19)) ^ ((c >>> 22) | (c << 10));
291
- s1 = ((g >>> 6) | (g << 26)) ^ ((g >>> 11) | (g << 21)) ^ ((g >>> 25) | (g << 7));
292
- cd = c & d;
293
- maj = cd ^ (c & a) ^ da;
294
- ch = (g & h) ^ (~g & e);
295
- t1 = f + s1 + ch + K[j + 2] + blocks[j + 2];
296
- t2 = s0 + maj;
297
- f = b + t1 << 0;
298
- b = t1 + t2 << 0;
299
- s0 = ((b >>> 2) | (b << 30)) ^ ((b >>> 13) | (b << 19)) ^ ((b >>> 22) | (b << 10));
300
- s1 = ((f >>> 6) | (f << 26)) ^ ((f >>> 11) | (f << 21)) ^ ((f >>> 25) | (f << 7));
301
- bc = b & c;
302
- maj = bc ^ (b & d) ^ cd;
303
- ch = (f & g) ^ (~f & h);
304
- t1 = e + s1 + ch + K[j + 3] + blocks[j + 3];
305
- t2 = s0 + maj;
306
- e = a + t1 << 0;
307
- a = t1 + t2 << 0;
308
- }
309
-
310
- this.h0 = this.h0 + a << 0;
311
- this.h1 = this.h1 + b << 0;
312
- this.h2 = this.h2 + c << 0;
313
- this.h3 = this.h3 + d << 0;
314
- this.h4 = this.h4 + e << 0;
315
- this.h5 = this.h5 + f << 0;
316
- this.h6 = this.h6 + g << 0;
317
- this.h7 = this.h7 + h << 0;
318
- };
319
-
320
- Sha256.prototype.hex = function () {
321
- this.finalize();
322
-
323
- var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5,
324
- h6 = this.h6, h7 = this.h7;
325
-
326
- var hex = HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
327
- HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
328
- HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
329
- HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
330
- HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
331
- HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
332
- HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
333
- HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
334
- HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
335
- HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
336
- HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
337
- HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
338
- HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F] +
339
- HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
340
- HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
341
- HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
342
- HEX_CHARS[(h4 >> 28) & 0x0F] + HEX_CHARS[(h4 >> 24) & 0x0F] +
343
- HEX_CHARS[(h4 >> 20) & 0x0F] + HEX_CHARS[(h4 >> 16) & 0x0F] +
344
- HEX_CHARS[(h4 >> 12) & 0x0F] + HEX_CHARS[(h4 >> 8) & 0x0F] +
345
- HEX_CHARS[(h4 >> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F] +
346
- HEX_CHARS[(h5 >> 28) & 0x0F] + HEX_CHARS[(h5 >> 24) & 0x0F] +
347
- HEX_CHARS[(h5 >> 20) & 0x0F] + HEX_CHARS[(h5 >> 16) & 0x0F] +
348
- HEX_CHARS[(h5 >> 12) & 0x0F] + HEX_CHARS[(h5 >> 8) & 0x0F] +
349
- HEX_CHARS[(h5 >> 4) & 0x0F] + HEX_CHARS[h5 & 0x0F] +
350
- HEX_CHARS[(h6 >> 28) & 0x0F] + HEX_CHARS[(h6 >> 24) & 0x0F] +
351
- HEX_CHARS[(h6 >> 20) & 0x0F] + HEX_CHARS[(h6 >> 16) & 0x0F] +
352
- HEX_CHARS[(h6 >> 12) & 0x0F] + HEX_CHARS[(h6 >> 8) & 0x0F] +
353
- HEX_CHARS[(h6 >> 4) & 0x0F] + HEX_CHARS[h6 & 0x0F];
354
- if (!this.is224) {
355
- hex += HEX_CHARS[(h7 >> 28) & 0x0F] + HEX_CHARS[(h7 >> 24) & 0x0F] +
356
- HEX_CHARS[(h7 >> 20) & 0x0F] + HEX_CHARS[(h7 >> 16) & 0x0F] +
357
- HEX_CHARS[(h7 >> 12) & 0x0F] + HEX_CHARS[(h7 >> 8) & 0x0F] +
358
- HEX_CHARS[(h7 >> 4) & 0x0F] + HEX_CHARS[h7 & 0x0F];
359
- }
360
- return hex;
361
- };
362
-
363
- Sha256.prototype.toString = Sha256.prototype.hex;
364
-
365
- Sha256.prototype.digest = function () {
366
- this.finalize();
367
-
368
- var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5,
369
- h6 = this.h6, h7 = this.h7;
370
-
371
- var arr = [
372
- (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, h0 & 0xFF,
373
- (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, h1 & 0xFF,
374
- (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, h2 & 0xFF,
375
- (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, h3 & 0xFF,
376
- (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, h4 & 0xFF,
377
- (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, h5 & 0xFF,
378
- (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, h6 & 0xFF
379
- ];
380
- if (!this.is224) {
381
- arr.push((h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, h7 & 0xFF);
382
- }
383
- return arr;
384
- };
385
-
386
- Sha256.prototype.array = Sha256.prototype.digest;
387
-
388
- Sha256.prototype.arrayBuffer = function () {
389
- this.finalize();
390
-
391
- var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
392
- var dataView = new DataView(buffer);
393
- dataView.setUint32(0, this.h0);
394
- dataView.setUint32(4, this.h1);
395
- dataView.setUint32(8, this.h2);
396
- dataView.setUint32(12, this.h3);
397
- dataView.setUint32(16, this.h4);
398
- dataView.setUint32(20, this.h5);
399
- dataView.setUint32(24, this.h6);
400
- if (!this.is224) {
401
- dataView.setUint32(28, this.h7);
402
- }
403
- return buffer;
404
- };
405
-
406
- function HmacSha256(key, is224, sharedMemory) {
407
- var i, type = typeof key;
408
- if (type === 'string') {
409
- var bytes = [], length = key.length, index = 0, code;
410
- for (i = 0; i < length; ++i) {
411
- code = key.charCodeAt(i);
412
- if (code < 0x80) {
413
- bytes[index++] = code;
414
- } else if (code < 0x800) {
415
- bytes[index++] = (0xc0 | (code >> 6));
416
- bytes[index++] = (0x80 | (code & 0x3f));
417
- } else if (code < 0xd800 || code >= 0xe000) {
418
- bytes[index++] = (0xe0 | (code >> 12));
419
- bytes[index++] = (0x80 | ((code >> 6) & 0x3f));
420
- bytes[index++] = (0x80 | (code & 0x3f));
421
- } else {
422
- code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
423
- bytes[index++] = (0xf0 | (code >> 18));
424
- bytes[index++] = (0x80 | ((code >> 12) & 0x3f));
425
- bytes[index++] = (0x80 | ((code >> 6) & 0x3f));
426
- bytes[index++] = (0x80 | (code & 0x3f));
427
- }
428
- }
429
- key = bytes;
430
- } else {
431
- if (type === 'object') {
432
- if (key === null) {
433
- throw new Error(ERROR);
434
- } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
435
- key = new Uint8Array(key);
436
- } else if (!Array.isArray(key)) {
437
- if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
438
- throw new Error(ERROR);
439
- }
440
- }
441
- } else {
442
- throw new Error(ERROR);
443
- }
444
- }
445
-
446
- if (key.length > 64) {
447
- key = (new Sha256(is224, true)).update(key).array();
448
- }
449
-
450
- var oKeyPad = [], iKeyPad = [];
451
- for (i = 0; i < 64; ++i) {
452
- var b = key[i] || 0;
453
- oKeyPad[i] = 0x5c ^ b;
454
- iKeyPad[i] = 0x36 ^ b;
455
- }
456
-
457
- Sha256.call(this, is224, sharedMemory);
458
-
459
- this.update(iKeyPad);
460
- this.oKeyPad = oKeyPad;
461
- this.inner = true;
462
- this.sharedMemory = sharedMemory;
463
- }
464
- HmacSha256.prototype = new Sha256();
465
-
466
- HmacSha256.prototype.finalize = function () {
467
- Sha256.prototype.finalize.call(this);
468
- if (this.inner) {
469
- this.inner = false;
470
- var innerHash = this.array();
471
- Sha256.call(this, this.is224, this.sharedMemory);
472
- this.update(this.oKeyPad);
473
- this.update(innerHash);
474
- Sha256.prototype.finalize.call(this);
475
- }
476
- };
477
-
478
- export default {
479
- sha256: createMethod(),
480
- sha224: createMethod(true),
481
- hmacsha256: createHmacMethod(),
482
- hmacsha224: createHmacMethod(true)
1
+ /*eslint-disable*/
2
+ /*
3
+ * @Author: why
4
+ * @Date: 2020-05-25 17:07:03
5
+ * @LastEditors: why
6
+ * @LastEditTime: 2020-05-25 17:41:42
7
+ * @Description:
8
+ */
9
+ /**
10
+ * [js-sha256]{@link https://github.com/emn178/js-sha256}
11
+ *
12
+ * @version 0.9.0
13
+ * @author Chen, Yi-Cyuan [emn178@gmail.com]
14
+ * @copyright Chen, Yi-Cyuan 2014-2017
15
+ * @license MIT
16
+ */
17
+ /*jslint bitwise: true */
18
+
19
+ var ERROR = 'input is invalid type';
20
+ var WINDOW = typeof window === 'object';
21
+ var root = WINDOW ? window : {};
22
+ if (root.JS_SHA256_NO_WINDOW) {
23
+ WINDOW = false;
24
+ }
25
+ var WEB_WORKER = !WINDOW && typeof self === 'object';
26
+ var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
27
+ if (NODE_JS) {
28
+ root = global;
29
+ } else if (WEB_WORKER) {
30
+ root = self;
31
+ }
32
+ var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
33
+ var HEX_CHARS = '0123456789abcdef'.split('');
34
+ var EXTRA = [-2147483648, 8388608, 32768, 128];
35
+ var SHIFT = [24, 16, 8, 0];
36
+ var K = [
37
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
38
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
39
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
40
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
41
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
42
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
43
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
44
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
45
+ ];
46
+ var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
47
+
48
+ var blocks = [];
49
+
50
+ if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
51
+ Array.isArray = function (obj) {
52
+ return Object.prototype.toString.call(obj) === '[object Array]';
53
+ };
54
+ }
55
+
56
+ if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
57
+ ArrayBuffer.isView = function (obj) {
58
+ return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
59
+ };
60
+ }
61
+
62
+ var createOutputMethod = function (outputType, is224) {
63
+ return function (message) {
64
+ return new Sha256(is224, true).update(message)[outputType]();
65
+ };
66
+ };
67
+
68
+ var createMethod = function (is224) {
69
+ var method = createOutputMethod('hex', is224);
70
+ method.create = function () {
71
+ return new Sha256(is224);
72
+ };
73
+ method.update = function (message) {
74
+ return method.create().update(message);
75
+ };
76
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
77
+ var type = OUTPUT_TYPES[i];
78
+ method[type] = createOutputMethod(type, is224);
79
+ }
80
+ return method;
81
+ };
82
+
83
+ var createHmacOutputMethod = function (outputType, is224) {
84
+ return function (key, message) {
85
+ return new HmacSha256(key, is224, true).update(message)[outputType]();
86
+ };
87
+ };
88
+
89
+ var createHmacMethod = function (is224) {
90
+ var method = createHmacOutputMethod('hex', is224);
91
+ method.create = function (key) {
92
+ return new HmacSha256(key, is224);
93
+ };
94
+ method.update = function (key, message) {
95
+ return method.create(key).update(message);
96
+ };
97
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
98
+ var type = OUTPUT_TYPES[i];
99
+ method[type] = createHmacOutputMethod(type, is224);
100
+ }
101
+ return method;
102
+ };
103
+
104
+ function Sha256(is224, sharedMemory) {
105
+ if (sharedMemory) {
106
+ blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
107
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
108
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
109
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
110
+ this.blocks = blocks;
111
+ } else {
112
+ this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
113
+ }
114
+
115
+ if (is224) {
116
+ this.h0 = 0xc1059ed8;
117
+ this.h1 = 0x367cd507;
118
+ this.h2 = 0x3070dd17;
119
+ this.h3 = 0xf70e5939;
120
+ this.h4 = 0xffc00b31;
121
+ this.h5 = 0x68581511;
122
+ this.h6 = 0x64f98fa7;
123
+ this.h7 = 0xbefa4fa4;
124
+ } else { // 256
125
+ this.h0 = 0x6a09e667;
126
+ this.h1 = 0xbb67ae85;
127
+ this.h2 = 0x3c6ef372;
128
+ this.h3 = 0xa54ff53a;
129
+ this.h4 = 0x510e527f;
130
+ this.h5 = 0x9b05688c;
131
+ this.h6 = 0x1f83d9ab;
132
+ this.h7 = 0x5be0cd19;
133
+ }
134
+
135
+ this.block = this.start = this.bytes = this.hBytes = 0;
136
+ this.finalized = this.hashed = false;
137
+ this.first = true;
138
+ this.is224 = is224;
139
+ }
140
+
141
+ Sha256.prototype.update = function (message) {
142
+ if (this.finalized) {
143
+ return;
144
+ }
145
+ var notString, type = typeof message;
146
+ if (type !== 'string') {
147
+ if (type === 'object') {
148
+ if (message === null) {
149
+ throw new Error(ERROR);
150
+ } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
151
+ message = new Uint8Array(message);
152
+ } else if (!Array.isArray(message)) {
153
+ if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
154
+ throw new Error(ERROR);
155
+ }
156
+ }
157
+ } else {
158
+ throw new Error(ERROR);
159
+ }
160
+ notString = true;
161
+ }
162
+ var code, index = 0, i, length = message.length, blocks = this.blocks;
163
+
164
+ while (index < length) {
165
+ if (this.hashed) {
166
+ this.hashed = false;
167
+ blocks[0] = this.block;
168
+ blocks[16] = blocks[1] = blocks[2] = blocks[3] =
169
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
170
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
171
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
172
+ }
173
+
174
+ if (notString) {
175
+ for (i = this.start; index < length && i < 64; ++index) {
176
+ blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
177
+ }
178
+ } else {
179
+ for (i = this.start; index < length && i < 64; ++index) {
180
+ code = message.charCodeAt(index);
181
+ if (code < 0x80) {
182
+ blocks[i >> 2] |= code << SHIFT[i++ & 3];
183
+ } else if (code < 0x800) {
184
+ blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
185
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
186
+ } else if (code < 0xd800 || code >= 0xe000) {
187
+ blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
188
+ blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
189
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
190
+ } else {
191
+ code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
192
+ blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
193
+ blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
194
+ blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
195
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
196
+ }
197
+ }
198
+ }
199
+
200
+ this.lastByteIndex = i;
201
+ this.bytes += i - this.start;
202
+ if (i >= 64) {
203
+ this.block = blocks[16];
204
+ this.start = i - 64;
205
+ this.hash();
206
+ this.hashed = true;
207
+ } else {
208
+ this.start = i;
209
+ }
210
+ }
211
+ if (this.bytes > 4294967295) {
212
+ this.hBytes += this.bytes / 4294967296 << 0;
213
+ this.bytes = this.bytes % 4294967296;
214
+ }
215
+ return this;
216
+ };
217
+
218
+ Sha256.prototype.finalize = function () {
219
+ if (this.finalized) {
220
+ return;
221
+ }
222
+ this.finalized = true;
223
+ var blocks = this.blocks, i = this.lastByteIndex;
224
+ blocks[16] = this.block;
225
+ blocks[i >> 2] |= EXTRA[i & 3];
226
+ this.block = blocks[16];
227
+ if (i >= 56) {
228
+ if (!this.hashed) {
229
+ this.hash();
230
+ }
231
+ blocks[0] = this.block;
232
+ blocks[16] = blocks[1] = blocks[2] = blocks[3] =
233
+ blocks[4] = blocks[5] = blocks[6] = blocks[7] =
234
+ blocks[8] = blocks[9] = blocks[10] = blocks[11] =
235
+ blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
236
+ }
237
+ blocks[14] = this.hBytes << 3 | this.bytes >>> 29;
238
+ blocks[15] = this.bytes << 3;
239
+ this.hash();
240
+ };
241
+
242
+ Sha256.prototype.hash = function () {
243
+ var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6,
244
+ h = this.h7, blocks = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
245
+
246
+ for (j = 16; j < 64; ++j) {
247
+ // rightrotate
248
+ t1 = blocks[j - 15];
249
+ s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3);
250
+ t1 = blocks[j - 2];
251
+ s1 = ((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10);
252
+ blocks[j] = blocks[j - 16] + s0 + blocks[j - 7] + s1 << 0;
253
+ }
254
+
255
+ bc = b & c;
256
+ for (j = 0; j < 64; j += 4) {
257
+ if (this.first) {
258
+ if (this.is224) {
259
+ ab = 300032;
260
+ t1 = blocks[0] - 1413257819;
261
+ h = t1 - 150054599 << 0;
262
+ d = t1 + 24177077 << 0;
263
+ } else {
264
+ ab = 704751109;
265
+ t1 = blocks[0] - 210244248;
266
+ h = t1 - 1521486534 << 0;
267
+ d = t1 + 143694565 << 0;
268
+ }
269
+ this.first = false;
270
+ } else {
271
+ s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
272
+ s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
273
+ ab = a & b;
274
+ maj = ab ^ (a & c) ^ bc;
275
+ ch = (e & f) ^ (~e & g);
276
+ t1 = h + s1 + ch + K[j] + blocks[j];
277
+ t2 = s0 + maj;
278
+ h = d + t1 << 0;
279
+ d = t1 + t2 << 0;
280
+ }
281
+ s0 = ((d >>> 2) | (d << 30)) ^ ((d >>> 13) | (d << 19)) ^ ((d >>> 22) | (d << 10));
282
+ s1 = ((h >>> 6) | (h << 26)) ^ ((h >>> 11) | (h << 21)) ^ ((h >>> 25) | (h << 7));
283
+ da = d & a;
284
+ maj = da ^ (d & b) ^ ab;
285
+ ch = (h & e) ^ (~h & f);
286
+ t1 = g + s1 + ch + K[j + 1] + blocks[j + 1];
287
+ t2 = s0 + maj;
288
+ g = c + t1 << 0;
289
+ c = t1 + t2 << 0;
290
+ s0 = ((c >>> 2) | (c << 30)) ^ ((c >>> 13) | (c << 19)) ^ ((c >>> 22) | (c << 10));
291
+ s1 = ((g >>> 6) | (g << 26)) ^ ((g >>> 11) | (g << 21)) ^ ((g >>> 25) | (g << 7));
292
+ cd = c & d;
293
+ maj = cd ^ (c & a) ^ da;
294
+ ch = (g & h) ^ (~g & e);
295
+ t1 = f + s1 + ch + K[j + 2] + blocks[j + 2];
296
+ t2 = s0 + maj;
297
+ f = b + t1 << 0;
298
+ b = t1 + t2 << 0;
299
+ s0 = ((b >>> 2) | (b << 30)) ^ ((b >>> 13) | (b << 19)) ^ ((b >>> 22) | (b << 10));
300
+ s1 = ((f >>> 6) | (f << 26)) ^ ((f >>> 11) | (f << 21)) ^ ((f >>> 25) | (f << 7));
301
+ bc = b & c;
302
+ maj = bc ^ (b & d) ^ cd;
303
+ ch = (f & g) ^ (~f & h);
304
+ t1 = e + s1 + ch + K[j + 3] + blocks[j + 3];
305
+ t2 = s0 + maj;
306
+ e = a + t1 << 0;
307
+ a = t1 + t2 << 0;
308
+ }
309
+
310
+ this.h0 = this.h0 + a << 0;
311
+ this.h1 = this.h1 + b << 0;
312
+ this.h2 = this.h2 + c << 0;
313
+ this.h3 = this.h3 + d << 0;
314
+ this.h4 = this.h4 + e << 0;
315
+ this.h5 = this.h5 + f << 0;
316
+ this.h6 = this.h6 + g << 0;
317
+ this.h7 = this.h7 + h << 0;
318
+ };
319
+
320
+ Sha256.prototype.hex = function () {
321
+ this.finalize();
322
+
323
+ var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5,
324
+ h6 = this.h6, h7 = this.h7;
325
+
326
+ var hex = HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
327
+ HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
328
+ HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
329
+ HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
330
+ HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
331
+ HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
332
+ HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
333
+ HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
334
+ HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
335
+ HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
336
+ HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
337
+ HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
338
+ HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F] +
339
+ HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
340
+ HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
341
+ HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
342
+ HEX_CHARS[(h4 >> 28) & 0x0F] + HEX_CHARS[(h4 >> 24) & 0x0F] +
343
+ HEX_CHARS[(h4 >> 20) & 0x0F] + HEX_CHARS[(h4 >> 16) & 0x0F] +
344
+ HEX_CHARS[(h4 >> 12) & 0x0F] + HEX_CHARS[(h4 >> 8) & 0x0F] +
345
+ HEX_CHARS[(h4 >> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F] +
346
+ HEX_CHARS[(h5 >> 28) & 0x0F] + HEX_CHARS[(h5 >> 24) & 0x0F] +
347
+ HEX_CHARS[(h5 >> 20) & 0x0F] + HEX_CHARS[(h5 >> 16) & 0x0F] +
348
+ HEX_CHARS[(h5 >> 12) & 0x0F] + HEX_CHARS[(h5 >> 8) & 0x0F] +
349
+ HEX_CHARS[(h5 >> 4) & 0x0F] + HEX_CHARS[h5 & 0x0F] +
350
+ HEX_CHARS[(h6 >> 28) & 0x0F] + HEX_CHARS[(h6 >> 24) & 0x0F] +
351
+ HEX_CHARS[(h6 >> 20) & 0x0F] + HEX_CHARS[(h6 >> 16) & 0x0F] +
352
+ HEX_CHARS[(h6 >> 12) & 0x0F] + HEX_CHARS[(h6 >> 8) & 0x0F] +
353
+ HEX_CHARS[(h6 >> 4) & 0x0F] + HEX_CHARS[h6 & 0x0F];
354
+ if (!this.is224) {
355
+ hex += HEX_CHARS[(h7 >> 28) & 0x0F] + HEX_CHARS[(h7 >> 24) & 0x0F] +
356
+ HEX_CHARS[(h7 >> 20) & 0x0F] + HEX_CHARS[(h7 >> 16) & 0x0F] +
357
+ HEX_CHARS[(h7 >> 12) & 0x0F] + HEX_CHARS[(h7 >> 8) & 0x0F] +
358
+ HEX_CHARS[(h7 >> 4) & 0x0F] + HEX_CHARS[h7 & 0x0F];
359
+ }
360
+ return hex;
361
+ };
362
+
363
+ Sha256.prototype.toString = Sha256.prototype.hex;
364
+
365
+ Sha256.prototype.digest = function () {
366
+ this.finalize();
367
+
368
+ var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5,
369
+ h6 = this.h6, h7 = this.h7;
370
+
371
+ var arr = [
372
+ (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, h0 & 0xFF,
373
+ (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, h1 & 0xFF,
374
+ (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, h2 & 0xFF,
375
+ (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, h3 & 0xFF,
376
+ (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, h4 & 0xFF,
377
+ (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, h5 & 0xFF,
378
+ (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, h6 & 0xFF
379
+ ];
380
+ if (!this.is224) {
381
+ arr.push((h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, h7 & 0xFF);
382
+ }
383
+ return arr;
384
+ };
385
+
386
+ Sha256.prototype.array = Sha256.prototype.digest;
387
+
388
+ Sha256.prototype.arrayBuffer = function () {
389
+ this.finalize();
390
+
391
+ var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
392
+ var dataView = new DataView(buffer);
393
+ dataView.setUint32(0, this.h0);
394
+ dataView.setUint32(4, this.h1);
395
+ dataView.setUint32(8, this.h2);
396
+ dataView.setUint32(12, this.h3);
397
+ dataView.setUint32(16, this.h4);
398
+ dataView.setUint32(20, this.h5);
399
+ dataView.setUint32(24, this.h6);
400
+ if (!this.is224) {
401
+ dataView.setUint32(28, this.h7);
402
+ }
403
+ return buffer;
404
+ };
405
+
406
+ function HmacSha256(key, is224, sharedMemory) {
407
+ var i, type = typeof key;
408
+ if (type === 'string') {
409
+ var bytes = [], length = key.length, index = 0, code;
410
+ for (i = 0; i < length; ++i) {
411
+ code = key.charCodeAt(i);
412
+ if (code < 0x80) {
413
+ bytes[index++] = code;
414
+ } else if (code < 0x800) {
415
+ bytes[index++] = (0xc0 | (code >> 6));
416
+ bytes[index++] = (0x80 | (code & 0x3f));
417
+ } else if (code < 0xd800 || code >= 0xe000) {
418
+ bytes[index++] = (0xe0 | (code >> 12));
419
+ bytes[index++] = (0x80 | ((code >> 6) & 0x3f));
420
+ bytes[index++] = (0x80 | (code & 0x3f));
421
+ } else {
422
+ code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
423
+ bytes[index++] = (0xf0 | (code >> 18));
424
+ bytes[index++] = (0x80 | ((code >> 12) & 0x3f));
425
+ bytes[index++] = (0x80 | ((code >> 6) & 0x3f));
426
+ bytes[index++] = (0x80 | (code & 0x3f));
427
+ }
428
+ }
429
+ key = bytes;
430
+ } else {
431
+ if (type === 'object') {
432
+ if (key === null) {
433
+ throw new Error(ERROR);
434
+ } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
435
+ key = new Uint8Array(key);
436
+ } else if (!Array.isArray(key)) {
437
+ if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
438
+ throw new Error(ERROR);
439
+ }
440
+ }
441
+ } else {
442
+ throw new Error(ERROR);
443
+ }
444
+ }
445
+
446
+ if (key.length > 64) {
447
+ key = (new Sha256(is224, true)).update(key).array();
448
+ }
449
+
450
+ var oKeyPad = [], iKeyPad = [];
451
+ for (i = 0; i < 64; ++i) {
452
+ var b = key[i] || 0;
453
+ oKeyPad[i] = 0x5c ^ b;
454
+ iKeyPad[i] = 0x36 ^ b;
455
+ }
456
+
457
+ Sha256.call(this, is224, sharedMemory);
458
+
459
+ this.update(iKeyPad);
460
+ this.oKeyPad = oKeyPad;
461
+ this.inner = true;
462
+ this.sharedMemory = sharedMemory;
463
+ }
464
+ HmacSha256.prototype = new Sha256();
465
+
466
+ HmacSha256.prototype.finalize = function () {
467
+ Sha256.prototype.finalize.call(this);
468
+ if (this.inner) {
469
+ this.inner = false;
470
+ var innerHash = this.array();
471
+ Sha256.call(this, this.is224, this.sharedMemory);
472
+ this.update(this.oKeyPad);
473
+ this.update(innerHash);
474
+ Sha256.prototype.finalize.call(this);
475
+ }
476
+ };
477
+
478
+ export default {
479
+ sha256: createMethod(),
480
+ sha224: createMethod(true),
481
+ hmacsha256: createHmacMethod(),
482
+ hmacsha224: createHmacMethod(true)
483
483
  }