@pluve/logger-sdk 0.0.20 → 0.0.22
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/core/loggerSDK.ts
|
|
2
|
+
import md5 from "md5";
|
|
2
3
|
import { registerJsErrorCapture } from "../capture/jsError";
|
|
3
4
|
import { registerPromiseErrorCapture } from "../capture/promiseError";
|
|
4
5
|
import { registerResourceErrorCapture } from "../capture/resourceError";
|
|
@@ -11,7 +12,6 @@ import { uuid } from "../utils/uuid";
|
|
|
11
12
|
import { HttpClient } from "./httpClient";
|
|
12
13
|
import { QueueManager } from "./queueManager";
|
|
13
14
|
import { RetryManager } from "./retryManager";
|
|
14
|
-
import { Md5 } from "../utils/innerMD5";
|
|
15
15
|
import { SecurityType } from "../types/securityType";
|
|
16
16
|
var LoggerSDK = class {
|
|
17
17
|
constructor() {
|
|
@@ -153,13 +153,24 @@ var LoggerSDK = class {
|
|
|
153
153
|
this.opts.userId = userId;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* 设置 token 信息
|
|
158
|
+
* @param token token
|
|
159
|
+
*/
|
|
160
|
+
setToken(token, securityType) {
|
|
161
|
+
var _a;
|
|
162
|
+
logDebug(!!((_a = this.opts) == null ? void 0 : _a.debug), "setToken", token, securityType);
|
|
163
|
+
if (this.opts) {
|
|
164
|
+
this.opts.token = token;
|
|
165
|
+
this.opts.securityType = securityType;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
156
168
|
/** 设置店铺编码 */
|
|
157
|
-
setStoreCode(storeCode
|
|
169
|
+
setStoreCode(storeCode) {
|
|
158
170
|
var _a;
|
|
159
|
-
logDebug(!!((_a = this.opts) == null ? void 0 : _a.debug), "setStoreCode", storeCode
|
|
171
|
+
logDebug(!!((_a = this.opts) == null ? void 0 : _a.debug), "setStoreCode", storeCode);
|
|
160
172
|
if (this.opts) {
|
|
161
173
|
this.opts.storeCode = storeCode;
|
|
162
|
-
this.opts.securityType = securityType;
|
|
163
174
|
}
|
|
164
175
|
}
|
|
165
176
|
/** 设置日志 stage(env) */
|
|
@@ -418,7 +429,7 @@ var LoggerSDK = class {
|
|
|
418
429
|
generateToken() {
|
|
419
430
|
var _a;
|
|
420
431
|
const logTime = Date.now();
|
|
421
|
-
const token = ((_a = this.opts) == null ? void 0 : _a.token) ||
|
|
432
|
+
const token = ((_a = this.opts) == null ? void 0 : _a.token) || md5(`${this.opts.appId}${this.opts.logStage}${logTime}`);
|
|
422
433
|
return {
|
|
423
434
|
token,
|
|
424
435
|
logTime
|
|
@@ -40,8 +40,13 @@ export declare class LoggerSDK {
|
|
|
40
40
|
* 设置用户信息
|
|
41
41
|
*/
|
|
42
42
|
identify(userId: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* 设置 token 信息
|
|
45
|
+
* @param token token
|
|
46
|
+
*/
|
|
47
|
+
setToken(token: string, securityType: SecurityType): void;
|
|
43
48
|
/** 设置店铺编码 */
|
|
44
|
-
setStoreCode(storeCode: string
|
|
49
|
+
setStoreCode(storeCode: string): void;
|
|
45
50
|
/** 设置日志 stage(env) */
|
|
46
51
|
setStage(stage: Env): void;
|
|
47
52
|
private flattenEnvTags;
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluve/logger-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "logger sdk",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logger"
|
|
@@ -22,8 +22,12 @@
|
|
|
22
22
|
},
|
|
23
23
|
"typesVersions": {
|
|
24
24
|
"*": {
|
|
25
|
-
"index": [
|
|
26
|
-
|
|
25
|
+
"index": [
|
|
26
|
+
"dist/types/index.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"*": [
|
|
29
|
+
"dist/types/*"
|
|
30
|
+
]
|
|
27
31
|
}
|
|
28
32
|
},
|
|
29
33
|
"unpkg": "dist/umd/logger-sdk.min.js",
|
|
@@ -57,15 +61,17 @@
|
|
|
57
61
|
"generate-mermaid": "mermaid-cli logger-sdk.mermaid -o logger-sdk.svg"
|
|
58
62
|
},
|
|
59
63
|
"devDependencies": {
|
|
64
|
+
"@types/md5": "^2.3.6",
|
|
60
65
|
"jsdom": "^27.4.0",
|
|
61
66
|
"vitest": "^4.0.15"
|
|
62
67
|
},
|
|
63
68
|
"dependencies": {
|
|
64
69
|
"fflate": "^0.8.2",
|
|
70
|
+
"md5": "^2.3.0",
|
|
65
71
|
"stacktrace-js": "^2.0.2"
|
|
66
72
|
},
|
|
67
73
|
"peerDependencies": {
|
|
68
|
-
"
|
|
69
|
-
"
|
|
74
|
+
"js-base64": "^3.7.8",
|
|
75
|
+
"localforage": "^1.10.0"
|
|
70
76
|
}
|
|
71
77
|
}
|
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
// src/utils/innerMD5.ts
|
|
2
|
-
var EMPTY_STATE = new Int32Array(4);
|
|
3
|
-
var _Md5 = class {
|
|
4
|
-
constructor() {
|
|
5
|
-
this._dataLength = 0;
|
|
6
|
-
this._bufferLength = 0;
|
|
7
|
-
this._state = new Int32Array(4);
|
|
8
|
-
this._buffer = new ArrayBuffer(68);
|
|
9
|
-
this._buffer8 = new Uint8Array(this._buffer, 0, 68);
|
|
10
|
-
this._buffer32 = new Uint32Array(this._buffer, 0, 17);
|
|
11
|
-
this.start();
|
|
12
|
-
}
|
|
13
|
-
static hashStr(str, raw = false) {
|
|
14
|
-
return this.onePassHasher.start().appendStr(str).end(raw);
|
|
15
|
-
}
|
|
16
|
-
static hashAsciiStr(str, raw = false) {
|
|
17
|
-
return this.onePassHasher.start().appendAsciiStr(str).end(raw);
|
|
18
|
-
}
|
|
19
|
-
static _hex(x) {
|
|
20
|
-
const hc = _Md5.hexChars;
|
|
21
|
-
const ho = _Md5.hexOut;
|
|
22
|
-
let n;
|
|
23
|
-
let offset;
|
|
24
|
-
let j;
|
|
25
|
-
let i;
|
|
26
|
-
for (i = 0; i < 4; i += 1) {
|
|
27
|
-
offset = i * 8;
|
|
28
|
-
n = x[i];
|
|
29
|
-
for (j = 0; j < 8; j += 2) {
|
|
30
|
-
ho[offset + 1 + j] = hc.charAt(n & 15);
|
|
31
|
-
n >>>= 4;
|
|
32
|
-
ho[offset + 0 + j] = hc.charAt(n & 15);
|
|
33
|
-
n >>>= 4;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return ho.join("");
|
|
37
|
-
}
|
|
38
|
-
static _md5cycle(x, k) {
|
|
39
|
-
let a = x[0];
|
|
40
|
-
let b = x[1];
|
|
41
|
-
let c = x[2];
|
|
42
|
-
let d = x[3];
|
|
43
|
-
a += (b & c | ~b & d) + k[0] - 680876936 | 0;
|
|
44
|
-
a = (a << 7 | a >>> 25) + b | 0;
|
|
45
|
-
d += (a & b | ~a & c) + k[1] - 389564586 | 0;
|
|
46
|
-
d = (d << 12 | d >>> 20) + a | 0;
|
|
47
|
-
c += (d & a | ~d & b) + k[2] + 606105819 | 0;
|
|
48
|
-
c = (c << 17 | c >>> 15) + d | 0;
|
|
49
|
-
b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
|
|
50
|
-
b = (b << 22 | b >>> 10) + c | 0;
|
|
51
|
-
a += (b & c | ~b & d) + k[4] - 176418897 | 0;
|
|
52
|
-
a = (a << 7 | a >>> 25) + b | 0;
|
|
53
|
-
d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
|
|
54
|
-
d = (d << 12 | d >>> 20) + a | 0;
|
|
55
|
-
c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
|
|
56
|
-
c = (c << 17 | c >>> 15) + d | 0;
|
|
57
|
-
b += (c & d | ~c & a) + k[7] - 45705983 | 0;
|
|
58
|
-
b = (b << 22 | b >>> 10) + c | 0;
|
|
59
|
-
a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
|
|
60
|
-
a = (a << 7 | a >>> 25) + b | 0;
|
|
61
|
-
d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
|
|
62
|
-
d = (d << 12 | d >>> 20) + a | 0;
|
|
63
|
-
c += (d & a | ~d & b) + k[10] - 42063 | 0;
|
|
64
|
-
c = (c << 17 | c >>> 15) + d | 0;
|
|
65
|
-
b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
|
|
66
|
-
b = (b << 22 | b >>> 10) + c | 0;
|
|
67
|
-
a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
|
|
68
|
-
a = (a << 7 | a >>> 25) + b | 0;
|
|
69
|
-
d += (a & b | ~a & c) + k[13] - 40341101 | 0;
|
|
70
|
-
d = (d << 12 | d >>> 20) + a | 0;
|
|
71
|
-
c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
|
|
72
|
-
c = (c << 17 | c >>> 15) + d | 0;
|
|
73
|
-
b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
|
|
74
|
-
b = (b << 22 | b >>> 10) + c | 0;
|
|
75
|
-
a += (b & d | c & ~d) + k[1] - 165796510 | 0;
|
|
76
|
-
a = (a << 5 | a >>> 27) + b | 0;
|
|
77
|
-
d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
|
|
78
|
-
d = (d << 9 | d >>> 23) + a | 0;
|
|
79
|
-
c += (d & b | a & ~b) + k[11] + 643717713 | 0;
|
|
80
|
-
c = (c << 14 | c >>> 18) + d | 0;
|
|
81
|
-
b += (c & a | d & ~a) + k[0] - 373897302 | 0;
|
|
82
|
-
b = (b << 20 | b >>> 12) + c | 0;
|
|
83
|
-
a += (b & d | c & ~d) + k[5] - 701558691 | 0;
|
|
84
|
-
a = (a << 5 | a >>> 27) + b | 0;
|
|
85
|
-
d += (a & c | b & ~c) + k[10] + 38016083 | 0;
|
|
86
|
-
d = (d << 9 | d >>> 23) + a | 0;
|
|
87
|
-
c += (d & b | a & ~b) + k[15] - 660478335 | 0;
|
|
88
|
-
c = (c << 14 | c >>> 18) + d | 0;
|
|
89
|
-
b += (c & a | d & ~a) + k[4] - 405537848 | 0;
|
|
90
|
-
b = (b << 20 | b >>> 12) + c | 0;
|
|
91
|
-
a += (b & d | c & ~d) + k[9] + 568446438 | 0;
|
|
92
|
-
a = (a << 5 | a >>> 27) + b | 0;
|
|
93
|
-
d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
|
|
94
|
-
d = (d << 9 | d >>> 23) + a | 0;
|
|
95
|
-
c += (d & b | a & ~b) + k[3] - 187363961 | 0;
|
|
96
|
-
c = (c << 14 | c >>> 18) + d | 0;
|
|
97
|
-
b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
|
|
98
|
-
b = (b << 20 | b >>> 12) + c | 0;
|
|
99
|
-
a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
|
|
100
|
-
a = (a << 5 | a >>> 27) + b | 0;
|
|
101
|
-
d += (a & c | b & ~c) + k[2] - 51403784 | 0;
|
|
102
|
-
d = (d << 9 | d >>> 23) + a | 0;
|
|
103
|
-
c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
|
|
104
|
-
c = (c << 14 | c >>> 18) + d | 0;
|
|
105
|
-
b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
|
|
106
|
-
b = (b << 20 | b >>> 12) + c | 0;
|
|
107
|
-
a += (b ^ c ^ d) + k[5] - 378558 | 0;
|
|
108
|
-
a = (a << 4 | a >>> 28) + b | 0;
|
|
109
|
-
d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
|
|
110
|
-
d = (d << 11 | d >>> 21) + a | 0;
|
|
111
|
-
c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
|
|
112
|
-
c = (c << 16 | c >>> 16) + d | 0;
|
|
113
|
-
b += (c ^ d ^ a) + k[14] - 35309556 | 0;
|
|
114
|
-
b = (b << 23 | b >>> 9) + c | 0;
|
|
115
|
-
a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
|
|
116
|
-
a = (a << 4 | a >>> 28) + b | 0;
|
|
117
|
-
d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
|
|
118
|
-
d = (d << 11 | d >>> 21) + a | 0;
|
|
119
|
-
c += (d ^ a ^ b) + k[7] - 155497632 | 0;
|
|
120
|
-
c = (c << 16 | c >>> 16) + d | 0;
|
|
121
|
-
b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
|
|
122
|
-
b = (b << 23 | b >>> 9) + c | 0;
|
|
123
|
-
a += (b ^ c ^ d) + k[13] + 681279174 | 0;
|
|
124
|
-
a = (a << 4 | a >>> 28) + b | 0;
|
|
125
|
-
d += (a ^ b ^ c) + k[0] - 358537222 | 0;
|
|
126
|
-
d = (d << 11 | d >>> 21) + a | 0;
|
|
127
|
-
c += (d ^ a ^ b) + k[3] - 722521979 | 0;
|
|
128
|
-
c = (c << 16 | c >>> 16) + d | 0;
|
|
129
|
-
b += (c ^ d ^ a) + k[6] + 76029189 | 0;
|
|
130
|
-
b = (b << 23 | b >>> 9) + c | 0;
|
|
131
|
-
a += (b ^ c ^ d) + k[9] - 640364487 | 0;
|
|
132
|
-
a = (a << 4 | a >>> 28) + b | 0;
|
|
133
|
-
d += (a ^ b ^ c) + k[12] - 421815835 | 0;
|
|
134
|
-
d = (d << 11 | d >>> 21) + a | 0;
|
|
135
|
-
c += (d ^ a ^ b) + k[15] + 530742520 | 0;
|
|
136
|
-
c = (c << 16 | c >>> 16) + d | 0;
|
|
137
|
-
b += (c ^ d ^ a) + k[2] - 995338651 | 0;
|
|
138
|
-
b = (b << 23 | b >>> 9) + c | 0;
|
|
139
|
-
a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
|
|
140
|
-
a = (a << 6 | a >>> 26) + b | 0;
|
|
141
|
-
d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
|
|
142
|
-
d = (d << 10 | d >>> 22) + a | 0;
|
|
143
|
-
c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
|
|
144
|
-
c = (c << 15 | c >>> 17) + d | 0;
|
|
145
|
-
b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
|
|
146
|
-
b = (b << 21 | b >>> 11) + c | 0;
|
|
147
|
-
a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
|
|
148
|
-
a = (a << 6 | a >>> 26) + b | 0;
|
|
149
|
-
d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
|
|
150
|
-
d = (d << 10 | d >>> 22) + a | 0;
|
|
151
|
-
c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
|
|
152
|
-
c = (c << 15 | c >>> 17) + d | 0;
|
|
153
|
-
b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
|
|
154
|
-
b = (b << 21 | b >>> 11) + c | 0;
|
|
155
|
-
a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
|
|
156
|
-
a = (a << 6 | a >>> 26) + b | 0;
|
|
157
|
-
d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
|
|
158
|
-
d = (d << 10 | d >>> 22) + a | 0;
|
|
159
|
-
c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
|
|
160
|
-
c = (c << 15 | c >>> 17) + d | 0;
|
|
161
|
-
b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
|
|
162
|
-
b = (b << 21 | b >>> 11) + c | 0;
|
|
163
|
-
a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
|
|
164
|
-
a = (a << 6 | a >>> 26) + b | 0;
|
|
165
|
-
d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
|
|
166
|
-
d = (d << 10 | d >>> 22) + a | 0;
|
|
167
|
-
c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
|
|
168
|
-
c = (c << 15 | c >>> 17) + d | 0;
|
|
169
|
-
b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
|
|
170
|
-
b = (b << 21 | b >>> 11) + c | 0;
|
|
171
|
-
x[0] = a + x[0] | 0;
|
|
172
|
-
x[1] = b + x[1] | 0;
|
|
173
|
-
x[2] = c + x[2] | 0;
|
|
174
|
-
x[3] = d + x[3] | 0;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Initialise buffer to be hashed
|
|
178
|
-
*/
|
|
179
|
-
start() {
|
|
180
|
-
this._dataLength = 0;
|
|
181
|
-
this._bufferLength = 0;
|
|
182
|
-
this._state.set(_Md5.stateIdentity);
|
|
183
|
-
return this;
|
|
184
|
-
}
|
|
185
|
-
// Char to code point to to array conversion:
|
|
186
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt
|
|
187
|
-
// #Example.3A_Fixing_charCodeAt_to_handle_non-Basic-Multilingual-Plane_characters_if_their_presence_earlier_in_the_string_is_unknown
|
|
188
|
-
/**
|
|
189
|
-
* Append a UTF-8 string to the hash buffer
|
|
190
|
-
* @param str String to append
|
|
191
|
-
*/
|
|
192
|
-
appendStr(str) {
|
|
193
|
-
const buf8 = this._buffer8;
|
|
194
|
-
const buf32 = this._buffer32;
|
|
195
|
-
let bufLen = this._bufferLength;
|
|
196
|
-
let code;
|
|
197
|
-
let i;
|
|
198
|
-
for (i = 0; i < str.length; i += 1) {
|
|
199
|
-
code = str.charCodeAt(i);
|
|
200
|
-
if (code < 128) {
|
|
201
|
-
buf8[bufLen++] = code;
|
|
202
|
-
} else if (code < 2048) {
|
|
203
|
-
buf8[bufLen++] = (code >>> 6) + 192;
|
|
204
|
-
buf8[bufLen++] = code & 63 | 128;
|
|
205
|
-
} else if (code < 55296 || code > 56319) {
|
|
206
|
-
buf8[bufLen++] = (code >>> 12) + 224;
|
|
207
|
-
buf8[bufLen++] = code >>> 6 & 63 | 128;
|
|
208
|
-
buf8[bufLen++] = code & 63 | 128;
|
|
209
|
-
} else {
|
|
210
|
-
code = (code - 55296) * 1024 + (str.charCodeAt(++i) - 56320) + 65536;
|
|
211
|
-
if (code > 1114111) {
|
|
212
|
-
throw new Error(
|
|
213
|
-
"Unicode standard supports code points up to U+10FFFF"
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
buf8[bufLen++] = (code >>> 18) + 240;
|
|
217
|
-
buf8[bufLen++] = code >>> 12 & 63 | 128;
|
|
218
|
-
buf8[bufLen++] = code >>> 6 & 63 | 128;
|
|
219
|
-
buf8[bufLen++] = code & 63 | 128;
|
|
220
|
-
}
|
|
221
|
-
if (bufLen >= 64) {
|
|
222
|
-
this._dataLength += 64;
|
|
223
|
-
_Md5._md5cycle(this._state, buf32);
|
|
224
|
-
bufLen -= 64;
|
|
225
|
-
buf32[0] = buf32[16];
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
this._bufferLength = bufLen;
|
|
229
|
-
return this;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Append an ASCII string to the hash buffer
|
|
233
|
-
* @param str String to append
|
|
234
|
-
*/
|
|
235
|
-
appendAsciiStr(str) {
|
|
236
|
-
const buf8 = this._buffer8;
|
|
237
|
-
const buf32 = this._buffer32;
|
|
238
|
-
let bufLen = this._bufferLength;
|
|
239
|
-
let i;
|
|
240
|
-
let j = 0;
|
|
241
|
-
for (; ; ) {
|
|
242
|
-
i = Math.min(str.length - j, 64 - bufLen);
|
|
243
|
-
while (i--) {
|
|
244
|
-
buf8[bufLen++] = str.charCodeAt(j++);
|
|
245
|
-
}
|
|
246
|
-
if (bufLen < 64) {
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
this._dataLength += 64;
|
|
250
|
-
_Md5._md5cycle(this._state, buf32);
|
|
251
|
-
bufLen = 0;
|
|
252
|
-
}
|
|
253
|
-
this._bufferLength = bufLen;
|
|
254
|
-
return this;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Append a byte array to the hash buffer
|
|
258
|
-
* @param input array to append
|
|
259
|
-
*/
|
|
260
|
-
appendByteArray(input) {
|
|
261
|
-
const buf8 = this._buffer8;
|
|
262
|
-
const buf32 = this._buffer32;
|
|
263
|
-
let bufLen = this._bufferLength;
|
|
264
|
-
let i;
|
|
265
|
-
let j = 0;
|
|
266
|
-
for (; ; ) {
|
|
267
|
-
i = Math.min(input.length - j, 64 - bufLen);
|
|
268
|
-
while (i--) {
|
|
269
|
-
buf8[bufLen++] = input[j++];
|
|
270
|
-
}
|
|
271
|
-
if (bufLen < 64) {
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
this._dataLength += 64;
|
|
275
|
-
_Md5._md5cycle(this._state, buf32);
|
|
276
|
-
bufLen = 0;
|
|
277
|
-
}
|
|
278
|
-
this._bufferLength = bufLen;
|
|
279
|
-
return this;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Get the state of the hash buffer
|
|
283
|
-
*/
|
|
284
|
-
getState() {
|
|
285
|
-
const s = this._state;
|
|
286
|
-
return {
|
|
287
|
-
buffer: String.fromCharCode.apply(null, Array.from(this._buffer8)),
|
|
288
|
-
buflen: this._bufferLength,
|
|
289
|
-
length: this._dataLength,
|
|
290
|
-
state: [s[0], s[1], s[2], s[3]]
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Override the current state of the hash buffer
|
|
295
|
-
* @param state New hash buffer state
|
|
296
|
-
*/
|
|
297
|
-
setState(state) {
|
|
298
|
-
const buf = state.buffer;
|
|
299
|
-
const x = state.state;
|
|
300
|
-
const s = this._state;
|
|
301
|
-
let i;
|
|
302
|
-
this._dataLength = state.length;
|
|
303
|
-
this._bufferLength = state.buflen;
|
|
304
|
-
s[0] = x[0];
|
|
305
|
-
s[1] = x[1];
|
|
306
|
-
s[2] = x[2];
|
|
307
|
-
s[3] = x[3];
|
|
308
|
-
for (i = 0; i < buf.length; i += 1) {
|
|
309
|
-
this._buffer8[i] = buf.charCodeAt(i);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Hash the current state of the hash buffer and return the result
|
|
314
|
-
* @param raw Whether to return the value as an `Int32Array`
|
|
315
|
-
*/
|
|
316
|
-
end(raw = false) {
|
|
317
|
-
const bufLen = this._bufferLength;
|
|
318
|
-
const buf8 = this._buffer8;
|
|
319
|
-
const buf32 = this._buffer32;
|
|
320
|
-
const i = (bufLen >> 2) + 1;
|
|
321
|
-
this._dataLength += bufLen;
|
|
322
|
-
const dataBitsLen = this._dataLength * 8;
|
|
323
|
-
buf8[bufLen] = 128;
|
|
324
|
-
buf8[bufLen + 1] = buf8[bufLen + 2] = buf8[bufLen + 3] = 0;
|
|
325
|
-
buf32.set(_Md5.buffer32Identity.subarray(i), i);
|
|
326
|
-
if (bufLen > 55) {
|
|
327
|
-
_Md5._md5cycle(this._state, buf32);
|
|
328
|
-
buf32.set(_Md5.buffer32Identity);
|
|
329
|
-
}
|
|
330
|
-
if (dataBitsLen <= 4294967295) {
|
|
331
|
-
buf32[14] = dataBitsLen;
|
|
332
|
-
} else {
|
|
333
|
-
const matches = dataBitsLen.toString(16).match(/(.*?)(.{0,8})$/);
|
|
334
|
-
if (matches === null)
|
|
335
|
-
return raw ? EMPTY_STATE : "";
|
|
336
|
-
const lo = parseInt(matches[2], 16);
|
|
337
|
-
const hi = parseInt(matches[1], 16) || 0;
|
|
338
|
-
buf32[14] = lo;
|
|
339
|
-
buf32[15] = hi;
|
|
340
|
-
}
|
|
341
|
-
_Md5._md5cycle(this._state, buf32);
|
|
342
|
-
return raw ? this._state : _Md5._hex(this._state);
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
var Md5 = _Md5;
|
|
346
|
-
// Private Static Variables
|
|
347
|
-
Md5.stateIdentity = new Int32Array([
|
|
348
|
-
1732584193,
|
|
349
|
-
-271733879,
|
|
350
|
-
-1732584194,
|
|
351
|
-
271733878
|
|
352
|
-
]);
|
|
353
|
-
Md5.buffer32Identity = new Int32Array([
|
|
354
|
-
0,
|
|
355
|
-
0,
|
|
356
|
-
0,
|
|
357
|
-
0,
|
|
358
|
-
0,
|
|
359
|
-
0,
|
|
360
|
-
0,
|
|
361
|
-
0,
|
|
362
|
-
0,
|
|
363
|
-
0,
|
|
364
|
-
0,
|
|
365
|
-
0,
|
|
366
|
-
0,
|
|
367
|
-
0,
|
|
368
|
-
0,
|
|
369
|
-
0
|
|
370
|
-
]);
|
|
371
|
-
Md5.hexChars = "0123456789abcdef";
|
|
372
|
-
Md5.hexOut = [];
|
|
373
|
-
// Permanent instance is to use for one-call hashing
|
|
374
|
-
Md5.onePassHasher = new _Md5();
|
|
375
|
-
if (Md5.hashStr("hello") !== "5d41402abc4b2a76b9719d911017c592") {
|
|
376
|
-
throw new Error("Md5 self test failed.");
|
|
377
|
-
}
|
|
378
|
-
export {
|
|
379
|
-
Md5
|
|
380
|
-
};
|