@frontegg/redux-store 6.87.0 → 6.89.0-alpha.0
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/auth/Helpers/index.d.ts +1 -0
- package/auth/Helpers/index.js +1 -0
- package/auth/Helpers/isAuthRoute.d.ts +2 -0
- package/auth/Helpers/isAuthRoute.js +9 -0
- package/auth/index.d.ts +1 -0
- package/auth/index.js +1 -0
- package/helpers.js +2 -1
- package/index.js +1 -1
- package/node/auth/Helpers/index.js +16 -0
- package/node/auth/Helpers/isAuthRoute.js +17 -0
- package/node/auth/index.js +12 -0
- package/node/helpers.js +2 -2
- package/node/index.js +1 -1
- package/node/utils/sha256.js +432 -0
- package/package.json +1 -2
- package/utils/sha256.d.ts +22 -0
- package/utils/sha256.js +425 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './isAuthRoute';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './isAuthRoute';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["authenticatedUrl"];
|
|
4
|
+
import { authInitialState } from '../..';
|
|
5
|
+
export const isAuthRoute = (path, routes) => {
|
|
6
|
+
const _authInitialState$rou = _extends({}, authInitialState.routes, routes),
|
|
7
|
+
authRoutes = _objectWithoutPropertiesLoose(_authInitialState$rou, _excluded);
|
|
8
|
+
return Object.values(authRoutes).includes(path);
|
|
9
|
+
};
|
package/auth/index.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export * from './Provisioning';
|
|
|
50
50
|
export * from './Provisioning/interfaces';
|
|
51
51
|
export * from './PasskeysState';
|
|
52
52
|
export * from './PasskeysState/interfaces';
|
|
53
|
+
export * from './Helpers';
|
|
53
54
|
export type { AuthActions } from './reducer';
|
|
54
55
|
export { sagas as authSagas, mockSagas as authMockSagas, reducer as authReducers, actions as authActions, initialState as authInitialState, storeName as authStoreName, };
|
|
55
56
|
declare const _default: {
|
package/auth/index.js
CHANGED
|
@@ -52,6 +52,7 @@ export * from './Provisioning';
|
|
|
52
52
|
export * from './Provisioning/interfaces';
|
|
53
53
|
export * from './PasskeysState';
|
|
54
54
|
export * from './PasskeysState/interfaces';
|
|
55
|
+
export * from './Helpers';
|
|
55
56
|
export { sagas as authSagas, mockSagas as authMockSagas, reducer as authReducers, actions as authActions, initialState as authInitialState, storeName as authStoreName };
|
|
56
57
|
// export store
|
|
57
58
|
export default {
|
package/helpers.js
CHANGED
|
@@ -2,7 +2,8 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import { FeatureFlags } from '@frontegg/rest-api';
|
|
3
3
|
import { createAction } from '@reduxjs/toolkit';
|
|
4
4
|
import { select } from 'redux-saga/effects';
|
|
5
|
-
import { sha256 } from '
|
|
5
|
+
import { sha256 } from './utils/sha256';
|
|
6
|
+
|
|
6
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
8
|
export function omitProps(props, keys) {
|
|
8
9
|
const newProps = _extends({}, props);
|
package/index.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _isAuthRoute = require("./isAuthRoute");
|
|
7
|
+
Object.keys(_isAuthRoute).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _isAuthRoute[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _isAuthRoute[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.isAuthRoute = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
10
|
+
var _ = require("../..");
|
|
11
|
+
const _excluded = ["authenticatedUrl"];
|
|
12
|
+
const isAuthRoute = (path, routes) => {
|
|
13
|
+
const _authInitialState$rou = (0, _extends2.default)({}, _.authInitialState.routes, routes),
|
|
14
|
+
authRoutes = (0, _objectWithoutPropertiesLoose2.default)(_authInitialState$rou, _excluded);
|
|
15
|
+
return Object.values(authRoutes).includes(path);
|
|
16
|
+
};
|
|
17
|
+
exports.isAuthRoute = isAuthRoute;
|
package/node/auth/index.js
CHANGED
|
@@ -628,6 +628,18 @@ Object.keys(_interfaces24).forEach(function (key) {
|
|
|
628
628
|
}
|
|
629
629
|
});
|
|
630
630
|
});
|
|
631
|
+
var _Helpers = require("./Helpers");
|
|
632
|
+
Object.keys(_Helpers).forEach(function (key) {
|
|
633
|
+
if (key === "default" || key === "__esModule") return;
|
|
634
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
635
|
+
if (key in exports && exports[key] === _Helpers[key]) return;
|
|
636
|
+
Object.defineProperty(exports, key, {
|
|
637
|
+
enumerable: true,
|
|
638
|
+
get: function () {
|
|
639
|
+
return _Helpers[key];
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
});
|
|
631
643
|
// export types
|
|
632
644
|
// export store
|
|
633
645
|
var _default = {
|
package/node/helpers.js
CHANGED
|
@@ -16,7 +16,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
16
16
|
var _restApi = require("@frontegg/rest-api");
|
|
17
17
|
var _toolkit = require("@reduxjs/toolkit");
|
|
18
18
|
var _effects = require("redux-saga/effects");
|
|
19
|
-
var
|
|
19
|
+
var _sha = require("./utils/sha256");
|
|
20
20
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
21
|
function omitProps(props, keys) {
|
|
22
22
|
const newProps = (0, _extends2.default)({}, props);
|
|
@@ -32,7 +32,7 @@ function generateActionCreator(storeName) {
|
|
|
32
32
|
}
|
|
33
33
|
async function generateCodeChallengePureJs(codeVerifier) {
|
|
34
34
|
// noinspection TypeScriptValidateJSTypes pure sha256 recevie single params alg name
|
|
35
|
-
const digest =
|
|
35
|
+
const digest = _sha.sha256.digest(new TextEncoder().encode(codeVerifier));
|
|
36
36
|
return btoa(String.fromCharCode(...new Uint8Array(digest))).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
37
37
|
}
|
|
38
38
|
async function generateCodeChallengeNative(codeVerifier) {
|
package/node/index.js
CHANGED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sha256 = exports.hmac = void 0;
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* THIS IS CUSTOM VERSION OF JS-SHA256 that will be used only
|
|
11
|
+
* on non-secure domain due to the native `crypto.subtle.digest`
|
|
12
|
+
* isn't accessible from non-secure domains.
|
|
13
|
+
*
|
|
14
|
+
* NOTE: Changes from 0.9.0:
|
|
15
|
+
* - Remove any usage of eval scripts
|
|
16
|
+
* - Remove support for UMD and AMD exports
|
|
17
|
+
* - Remove support for CommonJS
|
|
18
|
+
* - Make it typescript
|
|
19
|
+
*
|
|
20
|
+
* [js-sha256]{@link https://github.com/emn178/js-sha256}
|
|
21
|
+
*
|
|
22
|
+
* @version 0.9.0
|
|
23
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
24
|
+
* @copyright Chen, Yi-Cyuan 2014-2017
|
|
25
|
+
* @license MIT
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const ERROR = 'input is invalid type';
|
|
29
|
+
const ARRAY_BUFFER = typeof ArrayBuffer !== 'undefined';
|
|
30
|
+
const HEX_CHARS = '0123456789abcdef'.split('');
|
|
31
|
+
const EXTRA = [-2147483648, 8388608, 32768, 128];
|
|
32
|
+
const SHIFT = [24, 16, 8, 0];
|
|
33
|
+
const K = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
|
|
34
|
+
const OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
|
|
35
|
+
const blocks = [];
|
|
36
|
+
if (!Array.isArray) {
|
|
37
|
+
Array.isArray = function (arg) {
|
|
38
|
+
return Object.prototype.toString.call(arg) === '[object Array]';
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (ARRAY_BUFFER && !ArrayBuffer.isView) {
|
|
42
|
+
ArrayBuffer.isView = function (arg) {
|
|
43
|
+
return typeof arg === 'object' && arg.buffer && arg.buffer.constructor === ArrayBuffer;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const createOutputMethod = function (outputType) {
|
|
47
|
+
return function (message) {
|
|
48
|
+
const instance = new Sha256(true);
|
|
49
|
+
const sha256MessageInstance = instance.update(message);
|
|
50
|
+
return sha256MessageInstance == null ? void 0 : sha256MessageInstance[outputType]();
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
const createMethod = function () {
|
|
54
|
+
const method = createOutputMethod('hex');
|
|
55
|
+
method.create = function () {
|
|
56
|
+
return new Sha256();
|
|
57
|
+
};
|
|
58
|
+
method.update = function (message) {
|
|
59
|
+
return method.create().update(message);
|
|
60
|
+
};
|
|
61
|
+
for (let i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
62
|
+
const type = OUTPUT_TYPES[i];
|
|
63
|
+
method[type] = createOutputMethod(type);
|
|
64
|
+
}
|
|
65
|
+
return method;
|
|
66
|
+
};
|
|
67
|
+
const createHmacOutputMethod = function (outputType) {
|
|
68
|
+
return function (key, message) {
|
|
69
|
+
const instance = new HmacSha256(key, true);
|
|
70
|
+
const hmacMessageInstance = instance.update(message);
|
|
71
|
+
return hmacMessageInstance == null ? void 0 : hmacMessageInstance[outputType]();
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const createHmacMethod = function () {
|
|
75
|
+
const method = createHmacOutputMethod('hex');
|
|
76
|
+
method.create = function (key) {
|
|
77
|
+
return new HmacSha256(key);
|
|
78
|
+
};
|
|
79
|
+
method.update = function (key, message) {
|
|
80
|
+
return method.create(key).update(message);
|
|
81
|
+
};
|
|
82
|
+
for (let i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
83
|
+
const type = OUTPUT_TYPES[i];
|
|
84
|
+
method[type] = createHmacOutputMethod(type);
|
|
85
|
+
}
|
|
86
|
+
return method;
|
|
87
|
+
};
|
|
88
|
+
class Sha256 {
|
|
89
|
+
constructor(sharedMemory = false) {
|
|
90
|
+
this.blocks = void 0;
|
|
91
|
+
this.h0 = void 0;
|
|
92
|
+
this.h1 = void 0;
|
|
93
|
+
this.h2 = void 0;
|
|
94
|
+
this.h3 = void 0;
|
|
95
|
+
this.h4 = void 0;
|
|
96
|
+
this.h5 = void 0;
|
|
97
|
+
this.h6 = void 0;
|
|
98
|
+
this.h7 = void 0;
|
|
99
|
+
this.block = void 0;
|
|
100
|
+
this.start = void 0;
|
|
101
|
+
this.bytes = void 0;
|
|
102
|
+
this.hBytes = void 0;
|
|
103
|
+
this.finalized = void 0;
|
|
104
|
+
this.hashed = void 0;
|
|
105
|
+
this.first = void 0;
|
|
106
|
+
this.lastByteIndex = void 0;
|
|
107
|
+
this.sharedMemory = false;
|
|
108
|
+
this.toString = () => this.hex();
|
|
109
|
+
this.array = () => Sha256.prototype.digest();
|
|
110
|
+
if (sharedMemory) {
|
|
111
|
+
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
112
|
+
this.blocks = blocks;
|
|
113
|
+
} else {
|
|
114
|
+
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
115
|
+
}
|
|
116
|
+
this.h0 = 0x6a09e667;
|
|
117
|
+
this.h1 = 0xbb67ae85;
|
|
118
|
+
this.h2 = 0x3c6ef372;
|
|
119
|
+
this.h3 = 0xa54ff53a;
|
|
120
|
+
this.h4 = 0x510e527f;
|
|
121
|
+
this.h5 = 0x9b05688c;
|
|
122
|
+
this.h6 = 0x1f83d9ab;
|
|
123
|
+
this.h7 = 0x5be0cd19;
|
|
124
|
+
this.block = this.start = this.bytes = this.hBytes = 0;
|
|
125
|
+
this.finalized = this.hashed = false;
|
|
126
|
+
this.first = true;
|
|
127
|
+
this.sharedMemory = sharedMemory;
|
|
128
|
+
}
|
|
129
|
+
update(message) {
|
|
130
|
+
if (this.finalized) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
let notString;
|
|
134
|
+
const type = typeof message;
|
|
135
|
+
if (type !== 'string') {
|
|
136
|
+
if (type === 'object') {
|
|
137
|
+
if (message === null) {
|
|
138
|
+
throw new Error(ERROR);
|
|
139
|
+
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
140
|
+
message = new Uint8Array(message);
|
|
141
|
+
} else if (!Array.isArray(message)) {
|
|
142
|
+
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
|
143
|
+
throw new Error(ERROR);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
throw new Error(ERROR);
|
|
148
|
+
}
|
|
149
|
+
notString = true;
|
|
150
|
+
}
|
|
151
|
+
let code,
|
|
152
|
+
index = 0,
|
|
153
|
+
i;
|
|
154
|
+
const length = message.length;
|
|
155
|
+
const blocks = this.blocks;
|
|
156
|
+
while (index < length) {
|
|
157
|
+
if (this.hashed) {
|
|
158
|
+
this.hashed = false;
|
|
159
|
+
blocks[0] = this.block;
|
|
160
|
+
blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
161
|
+
}
|
|
162
|
+
if (notString) {
|
|
163
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
164
|
+
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
168
|
+
code = message.charCodeAt(index);
|
|
169
|
+
if (code < 0x80) {
|
|
170
|
+
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
|
171
|
+
} else if (code < 0x800) {
|
|
172
|
+
blocks[i >> 2] |= (0xc0 | code >> 6) << SHIFT[i++ & 3];
|
|
173
|
+
blocks[i >> 2] |= (0x80 | code & 0x3f) << SHIFT[i++ & 3];
|
|
174
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
175
|
+
blocks[i >> 2] |= (0xe0 | code >> 12) << SHIFT[i++ & 3];
|
|
176
|
+
blocks[i >> 2] |= (0x80 | code >> 6 & 0x3f) << SHIFT[i++ & 3];
|
|
177
|
+
blocks[i >> 2] |= (0x80 | code & 0x3f) << SHIFT[i++ & 3];
|
|
178
|
+
} else {
|
|
179
|
+
code = 0x10000 + ((code & 0x3ff) << 10 | message.charCodeAt(++index) & 0x3ff);
|
|
180
|
+
blocks[i >> 2] |= (0xf0 | code >> 18) << SHIFT[i++ & 3];
|
|
181
|
+
blocks[i >> 2] |= (0x80 | code >> 12 & 0x3f) << SHIFT[i++ & 3];
|
|
182
|
+
blocks[i >> 2] |= (0x80 | code >> 6 & 0x3f) << SHIFT[i++ & 3];
|
|
183
|
+
blocks[i >> 2] |= (0x80 | code & 0x3f) << SHIFT[i++ & 3];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
this.lastByteIndex = i;
|
|
188
|
+
this.bytes += i - this.start;
|
|
189
|
+
if (i >= 64) {
|
|
190
|
+
this.block = blocks[16];
|
|
191
|
+
this.start = i - 64;
|
|
192
|
+
this.hash();
|
|
193
|
+
this.hashed = true;
|
|
194
|
+
} else {
|
|
195
|
+
this.start = i;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (this.bytes > 4294967295) {
|
|
199
|
+
this.hBytes += this.bytes / 4294967296 << 0;
|
|
200
|
+
this.bytes = this.bytes % 4294967296;
|
|
201
|
+
}
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
finalize() {
|
|
205
|
+
if (this.finalized) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
this.finalized = true;
|
|
209
|
+
const blocks = this.blocks,
|
|
210
|
+
i = this.lastByteIndex;
|
|
211
|
+
blocks[16] = this.block;
|
|
212
|
+
blocks[i >> 2] |= EXTRA[i & 3];
|
|
213
|
+
this.block = blocks[16];
|
|
214
|
+
if (i >= 56) {
|
|
215
|
+
if (!this.hashed) {
|
|
216
|
+
this.hash();
|
|
217
|
+
}
|
|
218
|
+
blocks[0] = this.block;
|
|
219
|
+
blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
220
|
+
}
|
|
221
|
+
blocks[14] = this.hBytes << 3 | this.bytes >>> 29;
|
|
222
|
+
blocks[15] = this.bytes << 3;
|
|
223
|
+
this.hash();
|
|
224
|
+
}
|
|
225
|
+
hash() {
|
|
226
|
+
let a = this.h0,
|
|
227
|
+
b = this.h1,
|
|
228
|
+
c = this.h2,
|
|
229
|
+
d = this.h3,
|
|
230
|
+
e = this.h4,
|
|
231
|
+
f = this.h5,
|
|
232
|
+
g = this.h6,
|
|
233
|
+
h = this.h7,
|
|
234
|
+
j,
|
|
235
|
+
s0,
|
|
236
|
+
s1,
|
|
237
|
+
maj,
|
|
238
|
+
t1,
|
|
239
|
+
t2,
|
|
240
|
+
ch,
|
|
241
|
+
ab,
|
|
242
|
+
da,
|
|
243
|
+
cd,
|
|
244
|
+
bc;
|
|
245
|
+
const blocks = this.blocks;
|
|
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
|
+
bc = b & c;
|
|
255
|
+
for (j = 0; j < 64; j += 4) {
|
|
256
|
+
if (this.first) {
|
|
257
|
+
ab = 704751109;
|
|
258
|
+
t1 = blocks[0] - 210244248;
|
|
259
|
+
h = t1 - 1521486534 << 0;
|
|
260
|
+
d = t1 + 143694565 << 0;
|
|
261
|
+
this.first = false;
|
|
262
|
+
} else {
|
|
263
|
+
s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
|
|
264
|
+
s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
|
|
265
|
+
ab = a & b;
|
|
266
|
+
maj = ab ^ a & c ^ bc;
|
|
267
|
+
ch = e & f ^ ~e & g;
|
|
268
|
+
t1 = h + s1 + ch + K[j] + blocks[j];
|
|
269
|
+
t2 = s0 + maj;
|
|
270
|
+
h = d + t1 << 0;
|
|
271
|
+
d = t1 + t2 << 0;
|
|
272
|
+
}
|
|
273
|
+
s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10);
|
|
274
|
+
s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7);
|
|
275
|
+
da = d & a;
|
|
276
|
+
maj = da ^ d & b ^ ab;
|
|
277
|
+
ch = h & e ^ ~h & f;
|
|
278
|
+
t1 = g + s1 + ch + K[j + 1] + blocks[j + 1];
|
|
279
|
+
t2 = s0 + maj;
|
|
280
|
+
g = c + t1 << 0;
|
|
281
|
+
c = t1 + t2 << 0;
|
|
282
|
+
s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10);
|
|
283
|
+
s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7);
|
|
284
|
+
cd = c & d;
|
|
285
|
+
maj = cd ^ c & a ^ da;
|
|
286
|
+
ch = g & h ^ ~g & e;
|
|
287
|
+
t1 = f + s1 + ch + K[j + 2] + blocks[j + 2];
|
|
288
|
+
t2 = s0 + maj;
|
|
289
|
+
f = b + t1 << 0;
|
|
290
|
+
b = t1 + t2 << 0;
|
|
291
|
+
s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10);
|
|
292
|
+
s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7);
|
|
293
|
+
bc = b & c;
|
|
294
|
+
maj = bc ^ b & d ^ cd;
|
|
295
|
+
ch = f & g ^ ~f & h;
|
|
296
|
+
t1 = e + s1 + ch + K[j + 3] + blocks[j + 3];
|
|
297
|
+
t2 = s0 + maj;
|
|
298
|
+
e = a + t1 << 0;
|
|
299
|
+
a = t1 + t2 << 0;
|
|
300
|
+
}
|
|
301
|
+
this.h0 = this.h0 + a << 0;
|
|
302
|
+
this.h1 = this.h1 + b << 0;
|
|
303
|
+
this.h2 = this.h2 + c << 0;
|
|
304
|
+
this.h3 = this.h3 + d << 0;
|
|
305
|
+
this.h4 = this.h4 + e << 0;
|
|
306
|
+
this.h5 = this.h5 + f << 0;
|
|
307
|
+
this.h6 = this.h6 + g << 0;
|
|
308
|
+
this.h7 = this.h7 + h << 0;
|
|
309
|
+
}
|
|
310
|
+
hex() {
|
|
311
|
+
this.finalize();
|
|
312
|
+
const h0 = this.h0,
|
|
313
|
+
h1 = this.h1,
|
|
314
|
+
h2 = this.h2,
|
|
315
|
+
h3 = this.h3,
|
|
316
|
+
h4 = this.h4,
|
|
317
|
+
h5 = this.h5,
|
|
318
|
+
h6 = this.h6,
|
|
319
|
+
h7 = this.h7;
|
|
320
|
+
let hex = HEX_CHARS[h0 >> 28 & 0x0f] + HEX_CHARS[h0 >> 24 & 0x0f] + HEX_CHARS[h0 >> 20 & 0x0f] + HEX_CHARS[h0 >> 16 & 0x0f] + HEX_CHARS[h0 >> 12 & 0x0f] + HEX_CHARS[h0 >> 8 & 0x0f] + HEX_CHARS[h0 >> 4 & 0x0f] + HEX_CHARS[h0 & 0x0f] + HEX_CHARS[h1 >> 28 & 0x0f] + HEX_CHARS[h1 >> 24 & 0x0f] + HEX_CHARS[h1 >> 20 & 0x0f] + HEX_CHARS[h1 >> 16 & 0x0f] + HEX_CHARS[h1 >> 12 & 0x0f] + HEX_CHARS[h1 >> 8 & 0x0f] + HEX_CHARS[h1 >> 4 & 0x0f] + HEX_CHARS[h1 & 0x0f] + HEX_CHARS[h2 >> 28 & 0x0f] + HEX_CHARS[h2 >> 24 & 0x0f] + HEX_CHARS[h2 >> 20 & 0x0f] + HEX_CHARS[h2 >> 16 & 0x0f] + HEX_CHARS[h2 >> 12 & 0x0f] + HEX_CHARS[h2 >> 8 & 0x0f] + HEX_CHARS[h2 >> 4 & 0x0f] + HEX_CHARS[h2 & 0x0f] + HEX_CHARS[h3 >> 28 & 0x0f] + HEX_CHARS[h3 >> 24 & 0x0f] + HEX_CHARS[h3 >> 20 & 0x0f] + HEX_CHARS[h3 >> 16 & 0x0f] + HEX_CHARS[h3 >> 12 & 0x0f] + HEX_CHARS[h3 >> 8 & 0x0f] + HEX_CHARS[h3 >> 4 & 0x0f] + HEX_CHARS[h3 & 0x0f] + HEX_CHARS[h4 >> 28 & 0x0f] + HEX_CHARS[h4 >> 24 & 0x0f] + HEX_CHARS[h4 >> 20 & 0x0f] + HEX_CHARS[h4 >> 16 & 0x0f] + HEX_CHARS[h4 >> 12 & 0x0f] + HEX_CHARS[h4 >> 8 & 0x0f] + HEX_CHARS[h4 >> 4 & 0x0f] + HEX_CHARS[h4 & 0x0f] + HEX_CHARS[h5 >> 28 & 0x0f] + HEX_CHARS[h5 >> 24 & 0x0f] + HEX_CHARS[h5 >> 20 & 0x0f] + HEX_CHARS[h5 >> 16 & 0x0f] + HEX_CHARS[h5 >> 12 & 0x0f] + HEX_CHARS[h5 >> 8 & 0x0f] + HEX_CHARS[h5 >> 4 & 0x0f] + HEX_CHARS[h5 & 0x0f] + HEX_CHARS[h6 >> 28 & 0x0f] + HEX_CHARS[h6 >> 24 & 0x0f] + HEX_CHARS[h6 >> 20 & 0x0f] + HEX_CHARS[h6 >> 16 & 0x0f] + HEX_CHARS[h6 >> 12 & 0x0f] + HEX_CHARS[h6 >> 8 & 0x0f] + HEX_CHARS[h6 >> 4 & 0x0f] + HEX_CHARS[h6 & 0x0f];
|
|
321
|
+
hex += HEX_CHARS[h7 >> 28 & 0x0f] + HEX_CHARS[h7 >> 24 & 0x0f] + HEX_CHARS[h7 >> 20 & 0x0f] + HEX_CHARS[h7 >> 16 & 0x0f] + HEX_CHARS[h7 >> 12 & 0x0f] + HEX_CHARS[h7 >> 8 & 0x0f] + HEX_CHARS[h7 >> 4 & 0x0f] + HEX_CHARS[h7 & 0x0f];
|
|
322
|
+
return hex;
|
|
323
|
+
}
|
|
324
|
+
digest() {
|
|
325
|
+
this.finalize();
|
|
326
|
+
const h0 = this.h0,
|
|
327
|
+
h1 = this.h1,
|
|
328
|
+
h2 = this.h2,
|
|
329
|
+
h3 = this.h3,
|
|
330
|
+
h4 = this.h4,
|
|
331
|
+
h5 = this.h5,
|
|
332
|
+
h6 = this.h6,
|
|
333
|
+
h7 = this.h7;
|
|
334
|
+
const arr = [h0 >> 24 & 0xff, h0 >> 16 & 0xff, h0 >> 8 & 0xff, h0 & 0xff, h1 >> 24 & 0xff, h1 >> 16 & 0xff, h1 >> 8 & 0xff, h1 & 0xff, h2 >> 24 & 0xff, h2 >> 16 & 0xff, h2 >> 8 & 0xff, h2 & 0xff, h3 >> 24 & 0xff, h3 >> 16 & 0xff, h3 >> 8 & 0xff, h3 & 0xff, h4 >> 24 & 0xff, h4 >> 16 & 0xff, h4 >> 8 & 0xff, h4 & 0xff, h5 >> 24 & 0xff, h5 >> 16 & 0xff, h5 >> 8 & 0xff, h5 & 0xff, h6 >> 24 & 0xff, h6 >> 16 & 0xff, h6 >> 8 & 0xff, h6 & 0xff];
|
|
335
|
+
arr.push(h7 >> 24 & 0xff, h7 >> 16 & 0xff, h7 >> 8 & 0xff, h7 & 0xff);
|
|
336
|
+
return arr;
|
|
337
|
+
}
|
|
338
|
+
arrayBuffer() {
|
|
339
|
+
this.finalize();
|
|
340
|
+
const buffer = new ArrayBuffer(32);
|
|
341
|
+
const dataView = new DataView(buffer);
|
|
342
|
+
dataView.setUint32(0, this.h0);
|
|
343
|
+
dataView.setUint32(4, this.h1);
|
|
344
|
+
dataView.setUint32(8, this.h2);
|
|
345
|
+
dataView.setUint32(12, this.h3);
|
|
346
|
+
dataView.setUint32(16, this.h4);
|
|
347
|
+
dataView.setUint32(20, this.h5);
|
|
348
|
+
dataView.setUint32(24, this.h6);
|
|
349
|
+
dataView.setUint32(28, this.h7);
|
|
350
|
+
return buffer;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
class HmacSha256 extends Sha256 {
|
|
354
|
+
constructor(key, sharedMemory = false) {
|
|
355
|
+
super(sharedMemory);
|
|
356
|
+
this.inner = void 0;
|
|
357
|
+
this.oKeyPad = void 0;
|
|
358
|
+
let i;
|
|
359
|
+
const type = typeof key;
|
|
360
|
+
if (type === 'string') {
|
|
361
|
+
const bytes = [],
|
|
362
|
+
length = key.length;
|
|
363
|
+
let index = 0,
|
|
364
|
+
code;
|
|
365
|
+
for (i = 0; i < length; ++i) {
|
|
366
|
+
code = key.charCodeAt(i);
|
|
367
|
+
if (code < 0x80) {
|
|
368
|
+
bytes[index++] = code;
|
|
369
|
+
} else if (code < 0x800) {
|
|
370
|
+
bytes[index++] = 0xc0 | code >> 6;
|
|
371
|
+
bytes[index++] = 0x80 | code & 0x3f;
|
|
372
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
373
|
+
bytes[index++] = 0xe0 | code >> 12;
|
|
374
|
+
bytes[index++] = 0x80 | code >> 6 & 0x3f;
|
|
375
|
+
bytes[index++] = 0x80 | code & 0x3f;
|
|
376
|
+
} else {
|
|
377
|
+
code = 0x10000 + ((code & 0x3ff) << 10 | key.charCodeAt(++i) & 0x3ff);
|
|
378
|
+
bytes[index++] = 0xf0 | code >> 18;
|
|
379
|
+
bytes[index++] = 0x80 | code >> 12 & 0x3f;
|
|
380
|
+
bytes[index++] = 0x80 | code >> 6 & 0x3f;
|
|
381
|
+
bytes[index++] = 0x80 | code & 0x3f;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
key = bytes;
|
|
385
|
+
} else {
|
|
386
|
+
if (type === 'object') {
|
|
387
|
+
if (key === null) {
|
|
388
|
+
throw new Error(ERROR);
|
|
389
|
+
} else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
|
|
390
|
+
key = new Uint8Array(key);
|
|
391
|
+
} else if (!Array.isArray(key)) {
|
|
392
|
+
if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
|
|
393
|
+
throw new Error(ERROR);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
} else {
|
|
397
|
+
throw new Error(ERROR);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (key.length > 64) {
|
|
401
|
+
var _Sha256$update;
|
|
402
|
+
key = (_Sha256$update = new Sha256(true).update(key)) == null ? void 0 : _Sha256$update.array();
|
|
403
|
+
}
|
|
404
|
+
const oKeyPad = [],
|
|
405
|
+
iKeyPad = [];
|
|
406
|
+
for (i = 0; i < 64; ++i) {
|
|
407
|
+
const b = key[i] || 0;
|
|
408
|
+
oKeyPad[i] = 0x5c ^ b;
|
|
409
|
+
iKeyPad[i] = 0x36 ^ b;
|
|
410
|
+
}
|
|
411
|
+
Sha256.call(this, sharedMemory);
|
|
412
|
+
this.update(iKeyPad);
|
|
413
|
+
this.oKeyPad = oKeyPad;
|
|
414
|
+
this.inner = true;
|
|
415
|
+
this.sharedMemory = sharedMemory;
|
|
416
|
+
}
|
|
417
|
+
finalize() {
|
|
418
|
+
super.finalize();
|
|
419
|
+
if (this.inner) {
|
|
420
|
+
this.inner = false;
|
|
421
|
+
const innerHash = this.array();
|
|
422
|
+
Sha256.call(this, this.sharedMemory);
|
|
423
|
+
this.update(this.oKeyPad);
|
|
424
|
+
this.update(innerHash);
|
|
425
|
+
Sha256.prototype.finalize.call(this);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const sha256 = createMethod();
|
|
430
|
+
exports.sha256 = sha256;
|
|
431
|
+
const hmac = createHmacMethod();
|
|
432
|
+
exports.hmac = hmac;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/redux-store",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.89.0-alpha.0",
|
|
4
4
|
"main": "./node/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Frontegg LTD",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"@babel/runtime": "^7.18.6",
|
|
9
9
|
"@frontegg/rest-api": "^3.0.95",
|
|
10
10
|
"@reduxjs/toolkit": "^1.8.5",
|
|
11
|
-
"js-sha256": "0.9.0",
|
|
12
11
|
"redux-saga": "^1.2.1",
|
|
13
12
|
"uuid": "^8.3.2"
|
|
14
13
|
},
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* THIS IS CUSTOM VERSION OF JS-SHA256 that will be used only
|
|
4
|
+
* on non-secure domain due to the native `crypto.subtle.digest`
|
|
5
|
+
* isn't accessible from non-secure domains.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: Changes from 0.9.0:
|
|
8
|
+
* - Remove any usage of eval scripts
|
|
9
|
+
* - Remove support for UMD and AMD exports
|
|
10
|
+
* - Remove support for CommonJS
|
|
11
|
+
* - Make it typescript
|
|
12
|
+
*
|
|
13
|
+
* [js-sha256]{@link https://github.com/emn178/js-sha256}
|
|
14
|
+
*
|
|
15
|
+
* @version 0.9.0
|
|
16
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
17
|
+
* @copyright Chen, Yi-Cyuan 2014-2017
|
|
18
|
+
* @license MIT
|
|
19
|
+
*/
|
|
20
|
+
declare const sha256: any;
|
|
21
|
+
declare const hmac: any;
|
|
22
|
+
export { sha256, hmac };
|
package/utils/sha256.js
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* THIS IS CUSTOM VERSION OF JS-SHA256 that will be used only
|
|
5
|
+
* on non-secure domain due to the native `crypto.subtle.digest`
|
|
6
|
+
* isn't accessible from non-secure domains.
|
|
7
|
+
*
|
|
8
|
+
* NOTE: Changes from 0.9.0:
|
|
9
|
+
* - Remove any usage of eval scripts
|
|
10
|
+
* - Remove support for UMD and AMD exports
|
|
11
|
+
* - Remove support for CommonJS
|
|
12
|
+
* - Make it typescript
|
|
13
|
+
*
|
|
14
|
+
* [js-sha256]{@link https://github.com/emn178/js-sha256}
|
|
15
|
+
*
|
|
16
|
+
* @version 0.9.0
|
|
17
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
18
|
+
* @copyright Chen, Yi-Cyuan 2014-2017
|
|
19
|
+
* @license MIT
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const ERROR = 'input is invalid type';
|
|
23
|
+
const ARRAY_BUFFER = typeof ArrayBuffer !== 'undefined';
|
|
24
|
+
const HEX_CHARS = '0123456789abcdef'.split('');
|
|
25
|
+
const EXTRA = [-2147483648, 8388608, 32768, 128];
|
|
26
|
+
const SHIFT = [24, 16, 8, 0];
|
|
27
|
+
const K = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
|
|
28
|
+
const OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
|
|
29
|
+
const blocks = [];
|
|
30
|
+
if (!Array.isArray) {
|
|
31
|
+
Array.isArray = function (arg) {
|
|
32
|
+
return Object.prototype.toString.call(arg) === '[object Array]';
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (ARRAY_BUFFER && !ArrayBuffer.isView) {
|
|
36
|
+
ArrayBuffer.isView = function (arg) {
|
|
37
|
+
return typeof arg === 'object' && arg.buffer && arg.buffer.constructor === ArrayBuffer;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const createOutputMethod = function (outputType) {
|
|
41
|
+
return function (message) {
|
|
42
|
+
const instance = new Sha256(true);
|
|
43
|
+
const sha256MessageInstance = instance.update(message);
|
|
44
|
+
return sha256MessageInstance == null ? void 0 : sha256MessageInstance[outputType]();
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
const createMethod = function () {
|
|
48
|
+
const method = createOutputMethod('hex');
|
|
49
|
+
method.create = function () {
|
|
50
|
+
return new Sha256();
|
|
51
|
+
};
|
|
52
|
+
method.update = function (message) {
|
|
53
|
+
return method.create().update(message);
|
|
54
|
+
};
|
|
55
|
+
for (let i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
56
|
+
const type = OUTPUT_TYPES[i];
|
|
57
|
+
method[type] = createOutputMethod(type);
|
|
58
|
+
}
|
|
59
|
+
return method;
|
|
60
|
+
};
|
|
61
|
+
const createHmacOutputMethod = function (outputType) {
|
|
62
|
+
return function (key, message) {
|
|
63
|
+
const instance = new HmacSha256(key, true);
|
|
64
|
+
const hmacMessageInstance = instance.update(message);
|
|
65
|
+
return hmacMessageInstance == null ? void 0 : hmacMessageInstance[outputType]();
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const createHmacMethod = function () {
|
|
69
|
+
const method = createHmacOutputMethod('hex');
|
|
70
|
+
method.create = function (key) {
|
|
71
|
+
return new HmacSha256(key);
|
|
72
|
+
};
|
|
73
|
+
method.update = function (key, message) {
|
|
74
|
+
return method.create(key).update(message);
|
|
75
|
+
};
|
|
76
|
+
for (let i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
77
|
+
const type = OUTPUT_TYPES[i];
|
|
78
|
+
method[type] = createHmacOutputMethod(type);
|
|
79
|
+
}
|
|
80
|
+
return method;
|
|
81
|
+
};
|
|
82
|
+
class Sha256 {
|
|
83
|
+
constructor(sharedMemory = false) {
|
|
84
|
+
this.blocks = void 0;
|
|
85
|
+
this.h0 = void 0;
|
|
86
|
+
this.h1 = void 0;
|
|
87
|
+
this.h2 = void 0;
|
|
88
|
+
this.h3 = void 0;
|
|
89
|
+
this.h4 = void 0;
|
|
90
|
+
this.h5 = void 0;
|
|
91
|
+
this.h6 = void 0;
|
|
92
|
+
this.h7 = void 0;
|
|
93
|
+
this.block = void 0;
|
|
94
|
+
this.start = void 0;
|
|
95
|
+
this.bytes = void 0;
|
|
96
|
+
this.hBytes = void 0;
|
|
97
|
+
this.finalized = void 0;
|
|
98
|
+
this.hashed = void 0;
|
|
99
|
+
this.first = void 0;
|
|
100
|
+
this.lastByteIndex = void 0;
|
|
101
|
+
this.sharedMemory = false;
|
|
102
|
+
this.toString = () => this.hex();
|
|
103
|
+
this.array = () => Sha256.prototype.digest();
|
|
104
|
+
if (sharedMemory) {
|
|
105
|
+
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
106
|
+
this.blocks = blocks;
|
|
107
|
+
} else {
|
|
108
|
+
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
109
|
+
}
|
|
110
|
+
this.h0 = 0x6a09e667;
|
|
111
|
+
this.h1 = 0xbb67ae85;
|
|
112
|
+
this.h2 = 0x3c6ef372;
|
|
113
|
+
this.h3 = 0xa54ff53a;
|
|
114
|
+
this.h4 = 0x510e527f;
|
|
115
|
+
this.h5 = 0x9b05688c;
|
|
116
|
+
this.h6 = 0x1f83d9ab;
|
|
117
|
+
this.h7 = 0x5be0cd19;
|
|
118
|
+
this.block = this.start = this.bytes = this.hBytes = 0;
|
|
119
|
+
this.finalized = this.hashed = false;
|
|
120
|
+
this.first = true;
|
|
121
|
+
this.sharedMemory = sharedMemory;
|
|
122
|
+
}
|
|
123
|
+
update(message) {
|
|
124
|
+
if (this.finalized) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
let notString;
|
|
128
|
+
const type = typeof message;
|
|
129
|
+
if (type !== 'string') {
|
|
130
|
+
if (type === 'object') {
|
|
131
|
+
if (message === null) {
|
|
132
|
+
throw new Error(ERROR);
|
|
133
|
+
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
134
|
+
message = new Uint8Array(message);
|
|
135
|
+
} else if (!Array.isArray(message)) {
|
|
136
|
+
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
|
137
|
+
throw new Error(ERROR);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
throw new Error(ERROR);
|
|
142
|
+
}
|
|
143
|
+
notString = true;
|
|
144
|
+
}
|
|
145
|
+
let code,
|
|
146
|
+
index = 0,
|
|
147
|
+
i;
|
|
148
|
+
const length = message.length;
|
|
149
|
+
const blocks = this.blocks;
|
|
150
|
+
while (index < length) {
|
|
151
|
+
if (this.hashed) {
|
|
152
|
+
this.hashed = false;
|
|
153
|
+
blocks[0] = this.block;
|
|
154
|
+
blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
155
|
+
}
|
|
156
|
+
if (notString) {
|
|
157
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
158
|
+
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
for (i = this.start; index < length && i < 64; ++index) {
|
|
162
|
+
code = message.charCodeAt(index);
|
|
163
|
+
if (code < 0x80) {
|
|
164
|
+
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
|
165
|
+
} else if (code < 0x800) {
|
|
166
|
+
blocks[i >> 2] |= (0xc0 | code >> 6) << SHIFT[i++ & 3];
|
|
167
|
+
blocks[i >> 2] |= (0x80 | code & 0x3f) << SHIFT[i++ & 3];
|
|
168
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
169
|
+
blocks[i >> 2] |= (0xe0 | code >> 12) << SHIFT[i++ & 3];
|
|
170
|
+
blocks[i >> 2] |= (0x80 | code >> 6 & 0x3f) << SHIFT[i++ & 3];
|
|
171
|
+
blocks[i >> 2] |= (0x80 | code & 0x3f) << SHIFT[i++ & 3];
|
|
172
|
+
} else {
|
|
173
|
+
code = 0x10000 + ((code & 0x3ff) << 10 | message.charCodeAt(++index) & 0x3ff);
|
|
174
|
+
blocks[i >> 2] |= (0xf0 | code >> 18) << SHIFT[i++ & 3];
|
|
175
|
+
blocks[i >> 2] |= (0x80 | code >> 12 & 0x3f) << SHIFT[i++ & 3];
|
|
176
|
+
blocks[i >> 2] |= (0x80 | code >> 6 & 0x3f) << SHIFT[i++ & 3];
|
|
177
|
+
blocks[i >> 2] |= (0x80 | code & 0x3f) << SHIFT[i++ & 3];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
this.lastByteIndex = i;
|
|
182
|
+
this.bytes += i - this.start;
|
|
183
|
+
if (i >= 64) {
|
|
184
|
+
this.block = blocks[16];
|
|
185
|
+
this.start = i - 64;
|
|
186
|
+
this.hash();
|
|
187
|
+
this.hashed = true;
|
|
188
|
+
} else {
|
|
189
|
+
this.start = i;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (this.bytes > 4294967295) {
|
|
193
|
+
this.hBytes += this.bytes / 4294967296 << 0;
|
|
194
|
+
this.bytes = this.bytes % 4294967296;
|
|
195
|
+
}
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
finalize() {
|
|
199
|
+
if (this.finalized) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
this.finalized = true;
|
|
203
|
+
const blocks = this.blocks,
|
|
204
|
+
i = this.lastByteIndex;
|
|
205
|
+
blocks[16] = this.block;
|
|
206
|
+
blocks[i >> 2] |= EXTRA[i & 3];
|
|
207
|
+
this.block = blocks[16];
|
|
208
|
+
if (i >= 56) {
|
|
209
|
+
if (!this.hashed) {
|
|
210
|
+
this.hash();
|
|
211
|
+
}
|
|
212
|
+
blocks[0] = this.block;
|
|
213
|
+
blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
|
|
214
|
+
}
|
|
215
|
+
blocks[14] = this.hBytes << 3 | this.bytes >>> 29;
|
|
216
|
+
blocks[15] = this.bytes << 3;
|
|
217
|
+
this.hash();
|
|
218
|
+
}
|
|
219
|
+
hash() {
|
|
220
|
+
let a = this.h0,
|
|
221
|
+
b = this.h1,
|
|
222
|
+
c = this.h2,
|
|
223
|
+
d = this.h3,
|
|
224
|
+
e = this.h4,
|
|
225
|
+
f = this.h5,
|
|
226
|
+
g = this.h6,
|
|
227
|
+
h = this.h7,
|
|
228
|
+
j,
|
|
229
|
+
s0,
|
|
230
|
+
s1,
|
|
231
|
+
maj,
|
|
232
|
+
t1,
|
|
233
|
+
t2,
|
|
234
|
+
ch,
|
|
235
|
+
ab,
|
|
236
|
+
da,
|
|
237
|
+
cd,
|
|
238
|
+
bc;
|
|
239
|
+
const blocks = this.blocks;
|
|
240
|
+
for (j = 16; j < 64; ++j) {
|
|
241
|
+
// rightrotate
|
|
242
|
+
t1 = blocks[j - 15];
|
|
243
|
+
s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3;
|
|
244
|
+
t1 = blocks[j - 2];
|
|
245
|
+
s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10;
|
|
246
|
+
blocks[j] = blocks[j - 16] + s0 + blocks[j - 7] + s1 << 0;
|
|
247
|
+
}
|
|
248
|
+
bc = b & c;
|
|
249
|
+
for (j = 0; j < 64; j += 4) {
|
|
250
|
+
if (this.first) {
|
|
251
|
+
ab = 704751109;
|
|
252
|
+
t1 = blocks[0] - 210244248;
|
|
253
|
+
h = t1 - 1521486534 << 0;
|
|
254
|
+
d = t1 + 143694565 << 0;
|
|
255
|
+
this.first = false;
|
|
256
|
+
} else {
|
|
257
|
+
s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
|
|
258
|
+
s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
|
|
259
|
+
ab = a & b;
|
|
260
|
+
maj = ab ^ a & c ^ bc;
|
|
261
|
+
ch = e & f ^ ~e & g;
|
|
262
|
+
t1 = h + s1 + ch + K[j] + blocks[j];
|
|
263
|
+
t2 = s0 + maj;
|
|
264
|
+
h = d + t1 << 0;
|
|
265
|
+
d = t1 + t2 << 0;
|
|
266
|
+
}
|
|
267
|
+
s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10);
|
|
268
|
+
s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7);
|
|
269
|
+
da = d & a;
|
|
270
|
+
maj = da ^ d & b ^ ab;
|
|
271
|
+
ch = h & e ^ ~h & f;
|
|
272
|
+
t1 = g + s1 + ch + K[j + 1] + blocks[j + 1];
|
|
273
|
+
t2 = s0 + maj;
|
|
274
|
+
g = c + t1 << 0;
|
|
275
|
+
c = t1 + t2 << 0;
|
|
276
|
+
s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10);
|
|
277
|
+
s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7);
|
|
278
|
+
cd = c & d;
|
|
279
|
+
maj = cd ^ c & a ^ da;
|
|
280
|
+
ch = g & h ^ ~g & e;
|
|
281
|
+
t1 = f + s1 + ch + K[j + 2] + blocks[j + 2];
|
|
282
|
+
t2 = s0 + maj;
|
|
283
|
+
f = b + t1 << 0;
|
|
284
|
+
b = t1 + t2 << 0;
|
|
285
|
+
s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10);
|
|
286
|
+
s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7);
|
|
287
|
+
bc = b & c;
|
|
288
|
+
maj = bc ^ b & d ^ cd;
|
|
289
|
+
ch = f & g ^ ~f & h;
|
|
290
|
+
t1 = e + s1 + ch + K[j + 3] + blocks[j + 3];
|
|
291
|
+
t2 = s0 + maj;
|
|
292
|
+
e = a + t1 << 0;
|
|
293
|
+
a = t1 + t2 << 0;
|
|
294
|
+
}
|
|
295
|
+
this.h0 = this.h0 + a << 0;
|
|
296
|
+
this.h1 = this.h1 + b << 0;
|
|
297
|
+
this.h2 = this.h2 + c << 0;
|
|
298
|
+
this.h3 = this.h3 + d << 0;
|
|
299
|
+
this.h4 = this.h4 + e << 0;
|
|
300
|
+
this.h5 = this.h5 + f << 0;
|
|
301
|
+
this.h6 = this.h6 + g << 0;
|
|
302
|
+
this.h7 = this.h7 + h << 0;
|
|
303
|
+
}
|
|
304
|
+
hex() {
|
|
305
|
+
this.finalize();
|
|
306
|
+
const h0 = this.h0,
|
|
307
|
+
h1 = this.h1,
|
|
308
|
+
h2 = this.h2,
|
|
309
|
+
h3 = this.h3,
|
|
310
|
+
h4 = this.h4,
|
|
311
|
+
h5 = this.h5,
|
|
312
|
+
h6 = this.h6,
|
|
313
|
+
h7 = this.h7;
|
|
314
|
+
let hex = HEX_CHARS[h0 >> 28 & 0x0f] + HEX_CHARS[h0 >> 24 & 0x0f] + HEX_CHARS[h0 >> 20 & 0x0f] + HEX_CHARS[h0 >> 16 & 0x0f] + HEX_CHARS[h0 >> 12 & 0x0f] + HEX_CHARS[h0 >> 8 & 0x0f] + HEX_CHARS[h0 >> 4 & 0x0f] + HEX_CHARS[h0 & 0x0f] + HEX_CHARS[h1 >> 28 & 0x0f] + HEX_CHARS[h1 >> 24 & 0x0f] + HEX_CHARS[h1 >> 20 & 0x0f] + HEX_CHARS[h1 >> 16 & 0x0f] + HEX_CHARS[h1 >> 12 & 0x0f] + HEX_CHARS[h1 >> 8 & 0x0f] + HEX_CHARS[h1 >> 4 & 0x0f] + HEX_CHARS[h1 & 0x0f] + HEX_CHARS[h2 >> 28 & 0x0f] + HEX_CHARS[h2 >> 24 & 0x0f] + HEX_CHARS[h2 >> 20 & 0x0f] + HEX_CHARS[h2 >> 16 & 0x0f] + HEX_CHARS[h2 >> 12 & 0x0f] + HEX_CHARS[h2 >> 8 & 0x0f] + HEX_CHARS[h2 >> 4 & 0x0f] + HEX_CHARS[h2 & 0x0f] + HEX_CHARS[h3 >> 28 & 0x0f] + HEX_CHARS[h3 >> 24 & 0x0f] + HEX_CHARS[h3 >> 20 & 0x0f] + HEX_CHARS[h3 >> 16 & 0x0f] + HEX_CHARS[h3 >> 12 & 0x0f] + HEX_CHARS[h3 >> 8 & 0x0f] + HEX_CHARS[h3 >> 4 & 0x0f] + HEX_CHARS[h3 & 0x0f] + HEX_CHARS[h4 >> 28 & 0x0f] + HEX_CHARS[h4 >> 24 & 0x0f] + HEX_CHARS[h4 >> 20 & 0x0f] + HEX_CHARS[h4 >> 16 & 0x0f] + HEX_CHARS[h4 >> 12 & 0x0f] + HEX_CHARS[h4 >> 8 & 0x0f] + HEX_CHARS[h4 >> 4 & 0x0f] + HEX_CHARS[h4 & 0x0f] + HEX_CHARS[h5 >> 28 & 0x0f] + HEX_CHARS[h5 >> 24 & 0x0f] + HEX_CHARS[h5 >> 20 & 0x0f] + HEX_CHARS[h5 >> 16 & 0x0f] + HEX_CHARS[h5 >> 12 & 0x0f] + HEX_CHARS[h5 >> 8 & 0x0f] + HEX_CHARS[h5 >> 4 & 0x0f] + HEX_CHARS[h5 & 0x0f] + HEX_CHARS[h6 >> 28 & 0x0f] + HEX_CHARS[h6 >> 24 & 0x0f] + HEX_CHARS[h6 >> 20 & 0x0f] + HEX_CHARS[h6 >> 16 & 0x0f] + HEX_CHARS[h6 >> 12 & 0x0f] + HEX_CHARS[h6 >> 8 & 0x0f] + HEX_CHARS[h6 >> 4 & 0x0f] + HEX_CHARS[h6 & 0x0f];
|
|
315
|
+
hex += HEX_CHARS[h7 >> 28 & 0x0f] + HEX_CHARS[h7 >> 24 & 0x0f] + HEX_CHARS[h7 >> 20 & 0x0f] + HEX_CHARS[h7 >> 16 & 0x0f] + HEX_CHARS[h7 >> 12 & 0x0f] + HEX_CHARS[h7 >> 8 & 0x0f] + HEX_CHARS[h7 >> 4 & 0x0f] + HEX_CHARS[h7 & 0x0f];
|
|
316
|
+
return hex;
|
|
317
|
+
}
|
|
318
|
+
digest() {
|
|
319
|
+
this.finalize();
|
|
320
|
+
const h0 = this.h0,
|
|
321
|
+
h1 = this.h1,
|
|
322
|
+
h2 = this.h2,
|
|
323
|
+
h3 = this.h3,
|
|
324
|
+
h4 = this.h4,
|
|
325
|
+
h5 = this.h5,
|
|
326
|
+
h6 = this.h6,
|
|
327
|
+
h7 = this.h7;
|
|
328
|
+
const arr = [h0 >> 24 & 0xff, h0 >> 16 & 0xff, h0 >> 8 & 0xff, h0 & 0xff, h1 >> 24 & 0xff, h1 >> 16 & 0xff, h1 >> 8 & 0xff, h1 & 0xff, h2 >> 24 & 0xff, h2 >> 16 & 0xff, h2 >> 8 & 0xff, h2 & 0xff, h3 >> 24 & 0xff, h3 >> 16 & 0xff, h3 >> 8 & 0xff, h3 & 0xff, h4 >> 24 & 0xff, h4 >> 16 & 0xff, h4 >> 8 & 0xff, h4 & 0xff, h5 >> 24 & 0xff, h5 >> 16 & 0xff, h5 >> 8 & 0xff, h5 & 0xff, h6 >> 24 & 0xff, h6 >> 16 & 0xff, h6 >> 8 & 0xff, h6 & 0xff];
|
|
329
|
+
arr.push(h7 >> 24 & 0xff, h7 >> 16 & 0xff, h7 >> 8 & 0xff, h7 & 0xff);
|
|
330
|
+
return arr;
|
|
331
|
+
}
|
|
332
|
+
arrayBuffer() {
|
|
333
|
+
this.finalize();
|
|
334
|
+
const buffer = new ArrayBuffer(32);
|
|
335
|
+
const dataView = new DataView(buffer);
|
|
336
|
+
dataView.setUint32(0, this.h0);
|
|
337
|
+
dataView.setUint32(4, this.h1);
|
|
338
|
+
dataView.setUint32(8, this.h2);
|
|
339
|
+
dataView.setUint32(12, this.h3);
|
|
340
|
+
dataView.setUint32(16, this.h4);
|
|
341
|
+
dataView.setUint32(20, this.h5);
|
|
342
|
+
dataView.setUint32(24, this.h6);
|
|
343
|
+
dataView.setUint32(28, this.h7);
|
|
344
|
+
return buffer;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
class HmacSha256 extends Sha256 {
|
|
348
|
+
constructor(key, sharedMemory = false) {
|
|
349
|
+
super(sharedMemory);
|
|
350
|
+
this.inner = void 0;
|
|
351
|
+
this.oKeyPad = void 0;
|
|
352
|
+
let i;
|
|
353
|
+
const type = typeof key;
|
|
354
|
+
if (type === 'string') {
|
|
355
|
+
const bytes = [],
|
|
356
|
+
length = key.length;
|
|
357
|
+
let index = 0,
|
|
358
|
+
code;
|
|
359
|
+
for (i = 0; i < length; ++i) {
|
|
360
|
+
code = key.charCodeAt(i);
|
|
361
|
+
if (code < 0x80) {
|
|
362
|
+
bytes[index++] = code;
|
|
363
|
+
} else if (code < 0x800) {
|
|
364
|
+
bytes[index++] = 0xc0 | code >> 6;
|
|
365
|
+
bytes[index++] = 0x80 | code & 0x3f;
|
|
366
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
367
|
+
bytes[index++] = 0xe0 | code >> 12;
|
|
368
|
+
bytes[index++] = 0x80 | code >> 6 & 0x3f;
|
|
369
|
+
bytes[index++] = 0x80 | code & 0x3f;
|
|
370
|
+
} else {
|
|
371
|
+
code = 0x10000 + ((code & 0x3ff) << 10 | key.charCodeAt(++i) & 0x3ff);
|
|
372
|
+
bytes[index++] = 0xf0 | code >> 18;
|
|
373
|
+
bytes[index++] = 0x80 | code >> 12 & 0x3f;
|
|
374
|
+
bytes[index++] = 0x80 | code >> 6 & 0x3f;
|
|
375
|
+
bytes[index++] = 0x80 | code & 0x3f;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
key = bytes;
|
|
379
|
+
} else {
|
|
380
|
+
if (type === 'object') {
|
|
381
|
+
if (key === null) {
|
|
382
|
+
throw new Error(ERROR);
|
|
383
|
+
} else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
|
|
384
|
+
key = new Uint8Array(key);
|
|
385
|
+
} else if (!Array.isArray(key)) {
|
|
386
|
+
if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
|
|
387
|
+
throw new Error(ERROR);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
} else {
|
|
391
|
+
throw new Error(ERROR);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (key.length > 64) {
|
|
395
|
+
var _Sha256$update;
|
|
396
|
+
key = (_Sha256$update = new Sha256(true).update(key)) == null ? void 0 : _Sha256$update.array();
|
|
397
|
+
}
|
|
398
|
+
const oKeyPad = [],
|
|
399
|
+
iKeyPad = [];
|
|
400
|
+
for (i = 0; i < 64; ++i) {
|
|
401
|
+
const b = key[i] || 0;
|
|
402
|
+
oKeyPad[i] = 0x5c ^ b;
|
|
403
|
+
iKeyPad[i] = 0x36 ^ b;
|
|
404
|
+
}
|
|
405
|
+
Sha256.call(this, sharedMemory);
|
|
406
|
+
this.update(iKeyPad);
|
|
407
|
+
this.oKeyPad = oKeyPad;
|
|
408
|
+
this.inner = true;
|
|
409
|
+
this.sharedMemory = sharedMemory;
|
|
410
|
+
}
|
|
411
|
+
finalize() {
|
|
412
|
+
super.finalize();
|
|
413
|
+
if (this.inner) {
|
|
414
|
+
this.inner = false;
|
|
415
|
+
const innerHash = this.array();
|
|
416
|
+
Sha256.call(this, this.sharedMemory);
|
|
417
|
+
this.update(this.oKeyPad);
|
|
418
|
+
this.update(innerHash);
|
|
419
|
+
Sha256.prototype.finalize.call(this);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const sha256 = createMethod();
|
|
424
|
+
const hmac = createHmacMethod();
|
|
425
|
+
export { sha256, hmac };
|