@queue-it/fastly 1.1.0 → 2.0.0-beta.1
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.
- package/package.json +16 -21
- package/{assembly → src}/contextProvider.ts +12 -8
- package/{assembly → src}/index.ts +1 -1
- package/{assembly → src}/integrationConfigProvider.ts +20 -23
- package/{assembly → src}/requestResponseHandler.ts +9 -15
- package/{assembly → src}/sdk/HttpContextProvider.ts +1 -2
- package/src/sdk/IntegrationConfig/CustomerIntegrationDecodingHandler.ts +57 -0
- package/{assembly → src}/sdk/IntegrationConfig/IntegrationConfigHelpers.ts +14 -16
- package/{assembly → src}/sdk/IntegrationConfig/IntegrationConfigModel.ts +5 -5
- package/{assembly → src}/sdk/KnownUser.ts +7 -9
- package/{assembly → src}/sdk/Models.ts +6 -6
- package/{assembly → src}/sdk/QueueITHelpers.ts +33 -29
- package/{assembly → src}/sdk/UserInQueueService.ts +4 -4
- package/{assembly → src}/sdk/UserInQueueStateCookieRepository.ts +26 -27
- package/src/sdk/helpers/Uri.ts +4 -0
- package/{assembly → src}/sdk/helpers/crypto.ts +28 -30
- package/LICENSE +0 -21
- package/assembly/sdk/IntegrationConfig/CustomerIntegrationDecodingHandler.ts +0 -221
- package/assembly/sdk/helpers/Uri.ts +0 -308
- /package/{assembly → src}/helper.ts +0 -0
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
//@ts-ignore
|
|
2
|
-
import {RegExp} from "assemblyscript-regex";
|
|
3
1
|
import {KeyValuePair, RequestValidationResult} from "./Models";
|
|
4
2
|
import {IDateTimeProvider} from "./HttpContextProvider";
|
|
5
|
-
import {Date as WasiDate} from "as-wasi";
|
|
6
3
|
import {encodeURIComponent, decodeURIComponent} from "./helpers/Uri";
|
|
7
4
|
import {KnownUser} from "./KnownUser";
|
|
8
|
-
import {Response} from "@fastly/as-compute";
|
|
9
5
|
import {UserInQueueService} from "./UserInQueueService";
|
|
10
6
|
|
|
11
7
|
export class QueueUrlParams {
|
|
12
|
-
public timeStamp:
|
|
8
|
+
public timeStamp: number = 0;
|
|
13
9
|
public eventId: string = "";
|
|
14
10
|
public hashCode: string = "";
|
|
15
|
-
public extendableCookie:
|
|
16
|
-
public cookieValidityMinutes:
|
|
11
|
+
public extendableCookie: boolean = false;
|
|
12
|
+
public cookieValidityMinutes: number = 0;
|
|
17
13
|
public queueITToken: string = "";
|
|
18
14
|
public queueITTokenWithoutHash: string = "";
|
|
19
15
|
public queueId: string = "";
|
|
@@ -37,12 +33,16 @@ export class Utils {
|
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
static decodeUrl(url: string): string {
|
|
40
|
-
|
|
36
|
+
try {
|
|
37
|
+
return decodeURIComponent(url);
|
|
38
|
+
} catch {
|
|
39
|
+
return url;
|
|
40
|
+
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
static generateSHA256Hash: (a: string, b: string) => string = (secretKey: string, stringToHash: string): string => "";
|
|
44
44
|
|
|
45
|
-
static endsWith(str: string, search: string):
|
|
45
|
+
static endsWith(str: string, search: string): boolean {
|
|
46
46
|
if (str == search)
|
|
47
47
|
return true;
|
|
48
48
|
if (str.length == 0 || search.length == 0)
|
|
@@ -50,11 +50,11 @@ export class Utils {
|
|
|
50
50
|
return str.substring(str.length - search.length, str.length) == search;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
static getCurrentTime():
|
|
54
|
-
return Math.floor(
|
|
53
|
+
static getCurrentTime(): number {
|
|
54
|
+
return Math.floor(Date.now() / 1000);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
private static _hex2bin:
|
|
57
|
+
private static _hex2bin: number[] = [
|
|
58
58
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
59
59
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
60
60
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
@@ -78,8 +78,8 @@ export class Utils {
|
|
|
78
78
|
let rv = '';
|
|
79
79
|
let i = 0;
|
|
80
80
|
|
|
81
|
-
let c1:
|
|
82
|
-
let c2:
|
|
81
|
+
let c1: number;
|
|
82
|
+
let c2: number;
|
|
83
83
|
|
|
84
84
|
while (len > 1) {
|
|
85
85
|
let h1 = str.charAt(i++);
|
|
@@ -101,29 +101,33 @@ export class Utils {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
static getParameterByName(url: string, name: string): string {
|
|
104
|
-
const namePart =
|
|
104
|
+
const namePart = /[\[\]]/g;
|
|
105
105
|
let match = namePart.exec(name);
|
|
106
|
-
while (match
|
|
107
|
-
let rxmatch = match
|
|
106
|
+
while (match !== null) {
|
|
107
|
+
let rxmatch = match[0];
|
|
108
108
|
name = name.replaceAll(rxmatch, '\\$&')
|
|
109
109
|
match = namePart.exec(name);
|
|
110
110
|
}
|
|
111
111
|
const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
|
|
112
112
|
const results = regex.exec(url);
|
|
113
|
-
if (results
|
|
114
|
-
if (results.
|
|
113
|
+
if (results === null) return '';
|
|
114
|
+
if (results.length < 3 || results[2] === null || results[2] === undefined) {
|
|
115
115
|
return '';
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
try {
|
|
119
|
+
return decodeURIComponent(results[2].replaceAll('+', ' '));
|
|
120
|
+
} catch {
|
|
121
|
+
return results[2];
|
|
122
|
+
}
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
static removeQueueItToken(url: string): string {
|
|
122
|
-
const pattern = new RegExp("([
|
|
126
|
+
const pattern = new RegExp("([?&])(" + KnownUser.QueueITTokenKey + "=[^&]*)", 'gi');
|
|
123
127
|
const match = pattern.exec(url);
|
|
124
|
-
if (match
|
|
128
|
+
if (match === null) return url;
|
|
125
129
|
|
|
126
|
-
url = url.replaceAll(match
|
|
130
|
+
url = url.replaceAll(match[0], '')
|
|
127
131
|
return url;
|
|
128
132
|
}
|
|
129
133
|
}
|
|
@@ -159,9 +163,9 @@ export class QueueParameterHelper {
|
|
|
159
163
|
if (keyValueArr[0] == QueueParameterHelper.HashKey) {
|
|
160
164
|
result.hashCode = keyValueArr[1];
|
|
161
165
|
} else if (keyValueArr[0] == QueueParameterHelper.TimeStampKey) {
|
|
162
|
-
result.timeStamp =
|
|
166
|
+
result.timeStamp = parseInt(keyValueArr[1], 10) || 0;
|
|
163
167
|
} else if (keyValueArr[0] == QueueParameterHelper.CookieValidityMinutesKey) {
|
|
164
|
-
result.cookieValidityMinutes =
|
|
168
|
+
result.cookieValidityMinutes = parseInt(keyValueArr[1], 10) || 0;
|
|
165
169
|
} else if (keyValueArr[0] == QueueParameterHelper.EventIdKey) {
|
|
166
170
|
result.eventId = keyValueArr[1];
|
|
167
171
|
} else if (keyValueArr[0] == QueueParameterHelper.ExtendableCookieKey) {
|
|
@@ -211,9 +215,9 @@ export class CookieHelper {
|
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
export class ConnectorDiagnostics {
|
|
214
|
-
public isEnabled:
|
|
215
|
-
public hasError:
|
|
216
|
-
public validationResult: RequestValidationResult | null
|
|
218
|
+
public isEnabled: boolean = false;
|
|
219
|
+
public hasError: boolean = false;
|
|
220
|
+
public validationResult: RequestValidationResult | null = null
|
|
217
221
|
|
|
218
222
|
private setStateWithTokenError(customerId: string, errorCode: string): void {
|
|
219
223
|
this.hasError = true;
|
|
@@ -258,6 +262,6 @@ export class ConnectorDiagnostics {
|
|
|
258
262
|
|
|
259
263
|
export class DateTimeProvider implements IDateTimeProvider {
|
|
260
264
|
getCurrentTime(): Date {
|
|
261
|
-
return new Date(
|
|
265
|
+
return new Date(Date.now());
|
|
262
266
|
}
|
|
263
267
|
}
|
|
@@ -81,7 +81,7 @@ export class UserInQueueService {
|
|
|
81
81
|
private getQueryString(
|
|
82
82
|
customerId: string,
|
|
83
83
|
eventId: string,
|
|
84
|
-
configVersion:
|
|
84
|
+
configVersion: number,
|
|
85
85
|
culture: string,
|
|
86
86
|
layoutName: string,
|
|
87
87
|
actionName: string)
|
|
@@ -143,7 +143,7 @@ export class UserInQueueService {
|
|
|
143
143
|
const queueParams = QueueParameterHelper.extractQueueParams(queueitToken);
|
|
144
144
|
|
|
145
145
|
let requestValidationResult: RequestValidationResult | null;
|
|
146
|
-
let isTokenValid:
|
|
146
|
+
let isTokenValid: boolean = false;
|
|
147
147
|
|
|
148
148
|
if (queueParams != null) {
|
|
149
149
|
const tokenValidationResult = this.validateToken(config, queueParams, secretKey);
|
|
@@ -201,7 +201,7 @@ export class UserInQueueService {
|
|
|
201
201
|
|
|
202
202
|
public extendQueueCookie(
|
|
203
203
|
eventId: string,
|
|
204
|
-
cookieValidityMinutes:
|
|
204
|
+
cookieValidityMinutes: number,
|
|
205
205
|
cookieDomain: string,
|
|
206
206
|
secretKey: string): void {
|
|
207
207
|
this.userInQueueStateRepository.reissueQueueCookie(eventId, cookieValidityMinutes, cookieDomain, secretKey)
|
|
@@ -237,7 +237,7 @@ export class UserInQueueService {
|
|
|
237
237
|
|
|
238
238
|
class TokenValidationResult {
|
|
239
239
|
constructor(
|
|
240
|
-
public isValid:
|
|
240
|
+
public isValid: boolean,
|
|
241
241
|
public errorCode: string) {
|
|
242
242
|
|
|
243
243
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {IHttpContextProvider} from './HttpContextProvider'
|
|
2
2
|
import {Utils, CookieHelper} from './QueueITHelpers'
|
|
3
|
-
import {Date as WasiDate} from "as-wasi";
|
|
4
3
|
import {KeyValuePair} from "./Models";
|
|
5
4
|
|
|
6
5
|
export class UserInQueueStateCookieRepository {
|
|
@@ -19,7 +18,7 @@ export class UserInQueueStateCookieRepository {
|
|
|
19
18
|
return UserInQueueStateCookieRepository._QueueITDataKey + "_" + eventId;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
public store(eventId: string, queueId: string, fixedCookieValidityMinutes:
|
|
21
|
+
public store(eventId: string, queueId: string, fixedCookieValidityMinutes: number,
|
|
23
22
|
cookieDomain: string, redirectType: string, secretKey: string): void {
|
|
24
23
|
this.createCookie(
|
|
25
24
|
eventId, queueId,
|
|
@@ -52,8 +51,8 @@ export class UserInQueueStateCookieRepository {
|
|
|
52
51
|
UserInQueueStateCookieRepository._HashKey,
|
|
53
52
|
this.generateHash(eventId.toLowerCase(), queueId, fixedCookieValidityMinutes, redirectType.toLowerCase(), issueTime, secretKey)
|
|
54
53
|
));
|
|
55
|
-
const tomorrow: Date = new Date(
|
|
56
|
-
const expire:
|
|
54
|
+
const tomorrow: Date = new Date(Date.now() + 1000 * 60 * 60 * 24);
|
|
55
|
+
const expire: number = Math.floor(tomorrow.getTime() / 1000);
|
|
57
56
|
let cookieValue = CookieHelper.toValueFromKeyValueCollection(cookieValues);
|
|
58
57
|
|
|
59
58
|
this.httpContextProvider.getHttpResponse().setCookie(cookieKey,
|
|
@@ -61,7 +60,7 @@ export class UserInQueueStateCookieRepository {
|
|
|
61
60
|
cookieDomain, expire);
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
public getState(eventId: string, cookieValidityMinutes:
|
|
63
|
+
public getState(eventId: string, cookieValidityMinutes: number, secretKey: string, validateTime: boolean): StateInfo {
|
|
65
64
|
const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
|
|
66
65
|
const cookie = this.httpContextProvider.getHttpRequest().getCookieValue(cookieKey);
|
|
67
66
|
|
|
@@ -74,37 +73,37 @@ export class UserInQueueStateCookieRepository {
|
|
|
74
73
|
return new StateInfo(true, false, "", 0, "");
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
const fixedCookieValidity:
|
|
78
|
-
?
|
|
76
|
+
const fixedCookieValidity: number = cookieValues.has(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)
|
|
77
|
+
? parseInt(cookieValues.get(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)!, 10)
|
|
79
78
|
: 0;
|
|
80
79
|
|
|
81
80
|
return new StateInfo(
|
|
82
81
|
true,
|
|
83
82
|
true,
|
|
84
|
-
cookieValues.get(UserInQueueStateCookieRepository._QueueIdKey)
|
|
83
|
+
cookieValues.get(UserInQueueStateCookieRepository._QueueIdKey)!,
|
|
85
84
|
fixedCookieValidity,
|
|
86
|
-
cookieValues.get(UserInQueueStateCookieRepository._RedirectTypeKey));
|
|
85
|
+
cookieValues.get(UserInQueueStateCookieRepository._RedirectTypeKey)!);
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
private isCookieValid(
|
|
90
89
|
secretKey: string,
|
|
91
90
|
cookieValueMap: Map<string, string>,
|
|
92
91
|
eventId: string,
|
|
93
|
-
cookieValidityMinutes:
|
|
94
|
-
validateTime:
|
|
92
|
+
cookieValidityMinutes: number,
|
|
93
|
+
validateTime: boolean): boolean {
|
|
95
94
|
|
|
96
95
|
const storedHash = cookieValueMap.has(UserInQueueStateCookieRepository._HashKey) ?
|
|
97
|
-
cookieValueMap.get(UserInQueueStateCookieRepository._HashKey) : "";
|
|
96
|
+
cookieValueMap.get(UserInQueueStateCookieRepository._HashKey)! : "";
|
|
98
97
|
const issueTimeString = cookieValueMap.has(UserInQueueStateCookieRepository._IssueTimeKey) ?
|
|
99
|
-
cookieValueMap.get(UserInQueueStateCookieRepository._IssueTimeKey) : "";
|
|
98
|
+
cookieValueMap.get(UserInQueueStateCookieRepository._IssueTimeKey)! : "";
|
|
100
99
|
const queueId = cookieValueMap.has(UserInQueueStateCookieRepository._QueueIdKey) ?
|
|
101
|
-
cookieValueMap.get(UserInQueueStateCookieRepository._QueueIdKey) : "";
|
|
100
|
+
cookieValueMap.get(UserInQueueStateCookieRepository._QueueIdKey)! : "";
|
|
102
101
|
const eventIdFromCookie = cookieValueMap.has(UserInQueueStateCookieRepository._EventIdKey) ?
|
|
103
|
-
cookieValueMap.get(UserInQueueStateCookieRepository._EventIdKey) : "";
|
|
102
|
+
cookieValueMap.get(UserInQueueStateCookieRepository._EventIdKey)! : "";
|
|
104
103
|
const redirectType = cookieValueMap.has(UserInQueueStateCookieRepository._RedirectTypeKey) ?
|
|
105
|
-
cookieValueMap.get(UserInQueueStateCookieRepository._RedirectTypeKey) : "";
|
|
104
|
+
cookieValueMap.get(UserInQueueStateCookieRepository._RedirectTypeKey)! : "";
|
|
106
105
|
let fixedCookieValidityMinutes = cookieValueMap.has(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey) ?
|
|
107
|
-
cookieValueMap.get(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey) : "";
|
|
106
|
+
cookieValueMap.get(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)! : "";
|
|
108
107
|
|
|
109
108
|
const expectedHash = this.generateHash(
|
|
110
109
|
eventIdFromCookie,
|
|
@@ -124,8 +123,8 @@ export class UserInQueueStateCookieRepository {
|
|
|
124
123
|
return false;
|
|
125
124
|
|
|
126
125
|
if (validateTime) {
|
|
127
|
-
let validity:
|
|
128
|
-
let expirationTime:
|
|
126
|
+
let validity: number = fixedCookieValidityMinutes.length > 0 ? parseInt(fixedCookieValidityMinutes, 10) : cookieValidityMinutes;
|
|
127
|
+
let expirationTime: number = parseInt(issueTimeString, 10) + validity * 60;
|
|
129
128
|
|
|
130
129
|
if (expirationTime < Utils.getCurrentTime())
|
|
131
130
|
return false;
|
|
@@ -138,7 +137,7 @@ export class UserInQueueStateCookieRepository {
|
|
|
138
137
|
this.httpContextProvider.getHttpResponse().setCookie(cookieKey, "", cookieDomain, 0);
|
|
139
138
|
}
|
|
140
139
|
|
|
141
|
-
public reissueQueueCookie(eventId: string, cookieValidityMinutes:
|
|
140
|
+
public reissueQueueCookie(eventId: string, cookieValidityMinutes: number, cookieDomain: string, secretKey: string): void {
|
|
142
141
|
const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
|
|
143
142
|
const cookie = this.httpContextProvider.getHttpRequest().getCookieValue(cookieKey);
|
|
144
143
|
|
|
@@ -152,14 +151,14 @@ export class UserInQueueStateCookieRepository {
|
|
|
152
151
|
|
|
153
152
|
let fixedCookieValidityMinutes = "";
|
|
154
153
|
if (cookieValues.has(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)) {
|
|
155
|
-
fixedCookieValidityMinutes = cookieValues.get(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)
|
|
154
|
+
fixedCookieValidityMinutes = cookieValues.get(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)!.toString();
|
|
156
155
|
}
|
|
157
156
|
|
|
158
157
|
this.createCookie(
|
|
159
158
|
eventId,
|
|
160
|
-
cookieValues.get(UserInQueueStateCookieRepository._QueueIdKey)
|
|
159
|
+
cookieValues.get(UserInQueueStateCookieRepository._QueueIdKey)!,
|
|
161
160
|
fixedCookieValidityMinutes,
|
|
162
|
-
cookieValues.get(UserInQueueStateCookieRepository._RedirectTypeKey)
|
|
161
|
+
cookieValues.get(UserInQueueStateCookieRepository._RedirectTypeKey)!,
|
|
163
162
|
cookieDomain, secretKey);
|
|
164
163
|
}
|
|
165
164
|
|
|
@@ -176,14 +175,14 @@ export class UserInQueueStateCookieRepository {
|
|
|
176
175
|
}
|
|
177
176
|
|
|
178
177
|
export class StateInfo {
|
|
179
|
-
constructor(public isFound:
|
|
180
|
-
public isValid:
|
|
178
|
+
constructor(public isFound: boolean,
|
|
179
|
+
public isValid: boolean,
|
|
181
180
|
public queueId: string,
|
|
182
|
-
public fixedCookieValidityMinutes:
|
|
181
|
+
public fixedCookieValidityMinutes: number,
|
|
183
182
|
public redirectType: string) {
|
|
184
183
|
}
|
|
185
184
|
|
|
186
|
-
isStateExtendable():
|
|
185
|
+
isStateExtendable(): boolean {
|
|
187
186
|
return this.isValid && !this.fixedCookieValidityMinutes;
|
|
188
187
|
}
|
|
189
188
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// Hash implements SHA256 hash algorithm.
|
|
2
2
|
export class Hash {
|
|
3
|
-
blockSize:
|
|
4
|
-
digestLength:
|
|
3
|
+
blockSize: number;
|
|
4
|
+
digestLength: number;
|
|
5
5
|
private readonly state: Int32Array;
|
|
6
6
|
private readonly temp: Int32Array;
|
|
7
7
|
private readonly buffer: Uint8Array;
|
|
8
|
-
private bufferLength:
|
|
9
|
-
private bytesHashed:
|
|
10
|
-
finished:
|
|
8
|
+
private bufferLength: number;
|
|
9
|
+
private bytesHashed: number;
|
|
10
|
+
finished: boolean = false
|
|
11
11
|
|
|
12
12
|
// SHA-256 constants
|
|
13
|
-
static K:
|
|
13
|
+
static K: number[] = [
|
|
14
14
|
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
|
|
15
15
|
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
|
|
16
16
|
0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
|
|
@@ -73,7 +73,7 @@ export class Hash {
|
|
|
73
73
|
|
|
74
74
|
// Throws error when trying to update already finalized hash:
|
|
75
75
|
// instance must be reset to use it again.
|
|
76
|
-
update(data: Uint8Array, dataLength:
|
|
76
|
+
update(data: Uint8Array, dataLength: number = 0): Hash {
|
|
77
77
|
if (dataLength == 0) {
|
|
78
78
|
dataLength = data.length;
|
|
79
79
|
}
|
|
@@ -81,7 +81,7 @@ export class Hash {
|
|
|
81
81
|
throw new Error("SHA256: can't update because hash was finished.");
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
let dataPos:
|
|
84
|
+
let dataPos: number = 0;
|
|
85
85
|
this.bytesHashed += dataLength;
|
|
86
86
|
if (this.bufferLength > 0) {
|
|
87
87
|
while (this.bufferLength < 64 && dataLength > 0) {
|
|
@@ -109,11 +109,11 @@ export class Hash {
|
|
|
109
109
|
// If hash was already finalized, puts the same value.
|
|
110
110
|
finish(out: Uint8Array): Hash {
|
|
111
111
|
if (!this.finished) {
|
|
112
|
-
let bytesHashed:
|
|
113
|
-
let left:
|
|
114
|
-
let bitLenHi:
|
|
115
|
-
let bitLenLo:
|
|
116
|
-
let padLength:
|
|
112
|
+
let bytesHashed: number = this.bytesHashed;
|
|
113
|
+
let left: number = this.bufferLength;
|
|
114
|
+
let bitLenHi: number = (bytesHashed / 0x20000000) | 0;
|
|
115
|
+
let bitLenLo: number = bytesHashed << 3;
|
|
116
|
+
let padLength: number = (bytesHashed % 64 < 56) ? 64 : 128;
|
|
117
117
|
this.buffer[left] = 0x80;
|
|
118
118
|
for (let i = left + 1; i < padLength - 8; i++) {
|
|
119
119
|
this.buffer[i] = 0;
|
|
@@ -154,7 +154,7 @@ export class Hash {
|
|
|
154
154
|
};
|
|
155
155
|
|
|
156
156
|
// Internal function for use in HMAC for optimization.
|
|
157
|
-
_restoreState(from: Uint32Array, bytesHashed:
|
|
157
|
+
_restoreState(from: Uint32Array, bytesHashed: number): void {
|
|
158
158
|
for (let i = 0; i < this.state.length; i++) {
|
|
159
159
|
this.state[i] = from[i];
|
|
160
160
|
}
|
|
@@ -163,8 +163,8 @@ export class Hash {
|
|
|
163
163
|
this.bufferLength = 0;
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
-
static hashBlocks(w: Int32Array, v: Int32Array, p: Uint8Array, pos:
|
|
167
|
-
let a:
|
|
166
|
+
static hashBlocks(w: Int32Array, v: Int32Array, p: Uint8Array, pos: number, len: number): number {
|
|
167
|
+
let a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, u: number, i: number, j: number, t1: number, t2: number;
|
|
168
168
|
while (len >= 64) {
|
|
169
169
|
a = v[0];
|
|
170
170
|
b = v[1];
|
|
@@ -176,10 +176,10 @@ export class Hash {
|
|
|
176
176
|
h = v[7];
|
|
177
177
|
for (i = 0; i < 16; i++) {
|
|
178
178
|
j = pos + i * 4;
|
|
179
|
-
let p1 = ((
|
|
180
|
-
let p2 = ((
|
|
181
|
-
let p3 = ((
|
|
182
|
-
let p4 = (
|
|
179
|
+
let p1 = ((p[j] & 0xff) << 24);
|
|
180
|
+
let p2 = ((p[j + 1] & 0xff) << 16);
|
|
181
|
+
let p3 = ((p[j + 2] & 0xff) << 8);
|
|
182
|
+
let p4 = (p[j + 3] & 0xff);
|
|
183
183
|
w[i] = p1 | p2 | p3 | p4;
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -193,7 +193,7 @@ export class Hash {
|
|
|
193
193
|
for (i = 0; i < 64; i++) {
|
|
194
194
|
t1 = (((((e >>> 6 | e << (32 - 6)) ^ (e >>> 11 | e << (32 - 11)) ^
|
|
195
195
|
(e >>> 25 | e << (32 - 25))) + ((e & f) ^ (~e & g))) | 0) +
|
|
196
|
-
((h + ((
|
|
196
|
+
((h + ((Hash.K[i] + w[i]) | 0)) | 0)) | 0;
|
|
197
197
|
t2 = (((a >>> 2 | a << (32 - 2)) ^ (a >>> 13 | a << (32 - 13)) ^
|
|
198
198
|
(a >>> 22 | a << (32 - 22))) + ((a & b) ^ (a & c) ^ (b & c))) | 0;
|
|
199
199
|
h = g;
|
|
@@ -224,8 +224,8 @@ export class Hash {
|
|
|
224
224
|
export class HMAC {
|
|
225
225
|
private inner: Hash
|
|
226
226
|
private outer: Hash
|
|
227
|
-
blockSize:
|
|
228
|
-
digestLength:
|
|
227
|
+
blockSize: number
|
|
228
|
+
digestLength: number
|
|
229
229
|
private readonly istate: Uint32Array
|
|
230
230
|
private readonly ostate: Uint32Array
|
|
231
231
|
|
|
@@ -311,7 +311,7 @@ export function hash(data: Uint8Array): Uint8Array {
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
export function hashString(data: string): string {
|
|
314
|
-
return toHex(hash(
|
|
314
|
+
return toHex(hash(new TextEncoder().encode(data)));
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
// Returns HMAC-SHA256 of data under the key.
|
|
@@ -324,17 +324,15 @@ export function hmac(key: Uint8Array, data: Uint8Array): Uint8Array {
|
|
|
324
324
|
|
|
325
325
|
export function toHex(byteArray: Uint8Array): string {
|
|
326
326
|
let acc = '';
|
|
327
|
-
for(let i=0; i<byteArray.length; i++){
|
|
327
|
+
for (let i = 0; i < byteArray.length; i++) {
|
|
328
328
|
let val = byteArray[i];
|
|
329
329
|
acc += ('0' + val.toString(16)).slice(-2);
|
|
330
330
|
}
|
|
331
331
|
return acc;
|
|
332
|
-
//return byteArray.reduce((acc, val) => (acc + ('0' + val.toString(16)).slice(-2)), '');
|
|
333
332
|
}
|
|
334
333
|
|
|
335
334
|
export function hmacString(key: string, data: string): string {
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
return toHex(hash)
|
|
335
|
+
const encoder = new TextEncoder();
|
|
336
|
+
const result = hmac(encoder.encode(key), encoder.encode(data));
|
|
337
|
+
return toHex(result);
|
|
340
338
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Queue-it
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|