@querypanel/node-sdk 1.0.28 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +51 -1220
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +47 -1216
- package/dist/index.js.map +1 -1
- package/package.json +71 -73
package/dist/index.cjs
CHANGED
|
@@ -553,1214 +553,8 @@ function sanitize2(value) {
|
|
|
553
553
|
return trimmed.length ? trimmed : void 0;
|
|
554
554
|
}
|
|
555
555
|
|
|
556
|
-
// node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
557
|
-
var encoder = new TextEncoder();
|
|
558
|
-
var decoder = new TextDecoder();
|
|
559
|
-
var MAX_INT32 = 2 ** 32;
|
|
560
|
-
function concat(...buffers) {
|
|
561
|
-
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
562
|
-
const buf = new Uint8Array(size);
|
|
563
|
-
let i = 0;
|
|
564
|
-
for (const buffer of buffers) {
|
|
565
|
-
buf.set(buffer, i);
|
|
566
|
-
i += buffer.length;
|
|
567
|
-
}
|
|
568
|
-
return buf;
|
|
569
|
-
}
|
|
570
|
-
function encode(string) {
|
|
571
|
-
const bytes = new Uint8Array(string.length);
|
|
572
|
-
for (let i = 0; i < string.length; i++) {
|
|
573
|
-
const code = string.charCodeAt(i);
|
|
574
|
-
if (code > 127) {
|
|
575
|
-
throw new TypeError("non-ASCII string encountered in encode()");
|
|
576
|
-
}
|
|
577
|
-
bytes[i] = code;
|
|
578
|
-
}
|
|
579
|
-
return bytes;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
// node_modules/jose/dist/webapi/lib/base64.js
|
|
583
|
-
function encodeBase64(input) {
|
|
584
|
-
if (Uint8Array.prototype.toBase64) {
|
|
585
|
-
return input.toBase64();
|
|
586
|
-
}
|
|
587
|
-
const CHUNK_SIZE = 32768;
|
|
588
|
-
const arr = [];
|
|
589
|
-
for (let i = 0; i < input.length; i += CHUNK_SIZE) {
|
|
590
|
-
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
591
|
-
}
|
|
592
|
-
return btoa(arr.join(""));
|
|
593
|
-
}
|
|
594
|
-
function decodeBase64(encoded) {
|
|
595
|
-
if (Uint8Array.fromBase64) {
|
|
596
|
-
return Uint8Array.fromBase64(encoded);
|
|
597
|
-
}
|
|
598
|
-
const binary = atob(encoded);
|
|
599
|
-
const bytes = new Uint8Array(binary.length);
|
|
600
|
-
for (let i = 0; i < binary.length; i++) {
|
|
601
|
-
bytes[i] = binary.charCodeAt(i);
|
|
602
|
-
}
|
|
603
|
-
return bytes;
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
// node_modules/jose/dist/webapi/util/base64url.js
|
|
607
|
-
function decode(input) {
|
|
608
|
-
if (Uint8Array.fromBase64) {
|
|
609
|
-
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
610
|
-
alphabet: "base64url"
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
let encoded = input;
|
|
614
|
-
if (encoded instanceof Uint8Array) {
|
|
615
|
-
encoded = decoder.decode(encoded);
|
|
616
|
-
}
|
|
617
|
-
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
618
|
-
try {
|
|
619
|
-
return decodeBase64(encoded);
|
|
620
|
-
} catch {
|
|
621
|
-
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
function encode2(input) {
|
|
625
|
-
let unencoded = input;
|
|
626
|
-
if (typeof unencoded === "string") {
|
|
627
|
-
unencoded = encoder.encode(unencoded);
|
|
628
|
-
}
|
|
629
|
-
if (Uint8Array.prototype.toBase64) {
|
|
630
|
-
return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
631
|
-
}
|
|
632
|
-
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
// node_modules/jose/dist/webapi/util/errors.js
|
|
636
|
-
var JOSEError = class extends Error {
|
|
637
|
-
static code = "ERR_JOSE_GENERIC";
|
|
638
|
-
code = "ERR_JOSE_GENERIC";
|
|
639
|
-
constructor(message2, options) {
|
|
640
|
-
super(message2, options);
|
|
641
|
-
this.name = this.constructor.name;
|
|
642
|
-
Error.captureStackTrace?.(this, this.constructor);
|
|
643
|
-
}
|
|
644
|
-
};
|
|
645
|
-
var JOSENotSupported = class extends JOSEError {
|
|
646
|
-
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
647
|
-
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
648
|
-
};
|
|
649
|
-
var JWSInvalid = class extends JOSEError {
|
|
650
|
-
static code = "ERR_JWS_INVALID";
|
|
651
|
-
code = "ERR_JWS_INVALID";
|
|
652
|
-
};
|
|
653
|
-
var JWTInvalid = class extends JOSEError {
|
|
654
|
-
static code = "ERR_JWT_INVALID";
|
|
655
|
-
code = "ERR_JWT_INVALID";
|
|
656
|
-
};
|
|
657
|
-
|
|
658
|
-
// node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
659
|
-
var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
660
|
-
var isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
661
|
-
function getHashLength(hash) {
|
|
662
|
-
return parseInt(hash.name.slice(4), 10);
|
|
663
|
-
}
|
|
664
|
-
function getNamedCurve(alg) {
|
|
665
|
-
switch (alg) {
|
|
666
|
-
case "ES256":
|
|
667
|
-
return "P-256";
|
|
668
|
-
case "ES384":
|
|
669
|
-
return "P-384";
|
|
670
|
-
case "ES512":
|
|
671
|
-
return "P-521";
|
|
672
|
-
default:
|
|
673
|
-
throw new Error("unreachable");
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
function checkUsage(key, usage) {
|
|
677
|
-
if (usage && !key.usages.includes(usage)) {
|
|
678
|
-
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
function checkSigCryptoKey(key, alg, usage) {
|
|
682
|
-
switch (alg) {
|
|
683
|
-
case "HS256":
|
|
684
|
-
case "HS384":
|
|
685
|
-
case "HS512": {
|
|
686
|
-
if (!isAlgorithm(key.algorithm, "HMAC"))
|
|
687
|
-
throw unusable("HMAC");
|
|
688
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
689
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
690
|
-
if (actual !== expected)
|
|
691
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
692
|
-
break;
|
|
693
|
-
}
|
|
694
|
-
case "RS256":
|
|
695
|
-
case "RS384":
|
|
696
|
-
case "RS512": {
|
|
697
|
-
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
698
|
-
throw unusable("RSASSA-PKCS1-v1_5");
|
|
699
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
700
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
701
|
-
if (actual !== expected)
|
|
702
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
703
|
-
break;
|
|
704
|
-
}
|
|
705
|
-
case "PS256":
|
|
706
|
-
case "PS384":
|
|
707
|
-
case "PS512": {
|
|
708
|
-
if (!isAlgorithm(key.algorithm, "RSA-PSS"))
|
|
709
|
-
throw unusable("RSA-PSS");
|
|
710
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
711
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
712
|
-
if (actual !== expected)
|
|
713
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
714
|
-
break;
|
|
715
|
-
}
|
|
716
|
-
case "Ed25519":
|
|
717
|
-
case "EdDSA": {
|
|
718
|
-
if (!isAlgorithm(key.algorithm, "Ed25519"))
|
|
719
|
-
throw unusable("Ed25519");
|
|
720
|
-
break;
|
|
721
|
-
}
|
|
722
|
-
case "ML-DSA-44":
|
|
723
|
-
case "ML-DSA-65":
|
|
724
|
-
case "ML-DSA-87": {
|
|
725
|
-
if (!isAlgorithm(key.algorithm, alg))
|
|
726
|
-
throw unusable(alg);
|
|
727
|
-
break;
|
|
728
|
-
}
|
|
729
|
-
case "ES256":
|
|
730
|
-
case "ES384":
|
|
731
|
-
case "ES512": {
|
|
732
|
-
if (!isAlgorithm(key.algorithm, "ECDSA"))
|
|
733
|
-
throw unusable("ECDSA");
|
|
734
|
-
const expected = getNamedCurve(alg);
|
|
735
|
-
const actual = key.algorithm.namedCurve;
|
|
736
|
-
if (actual !== expected)
|
|
737
|
-
throw unusable(expected, "algorithm.namedCurve");
|
|
738
|
-
break;
|
|
739
|
-
}
|
|
740
|
-
default:
|
|
741
|
-
throw new TypeError("CryptoKey does not support this operation");
|
|
742
|
-
}
|
|
743
|
-
checkUsage(key, usage);
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
// node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
747
|
-
function message(msg, actual, ...types) {
|
|
748
|
-
types = types.filter(Boolean);
|
|
749
|
-
if (types.length > 2) {
|
|
750
|
-
const last = types.pop();
|
|
751
|
-
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
752
|
-
} else if (types.length === 2) {
|
|
753
|
-
msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
754
|
-
} else {
|
|
755
|
-
msg += `of type ${types[0]}.`;
|
|
756
|
-
}
|
|
757
|
-
if (actual == null) {
|
|
758
|
-
msg += ` Received ${actual}`;
|
|
759
|
-
} else if (typeof actual === "function" && actual.name) {
|
|
760
|
-
msg += ` Received function ${actual.name}`;
|
|
761
|
-
} else if (typeof actual === "object" && actual != null) {
|
|
762
|
-
if (actual.constructor?.name) {
|
|
763
|
-
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
return msg;
|
|
767
|
-
}
|
|
768
|
-
var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
769
|
-
var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
770
|
-
|
|
771
|
-
// node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
772
|
-
var isCryptoKey = (key) => {
|
|
773
|
-
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
774
|
-
return true;
|
|
775
|
-
try {
|
|
776
|
-
return key instanceof CryptoKey;
|
|
777
|
-
} catch {
|
|
778
|
-
return false;
|
|
779
|
-
}
|
|
780
|
-
};
|
|
781
|
-
var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
782
|
-
var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
783
|
-
|
|
784
|
-
// node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
785
|
-
function isDisjoint(...headers) {
|
|
786
|
-
const sources = headers.filter(Boolean);
|
|
787
|
-
if (sources.length === 0 || sources.length === 1) {
|
|
788
|
-
return true;
|
|
789
|
-
}
|
|
790
|
-
let acc;
|
|
791
|
-
for (const header of sources) {
|
|
792
|
-
const parameters = Object.keys(header);
|
|
793
|
-
if (!acc || acc.size === 0) {
|
|
794
|
-
acc = new Set(parameters);
|
|
795
|
-
continue;
|
|
796
|
-
}
|
|
797
|
-
for (const parameter of parameters) {
|
|
798
|
-
if (acc.has(parameter)) {
|
|
799
|
-
return false;
|
|
800
|
-
}
|
|
801
|
-
acc.add(parameter);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
return true;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
// node_modules/jose/dist/webapi/lib/is_object.js
|
|
808
|
-
var isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
809
|
-
function isObject(input) {
|
|
810
|
-
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
811
|
-
return false;
|
|
812
|
-
}
|
|
813
|
-
if (Object.getPrototypeOf(input) === null) {
|
|
814
|
-
return true;
|
|
815
|
-
}
|
|
816
|
-
let proto = input;
|
|
817
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
818
|
-
proto = Object.getPrototypeOf(proto);
|
|
819
|
-
}
|
|
820
|
-
return Object.getPrototypeOf(input) === proto;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
// node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
824
|
-
function checkKeyLength(alg, key) {
|
|
825
|
-
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
826
|
-
const { modulusLength } = key.algorithm;
|
|
827
|
-
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
828
|
-
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
// node_modules/jose/dist/webapi/lib/asn1.js
|
|
834
|
-
var bytesEqual = (a, b) => {
|
|
835
|
-
if (a.byteLength !== b.length)
|
|
836
|
-
return false;
|
|
837
|
-
for (let i = 0; i < a.byteLength; i++) {
|
|
838
|
-
if (a[i] !== b[i])
|
|
839
|
-
return false;
|
|
840
|
-
}
|
|
841
|
-
return true;
|
|
842
|
-
};
|
|
843
|
-
var createASN1State = (data) => ({ data, pos: 0 });
|
|
844
|
-
var parseLength = (state) => {
|
|
845
|
-
const first = state.data[state.pos++];
|
|
846
|
-
if (first & 128) {
|
|
847
|
-
const lengthOfLen = first & 127;
|
|
848
|
-
let length = 0;
|
|
849
|
-
for (let i = 0; i < lengthOfLen; i++) {
|
|
850
|
-
length = length << 8 | state.data[state.pos++];
|
|
851
|
-
}
|
|
852
|
-
return length;
|
|
853
|
-
}
|
|
854
|
-
return first;
|
|
855
|
-
};
|
|
856
|
-
var expectTag = (state, expectedTag, errorMessage) => {
|
|
857
|
-
if (state.data[state.pos++] !== expectedTag) {
|
|
858
|
-
throw new Error(errorMessage);
|
|
859
|
-
}
|
|
860
|
-
};
|
|
861
|
-
var getSubarray = (state, length) => {
|
|
862
|
-
const result = state.data.subarray(state.pos, state.pos + length);
|
|
863
|
-
state.pos += length;
|
|
864
|
-
return result;
|
|
865
|
-
};
|
|
866
|
-
var parseAlgorithmOID = (state) => {
|
|
867
|
-
expectTag(state, 6, "Expected algorithm OID");
|
|
868
|
-
const oidLen = parseLength(state);
|
|
869
|
-
return getSubarray(state, oidLen);
|
|
870
|
-
};
|
|
871
|
-
function parsePKCS8Header(state) {
|
|
872
|
-
expectTag(state, 48, "Invalid PKCS#8 structure");
|
|
873
|
-
parseLength(state);
|
|
874
|
-
expectTag(state, 2, "Expected version field");
|
|
875
|
-
const verLen = parseLength(state);
|
|
876
|
-
state.pos += verLen;
|
|
877
|
-
expectTag(state, 48, "Expected algorithm identifier");
|
|
878
|
-
const algIdLen = parseLength(state);
|
|
879
|
-
const algIdStart = state.pos;
|
|
880
|
-
return { algIdStart, algIdLength: algIdLen };
|
|
881
|
-
}
|
|
882
|
-
var parseECAlgorithmIdentifier = (state) => {
|
|
883
|
-
const algOid = parseAlgorithmOID(state);
|
|
884
|
-
if (bytesEqual(algOid, [43, 101, 110])) {
|
|
885
|
-
return "X25519";
|
|
886
|
-
}
|
|
887
|
-
if (!bytesEqual(algOid, [42, 134, 72, 206, 61, 2, 1])) {
|
|
888
|
-
throw new Error("Unsupported key algorithm");
|
|
889
|
-
}
|
|
890
|
-
expectTag(state, 6, "Expected curve OID");
|
|
891
|
-
const curveOidLen = parseLength(state);
|
|
892
|
-
const curveOid = getSubarray(state, curveOidLen);
|
|
893
|
-
for (const { name, oid } of [
|
|
894
|
-
{ name: "P-256", oid: [42, 134, 72, 206, 61, 3, 1, 7] },
|
|
895
|
-
{ name: "P-384", oid: [43, 129, 4, 0, 34] },
|
|
896
|
-
{ name: "P-521", oid: [43, 129, 4, 0, 35] }
|
|
897
|
-
]) {
|
|
898
|
-
if (bytesEqual(curveOid, oid)) {
|
|
899
|
-
return name;
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
throw new Error("Unsupported named curve");
|
|
903
|
-
};
|
|
904
|
-
var genericImport = async (keyFormat, keyData, alg, options) => {
|
|
905
|
-
let algorithm;
|
|
906
|
-
let keyUsages;
|
|
907
|
-
const isPublic = keyFormat === "spki";
|
|
908
|
-
const getSigUsages = () => isPublic ? ["verify"] : ["sign"];
|
|
909
|
-
const getEncUsages = () => isPublic ? ["encrypt", "wrapKey"] : ["decrypt", "unwrapKey"];
|
|
910
|
-
switch (alg) {
|
|
911
|
-
case "PS256":
|
|
912
|
-
case "PS384":
|
|
913
|
-
case "PS512":
|
|
914
|
-
algorithm = { name: "RSA-PSS", hash: `SHA-${alg.slice(-3)}` };
|
|
915
|
-
keyUsages = getSigUsages();
|
|
916
|
-
break;
|
|
917
|
-
case "RS256":
|
|
918
|
-
case "RS384":
|
|
919
|
-
case "RS512":
|
|
920
|
-
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${alg.slice(-3)}` };
|
|
921
|
-
keyUsages = getSigUsages();
|
|
922
|
-
break;
|
|
923
|
-
case "RSA-OAEP":
|
|
924
|
-
case "RSA-OAEP-256":
|
|
925
|
-
case "RSA-OAEP-384":
|
|
926
|
-
case "RSA-OAEP-512":
|
|
927
|
-
algorithm = {
|
|
928
|
-
name: "RSA-OAEP",
|
|
929
|
-
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`
|
|
930
|
-
};
|
|
931
|
-
keyUsages = getEncUsages();
|
|
932
|
-
break;
|
|
933
|
-
case "ES256":
|
|
934
|
-
case "ES384":
|
|
935
|
-
case "ES512": {
|
|
936
|
-
const curveMap = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
|
|
937
|
-
algorithm = { name: "ECDSA", namedCurve: curveMap[alg] };
|
|
938
|
-
keyUsages = getSigUsages();
|
|
939
|
-
break;
|
|
940
|
-
}
|
|
941
|
-
case "ECDH-ES":
|
|
942
|
-
case "ECDH-ES+A128KW":
|
|
943
|
-
case "ECDH-ES+A192KW":
|
|
944
|
-
case "ECDH-ES+A256KW": {
|
|
945
|
-
try {
|
|
946
|
-
const namedCurve = options.getNamedCurve(keyData);
|
|
947
|
-
algorithm = namedCurve === "X25519" ? { name: "X25519" } : { name: "ECDH", namedCurve };
|
|
948
|
-
} catch (cause) {
|
|
949
|
-
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
950
|
-
}
|
|
951
|
-
keyUsages = isPublic ? [] : ["deriveBits"];
|
|
952
|
-
break;
|
|
953
|
-
}
|
|
954
|
-
case "Ed25519":
|
|
955
|
-
case "EdDSA":
|
|
956
|
-
algorithm = { name: "Ed25519" };
|
|
957
|
-
keyUsages = getSigUsages();
|
|
958
|
-
break;
|
|
959
|
-
case "ML-DSA-44":
|
|
960
|
-
case "ML-DSA-65":
|
|
961
|
-
case "ML-DSA-87":
|
|
962
|
-
algorithm = { name: alg };
|
|
963
|
-
keyUsages = getSigUsages();
|
|
964
|
-
break;
|
|
965
|
-
default:
|
|
966
|
-
throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
|
|
967
|
-
}
|
|
968
|
-
return crypto.subtle.importKey(keyFormat, keyData, algorithm, options?.extractable ?? (isPublic ? true : false), keyUsages);
|
|
969
|
-
};
|
|
970
|
-
var processPEMData = (pem, pattern) => {
|
|
971
|
-
return decodeBase64(pem.replace(pattern, ""));
|
|
972
|
-
};
|
|
973
|
-
var fromPKCS8 = (pem, alg, options) => {
|
|
974
|
-
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
|
|
975
|
-
let opts = options;
|
|
976
|
-
if (alg?.startsWith?.("ECDH-ES")) {
|
|
977
|
-
opts ||= {};
|
|
978
|
-
opts.getNamedCurve = (keyData2) => {
|
|
979
|
-
const state = createASN1State(keyData2);
|
|
980
|
-
parsePKCS8Header(state);
|
|
981
|
-
return parseECAlgorithmIdentifier(state);
|
|
982
|
-
};
|
|
983
|
-
}
|
|
984
|
-
return genericImport("pkcs8", keyData, alg, opts);
|
|
985
|
-
};
|
|
986
|
-
|
|
987
|
-
// node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
988
|
-
function subtleMapping(jwk) {
|
|
989
|
-
let algorithm;
|
|
990
|
-
let keyUsages;
|
|
991
|
-
switch (jwk.kty) {
|
|
992
|
-
case "AKP": {
|
|
993
|
-
switch (jwk.alg) {
|
|
994
|
-
case "ML-DSA-44":
|
|
995
|
-
case "ML-DSA-65":
|
|
996
|
-
case "ML-DSA-87":
|
|
997
|
-
algorithm = { name: jwk.alg };
|
|
998
|
-
keyUsages = jwk.priv ? ["sign"] : ["verify"];
|
|
999
|
-
break;
|
|
1000
|
-
default:
|
|
1001
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1002
|
-
}
|
|
1003
|
-
break;
|
|
1004
|
-
}
|
|
1005
|
-
case "RSA": {
|
|
1006
|
-
switch (jwk.alg) {
|
|
1007
|
-
case "PS256":
|
|
1008
|
-
case "PS384":
|
|
1009
|
-
case "PS512":
|
|
1010
|
-
algorithm = { name: "RSA-PSS", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
1011
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1012
|
-
break;
|
|
1013
|
-
case "RS256":
|
|
1014
|
-
case "RS384":
|
|
1015
|
-
case "RS512":
|
|
1016
|
-
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
1017
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1018
|
-
break;
|
|
1019
|
-
case "RSA-OAEP":
|
|
1020
|
-
case "RSA-OAEP-256":
|
|
1021
|
-
case "RSA-OAEP-384":
|
|
1022
|
-
case "RSA-OAEP-512":
|
|
1023
|
-
algorithm = {
|
|
1024
|
-
name: "RSA-OAEP",
|
|
1025
|
-
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
1026
|
-
};
|
|
1027
|
-
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
1028
|
-
break;
|
|
1029
|
-
default:
|
|
1030
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1031
|
-
}
|
|
1032
|
-
break;
|
|
1033
|
-
}
|
|
1034
|
-
case "EC": {
|
|
1035
|
-
switch (jwk.alg) {
|
|
1036
|
-
case "ES256":
|
|
1037
|
-
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
1038
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1039
|
-
break;
|
|
1040
|
-
case "ES384":
|
|
1041
|
-
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
1042
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1043
|
-
break;
|
|
1044
|
-
case "ES512":
|
|
1045
|
-
algorithm = { name: "ECDSA", namedCurve: "P-521" };
|
|
1046
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1047
|
-
break;
|
|
1048
|
-
case "ECDH-ES":
|
|
1049
|
-
case "ECDH-ES+A128KW":
|
|
1050
|
-
case "ECDH-ES+A192KW":
|
|
1051
|
-
case "ECDH-ES+A256KW":
|
|
1052
|
-
algorithm = { name: "ECDH", namedCurve: jwk.crv };
|
|
1053
|
-
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
1054
|
-
break;
|
|
1055
|
-
default:
|
|
1056
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1057
|
-
}
|
|
1058
|
-
break;
|
|
1059
|
-
}
|
|
1060
|
-
case "OKP": {
|
|
1061
|
-
switch (jwk.alg) {
|
|
1062
|
-
case "Ed25519":
|
|
1063
|
-
case "EdDSA":
|
|
1064
|
-
algorithm = { name: "Ed25519" };
|
|
1065
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1066
|
-
break;
|
|
1067
|
-
case "ECDH-ES":
|
|
1068
|
-
case "ECDH-ES+A128KW":
|
|
1069
|
-
case "ECDH-ES+A192KW":
|
|
1070
|
-
case "ECDH-ES+A256KW":
|
|
1071
|
-
algorithm = { name: jwk.crv };
|
|
1072
|
-
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
1073
|
-
break;
|
|
1074
|
-
default:
|
|
1075
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1076
|
-
}
|
|
1077
|
-
break;
|
|
1078
|
-
}
|
|
1079
|
-
default:
|
|
1080
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
1081
|
-
}
|
|
1082
|
-
return { algorithm, keyUsages };
|
|
1083
|
-
}
|
|
1084
|
-
async function jwkToKey(jwk) {
|
|
1085
|
-
if (!jwk.alg) {
|
|
1086
|
-
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
1087
|
-
}
|
|
1088
|
-
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
1089
|
-
const keyData = { ...jwk };
|
|
1090
|
-
if (keyData.kty !== "AKP") {
|
|
1091
|
-
delete keyData.alg;
|
|
1092
|
-
}
|
|
1093
|
-
delete keyData.use;
|
|
1094
|
-
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
// node_modules/jose/dist/webapi/key/import.js
|
|
1098
|
-
async function importPKCS8(pkcs8, alg, options) {
|
|
1099
|
-
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
|
|
1100
|
-
throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
|
|
1101
|
-
}
|
|
1102
|
-
return fromPKCS8(pkcs8, alg, options);
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
// node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
1106
|
-
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
1107
|
-
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
1108
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
1109
|
-
}
|
|
1110
|
-
if (!protectedHeader || protectedHeader.crit === void 0) {
|
|
1111
|
-
return /* @__PURE__ */ new Set();
|
|
1112
|
-
}
|
|
1113
|
-
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
|
|
1114
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
1115
|
-
}
|
|
1116
|
-
let recognized;
|
|
1117
|
-
if (recognizedOption !== void 0) {
|
|
1118
|
-
recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
1119
|
-
} else {
|
|
1120
|
-
recognized = recognizedDefault;
|
|
1121
|
-
}
|
|
1122
|
-
for (const parameter of protectedHeader.crit) {
|
|
1123
|
-
if (!recognized.has(parameter)) {
|
|
1124
|
-
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
1125
|
-
}
|
|
1126
|
-
if (joseHeader[parameter] === void 0) {
|
|
1127
|
-
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
1128
|
-
}
|
|
1129
|
-
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
|
|
1130
|
-
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
return new Set(protectedHeader.crit);
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
// node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
1137
|
-
var isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
1138
|
-
var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
1139
|
-
var isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
1140
|
-
var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
1141
|
-
|
|
1142
|
-
// node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
1143
|
-
var cache;
|
|
1144
|
-
var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
1145
|
-
cache ||= /* @__PURE__ */ new WeakMap();
|
|
1146
|
-
let cached = cache.get(key);
|
|
1147
|
-
if (cached?.[alg]) {
|
|
1148
|
-
return cached[alg];
|
|
1149
|
-
}
|
|
1150
|
-
const cryptoKey = await jwkToKey({ ...jwk, alg });
|
|
1151
|
-
if (freeze)
|
|
1152
|
-
Object.freeze(key);
|
|
1153
|
-
if (!cached) {
|
|
1154
|
-
cache.set(key, { [alg]: cryptoKey });
|
|
1155
|
-
} else {
|
|
1156
|
-
cached[alg] = cryptoKey;
|
|
1157
|
-
}
|
|
1158
|
-
return cryptoKey;
|
|
1159
|
-
};
|
|
1160
|
-
var handleKeyObject = (keyObject, alg) => {
|
|
1161
|
-
cache ||= /* @__PURE__ */ new WeakMap();
|
|
1162
|
-
let cached = cache.get(keyObject);
|
|
1163
|
-
if (cached?.[alg]) {
|
|
1164
|
-
return cached[alg];
|
|
1165
|
-
}
|
|
1166
|
-
const isPublic = keyObject.type === "public";
|
|
1167
|
-
const extractable = isPublic ? true : false;
|
|
1168
|
-
let cryptoKey;
|
|
1169
|
-
if (keyObject.asymmetricKeyType === "x25519") {
|
|
1170
|
-
switch (alg) {
|
|
1171
|
-
case "ECDH-ES":
|
|
1172
|
-
case "ECDH-ES+A128KW":
|
|
1173
|
-
case "ECDH-ES+A192KW":
|
|
1174
|
-
case "ECDH-ES+A256KW":
|
|
1175
|
-
break;
|
|
1176
|
-
default:
|
|
1177
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1178
|
-
}
|
|
1179
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1180
|
-
}
|
|
1181
|
-
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
1182
|
-
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
1183
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1184
|
-
}
|
|
1185
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
1186
|
-
isPublic ? "verify" : "sign"
|
|
1187
|
-
]);
|
|
1188
|
-
}
|
|
1189
|
-
switch (keyObject.asymmetricKeyType) {
|
|
1190
|
-
case "ml-dsa-44":
|
|
1191
|
-
case "ml-dsa-65":
|
|
1192
|
-
case "ml-dsa-87": {
|
|
1193
|
-
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
|
|
1194
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1195
|
-
}
|
|
1196
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
1197
|
-
isPublic ? "verify" : "sign"
|
|
1198
|
-
]);
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
if (keyObject.asymmetricKeyType === "rsa") {
|
|
1202
|
-
let hash;
|
|
1203
|
-
switch (alg) {
|
|
1204
|
-
case "RSA-OAEP":
|
|
1205
|
-
hash = "SHA-1";
|
|
1206
|
-
break;
|
|
1207
|
-
case "RS256":
|
|
1208
|
-
case "PS256":
|
|
1209
|
-
case "RSA-OAEP-256":
|
|
1210
|
-
hash = "SHA-256";
|
|
1211
|
-
break;
|
|
1212
|
-
case "RS384":
|
|
1213
|
-
case "PS384":
|
|
1214
|
-
case "RSA-OAEP-384":
|
|
1215
|
-
hash = "SHA-384";
|
|
1216
|
-
break;
|
|
1217
|
-
case "RS512":
|
|
1218
|
-
case "PS512":
|
|
1219
|
-
case "RSA-OAEP-512":
|
|
1220
|
-
hash = "SHA-512";
|
|
1221
|
-
break;
|
|
1222
|
-
default:
|
|
1223
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1224
|
-
}
|
|
1225
|
-
if (alg.startsWith("RSA-OAEP")) {
|
|
1226
|
-
return keyObject.toCryptoKey({
|
|
1227
|
-
name: "RSA-OAEP",
|
|
1228
|
-
hash
|
|
1229
|
-
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
1230
|
-
}
|
|
1231
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1232
|
-
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
1233
|
-
hash
|
|
1234
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1235
|
-
}
|
|
1236
|
-
if (keyObject.asymmetricKeyType === "ec") {
|
|
1237
|
-
const nist = /* @__PURE__ */ new Map([
|
|
1238
|
-
["prime256v1", "P-256"],
|
|
1239
|
-
["secp384r1", "P-384"],
|
|
1240
|
-
["secp521r1", "P-521"]
|
|
1241
|
-
]);
|
|
1242
|
-
const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
1243
|
-
if (!namedCurve) {
|
|
1244
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1245
|
-
}
|
|
1246
|
-
if (alg === "ES256" && namedCurve === "P-256") {
|
|
1247
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1248
|
-
name: "ECDSA",
|
|
1249
|
-
namedCurve
|
|
1250
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1251
|
-
}
|
|
1252
|
-
if (alg === "ES384" && namedCurve === "P-384") {
|
|
1253
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1254
|
-
name: "ECDSA",
|
|
1255
|
-
namedCurve
|
|
1256
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1257
|
-
}
|
|
1258
|
-
if (alg === "ES512" && namedCurve === "P-521") {
|
|
1259
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1260
|
-
name: "ECDSA",
|
|
1261
|
-
namedCurve
|
|
1262
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1263
|
-
}
|
|
1264
|
-
if (alg.startsWith("ECDH-ES")) {
|
|
1265
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1266
|
-
name: "ECDH",
|
|
1267
|
-
namedCurve
|
|
1268
|
-
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
if (!cryptoKey) {
|
|
1272
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1273
|
-
}
|
|
1274
|
-
if (!cached) {
|
|
1275
|
-
cache.set(keyObject, { [alg]: cryptoKey });
|
|
1276
|
-
} else {
|
|
1277
|
-
cached[alg] = cryptoKey;
|
|
1278
|
-
}
|
|
1279
|
-
return cryptoKey;
|
|
1280
|
-
};
|
|
1281
|
-
async function normalizeKey(key, alg) {
|
|
1282
|
-
if (key instanceof Uint8Array) {
|
|
1283
|
-
return key;
|
|
1284
|
-
}
|
|
1285
|
-
if (isCryptoKey(key)) {
|
|
1286
|
-
return key;
|
|
1287
|
-
}
|
|
1288
|
-
if (isKeyObject(key)) {
|
|
1289
|
-
if (key.type === "secret") {
|
|
1290
|
-
return key.export();
|
|
1291
|
-
}
|
|
1292
|
-
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") {
|
|
1293
|
-
try {
|
|
1294
|
-
return handleKeyObject(key, alg);
|
|
1295
|
-
} catch (err) {
|
|
1296
|
-
if (err instanceof TypeError) {
|
|
1297
|
-
throw err;
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
let jwk = key.export({ format: "jwk" });
|
|
1302
|
-
return handleJWK(key, jwk, alg);
|
|
1303
|
-
}
|
|
1304
|
-
if (isJWK(key)) {
|
|
1305
|
-
if (key.k) {
|
|
1306
|
-
return decode(key.k);
|
|
1307
|
-
}
|
|
1308
|
-
return handleJWK(key, key, alg, true);
|
|
1309
|
-
}
|
|
1310
|
-
throw new Error("unreachable");
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
// node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
1314
|
-
var tag = (key) => key?.[Symbol.toStringTag];
|
|
1315
|
-
var jwkMatchesOp = (alg, key, usage) => {
|
|
1316
|
-
if (key.use !== void 0) {
|
|
1317
|
-
let expected;
|
|
1318
|
-
switch (usage) {
|
|
1319
|
-
case "sign":
|
|
1320
|
-
case "verify":
|
|
1321
|
-
expected = "sig";
|
|
1322
|
-
break;
|
|
1323
|
-
case "encrypt":
|
|
1324
|
-
case "decrypt":
|
|
1325
|
-
expected = "enc";
|
|
1326
|
-
break;
|
|
1327
|
-
}
|
|
1328
|
-
if (key.use !== expected) {
|
|
1329
|
-
throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
if (key.alg !== void 0 && key.alg !== alg) {
|
|
1333
|
-
throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
1334
|
-
}
|
|
1335
|
-
if (Array.isArray(key.key_ops)) {
|
|
1336
|
-
let expectedKeyOp;
|
|
1337
|
-
switch (true) {
|
|
1338
|
-
case (usage === "sign" || usage === "verify"):
|
|
1339
|
-
case alg === "dir":
|
|
1340
|
-
case alg.includes("CBC-HS"):
|
|
1341
|
-
expectedKeyOp = usage;
|
|
1342
|
-
break;
|
|
1343
|
-
case alg.startsWith("PBES2"):
|
|
1344
|
-
expectedKeyOp = "deriveBits";
|
|
1345
|
-
break;
|
|
1346
|
-
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
1347
|
-
if (!alg.includes("GCM") && alg.endsWith("KW")) {
|
|
1348
|
-
expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
1349
|
-
} else {
|
|
1350
|
-
expectedKeyOp = usage;
|
|
1351
|
-
}
|
|
1352
|
-
break;
|
|
1353
|
-
case (usage === "encrypt" && alg.startsWith("RSA")):
|
|
1354
|
-
expectedKeyOp = "wrapKey";
|
|
1355
|
-
break;
|
|
1356
|
-
case usage === "decrypt":
|
|
1357
|
-
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
1358
|
-
break;
|
|
1359
|
-
}
|
|
1360
|
-
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) {
|
|
1361
|
-
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
return true;
|
|
1365
|
-
};
|
|
1366
|
-
var symmetricTypeCheck = (alg, key, usage) => {
|
|
1367
|
-
if (key instanceof Uint8Array)
|
|
1368
|
-
return;
|
|
1369
|
-
if (isJWK(key)) {
|
|
1370
|
-
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1371
|
-
return;
|
|
1372
|
-
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`);
|
|
1373
|
-
}
|
|
1374
|
-
if (!isKeyLike(key)) {
|
|
1375
|
-
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
1376
|
-
}
|
|
1377
|
-
if (key.type !== "secret") {
|
|
1378
|
-
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
1379
|
-
}
|
|
1380
|
-
};
|
|
1381
|
-
var asymmetricTypeCheck = (alg, key, usage) => {
|
|
1382
|
-
if (isJWK(key)) {
|
|
1383
|
-
switch (usage) {
|
|
1384
|
-
case "decrypt":
|
|
1385
|
-
case "sign":
|
|
1386
|
-
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1387
|
-
return;
|
|
1388
|
-
throw new TypeError(`JSON Web Key for this operation be a private JWK`);
|
|
1389
|
-
case "encrypt":
|
|
1390
|
-
case "verify":
|
|
1391
|
-
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1392
|
-
return;
|
|
1393
|
-
throw new TypeError(`JSON Web Key for this operation be a public JWK`);
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
if (!isKeyLike(key)) {
|
|
1397
|
-
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
1398
|
-
}
|
|
1399
|
-
if (key.type === "secret") {
|
|
1400
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
1401
|
-
}
|
|
1402
|
-
if (key.type === "public") {
|
|
1403
|
-
switch (usage) {
|
|
1404
|
-
case "sign":
|
|
1405
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
1406
|
-
case "decrypt":
|
|
1407
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
if (key.type === "private") {
|
|
1411
|
-
switch (usage) {
|
|
1412
|
-
case "verify":
|
|
1413
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
1414
|
-
case "encrypt":
|
|
1415
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
};
|
|
1419
|
-
function checkKeyType(alg, key, usage) {
|
|
1420
|
-
switch (alg.substring(0, 2)) {
|
|
1421
|
-
case "A1":
|
|
1422
|
-
case "A2":
|
|
1423
|
-
case "di":
|
|
1424
|
-
case "HS":
|
|
1425
|
-
case "PB":
|
|
1426
|
-
symmetricTypeCheck(alg, key, usage);
|
|
1427
|
-
break;
|
|
1428
|
-
default:
|
|
1429
|
-
asymmetricTypeCheck(alg, key, usage);
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
// node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
1434
|
-
function subtleAlgorithm(alg, algorithm) {
|
|
1435
|
-
const hash = `SHA-${alg.slice(-3)}`;
|
|
1436
|
-
switch (alg) {
|
|
1437
|
-
case "HS256":
|
|
1438
|
-
case "HS384":
|
|
1439
|
-
case "HS512":
|
|
1440
|
-
return { hash, name: "HMAC" };
|
|
1441
|
-
case "PS256":
|
|
1442
|
-
case "PS384":
|
|
1443
|
-
case "PS512":
|
|
1444
|
-
return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
|
|
1445
|
-
case "RS256":
|
|
1446
|
-
case "RS384":
|
|
1447
|
-
case "RS512":
|
|
1448
|
-
return { hash, name: "RSASSA-PKCS1-v1_5" };
|
|
1449
|
-
case "ES256":
|
|
1450
|
-
case "ES384":
|
|
1451
|
-
case "ES512":
|
|
1452
|
-
return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
|
|
1453
|
-
case "Ed25519":
|
|
1454
|
-
case "EdDSA":
|
|
1455
|
-
return { name: "Ed25519" };
|
|
1456
|
-
case "ML-DSA-44":
|
|
1457
|
-
case "ML-DSA-65":
|
|
1458
|
-
case "ML-DSA-87":
|
|
1459
|
-
return { name: alg };
|
|
1460
|
-
default:
|
|
1461
|
-
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
// node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
1466
|
-
async function getSigKey(alg, key, usage) {
|
|
1467
|
-
if (key instanceof Uint8Array) {
|
|
1468
|
-
if (!alg.startsWith("HS")) {
|
|
1469
|
-
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
1470
|
-
}
|
|
1471
|
-
return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
|
|
1472
|
-
}
|
|
1473
|
-
checkSigCryptoKey(key, alg, usage);
|
|
1474
|
-
return key;
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
// node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
1478
|
-
var epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
1479
|
-
var minute = 60;
|
|
1480
|
-
var hour = minute * 60;
|
|
1481
|
-
var day = hour * 24;
|
|
1482
|
-
var week = day * 7;
|
|
1483
|
-
var year = day * 365.25;
|
|
1484
|
-
var REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
1485
|
-
function secs(str) {
|
|
1486
|
-
const matched = REGEX.exec(str);
|
|
1487
|
-
if (!matched || matched[4] && matched[1]) {
|
|
1488
|
-
throw new TypeError("Invalid time period format");
|
|
1489
|
-
}
|
|
1490
|
-
const value = parseFloat(matched[2]);
|
|
1491
|
-
const unit = matched[3].toLowerCase();
|
|
1492
|
-
let numericDate;
|
|
1493
|
-
switch (unit) {
|
|
1494
|
-
case "sec":
|
|
1495
|
-
case "secs":
|
|
1496
|
-
case "second":
|
|
1497
|
-
case "seconds":
|
|
1498
|
-
case "s":
|
|
1499
|
-
numericDate = Math.round(value);
|
|
1500
|
-
break;
|
|
1501
|
-
case "minute":
|
|
1502
|
-
case "minutes":
|
|
1503
|
-
case "min":
|
|
1504
|
-
case "mins":
|
|
1505
|
-
case "m":
|
|
1506
|
-
numericDate = Math.round(value * minute);
|
|
1507
|
-
break;
|
|
1508
|
-
case "hour":
|
|
1509
|
-
case "hours":
|
|
1510
|
-
case "hr":
|
|
1511
|
-
case "hrs":
|
|
1512
|
-
case "h":
|
|
1513
|
-
numericDate = Math.round(value * hour);
|
|
1514
|
-
break;
|
|
1515
|
-
case "day":
|
|
1516
|
-
case "days":
|
|
1517
|
-
case "d":
|
|
1518
|
-
numericDate = Math.round(value * day);
|
|
1519
|
-
break;
|
|
1520
|
-
case "week":
|
|
1521
|
-
case "weeks":
|
|
1522
|
-
case "w":
|
|
1523
|
-
numericDate = Math.round(value * week);
|
|
1524
|
-
break;
|
|
1525
|
-
default:
|
|
1526
|
-
numericDate = Math.round(value * year);
|
|
1527
|
-
break;
|
|
1528
|
-
}
|
|
1529
|
-
if (matched[1] === "-" || matched[4] === "ago") {
|
|
1530
|
-
return -numericDate;
|
|
1531
|
-
}
|
|
1532
|
-
return numericDate;
|
|
1533
|
-
}
|
|
1534
|
-
function validateInput(label, input) {
|
|
1535
|
-
if (!Number.isFinite(input)) {
|
|
1536
|
-
throw new TypeError(`Invalid ${label} input`);
|
|
1537
|
-
}
|
|
1538
|
-
return input;
|
|
1539
|
-
}
|
|
1540
|
-
var JWTClaimsBuilder = class {
|
|
1541
|
-
#payload;
|
|
1542
|
-
constructor(payload) {
|
|
1543
|
-
if (!isObject(payload)) {
|
|
1544
|
-
throw new TypeError("JWT Claims Set MUST be an object");
|
|
1545
|
-
}
|
|
1546
|
-
this.#payload = structuredClone(payload);
|
|
1547
|
-
}
|
|
1548
|
-
data() {
|
|
1549
|
-
return encoder.encode(JSON.stringify(this.#payload));
|
|
1550
|
-
}
|
|
1551
|
-
get iss() {
|
|
1552
|
-
return this.#payload.iss;
|
|
1553
|
-
}
|
|
1554
|
-
set iss(value) {
|
|
1555
|
-
this.#payload.iss = value;
|
|
1556
|
-
}
|
|
1557
|
-
get sub() {
|
|
1558
|
-
return this.#payload.sub;
|
|
1559
|
-
}
|
|
1560
|
-
set sub(value) {
|
|
1561
|
-
this.#payload.sub = value;
|
|
1562
|
-
}
|
|
1563
|
-
get aud() {
|
|
1564
|
-
return this.#payload.aud;
|
|
1565
|
-
}
|
|
1566
|
-
set aud(value) {
|
|
1567
|
-
this.#payload.aud = value;
|
|
1568
|
-
}
|
|
1569
|
-
set jti(value) {
|
|
1570
|
-
this.#payload.jti = value;
|
|
1571
|
-
}
|
|
1572
|
-
set nbf(value) {
|
|
1573
|
-
if (typeof value === "number") {
|
|
1574
|
-
this.#payload.nbf = validateInput("setNotBefore", value);
|
|
1575
|
-
} else if (value instanceof Date) {
|
|
1576
|
-
this.#payload.nbf = validateInput("setNotBefore", epoch(value));
|
|
1577
|
-
} else {
|
|
1578
|
-
this.#payload.nbf = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
set exp(value) {
|
|
1582
|
-
if (typeof value === "number") {
|
|
1583
|
-
this.#payload.exp = validateInput("setExpirationTime", value);
|
|
1584
|
-
} else if (value instanceof Date) {
|
|
1585
|
-
this.#payload.exp = validateInput("setExpirationTime", epoch(value));
|
|
1586
|
-
} else {
|
|
1587
|
-
this.#payload.exp = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
set iat(value) {
|
|
1591
|
-
if (value === void 0) {
|
|
1592
|
-
this.#payload.iat = epoch(/* @__PURE__ */ new Date());
|
|
1593
|
-
} else if (value instanceof Date) {
|
|
1594
|
-
this.#payload.iat = validateInput("setIssuedAt", epoch(value));
|
|
1595
|
-
} else if (typeof value === "string") {
|
|
1596
|
-
this.#payload.iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value));
|
|
1597
|
-
} else {
|
|
1598
|
-
this.#payload.iat = validateInput("setIssuedAt", value);
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
};
|
|
1602
|
-
|
|
1603
|
-
// node_modules/jose/dist/webapi/lib/sign.js
|
|
1604
|
-
async function sign(alg, key, data) {
|
|
1605
|
-
const cryptoKey = await getSigKey(alg, key, "sign");
|
|
1606
|
-
checkKeyLength(alg, cryptoKey);
|
|
1607
|
-
const signature = await crypto.subtle.sign(subtleAlgorithm(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
1608
|
-
return new Uint8Array(signature);
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
// node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
1612
|
-
var FlattenedSign = class {
|
|
1613
|
-
#payload;
|
|
1614
|
-
#protectedHeader;
|
|
1615
|
-
#unprotectedHeader;
|
|
1616
|
-
constructor(payload) {
|
|
1617
|
-
if (!(payload instanceof Uint8Array)) {
|
|
1618
|
-
throw new TypeError("payload must be an instance of Uint8Array");
|
|
1619
|
-
}
|
|
1620
|
-
this.#payload = payload;
|
|
1621
|
-
}
|
|
1622
|
-
setProtectedHeader(protectedHeader) {
|
|
1623
|
-
if (this.#protectedHeader) {
|
|
1624
|
-
throw new TypeError("setProtectedHeader can only be called once");
|
|
1625
|
-
}
|
|
1626
|
-
this.#protectedHeader = protectedHeader;
|
|
1627
|
-
return this;
|
|
1628
|
-
}
|
|
1629
|
-
setUnprotectedHeader(unprotectedHeader) {
|
|
1630
|
-
if (this.#unprotectedHeader) {
|
|
1631
|
-
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
1632
|
-
}
|
|
1633
|
-
this.#unprotectedHeader = unprotectedHeader;
|
|
1634
|
-
return this;
|
|
1635
|
-
}
|
|
1636
|
-
async sign(key, options) {
|
|
1637
|
-
if (!this.#protectedHeader && !this.#unprotectedHeader) {
|
|
1638
|
-
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
1639
|
-
}
|
|
1640
|
-
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader)) {
|
|
1641
|
-
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
1642
|
-
}
|
|
1643
|
-
const joseHeader = {
|
|
1644
|
-
...this.#protectedHeader,
|
|
1645
|
-
...this.#unprotectedHeader
|
|
1646
|
-
};
|
|
1647
|
-
const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, this.#protectedHeader, joseHeader);
|
|
1648
|
-
let b64 = true;
|
|
1649
|
-
if (extensions.has("b64")) {
|
|
1650
|
-
b64 = this.#protectedHeader.b64;
|
|
1651
|
-
if (typeof b64 !== "boolean") {
|
|
1652
|
-
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
const { alg } = joseHeader;
|
|
1656
|
-
if (typeof alg !== "string" || !alg) {
|
|
1657
|
-
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
1658
|
-
}
|
|
1659
|
-
checkKeyType(alg, key, "sign");
|
|
1660
|
-
let payloadS;
|
|
1661
|
-
let payloadB;
|
|
1662
|
-
if (b64) {
|
|
1663
|
-
payloadS = encode2(this.#payload);
|
|
1664
|
-
payloadB = encode(payloadS);
|
|
1665
|
-
} else {
|
|
1666
|
-
payloadB = this.#payload;
|
|
1667
|
-
payloadS = "";
|
|
1668
|
-
}
|
|
1669
|
-
let protectedHeaderString;
|
|
1670
|
-
let protectedHeaderBytes;
|
|
1671
|
-
if (this.#protectedHeader) {
|
|
1672
|
-
protectedHeaderString = encode2(JSON.stringify(this.#protectedHeader));
|
|
1673
|
-
protectedHeaderBytes = encode(protectedHeaderString);
|
|
1674
|
-
} else {
|
|
1675
|
-
protectedHeaderString = "";
|
|
1676
|
-
protectedHeaderBytes = new Uint8Array();
|
|
1677
|
-
}
|
|
1678
|
-
const data = concat(protectedHeaderBytes, encode("."), payloadB);
|
|
1679
|
-
const k = await normalizeKey(key, alg);
|
|
1680
|
-
const signature = await sign(alg, k, data);
|
|
1681
|
-
const jws = {
|
|
1682
|
-
signature: encode2(signature),
|
|
1683
|
-
payload: payloadS
|
|
1684
|
-
};
|
|
1685
|
-
if (this.#unprotectedHeader) {
|
|
1686
|
-
jws.header = this.#unprotectedHeader;
|
|
1687
|
-
}
|
|
1688
|
-
if (this.#protectedHeader) {
|
|
1689
|
-
jws.protected = protectedHeaderString;
|
|
1690
|
-
}
|
|
1691
|
-
return jws;
|
|
1692
|
-
}
|
|
1693
|
-
};
|
|
1694
|
-
|
|
1695
|
-
// node_modules/jose/dist/webapi/jws/compact/sign.js
|
|
1696
|
-
var CompactSign = class {
|
|
1697
|
-
#flattened;
|
|
1698
|
-
constructor(payload) {
|
|
1699
|
-
this.#flattened = new FlattenedSign(payload);
|
|
1700
|
-
}
|
|
1701
|
-
setProtectedHeader(protectedHeader) {
|
|
1702
|
-
this.#flattened.setProtectedHeader(protectedHeader);
|
|
1703
|
-
return this;
|
|
1704
|
-
}
|
|
1705
|
-
async sign(key, options) {
|
|
1706
|
-
const jws = await this.#flattened.sign(key, options);
|
|
1707
|
-
if (jws.payload === void 0) {
|
|
1708
|
-
throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
1709
|
-
}
|
|
1710
|
-
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
|
1711
|
-
}
|
|
1712
|
-
};
|
|
1713
|
-
|
|
1714
|
-
// node_modules/jose/dist/webapi/jwt/sign.js
|
|
1715
|
-
var SignJWT = class {
|
|
1716
|
-
#protectedHeader;
|
|
1717
|
-
#jwt;
|
|
1718
|
-
constructor(payload = {}) {
|
|
1719
|
-
this.#jwt = new JWTClaimsBuilder(payload);
|
|
1720
|
-
}
|
|
1721
|
-
setIssuer(issuer) {
|
|
1722
|
-
this.#jwt.iss = issuer;
|
|
1723
|
-
return this;
|
|
1724
|
-
}
|
|
1725
|
-
setSubject(subject) {
|
|
1726
|
-
this.#jwt.sub = subject;
|
|
1727
|
-
return this;
|
|
1728
|
-
}
|
|
1729
|
-
setAudience(audience) {
|
|
1730
|
-
this.#jwt.aud = audience;
|
|
1731
|
-
return this;
|
|
1732
|
-
}
|
|
1733
|
-
setJti(jwtId) {
|
|
1734
|
-
this.#jwt.jti = jwtId;
|
|
1735
|
-
return this;
|
|
1736
|
-
}
|
|
1737
|
-
setNotBefore(input) {
|
|
1738
|
-
this.#jwt.nbf = input;
|
|
1739
|
-
return this;
|
|
1740
|
-
}
|
|
1741
|
-
setExpirationTime(input) {
|
|
1742
|
-
this.#jwt.exp = input;
|
|
1743
|
-
return this;
|
|
1744
|
-
}
|
|
1745
|
-
setIssuedAt(input) {
|
|
1746
|
-
this.#jwt.iat = input;
|
|
1747
|
-
return this;
|
|
1748
|
-
}
|
|
1749
|
-
setProtectedHeader(protectedHeader) {
|
|
1750
|
-
this.#protectedHeader = protectedHeader;
|
|
1751
|
-
return this;
|
|
1752
|
-
}
|
|
1753
|
-
async sign(key, options) {
|
|
1754
|
-
const sig = new CompactSign(this.#jwt.data());
|
|
1755
|
-
sig.setProtectedHeader(this.#protectedHeader);
|
|
1756
|
-
if (Array.isArray(this.#protectedHeader?.crit) && this.#protectedHeader.crit.includes("b64") && this.#protectedHeader.b64 === false) {
|
|
1757
|
-
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
1758
|
-
}
|
|
1759
|
-
return sig.sign(key, options);
|
|
1760
|
-
}
|
|
1761
|
-
};
|
|
1762
|
-
|
|
1763
556
|
// src/core/client.ts
|
|
557
|
+
var import_node_crypto = require("crypto");
|
|
1764
558
|
var ApiClient = class {
|
|
1765
559
|
baseUrl;
|
|
1766
560
|
privateKey;
|
|
@@ -1768,7 +562,6 @@ var ApiClient = class {
|
|
|
1768
562
|
defaultTenantId;
|
|
1769
563
|
additionalHeaders;
|
|
1770
564
|
fetchImpl;
|
|
1771
|
-
cachedPrivateKey;
|
|
1772
565
|
constructor(baseUrl, privateKey, organizationId, options) {
|
|
1773
566
|
if (!baseUrl) {
|
|
1774
567
|
throw new Error("Base URL is required");
|
|
@@ -1797,14 +590,26 @@ var ApiClient = class {
|
|
|
1797
590
|
async get(path, tenantId, userId, scopes, signal, sessionId) {
|
|
1798
591
|
return await this.request(path, {
|
|
1799
592
|
method: "GET",
|
|
1800
|
-
headers: await this.buildHeaders(
|
|
593
|
+
headers: await this.buildHeaders(
|
|
594
|
+
tenantId,
|
|
595
|
+
userId,
|
|
596
|
+
scopes,
|
|
597
|
+
false,
|
|
598
|
+
sessionId
|
|
599
|
+
),
|
|
1801
600
|
signal
|
|
1802
601
|
});
|
|
1803
602
|
}
|
|
1804
603
|
async post(path, body, tenantId, userId, scopes, signal, sessionId) {
|
|
1805
604
|
return await this.request(path, {
|
|
1806
605
|
method: "POST",
|
|
1807
|
-
headers: await this.buildHeaders(
|
|
606
|
+
headers: await this.buildHeaders(
|
|
607
|
+
tenantId,
|
|
608
|
+
userId,
|
|
609
|
+
scopes,
|
|
610
|
+
true,
|
|
611
|
+
sessionId
|
|
612
|
+
),
|
|
1808
613
|
body: JSON.stringify(body ?? {}),
|
|
1809
614
|
signal
|
|
1810
615
|
});
|
|
@@ -1812,7 +617,13 @@ var ApiClient = class {
|
|
|
1812
617
|
async put(path, body, tenantId, userId, scopes, signal, sessionId) {
|
|
1813
618
|
return await this.request(path, {
|
|
1814
619
|
method: "PUT",
|
|
1815
|
-
headers: await this.buildHeaders(
|
|
620
|
+
headers: await this.buildHeaders(
|
|
621
|
+
tenantId,
|
|
622
|
+
userId,
|
|
623
|
+
scopes,
|
|
624
|
+
true,
|
|
625
|
+
sessionId
|
|
626
|
+
),
|
|
1816
627
|
body: JSON.stringify(body ?? {}),
|
|
1817
628
|
signal
|
|
1818
629
|
});
|
|
@@ -1820,7 +631,13 @@ var ApiClient = class {
|
|
|
1820
631
|
async delete(path, tenantId, userId, scopes, signal, sessionId) {
|
|
1821
632
|
return await this.request(path, {
|
|
1822
633
|
method: "DELETE",
|
|
1823
|
-
headers: await this.buildHeaders(
|
|
634
|
+
headers: await this.buildHeaders(
|
|
635
|
+
tenantId,
|
|
636
|
+
userId,
|
|
637
|
+
scopes,
|
|
638
|
+
false,
|
|
639
|
+
sessionId
|
|
640
|
+
),
|
|
1824
641
|
signal
|
|
1825
642
|
});
|
|
1826
643
|
}
|
|
@@ -1861,16 +678,30 @@ var ApiClient = class {
|
|
|
1861
678
|
return headers;
|
|
1862
679
|
}
|
|
1863
680
|
async generateJWT(tenantId, userId, scopes) {
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
681
|
+
const header = {
|
|
682
|
+
alg: "RS256",
|
|
683
|
+
typ: "JWT"
|
|
684
|
+
};
|
|
1867
685
|
const payload = {
|
|
1868
686
|
organizationId: this.organizationId,
|
|
1869
687
|
tenantId
|
|
1870
688
|
};
|
|
1871
689
|
if (userId) payload.userId = userId;
|
|
1872
690
|
if (scopes?.length) payload.scopes = scopes;
|
|
1873
|
-
|
|
691
|
+
const encodeJson = (obj) => {
|
|
692
|
+
const json = JSON.stringify(obj);
|
|
693
|
+
const base64 = Buffer.from(json).toString("base64");
|
|
694
|
+
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
695
|
+
};
|
|
696
|
+
const encodedHeader = encodeJson(header);
|
|
697
|
+
const encodedPayload = encodeJson(payload);
|
|
698
|
+
const data = `${encodedHeader}.${encodedPayload}`;
|
|
699
|
+
const signer = (0, import_node_crypto.createSign)("RSA-SHA256");
|
|
700
|
+
signer.update(data);
|
|
701
|
+
signer.end();
|
|
702
|
+
const signature = signer.sign(this.privateKey);
|
|
703
|
+
const encodedSignature = signature.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
704
|
+
return `${data}.${encodedSignature}`;
|
|
1874
705
|
}
|
|
1875
706
|
};
|
|
1876
707
|
|
|
@@ -2183,7 +1014,7 @@ function resolveTenantId2(client, tenantId) {
|
|
|
2183
1014
|
}
|
|
2184
1015
|
|
|
2185
1016
|
// src/routes/ingest.ts
|
|
2186
|
-
var
|
|
1017
|
+
var import_node_crypto2 = require("crypto");
|
|
2187
1018
|
async function syncSchema(client, queryEngine, databaseName, options, signal) {
|
|
2188
1019
|
const tenantId = resolveTenantId3(client, options.tenantId);
|
|
2189
1020
|
const adapter = queryEngine.getDatabase(databaseName);
|
|
@@ -2191,7 +1022,7 @@ async function syncSchema(client, queryEngine, databaseName, options, signal) {
|
|
|
2191
1022
|
options.tables ? { tables: options.tables } : void 0
|
|
2192
1023
|
);
|
|
2193
1024
|
const payload = buildSchemaRequest(databaseName, adapter, introspection);
|
|
2194
|
-
const sessionId = (0,
|
|
1025
|
+
const sessionId = (0, import_node_crypto2.randomUUID)();
|
|
2195
1026
|
const response = await client.post(
|
|
2196
1027
|
"/ingest",
|
|
2197
1028
|
payload,
|
|
@@ -2232,10 +1063,10 @@ function buildSchemaRequest(databaseName, adapter, introspection) {
|
|
|
2232
1063
|
}
|
|
2233
1064
|
|
|
2234
1065
|
// src/routes/query.ts
|
|
2235
|
-
var
|
|
1066
|
+
var import_node_crypto3 = require("crypto");
|
|
2236
1067
|
async function ask(client, queryEngine, question, options, signal) {
|
|
2237
1068
|
const tenantId = resolveTenantId4(client, options.tenantId);
|
|
2238
|
-
const sessionId = (0,
|
|
1069
|
+
const sessionId = (0, import_node_crypto3.randomUUID)();
|
|
2239
1070
|
const maxRetry = options.maxRetry ?? 0;
|
|
2240
1071
|
let attempt = 0;
|
|
2241
1072
|
let lastError = options.lastError;
|