@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.
@@ -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: i64 = 0;
8
+ public timeStamp: number = 0;
13
9
  public eventId: string = "";
14
10
  public hashCode: string = "";
15
- public extendableCookie: bool = false;
16
- public cookieValidityMinutes: i64 = 0;
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
- return decodeURIComponent(url);
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): bool {
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(): i64 {
54
- return Math.floor((WasiDate.now() / 1000) as f64) as i64;
53
+ static getCurrentTime(): number {
54
+ return Math.floor(Date.now() / 1000);
55
55
  }
56
56
 
57
- private static _hex2bin: u8[] = [
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: i32;
82
- let c2: i32;
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 = new RegExp(`[\[\]]`, 'g')
104
+ const namePart = /[\[\]]/g;
105
105
  let match = namePart.exec(name);
106
- while (match != null) {
107
- let rxmatch = match.matches[0];
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 == null) return '';
114
- if (results.matches.length < 3) {
113
+ if (results === null) return '';
114
+ if (results.length < 3 || results[2] === null || results[2] === undefined) {
115
115
  return '';
116
116
  }
117
117
 
118
- return decodeURIComponent(results.matches[2].replaceAll('+', ' '));
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("([\?&])(" + KnownUser.QueueITTokenKey + "=[^&]*)", 'gi');
126
+ const pattern = new RegExp("([?&])(" + KnownUser.QueueITTokenKey + "=[^&]*)", 'gi');
123
127
  const match = pattern.exec(url);
124
- if (match == null) return url;
128
+ if (match === null) return url;
125
129
 
126
- url = url.replaceAll(match.matches[0], '')
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 = I64.parseInt(keyValueArr[1]);
166
+ result.timeStamp = parseInt(keyValueArr[1], 10) || 0;
163
167
  } else if (keyValueArr[0] == QueueParameterHelper.CookieValidityMinutesKey) {
164
- result.cookieValidityMinutes = I64.parseInt(keyValueArr[1]);
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: bool = false;
215
- public hasError: bool = false;
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(i64(WasiDate.now()));
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: i64,
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: bool = false;
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: i64,
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: bool,
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: i64,
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(i64(WasiDate.now()) + 1000 * 60 * 60 * 24);
56
- const expire: i32 = Math.floor((tomorrow.getTime() / 1000) as f64) as i32;
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: i64, secretKey: string, validateTime: bool): StateInfo {
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: i64 = cookieValues.has(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)
78
- ? I64.parseInt(cookieValues.get(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey))
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: i64,
94
- validateTime: bool): bool {
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: i64 = fixedCookieValidityMinutes.length > 0 ? I64.parseInt(fixedCookieValidityMinutes) : cookieValidityMinutes;
128
- let expirationTime: i64 = I64.parseInt(issueTimeString) + validity * 60;
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: i64, cookieDomain: string, secretKey: string): void {
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).toString();
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: bool,
180
- public isValid: bool,
178
+ constructor(public isFound: boolean,
179
+ public isValid: boolean,
181
180
  public queueId: string,
182
- public fixedCookieValidityMinutes: i64,
181
+ public fixedCookieValidityMinutes: number,
183
182
  public redirectType: string) {
184
183
  }
185
184
 
186
- isStateExtendable(): bool {
185
+ isStateExtendable(): boolean {
187
186
  return this.isValid && !this.fixedCookieValidityMinutes;
188
187
  }
189
188
  }
@@ -0,0 +1,4 @@
1
+ export const encodeURI = globalThis.encodeURI;
2
+ export const decodeURI = globalThis.decodeURI;
3
+ export const encodeURIComponent = globalThis.encodeURIComponent;
4
+ export const decodeURIComponent = globalThis.decodeURIComponent;
@@ -1,16 +1,16 @@
1
1
  // Hash implements SHA256 hash algorithm.
2
2
  export class Hash {
3
- blockSize: i32;
4
- digestLength: i32;
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: i32;
9
- private bytesHashed: i32;
10
- finished: bool = false
8
+ private bufferLength: number;
9
+ private bytesHashed: number;
10
+ finished: boolean = false
11
11
 
12
12
  // SHA-256 constants
13
- static K: u64[] = [
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: i32 = 0): Hash {
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: i32 = 0;
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: i32 = this.bytesHashed;
113
- let left: i32 = this.bufferLength;
114
- let bitLenHi: u32 = (bytesHashed / 0x20000000) | 0;
115
- let bitLenLo: u32 = bytesHashed << 3;
116
- let padLength: i32 = (bytesHashed % 64 < 56) ? 64 : 128;
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: i32): void {
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: i32, len: u64): i32 {
167
- let a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32, u: i32, i: i8, j: i32, t1: i32, t2: i32;
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 = (((p[j] as i32) & 0xff) << 24);
180
- let p2 = (((p[j + 1] as i32) & 0xff) << 16);
181
- let p3 = (((p[j + 2] as i32) & 0xff) << 8);
182
- let p4 = ((p[j + 3] as i32) & 0xff);
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 + (((Hash.K[i] as i32) + w[i]) | 0)) | 0)) | 0;
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: i32
228
- digestLength: i32
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(Uint8Array.wrap(String.UTF8.encode(data))))
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 hash = hmac(
337
- Uint8Array.wrap(String.UTF8.encode(key)),
338
- Uint8Array.wrap(String.UTF8.encode(data)));
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.