@liquidcommercedev/rmn-sdk 1.4.1-beta.2 → 1.4.1-beta.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +1174 -15
- package/dist/index.esm.js +1172 -13
- package/package.json +1 -2
- package/umd/liquidcommerce-rmn-sdk.min.js +1 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.esm.js.map +0 -1
- package/umd/liquidcommerce-rmn-sdk.min.js.map +0 -1
package/dist/index.esm.js
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
import { jwtVerify, SignJWT } from 'jose';
|
2
|
-
|
3
1
|
var RMN_SPOT_TYPE;
|
4
2
|
(function (RMN_SPOT_TYPE) {
|
5
3
|
// Reserve Bar Spot Types
|
@@ -434,7 +432,7 @@ const isNumber = typeOfTest('number');
|
|
434
432
|
*
|
435
433
|
* @returns {boolean} True if value is an Object, otherwise false
|
436
434
|
*/
|
437
|
-
const isObject = (thing) => thing !== null && typeof thing === 'object';
|
435
|
+
const isObject$1 = (thing) => thing !== null && typeof thing === 'object';
|
438
436
|
|
439
437
|
/**
|
440
438
|
* Determine if a value is a Boolean
|
@@ -503,7 +501,7 @@ const isFileList = kindOfTest('FileList');
|
|
503
501
|
*
|
504
502
|
* @returns {boolean} True if value is a Stream, otherwise false
|
505
503
|
*/
|
506
|
-
const isStream = (val) => isObject(val) && isFunction(val.pipe);
|
504
|
+
const isStream = (val) => isObject$1(val) && isFunction(val.pipe);
|
507
505
|
|
508
506
|
/**
|
509
507
|
* Determine if a value is a FormData
|
@@ -963,7 +961,7 @@ const toJSONObject = (obj) => {
|
|
963
961
|
|
964
962
|
const visit = (source, i) => {
|
965
963
|
|
966
|
-
if (isObject(source)) {
|
964
|
+
if (isObject$1(source)) {
|
967
965
|
if (stack.indexOf(source) >= 0) {
|
968
966
|
return;
|
969
967
|
}
|
@@ -992,7 +990,7 @@ const toJSONObject = (obj) => {
|
|
992
990
|
const isAsyncFn = kindOfTest('AsyncFunction');
|
993
991
|
|
994
992
|
const isThenable = (thing) =>
|
995
|
-
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
993
|
+
thing && (isObject$1(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
996
994
|
|
997
995
|
// original code
|
998
996
|
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
@@ -1033,7 +1031,7 @@ var utils$1 = {
|
|
1033
1031
|
isString,
|
1034
1032
|
isNumber,
|
1035
1033
|
isBoolean,
|
1036
|
-
isObject,
|
1034
|
+
isObject: isObject$1,
|
1037
1035
|
isPlainObject,
|
1038
1036
|
isReadableStream,
|
1039
1037
|
isRequest,
|
@@ -3381,7 +3379,7 @@ function toFormData(obj, formData, options) {
|
|
3381
3379
|
*
|
3382
3380
|
* @returns {string} The encoded string.
|
3383
3381
|
*/
|
3384
|
-
function encode$
|
3382
|
+
function encode$2(str) {
|
3385
3383
|
const charMap = {
|
3386
3384
|
'!': '%21',
|
3387
3385
|
"'": '%27',
|
@@ -3418,8 +3416,8 @@ prototype.append = function append(name, value) {
|
|
3418
3416
|
|
3419
3417
|
prototype.toString = function toString(encoder) {
|
3420
3418
|
const _encode = encoder ? function(value) {
|
3421
|
-
return encoder.call(this, value, encode$
|
3422
|
-
} : encode$
|
3419
|
+
return encoder.call(this, value, encode$2);
|
3420
|
+
} : encode$2;
|
3423
3421
|
|
3424
3422
|
return this._pairs.map(function each(pair) {
|
3425
3423
|
return _encode(pair[0]) + '=' + _encode(pair[1]);
|
@@ -3434,7 +3432,7 @@ prototype.toString = function toString(encoder) {
|
|
3434
3432
|
*
|
3435
3433
|
* @returns {string} The encoded value.
|
3436
3434
|
*/
|
3437
|
-
function encode(val) {
|
3435
|
+
function encode$1(val) {
|
3438
3436
|
return encodeURIComponent(val).
|
3439
3437
|
replace(/%3A/gi, ':').
|
3440
3438
|
replace(/%24/g, '$').
|
@@ -3459,7 +3457,7 @@ function buildURL(url, params, options) {
|
|
3459
3457
|
return url;
|
3460
3458
|
}
|
3461
3459
|
|
3462
|
-
const _encode = options && options.encode || encode;
|
3460
|
+
const _encode = options && options.encode || encode$1;
|
3463
3461
|
|
3464
3462
|
const serializeFn = options && options.serialize;
|
3465
3463
|
|
@@ -13659,6 +13657,1168 @@ function requireBlowfish () {
|
|
13659
13657
|
|
13660
13658
|
var cryptoJsExports = cryptoJs.exports;
|
13661
13659
|
|
13660
|
+
var crypto$1 = crypto;
|
13661
|
+
const isCryptoKey = (key) => key instanceof CryptoKey;
|
13662
|
+
|
13663
|
+
const encoder = new TextEncoder();
|
13664
|
+
const decoder = new TextDecoder();
|
13665
|
+
function concat(...buffers) {
|
13666
|
+
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
13667
|
+
const buf = new Uint8Array(size);
|
13668
|
+
let i = 0;
|
13669
|
+
for (const buffer of buffers) {
|
13670
|
+
buf.set(buffer, i);
|
13671
|
+
i += buffer.length;
|
13672
|
+
}
|
13673
|
+
return buf;
|
13674
|
+
}
|
13675
|
+
|
13676
|
+
const encodeBase64 = (input) => {
|
13677
|
+
let unencoded = input;
|
13678
|
+
if (typeof unencoded === 'string') {
|
13679
|
+
unencoded = encoder.encode(unencoded);
|
13680
|
+
}
|
13681
|
+
const CHUNK_SIZE = 0x8000;
|
13682
|
+
const arr = [];
|
13683
|
+
for (let i = 0; i < unencoded.length; i += CHUNK_SIZE) {
|
13684
|
+
arr.push(String.fromCharCode.apply(null, unencoded.subarray(i, i + CHUNK_SIZE)));
|
13685
|
+
}
|
13686
|
+
return btoa(arr.join(''));
|
13687
|
+
};
|
13688
|
+
const encode = (input) => {
|
13689
|
+
return encodeBase64(input).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
13690
|
+
};
|
13691
|
+
const decodeBase64 = (encoded) => {
|
13692
|
+
const binary = atob(encoded);
|
13693
|
+
const bytes = new Uint8Array(binary.length);
|
13694
|
+
for (let i = 0; i < binary.length; i++) {
|
13695
|
+
bytes[i] = binary.charCodeAt(i);
|
13696
|
+
}
|
13697
|
+
return bytes;
|
13698
|
+
};
|
13699
|
+
const decode = (input) => {
|
13700
|
+
let encoded = input;
|
13701
|
+
if (encoded instanceof Uint8Array) {
|
13702
|
+
encoded = decoder.decode(encoded);
|
13703
|
+
}
|
13704
|
+
encoded = encoded.replace(/-/g, '+').replace(/_/g, '/').replace(/\s/g, '');
|
13705
|
+
try {
|
13706
|
+
return decodeBase64(encoded);
|
13707
|
+
}
|
13708
|
+
catch {
|
13709
|
+
throw new TypeError('The input to be decoded is not correctly encoded.');
|
13710
|
+
}
|
13711
|
+
};
|
13712
|
+
|
13713
|
+
class JOSEError extends Error {
|
13714
|
+
static get code() {
|
13715
|
+
return 'ERR_JOSE_GENERIC';
|
13716
|
+
}
|
13717
|
+
constructor(message) {
|
13718
|
+
super(message);
|
13719
|
+
this.code = 'ERR_JOSE_GENERIC';
|
13720
|
+
this.name = this.constructor.name;
|
13721
|
+
Error.captureStackTrace?.(this, this.constructor);
|
13722
|
+
}
|
13723
|
+
}
|
13724
|
+
class JWTClaimValidationFailed extends JOSEError {
|
13725
|
+
static get code() {
|
13726
|
+
return 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
13727
|
+
}
|
13728
|
+
constructor(message, payload, claim = 'unspecified', reason = 'unspecified') {
|
13729
|
+
super(message);
|
13730
|
+
this.code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
|
13731
|
+
this.claim = claim;
|
13732
|
+
this.reason = reason;
|
13733
|
+
this.payload = payload;
|
13734
|
+
}
|
13735
|
+
}
|
13736
|
+
class JWTExpired extends JOSEError {
|
13737
|
+
static get code() {
|
13738
|
+
return 'ERR_JWT_EXPIRED';
|
13739
|
+
}
|
13740
|
+
constructor(message, payload, claim = 'unspecified', reason = 'unspecified') {
|
13741
|
+
super(message);
|
13742
|
+
this.code = 'ERR_JWT_EXPIRED';
|
13743
|
+
this.claim = claim;
|
13744
|
+
this.reason = reason;
|
13745
|
+
this.payload = payload;
|
13746
|
+
}
|
13747
|
+
}
|
13748
|
+
class JOSENotSupported extends JOSEError {
|
13749
|
+
constructor() {
|
13750
|
+
super(...arguments);
|
13751
|
+
this.code = 'ERR_JOSE_NOT_SUPPORTED';
|
13752
|
+
}
|
13753
|
+
static get code() {
|
13754
|
+
return 'ERR_JOSE_NOT_SUPPORTED';
|
13755
|
+
}
|
13756
|
+
}
|
13757
|
+
class JWSInvalid extends JOSEError {
|
13758
|
+
constructor() {
|
13759
|
+
super(...arguments);
|
13760
|
+
this.code = 'ERR_JWS_INVALID';
|
13761
|
+
}
|
13762
|
+
static get code() {
|
13763
|
+
return 'ERR_JWS_INVALID';
|
13764
|
+
}
|
13765
|
+
}
|
13766
|
+
class JWTInvalid extends JOSEError {
|
13767
|
+
constructor() {
|
13768
|
+
super(...arguments);
|
13769
|
+
this.code = 'ERR_JWT_INVALID';
|
13770
|
+
}
|
13771
|
+
static get code() {
|
13772
|
+
return 'ERR_JWT_INVALID';
|
13773
|
+
}
|
13774
|
+
}
|
13775
|
+
class JWSSignatureVerificationFailed extends JOSEError {
|
13776
|
+
constructor() {
|
13777
|
+
super(...arguments);
|
13778
|
+
this.code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
13779
|
+
this.message = 'signature verification failed';
|
13780
|
+
}
|
13781
|
+
static get code() {
|
13782
|
+
return 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
|
13783
|
+
}
|
13784
|
+
}
|
13785
|
+
|
13786
|
+
function unusable(name, prop = 'algorithm.name') {
|
13787
|
+
return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
13788
|
+
}
|
13789
|
+
function isAlgorithm(algorithm, name) {
|
13790
|
+
return algorithm.name === name;
|
13791
|
+
}
|
13792
|
+
function getHashLength(hash) {
|
13793
|
+
return parseInt(hash.name.slice(4), 10);
|
13794
|
+
}
|
13795
|
+
function getNamedCurve(alg) {
|
13796
|
+
switch (alg) {
|
13797
|
+
case 'ES256':
|
13798
|
+
return 'P-256';
|
13799
|
+
case 'ES384':
|
13800
|
+
return 'P-384';
|
13801
|
+
case 'ES512':
|
13802
|
+
return 'P-521';
|
13803
|
+
default:
|
13804
|
+
throw new Error('unreachable');
|
13805
|
+
}
|
13806
|
+
}
|
13807
|
+
function checkUsage(key, usages) {
|
13808
|
+
if (usages.length && !usages.some((expected) => key.usages.includes(expected))) {
|
13809
|
+
let msg = 'CryptoKey does not support this operation, its usages must include ';
|
13810
|
+
if (usages.length > 2) {
|
13811
|
+
const last = usages.pop();
|
13812
|
+
msg += `one of ${usages.join(', ')}, or ${last}.`;
|
13813
|
+
}
|
13814
|
+
else if (usages.length === 2) {
|
13815
|
+
msg += `one of ${usages[0]} or ${usages[1]}.`;
|
13816
|
+
}
|
13817
|
+
else {
|
13818
|
+
msg += `${usages[0]}.`;
|
13819
|
+
}
|
13820
|
+
throw new TypeError(msg);
|
13821
|
+
}
|
13822
|
+
}
|
13823
|
+
function checkSigCryptoKey(key, alg, ...usages) {
|
13824
|
+
switch (alg) {
|
13825
|
+
case 'HS256':
|
13826
|
+
case 'HS384':
|
13827
|
+
case 'HS512': {
|
13828
|
+
if (!isAlgorithm(key.algorithm, 'HMAC'))
|
13829
|
+
throw unusable('HMAC');
|
13830
|
+
const expected = parseInt(alg.slice(2), 10);
|
13831
|
+
const actual = getHashLength(key.algorithm.hash);
|
13832
|
+
if (actual !== expected)
|
13833
|
+
throw unusable(`SHA-${expected}`, 'algorithm.hash');
|
13834
|
+
break;
|
13835
|
+
}
|
13836
|
+
case 'RS256':
|
13837
|
+
case 'RS384':
|
13838
|
+
case 'RS512': {
|
13839
|
+
if (!isAlgorithm(key.algorithm, 'RSASSA-PKCS1-v1_5'))
|
13840
|
+
throw unusable('RSASSA-PKCS1-v1_5');
|
13841
|
+
const expected = parseInt(alg.slice(2), 10);
|
13842
|
+
const actual = getHashLength(key.algorithm.hash);
|
13843
|
+
if (actual !== expected)
|
13844
|
+
throw unusable(`SHA-${expected}`, 'algorithm.hash');
|
13845
|
+
break;
|
13846
|
+
}
|
13847
|
+
case 'PS256':
|
13848
|
+
case 'PS384':
|
13849
|
+
case 'PS512': {
|
13850
|
+
if (!isAlgorithm(key.algorithm, 'RSA-PSS'))
|
13851
|
+
throw unusable('RSA-PSS');
|
13852
|
+
const expected = parseInt(alg.slice(2), 10);
|
13853
|
+
const actual = getHashLength(key.algorithm.hash);
|
13854
|
+
if (actual !== expected)
|
13855
|
+
throw unusable(`SHA-${expected}`, 'algorithm.hash');
|
13856
|
+
break;
|
13857
|
+
}
|
13858
|
+
case 'EdDSA': {
|
13859
|
+
if (key.algorithm.name !== 'Ed25519' && key.algorithm.name !== 'Ed448') {
|
13860
|
+
throw unusable('Ed25519 or Ed448');
|
13861
|
+
}
|
13862
|
+
break;
|
13863
|
+
}
|
13864
|
+
case 'ES256':
|
13865
|
+
case 'ES384':
|
13866
|
+
case 'ES512': {
|
13867
|
+
if (!isAlgorithm(key.algorithm, 'ECDSA'))
|
13868
|
+
throw unusable('ECDSA');
|
13869
|
+
const expected = getNamedCurve(alg);
|
13870
|
+
const actual = key.algorithm.namedCurve;
|
13871
|
+
if (actual !== expected)
|
13872
|
+
throw unusable(expected, 'algorithm.namedCurve');
|
13873
|
+
break;
|
13874
|
+
}
|
13875
|
+
default:
|
13876
|
+
throw new TypeError('CryptoKey does not support this operation');
|
13877
|
+
}
|
13878
|
+
checkUsage(key, usages);
|
13879
|
+
}
|
13880
|
+
|
13881
|
+
function message(msg, actual, ...types) {
|
13882
|
+
types = types.filter(Boolean);
|
13883
|
+
if (types.length > 2) {
|
13884
|
+
const last = types.pop();
|
13885
|
+
msg += `one of type ${types.join(', ')}, or ${last}.`;
|
13886
|
+
}
|
13887
|
+
else if (types.length === 2) {
|
13888
|
+
msg += `one of type ${types[0]} or ${types[1]}.`;
|
13889
|
+
}
|
13890
|
+
else {
|
13891
|
+
msg += `of type ${types[0]}.`;
|
13892
|
+
}
|
13893
|
+
if (actual == null) {
|
13894
|
+
msg += ` Received ${actual}`;
|
13895
|
+
}
|
13896
|
+
else if (typeof actual === 'function' && actual.name) {
|
13897
|
+
msg += ` Received function ${actual.name}`;
|
13898
|
+
}
|
13899
|
+
else if (typeof actual === 'object' && actual != null) {
|
13900
|
+
if (actual.constructor?.name) {
|
13901
|
+
msg += ` Received an instance of ${actual.constructor.name}`;
|
13902
|
+
}
|
13903
|
+
}
|
13904
|
+
return msg;
|
13905
|
+
}
|
13906
|
+
var invalidKeyInput = (actual, ...types) => {
|
13907
|
+
return message('Key must be ', actual, ...types);
|
13908
|
+
};
|
13909
|
+
function withAlg(alg, actual, ...types) {
|
13910
|
+
return message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
13911
|
+
}
|
13912
|
+
|
13913
|
+
var isKeyLike = (key) => {
|
13914
|
+
if (isCryptoKey(key)) {
|
13915
|
+
return true;
|
13916
|
+
}
|
13917
|
+
return key?.[Symbol.toStringTag] === 'KeyObject';
|
13918
|
+
};
|
13919
|
+
const types = ['CryptoKey'];
|
13920
|
+
|
13921
|
+
const isDisjoint = (...headers) => {
|
13922
|
+
const sources = headers.filter(Boolean);
|
13923
|
+
if (sources.length === 0 || sources.length === 1) {
|
13924
|
+
return true;
|
13925
|
+
}
|
13926
|
+
let acc;
|
13927
|
+
for (const header of sources) {
|
13928
|
+
const parameters = Object.keys(header);
|
13929
|
+
if (!acc || acc.size === 0) {
|
13930
|
+
acc = new Set(parameters);
|
13931
|
+
continue;
|
13932
|
+
}
|
13933
|
+
for (const parameter of parameters) {
|
13934
|
+
if (acc.has(parameter)) {
|
13935
|
+
return false;
|
13936
|
+
}
|
13937
|
+
acc.add(parameter);
|
13938
|
+
}
|
13939
|
+
}
|
13940
|
+
return true;
|
13941
|
+
};
|
13942
|
+
|
13943
|
+
function isObjectLike(value) {
|
13944
|
+
return typeof value === 'object' && value !== null;
|
13945
|
+
}
|
13946
|
+
function isObject(input) {
|
13947
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== '[object Object]') {
|
13948
|
+
return false;
|
13949
|
+
}
|
13950
|
+
if (Object.getPrototypeOf(input) === null) {
|
13951
|
+
return true;
|
13952
|
+
}
|
13953
|
+
let proto = input;
|
13954
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
13955
|
+
proto = Object.getPrototypeOf(proto);
|
13956
|
+
}
|
13957
|
+
return Object.getPrototypeOf(input) === proto;
|
13958
|
+
}
|
13959
|
+
|
13960
|
+
var checkKeyLength = (alg, key) => {
|
13961
|
+
if (alg.startsWith('RS') || alg.startsWith('PS')) {
|
13962
|
+
const { modulusLength } = key.algorithm;
|
13963
|
+
if (typeof modulusLength !== 'number' || modulusLength < 2048) {
|
13964
|
+
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
13965
|
+
}
|
13966
|
+
}
|
13967
|
+
};
|
13968
|
+
|
13969
|
+
function isJWK(key) {
|
13970
|
+
return isObject(key) && typeof key.kty === 'string';
|
13971
|
+
}
|
13972
|
+
function isPrivateJWK(key) {
|
13973
|
+
return key.kty !== 'oct' && typeof key.d === 'string';
|
13974
|
+
}
|
13975
|
+
function isPublicJWK(key) {
|
13976
|
+
return key.kty !== 'oct' && typeof key.d === 'undefined';
|
13977
|
+
}
|
13978
|
+
function isSecretJWK(key) {
|
13979
|
+
return isJWK(key) && key.kty === 'oct' && typeof key.k === 'string';
|
13980
|
+
}
|
13981
|
+
|
13982
|
+
function subtleMapping(jwk) {
|
13983
|
+
let algorithm;
|
13984
|
+
let keyUsages;
|
13985
|
+
switch (jwk.kty) {
|
13986
|
+
case 'RSA': {
|
13987
|
+
switch (jwk.alg) {
|
13988
|
+
case 'PS256':
|
13989
|
+
case 'PS384':
|
13990
|
+
case 'PS512':
|
13991
|
+
algorithm = { name: 'RSA-PSS', hash: `SHA-${jwk.alg.slice(-3)}` };
|
13992
|
+
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
13993
|
+
break;
|
13994
|
+
case 'RS256':
|
13995
|
+
case 'RS384':
|
13996
|
+
case 'RS512':
|
13997
|
+
algorithm = { name: 'RSASSA-PKCS1-v1_5', hash: `SHA-${jwk.alg.slice(-3)}` };
|
13998
|
+
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
13999
|
+
break;
|
14000
|
+
case 'RSA-OAEP':
|
14001
|
+
case 'RSA-OAEP-256':
|
14002
|
+
case 'RSA-OAEP-384':
|
14003
|
+
case 'RSA-OAEP-512':
|
14004
|
+
algorithm = {
|
14005
|
+
name: 'RSA-OAEP',
|
14006
|
+
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`,
|
14007
|
+
};
|
14008
|
+
keyUsages = jwk.d ? ['decrypt', 'unwrapKey'] : ['encrypt', 'wrapKey'];
|
14009
|
+
break;
|
14010
|
+
default:
|
14011
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
14012
|
+
}
|
14013
|
+
break;
|
14014
|
+
}
|
14015
|
+
case 'EC': {
|
14016
|
+
switch (jwk.alg) {
|
14017
|
+
case 'ES256':
|
14018
|
+
algorithm = { name: 'ECDSA', namedCurve: 'P-256' };
|
14019
|
+
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
14020
|
+
break;
|
14021
|
+
case 'ES384':
|
14022
|
+
algorithm = { name: 'ECDSA', namedCurve: 'P-384' };
|
14023
|
+
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
14024
|
+
break;
|
14025
|
+
case 'ES512':
|
14026
|
+
algorithm = { name: 'ECDSA', namedCurve: 'P-521' };
|
14027
|
+
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
14028
|
+
break;
|
14029
|
+
case 'ECDH-ES':
|
14030
|
+
case 'ECDH-ES+A128KW':
|
14031
|
+
case 'ECDH-ES+A192KW':
|
14032
|
+
case 'ECDH-ES+A256KW':
|
14033
|
+
algorithm = { name: 'ECDH', namedCurve: jwk.crv };
|
14034
|
+
keyUsages = jwk.d ? ['deriveBits'] : [];
|
14035
|
+
break;
|
14036
|
+
default:
|
14037
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
14038
|
+
}
|
14039
|
+
break;
|
14040
|
+
}
|
14041
|
+
case 'OKP': {
|
14042
|
+
switch (jwk.alg) {
|
14043
|
+
case 'EdDSA':
|
14044
|
+
algorithm = { name: jwk.crv };
|
14045
|
+
keyUsages = jwk.d ? ['sign'] : ['verify'];
|
14046
|
+
break;
|
14047
|
+
case 'ECDH-ES':
|
14048
|
+
case 'ECDH-ES+A128KW':
|
14049
|
+
case 'ECDH-ES+A192KW':
|
14050
|
+
case 'ECDH-ES+A256KW':
|
14051
|
+
algorithm = { name: jwk.crv };
|
14052
|
+
keyUsages = jwk.d ? ['deriveBits'] : [];
|
14053
|
+
break;
|
14054
|
+
default:
|
14055
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
14056
|
+
}
|
14057
|
+
break;
|
14058
|
+
}
|
14059
|
+
default:
|
14060
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
14061
|
+
}
|
14062
|
+
return { algorithm, keyUsages };
|
14063
|
+
}
|
14064
|
+
const parse = async (jwk) => {
|
14065
|
+
if (!jwk.alg) {
|
14066
|
+
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
14067
|
+
}
|
14068
|
+
const { algorithm, keyUsages } = subtleMapping(jwk);
|
14069
|
+
const rest = [
|
14070
|
+
algorithm,
|
14071
|
+
jwk.ext ?? false,
|
14072
|
+
jwk.key_ops ?? keyUsages,
|
14073
|
+
];
|
14074
|
+
const keyData = { ...jwk };
|
14075
|
+
delete keyData.alg;
|
14076
|
+
delete keyData.use;
|
14077
|
+
return crypto$1.subtle.importKey('jwk', keyData, ...rest);
|
14078
|
+
};
|
14079
|
+
|
14080
|
+
const exportKeyValue = (k) => decode(k);
|
14081
|
+
let privCache;
|
14082
|
+
let pubCache;
|
14083
|
+
const isKeyObject = (key) => {
|
14084
|
+
return key?.[Symbol.toStringTag] === 'KeyObject';
|
14085
|
+
};
|
14086
|
+
const importAndCache = async (cache, key, jwk, alg, freeze = false) => {
|
14087
|
+
let cached = cache.get(key);
|
14088
|
+
if (cached?.[alg]) {
|
14089
|
+
return cached[alg];
|
14090
|
+
}
|
14091
|
+
const cryptoKey = await parse({ ...jwk, alg });
|
14092
|
+
if (freeze)
|
14093
|
+
Object.freeze(key);
|
14094
|
+
if (!cached) {
|
14095
|
+
cache.set(key, { [alg]: cryptoKey });
|
14096
|
+
}
|
14097
|
+
else {
|
14098
|
+
cached[alg] = cryptoKey;
|
14099
|
+
}
|
14100
|
+
return cryptoKey;
|
14101
|
+
};
|
14102
|
+
const normalizePublicKey = (key, alg) => {
|
14103
|
+
if (isKeyObject(key)) {
|
14104
|
+
let jwk = key.export({ format: 'jwk' });
|
14105
|
+
delete jwk.d;
|
14106
|
+
delete jwk.dp;
|
14107
|
+
delete jwk.dq;
|
14108
|
+
delete jwk.p;
|
14109
|
+
delete jwk.q;
|
14110
|
+
delete jwk.qi;
|
14111
|
+
if (jwk.k) {
|
14112
|
+
return exportKeyValue(jwk.k);
|
14113
|
+
}
|
14114
|
+
pubCache || (pubCache = new WeakMap());
|
14115
|
+
return importAndCache(pubCache, key, jwk, alg);
|
14116
|
+
}
|
14117
|
+
if (isJWK(key)) {
|
14118
|
+
if (key.k)
|
14119
|
+
return decode(key.k);
|
14120
|
+
pubCache || (pubCache = new WeakMap());
|
14121
|
+
const cryptoKey = importAndCache(pubCache, key, key, alg, true);
|
14122
|
+
return cryptoKey;
|
14123
|
+
}
|
14124
|
+
return key;
|
14125
|
+
};
|
14126
|
+
const normalizePrivateKey = (key, alg) => {
|
14127
|
+
if (isKeyObject(key)) {
|
14128
|
+
let jwk = key.export({ format: 'jwk' });
|
14129
|
+
if (jwk.k) {
|
14130
|
+
return exportKeyValue(jwk.k);
|
14131
|
+
}
|
14132
|
+
privCache || (privCache = new WeakMap());
|
14133
|
+
return importAndCache(privCache, key, jwk, alg);
|
14134
|
+
}
|
14135
|
+
if (isJWK(key)) {
|
14136
|
+
if (key.k)
|
14137
|
+
return decode(key.k);
|
14138
|
+
privCache || (privCache = new WeakMap());
|
14139
|
+
const cryptoKey = importAndCache(privCache, key, key, alg, true);
|
14140
|
+
return cryptoKey;
|
14141
|
+
}
|
14142
|
+
return key;
|
14143
|
+
};
|
14144
|
+
var normalize = { normalizePublicKey, normalizePrivateKey };
|
14145
|
+
|
14146
|
+
async function importJWK(jwk, alg) {
|
14147
|
+
if (!isObject(jwk)) {
|
14148
|
+
throw new TypeError('JWK must be an object');
|
14149
|
+
}
|
14150
|
+
alg || (alg = jwk.alg);
|
14151
|
+
switch (jwk.kty) {
|
14152
|
+
case 'oct':
|
14153
|
+
if (typeof jwk.k !== 'string' || !jwk.k) {
|
14154
|
+
throw new TypeError('missing "k" (Key Value) Parameter value');
|
14155
|
+
}
|
14156
|
+
return decode(jwk.k);
|
14157
|
+
case 'RSA':
|
14158
|
+
if (jwk.oth !== undefined) {
|
14159
|
+
throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
14160
|
+
}
|
14161
|
+
case 'EC':
|
14162
|
+
case 'OKP':
|
14163
|
+
return parse({ ...jwk, alg });
|
14164
|
+
default:
|
14165
|
+
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
14166
|
+
}
|
14167
|
+
}
|
14168
|
+
|
14169
|
+
const tag = (key) => key?.[Symbol.toStringTag];
|
14170
|
+
const jwkMatchesOp = (alg, key, usage) => {
|
14171
|
+
if (key.use !== undefined && key.use !== 'sig') {
|
14172
|
+
throw new TypeError('Invalid key for this operation, when present its use must be sig');
|
14173
|
+
}
|
14174
|
+
if (key.key_ops !== undefined && key.key_ops.includes?.(usage) !== true) {
|
14175
|
+
throw new TypeError(`Invalid key for this operation, when present its key_ops must include ${usage}`);
|
14176
|
+
}
|
14177
|
+
if (key.alg !== undefined && key.alg !== alg) {
|
14178
|
+
throw new TypeError(`Invalid key for this operation, when present its alg must be ${alg}`);
|
14179
|
+
}
|
14180
|
+
return true;
|
14181
|
+
};
|
14182
|
+
const symmetricTypeCheck = (alg, key, usage, allowJwk) => {
|
14183
|
+
if (key instanceof Uint8Array)
|
14184
|
+
return;
|
14185
|
+
if (allowJwk && isJWK(key)) {
|
14186
|
+
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
|
14187
|
+
return;
|
14188
|
+
throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
|
14189
|
+
}
|
14190
|
+
if (!isKeyLike(key)) {
|
14191
|
+
throw new TypeError(withAlg(alg, key, ...types, 'Uint8Array', allowJwk ? 'JSON Web Key' : null));
|
14192
|
+
}
|
14193
|
+
if (key.type !== 'secret') {
|
14194
|
+
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
14195
|
+
}
|
14196
|
+
};
|
14197
|
+
const asymmetricTypeCheck = (alg, key, usage, allowJwk) => {
|
14198
|
+
if (allowJwk && isJWK(key)) {
|
14199
|
+
switch (usage) {
|
14200
|
+
case 'sign':
|
14201
|
+
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
|
14202
|
+
return;
|
14203
|
+
throw new TypeError(`JSON Web Key for this operation be a private JWK`);
|
14204
|
+
case 'verify':
|
14205
|
+
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
|
14206
|
+
return;
|
14207
|
+
throw new TypeError(`JSON Web Key for this operation be a public JWK`);
|
14208
|
+
}
|
14209
|
+
}
|
14210
|
+
if (!isKeyLike(key)) {
|
14211
|
+
throw new TypeError(withAlg(alg, key, ...types, allowJwk ? 'JSON Web Key' : null));
|
14212
|
+
}
|
14213
|
+
if (key.type === 'secret') {
|
14214
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
14215
|
+
}
|
14216
|
+
if (usage === 'sign' && key.type === 'public') {
|
14217
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
14218
|
+
}
|
14219
|
+
if (usage === 'decrypt' && key.type === 'public') {
|
14220
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
14221
|
+
}
|
14222
|
+
if (key.algorithm && usage === 'verify' && key.type === 'private') {
|
14223
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
14224
|
+
}
|
14225
|
+
if (key.algorithm && usage === 'encrypt' && key.type === 'private') {
|
14226
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
14227
|
+
}
|
14228
|
+
};
|
14229
|
+
function checkKeyType(allowJwk, alg, key, usage) {
|
14230
|
+
const symmetric = alg.startsWith('HS') ||
|
14231
|
+
alg === 'dir' ||
|
14232
|
+
alg.startsWith('PBES2') ||
|
14233
|
+
/^A\d{3}(?:GCM)?KW$/.test(alg);
|
14234
|
+
if (symmetric) {
|
14235
|
+
symmetricTypeCheck(alg, key, usage, allowJwk);
|
14236
|
+
}
|
14237
|
+
else {
|
14238
|
+
asymmetricTypeCheck(alg, key, usage, allowJwk);
|
14239
|
+
}
|
14240
|
+
}
|
14241
|
+
checkKeyType.bind(undefined, false);
|
14242
|
+
const checkKeyTypeWithJwk = checkKeyType.bind(undefined, true);
|
14243
|
+
|
14244
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
14245
|
+
if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
|
14246
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
14247
|
+
}
|
14248
|
+
if (!protectedHeader || protectedHeader.crit === undefined) {
|
14249
|
+
return new Set();
|
14250
|
+
}
|
14251
|
+
if (!Array.isArray(protectedHeader.crit) ||
|
14252
|
+
protectedHeader.crit.length === 0 ||
|
14253
|
+
protectedHeader.crit.some((input) => typeof input !== 'string' || input.length === 0)) {
|
14254
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
14255
|
+
}
|
14256
|
+
let recognized;
|
14257
|
+
if (recognizedOption !== undefined) {
|
14258
|
+
recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
14259
|
+
}
|
14260
|
+
else {
|
14261
|
+
recognized = recognizedDefault;
|
14262
|
+
}
|
14263
|
+
for (const parameter of protectedHeader.crit) {
|
14264
|
+
if (!recognized.has(parameter)) {
|
14265
|
+
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
14266
|
+
}
|
14267
|
+
if (joseHeader[parameter] === undefined) {
|
14268
|
+
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
14269
|
+
}
|
14270
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
|
14271
|
+
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
14272
|
+
}
|
14273
|
+
}
|
14274
|
+
return new Set(protectedHeader.crit);
|
14275
|
+
}
|
14276
|
+
|
14277
|
+
function subtleDsa(alg, algorithm) {
|
14278
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
14279
|
+
switch (alg) {
|
14280
|
+
case 'HS256':
|
14281
|
+
case 'HS384':
|
14282
|
+
case 'HS512':
|
14283
|
+
return { hash, name: 'HMAC' };
|
14284
|
+
case 'PS256':
|
14285
|
+
case 'PS384':
|
14286
|
+
case 'PS512':
|
14287
|
+
return { hash, name: 'RSA-PSS', saltLength: alg.slice(-3) >> 3 };
|
14288
|
+
case 'RS256':
|
14289
|
+
case 'RS384':
|
14290
|
+
case 'RS512':
|
14291
|
+
return { hash, name: 'RSASSA-PKCS1-v1_5' };
|
14292
|
+
case 'ES256':
|
14293
|
+
case 'ES384':
|
14294
|
+
case 'ES512':
|
14295
|
+
return { hash, name: 'ECDSA', namedCurve: algorithm.namedCurve };
|
14296
|
+
case 'EdDSA':
|
14297
|
+
return { name: algorithm.name };
|
14298
|
+
default:
|
14299
|
+
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
14300
|
+
}
|
14301
|
+
}
|
14302
|
+
|
14303
|
+
async function getCryptoKey(alg, key, usage) {
|
14304
|
+
if (usage === 'sign') {
|
14305
|
+
key = await normalize.normalizePrivateKey(key, alg);
|
14306
|
+
}
|
14307
|
+
if (usage === 'verify') {
|
14308
|
+
key = await normalize.normalizePublicKey(key, alg);
|
14309
|
+
}
|
14310
|
+
if (isCryptoKey(key)) {
|
14311
|
+
checkSigCryptoKey(key, alg, usage);
|
14312
|
+
return key;
|
14313
|
+
}
|
14314
|
+
if (key instanceof Uint8Array) {
|
14315
|
+
if (!alg.startsWith('HS')) {
|
14316
|
+
throw new TypeError(invalidKeyInput(key, ...types));
|
14317
|
+
}
|
14318
|
+
return crypto$1.subtle.importKey('raw', key, { hash: `SHA-${alg.slice(-3)}`, name: 'HMAC' }, false, [usage]);
|
14319
|
+
}
|
14320
|
+
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array', 'JSON Web Key'));
|
14321
|
+
}
|
14322
|
+
|
14323
|
+
const verify = async (alg, key, signature, data) => {
|
14324
|
+
const cryptoKey = await getCryptoKey(alg, key, 'verify');
|
14325
|
+
checkKeyLength(alg, cryptoKey);
|
14326
|
+
const algorithm = subtleDsa(alg, cryptoKey.algorithm);
|
14327
|
+
try {
|
14328
|
+
return await crypto$1.subtle.verify(algorithm, cryptoKey, signature, data);
|
14329
|
+
}
|
14330
|
+
catch {
|
14331
|
+
return false;
|
14332
|
+
}
|
14333
|
+
};
|
14334
|
+
|
14335
|
+
async function flattenedVerify(jws, key, options) {
|
14336
|
+
if (!isObject(jws)) {
|
14337
|
+
throw new JWSInvalid('Flattened JWS must be an object');
|
14338
|
+
}
|
14339
|
+
if (jws.protected === undefined && jws.header === undefined) {
|
14340
|
+
throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
|
14341
|
+
}
|
14342
|
+
if (jws.protected !== undefined && typeof jws.protected !== 'string') {
|
14343
|
+
throw new JWSInvalid('JWS Protected Header incorrect type');
|
14344
|
+
}
|
14345
|
+
if (jws.payload === undefined) {
|
14346
|
+
throw new JWSInvalid('JWS Payload missing');
|
14347
|
+
}
|
14348
|
+
if (typeof jws.signature !== 'string') {
|
14349
|
+
throw new JWSInvalid('JWS Signature missing or incorrect type');
|
14350
|
+
}
|
14351
|
+
if (jws.header !== undefined && !isObject(jws.header)) {
|
14352
|
+
throw new JWSInvalid('JWS Unprotected Header incorrect type');
|
14353
|
+
}
|
14354
|
+
let parsedProt = {};
|
14355
|
+
if (jws.protected) {
|
14356
|
+
try {
|
14357
|
+
const protectedHeader = decode(jws.protected);
|
14358
|
+
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
14359
|
+
}
|
14360
|
+
catch {
|
14361
|
+
throw new JWSInvalid('JWS Protected Header is invalid');
|
14362
|
+
}
|
14363
|
+
}
|
14364
|
+
if (!isDisjoint(parsedProt, jws.header)) {
|
14365
|
+
throw new JWSInvalid('JWS Protected and JWS Unprotected Header Parameter names must be disjoint');
|
14366
|
+
}
|
14367
|
+
const joseHeader = {
|
14368
|
+
...parsedProt,
|
14369
|
+
...jws.header,
|
14370
|
+
};
|
14371
|
+
const extensions = validateCrit(JWSInvalid, new Map([['b64', true]]), options?.crit, parsedProt, joseHeader);
|
14372
|
+
let b64 = true;
|
14373
|
+
if (extensions.has('b64')) {
|
14374
|
+
b64 = parsedProt.b64;
|
14375
|
+
if (typeof b64 !== 'boolean') {
|
14376
|
+
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
14377
|
+
}
|
14378
|
+
}
|
14379
|
+
const { alg } = joseHeader;
|
14380
|
+
if (typeof alg !== 'string' || !alg) {
|
14381
|
+
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
14382
|
+
}
|
14383
|
+
if (b64) {
|
14384
|
+
if (typeof jws.payload !== 'string') {
|
14385
|
+
throw new JWSInvalid('JWS Payload must be a string');
|
14386
|
+
}
|
14387
|
+
}
|
14388
|
+
else if (typeof jws.payload !== 'string' && !(jws.payload instanceof Uint8Array)) {
|
14389
|
+
throw new JWSInvalid('JWS Payload must be a string or an Uint8Array instance');
|
14390
|
+
}
|
14391
|
+
let resolvedKey = false;
|
14392
|
+
if (typeof key === 'function') {
|
14393
|
+
key = await key(parsedProt, jws);
|
14394
|
+
resolvedKey = true;
|
14395
|
+
checkKeyTypeWithJwk(alg, key, 'verify');
|
14396
|
+
if (isJWK(key)) {
|
14397
|
+
key = await importJWK(key, alg);
|
14398
|
+
}
|
14399
|
+
}
|
14400
|
+
else {
|
14401
|
+
checkKeyTypeWithJwk(alg, key, 'verify');
|
14402
|
+
}
|
14403
|
+
const data = concat(encoder.encode(jws.protected ?? ''), encoder.encode('.'), typeof jws.payload === 'string' ? encoder.encode(jws.payload) : jws.payload);
|
14404
|
+
let signature;
|
14405
|
+
try {
|
14406
|
+
signature = decode(jws.signature);
|
14407
|
+
}
|
14408
|
+
catch {
|
14409
|
+
throw new JWSInvalid('Failed to base64url decode the signature');
|
14410
|
+
}
|
14411
|
+
const verified = await verify(alg, key, signature, data);
|
14412
|
+
if (!verified) {
|
14413
|
+
throw new JWSSignatureVerificationFailed();
|
14414
|
+
}
|
14415
|
+
let payload;
|
14416
|
+
if (b64) {
|
14417
|
+
try {
|
14418
|
+
payload = decode(jws.payload);
|
14419
|
+
}
|
14420
|
+
catch {
|
14421
|
+
throw new JWSInvalid('Failed to base64url decode the payload');
|
14422
|
+
}
|
14423
|
+
}
|
14424
|
+
else if (typeof jws.payload === 'string') {
|
14425
|
+
payload = encoder.encode(jws.payload);
|
14426
|
+
}
|
14427
|
+
else {
|
14428
|
+
payload = jws.payload;
|
14429
|
+
}
|
14430
|
+
const result = { payload };
|
14431
|
+
if (jws.protected !== undefined) {
|
14432
|
+
result.protectedHeader = parsedProt;
|
14433
|
+
}
|
14434
|
+
if (jws.header !== undefined) {
|
14435
|
+
result.unprotectedHeader = jws.header;
|
14436
|
+
}
|
14437
|
+
if (resolvedKey) {
|
14438
|
+
return { ...result, key };
|
14439
|
+
}
|
14440
|
+
return result;
|
14441
|
+
}
|
14442
|
+
|
14443
|
+
async function compactVerify(jws, key, options) {
|
14444
|
+
if (jws instanceof Uint8Array) {
|
14445
|
+
jws = decoder.decode(jws);
|
14446
|
+
}
|
14447
|
+
if (typeof jws !== 'string') {
|
14448
|
+
throw new JWSInvalid('Compact JWS must be a string or Uint8Array');
|
14449
|
+
}
|
14450
|
+
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split('.');
|
14451
|
+
if (length !== 3) {
|
14452
|
+
throw new JWSInvalid('Invalid Compact JWS');
|
14453
|
+
}
|
14454
|
+
const verified = await flattenedVerify({ payload, protected: protectedHeader, signature }, key, options);
|
14455
|
+
const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
|
14456
|
+
if (typeof key === 'function') {
|
14457
|
+
return { ...result, key: verified.key };
|
14458
|
+
}
|
14459
|
+
return result;
|
14460
|
+
}
|
14461
|
+
|
14462
|
+
var epoch = (date) => Math.floor(date.getTime() / 1000);
|
14463
|
+
|
14464
|
+
const minute = 60;
|
14465
|
+
const hour = minute * 60;
|
14466
|
+
const day = hour * 24;
|
14467
|
+
const week = day * 7;
|
14468
|
+
const year = day * 365.25;
|
14469
|
+
const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
14470
|
+
var secs = (str) => {
|
14471
|
+
const matched = REGEX.exec(str);
|
14472
|
+
if (!matched || (matched[4] && matched[1])) {
|
14473
|
+
throw new TypeError('Invalid time period format');
|
14474
|
+
}
|
14475
|
+
const value = parseFloat(matched[2]);
|
14476
|
+
const unit = matched[3].toLowerCase();
|
14477
|
+
let numericDate;
|
14478
|
+
switch (unit) {
|
14479
|
+
case 'sec':
|
14480
|
+
case 'secs':
|
14481
|
+
case 'second':
|
14482
|
+
case 'seconds':
|
14483
|
+
case 's':
|
14484
|
+
numericDate = Math.round(value);
|
14485
|
+
break;
|
14486
|
+
case 'minute':
|
14487
|
+
case 'minutes':
|
14488
|
+
case 'min':
|
14489
|
+
case 'mins':
|
14490
|
+
case 'm':
|
14491
|
+
numericDate = Math.round(value * minute);
|
14492
|
+
break;
|
14493
|
+
case 'hour':
|
14494
|
+
case 'hours':
|
14495
|
+
case 'hr':
|
14496
|
+
case 'hrs':
|
14497
|
+
case 'h':
|
14498
|
+
numericDate = Math.round(value * hour);
|
14499
|
+
break;
|
14500
|
+
case 'day':
|
14501
|
+
case 'days':
|
14502
|
+
case 'd':
|
14503
|
+
numericDate = Math.round(value * day);
|
14504
|
+
break;
|
14505
|
+
case 'week':
|
14506
|
+
case 'weeks':
|
14507
|
+
case 'w':
|
14508
|
+
numericDate = Math.round(value * week);
|
14509
|
+
break;
|
14510
|
+
default:
|
14511
|
+
numericDate = Math.round(value * year);
|
14512
|
+
break;
|
14513
|
+
}
|
14514
|
+
if (matched[1] === '-' || matched[4] === 'ago') {
|
14515
|
+
return -numericDate;
|
14516
|
+
}
|
14517
|
+
return numericDate;
|
14518
|
+
};
|
14519
|
+
|
14520
|
+
const normalizeTyp = (value) => value.toLowerCase().replace(/^application\//, '');
|
14521
|
+
const checkAudiencePresence = (audPayload, audOption) => {
|
14522
|
+
if (typeof audPayload === 'string') {
|
14523
|
+
return audOption.includes(audPayload);
|
14524
|
+
}
|
14525
|
+
if (Array.isArray(audPayload)) {
|
14526
|
+
return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
|
14527
|
+
}
|
14528
|
+
return false;
|
14529
|
+
};
|
14530
|
+
var jwtPayload = (protectedHeader, encodedPayload, options = {}) => {
|
14531
|
+
let payload;
|
14532
|
+
try {
|
14533
|
+
payload = JSON.parse(decoder.decode(encodedPayload));
|
14534
|
+
}
|
14535
|
+
catch {
|
14536
|
+
}
|
14537
|
+
if (!isObject(payload)) {
|
14538
|
+
throw new JWTInvalid('JWT Claims Set must be a top-level JSON object');
|
14539
|
+
}
|
14540
|
+
const { typ } = options;
|
14541
|
+
if (typ &&
|
14542
|
+
(typeof protectedHeader.typ !== 'string' ||
|
14543
|
+
normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) {
|
14544
|
+
throw new JWTClaimValidationFailed('unexpected "typ" JWT header value', payload, 'typ', 'check_failed');
|
14545
|
+
}
|
14546
|
+
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
14547
|
+
const presenceCheck = [...requiredClaims];
|
14548
|
+
if (maxTokenAge !== undefined)
|
14549
|
+
presenceCheck.push('iat');
|
14550
|
+
if (audience !== undefined)
|
14551
|
+
presenceCheck.push('aud');
|
14552
|
+
if (subject !== undefined)
|
14553
|
+
presenceCheck.push('sub');
|
14554
|
+
if (issuer !== undefined)
|
14555
|
+
presenceCheck.push('iss');
|
14556
|
+
for (const claim of new Set(presenceCheck.reverse())) {
|
14557
|
+
if (!(claim in payload)) {
|
14558
|
+
throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, 'missing');
|
14559
|
+
}
|
14560
|
+
}
|
14561
|
+
if (issuer &&
|
14562
|
+
!(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) {
|
14563
|
+
throw new JWTClaimValidationFailed('unexpected "iss" claim value', payload, 'iss', 'check_failed');
|
14564
|
+
}
|
14565
|
+
if (subject && payload.sub !== subject) {
|
14566
|
+
throw new JWTClaimValidationFailed('unexpected "sub" claim value', payload, 'sub', 'check_failed');
|
14567
|
+
}
|
14568
|
+
if (audience &&
|
14569
|
+
!checkAudiencePresence(payload.aud, typeof audience === 'string' ? [audience] : audience)) {
|
14570
|
+
throw new JWTClaimValidationFailed('unexpected "aud" claim value', payload, 'aud', 'check_failed');
|
14571
|
+
}
|
14572
|
+
let tolerance;
|
14573
|
+
switch (typeof options.clockTolerance) {
|
14574
|
+
case 'string':
|
14575
|
+
tolerance = secs(options.clockTolerance);
|
14576
|
+
break;
|
14577
|
+
case 'number':
|
14578
|
+
tolerance = options.clockTolerance;
|
14579
|
+
break;
|
14580
|
+
case 'undefined':
|
14581
|
+
tolerance = 0;
|
14582
|
+
break;
|
14583
|
+
default:
|
14584
|
+
throw new TypeError('Invalid clockTolerance option type');
|
14585
|
+
}
|
14586
|
+
const { currentDate } = options;
|
14587
|
+
const now = epoch(currentDate || new Date());
|
14588
|
+
if ((payload.iat !== undefined || maxTokenAge) && typeof payload.iat !== 'number') {
|
14589
|
+
throw new JWTClaimValidationFailed('"iat" claim must be a number', payload, 'iat', 'invalid');
|
14590
|
+
}
|
14591
|
+
if (payload.nbf !== undefined) {
|
14592
|
+
if (typeof payload.nbf !== 'number') {
|
14593
|
+
throw new JWTClaimValidationFailed('"nbf" claim must be a number', payload, 'nbf', 'invalid');
|
14594
|
+
}
|
14595
|
+
if (payload.nbf > now + tolerance) {
|
14596
|
+
throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, 'nbf', 'check_failed');
|
14597
|
+
}
|
14598
|
+
}
|
14599
|
+
if (payload.exp !== undefined) {
|
14600
|
+
if (typeof payload.exp !== 'number') {
|
14601
|
+
throw new JWTClaimValidationFailed('"exp" claim must be a number', payload, 'exp', 'invalid');
|
14602
|
+
}
|
14603
|
+
if (payload.exp <= now - tolerance) {
|
14604
|
+
throw new JWTExpired('"exp" claim timestamp check failed', payload, 'exp', 'check_failed');
|
14605
|
+
}
|
14606
|
+
}
|
14607
|
+
if (maxTokenAge) {
|
14608
|
+
const age = now - payload.iat;
|
14609
|
+
const max = typeof maxTokenAge === 'number' ? maxTokenAge : secs(maxTokenAge);
|
14610
|
+
if (age - tolerance > max) {
|
14611
|
+
throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, 'iat', 'check_failed');
|
14612
|
+
}
|
14613
|
+
if (age < 0 - tolerance) {
|
14614
|
+
throw new JWTClaimValidationFailed('"iat" claim timestamp check failed (it should be in the past)', payload, 'iat', 'check_failed');
|
14615
|
+
}
|
14616
|
+
}
|
14617
|
+
return payload;
|
14618
|
+
};
|
14619
|
+
|
14620
|
+
async function jwtVerify(jwt, key, options) {
|
14621
|
+
const verified = await compactVerify(jwt, key, options);
|
14622
|
+
if (verified.protectedHeader.crit?.includes('b64') && verified.protectedHeader.b64 === false) {
|
14623
|
+
throw new JWTInvalid('JWTs MUST NOT use unencoded payload');
|
14624
|
+
}
|
14625
|
+
const payload = jwtPayload(verified.protectedHeader, verified.payload, options);
|
14626
|
+
const result = { payload, protectedHeader: verified.protectedHeader };
|
14627
|
+
if (typeof key === 'function') {
|
14628
|
+
return { ...result, key: verified.key };
|
14629
|
+
}
|
14630
|
+
return result;
|
14631
|
+
}
|
14632
|
+
|
14633
|
+
const sign = async (alg, key, data) => {
|
14634
|
+
const cryptoKey = await getCryptoKey(alg, key, 'sign');
|
14635
|
+
checkKeyLength(alg, cryptoKey);
|
14636
|
+
const signature = await crypto$1.subtle.sign(subtleDsa(alg, cryptoKey.algorithm), cryptoKey, data);
|
14637
|
+
return new Uint8Array(signature);
|
14638
|
+
};
|
14639
|
+
|
14640
|
+
class FlattenedSign {
|
14641
|
+
constructor(payload) {
|
14642
|
+
if (!(payload instanceof Uint8Array)) {
|
14643
|
+
throw new TypeError('payload must be an instance of Uint8Array');
|
14644
|
+
}
|
14645
|
+
this._payload = payload;
|
14646
|
+
}
|
14647
|
+
setProtectedHeader(protectedHeader) {
|
14648
|
+
if (this._protectedHeader) {
|
14649
|
+
throw new TypeError('setProtectedHeader can only be called once');
|
14650
|
+
}
|
14651
|
+
this._protectedHeader = protectedHeader;
|
14652
|
+
return this;
|
14653
|
+
}
|
14654
|
+
setUnprotectedHeader(unprotectedHeader) {
|
14655
|
+
if (this._unprotectedHeader) {
|
14656
|
+
throw new TypeError('setUnprotectedHeader can only be called once');
|
14657
|
+
}
|
14658
|
+
this._unprotectedHeader = unprotectedHeader;
|
14659
|
+
return this;
|
14660
|
+
}
|
14661
|
+
async sign(key, options) {
|
14662
|
+
if (!this._protectedHeader && !this._unprotectedHeader) {
|
14663
|
+
throw new JWSInvalid('either setProtectedHeader or setUnprotectedHeader must be called before #sign()');
|
14664
|
+
}
|
14665
|
+
if (!isDisjoint(this._protectedHeader, this._unprotectedHeader)) {
|
14666
|
+
throw new JWSInvalid('JWS Protected and JWS Unprotected Header Parameter names must be disjoint');
|
14667
|
+
}
|
14668
|
+
const joseHeader = {
|
14669
|
+
...this._protectedHeader,
|
14670
|
+
...this._unprotectedHeader,
|
14671
|
+
};
|
14672
|
+
const extensions = validateCrit(JWSInvalid, new Map([['b64', true]]), options?.crit, this._protectedHeader, joseHeader);
|
14673
|
+
let b64 = true;
|
14674
|
+
if (extensions.has('b64')) {
|
14675
|
+
b64 = this._protectedHeader.b64;
|
14676
|
+
if (typeof b64 !== 'boolean') {
|
14677
|
+
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
14678
|
+
}
|
14679
|
+
}
|
14680
|
+
const { alg } = joseHeader;
|
14681
|
+
if (typeof alg !== 'string' || !alg) {
|
14682
|
+
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
14683
|
+
}
|
14684
|
+
checkKeyTypeWithJwk(alg, key, 'sign');
|
14685
|
+
let payload = this._payload;
|
14686
|
+
if (b64) {
|
14687
|
+
payload = encoder.encode(encode(payload));
|
14688
|
+
}
|
14689
|
+
let protectedHeader;
|
14690
|
+
if (this._protectedHeader) {
|
14691
|
+
protectedHeader = encoder.encode(encode(JSON.stringify(this._protectedHeader)));
|
14692
|
+
}
|
14693
|
+
else {
|
14694
|
+
protectedHeader = encoder.encode('');
|
14695
|
+
}
|
14696
|
+
const data = concat(protectedHeader, encoder.encode('.'), payload);
|
14697
|
+
const signature = await sign(alg, key, data);
|
14698
|
+
const jws = {
|
14699
|
+
signature: encode(signature),
|
14700
|
+
payload: '',
|
14701
|
+
};
|
14702
|
+
if (b64) {
|
14703
|
+
jws.payload = decoder.decode(payload);
|
14704
|
+
}
|
14705
|
+
if (this._unprotectedHeader) {
|
14706
|
+
jws.header = this._unprotectedHeader;
|
14707
|
+
}
|
14708
|
+
if (this._protectedHeader) {
|
14709
|
+
jws.protected = decoder.decode(protectedHeader);
|
14710
|
+
}
|
14711
|
+
return jws;
|
14712
|
+
}
|
14713
|
+
}
|
14714
|
+
|
14715
|
+
class CompactSign {
|
14716
|
+
constructor(payload) {
|
14717
|
+
this._flattened = new FlattenedSign(payload);
|
14718
|
+
}
|
14719
|
+
setProtectedHeader(protectedHeader) {
|
14720
|
+
this._flattened.setProtectedHeader(protectedHeader);
|
14721
|
+
return this;
|
14722
|
+
}
|
14723
|
+
async sign(key, options) {
|
14724
|
+
const jws = await this._flattened.sign(key, options);
|
14725
|
+
if (jws.payload === undefined) {
|
14726
|
+
throw new TypeError('use the flattened module for creating JWS with b64: false');
|
14727
|
+
}
|
14728
|
+
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
14729
|
+
}
|
14730
|
+
}
|
14731
|
+
|
14732
|
+
function validateInput(label, input) {
|
14733
|
+
if (!Number.isFinite(input)) {
|
14734
|
+
throw new TypeError(`Invalid ${label} input`);
|
14735
|
+
}
|
14736
|
+
return input;
|
14737
|
+
}
|
14738
|
+
class ProduceJWT {
|
14739
|
+
constructor(payload = {}) {
|
14740
|
+
if (!isObject(payload)) {
|
14741
|
+
throw new TypeError('JWT Claims Set MUST be an object');
|
14742
|
+
}
|
14743
|
+
this._payload = payload;
|
14744
|
+
}
|
14745
|
+
setIssuer(issuer) {
|
14746
|
+
this._payload = { ...this._payload, iss: issuer };
|
14747
|
+
return this;
|
14748
|
+
}
|
14749
|
+
setSubject(subject) {
|
14750
|
+
this._payload = { ...this._payload, sub: subject };
|
14751
|
+
return this;
|
14752
|
+
}
|
14753
|
+
setAudience(audience) {
|
14754
|
+
this._payload = { ...this._payload, aud: audience };
|
14755
|
+
return this;
|
14756
|
+
}
|
14757
|
+
setJti(jwtId) {
|
14758
|
+
this._payload = { ...this._payload, jti: jwtId };
|
14759
|
+
return this;
|
14760
|
+
}
|
14761
|
+
setNotBefore(input) {
|
14762
|
+
if (typeof input === 'number') {
|
14763
|
+
this._payload = { ...this._payload, nbf: validateInput('setNotBefore', input) };
|
14764
|
+
}
|
14765
|
+
else if (input instanceof Date) {
|
14766
|
+
this._payload = { ...this._payload, nbf: validateInput('setNotBefore', epoch(input)) };
|
14767
|
+
}
|
14768
|
+
else {
|
14769
|
+
this._payload = { ...this._payload, nbf: epoch(new Date()) + secs(input) };
|
14770
|
+
}
|
14771
|
+
return this;
|
14772
|
+
}
|
14773
|
+
setExpirationTime(input) {
|
14774
|
+
if (typeof input === 'number') {
|
14775
|
+
this._payload = { ...this._payload, exp: validateInput('setExpirationTime', input) };
|
14776
|
+
}
|
14777
|
+
else if (input instanceof Date) {
|
14778
|
+
this._payload = { ...this._payload, exp: validateInput('setExpirationTime', epoch(input)) };
|
14779
|
+
}
|
14780
|
+
else {
|
14781
|
+
this._payload = { ...this._payload, exp: epoch(new Date()) + secs(input) };
|
14782
|
+
}
|
14783
|
+
return this;
|
14784
|
+
}
|
14785
|
+
setIssuedAt(input) {
|
14786
|
+
if (typeof input === 'undefined') {
|
14787
|
+
this._payload = { ...this._payload, iat: epoch(new Date()) };
|
14788
|
+
}
|
14789
|
+
else if (input instanceof Date) {
|
14790
|
+
this._payload = { ...this._payload, iat: validateInput('setIssuedAt', epoch(input)) };
|
14791
|
+
}
|
14792
|
+
else if (typeof input === 'string') {
|
14793
|
+
this._payload = {
|
14794
|
+
...this._payload,
|
14795
|
+
iat: validateInput('setIssuedAt', epoch(new Date()) + secs(input)),
|
14796
|
+
};
|
14797
|
+
}
|
14798
|
+
else {
|
14799
|
+
this._payload = { ...this._payload, iat: validateInput('setIssuedAt', input) };
|
14800
|
+
}
|
14801
|
+
return this;
|
14802
|
+
}
|
14803
|
+
}
|
14804
|
+
|
14805
|
+
class SignJWT extends ProduceJWT {
|
14806
|
+
setProtectedHeader(protectedHeader) {
|
14807
|
+
this._protectedHeader = protectedHeader;
|
14808
|
+
return this;
|
14809
|
+
}
|
14810
|
+
async sign(key, options) {
|
14811
|
+
const sig = new CompactSign(encoder.encode(JSON.stringify(this._payload)));
|
14812
|
+
sig.setProtectedHeader(this._protectedHeader);
|
14813
|
+
if (Array.isArray(this._protectedHeader?.crit) &&
|
14814
|
+
this._protectedHeader.crit.includes('b64') &&
|
14815
|
+
this._protectedHeader.b64 === false) {
|
14816
|
+
throw new JWTInvalid('JWTs MUST NOT use unencoded payload');
|
14817
|
+
}
|
14818
|
+
return sig.sign(key, options);
|
14819
|
+
}
|
14820
|
+
}
|
14821
|
+
|
13662
14822
|
class ApiError {
|
13663
14823
|
constructor(error) {
|
13664
14824
|
var _a, _b, _c, _d, _e, _f, _g;
|
@@ -15965,4 +17125,3 @@ function RmnCreateSpotElement(spot, config) {
|
|
15965
17125
|
}
|
15966
17126
|
|
15967
17127
|
export { LiquidCommerceRmnClient, RMN_ENV, RMN_FILTER_PROPERTIES, RMN_SPOT_EVENT, RMN_SPOT_TYPE, RmnClient, RmnCreateSpotElement };
|
15968
|
-
//# sourceMappingURL=index.esm.js.map
|