@liquidcommercedev/rmn-sdk 1.4.1-beta.2 → 1.4.1-beta.4

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