jsonauthtoken 3.0.4-beta-4 → 3.0.4
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/node.index.d.mts +6 -7
- package/dist/node.index.d.ts +6 -7
- package/dist/node.index.js +28 -16
- package/dist/node.index.mjs +27 -14
- package/dist/types.d-B-9YA5rY.d.mts +19 -0
- package/dist/types.d-B-9YA5rY.d.ts +19 -0
- package/dist/types.d.ts +21 -3
- package/dist/web.index.d.mts +3 -4
- package/dist/web.index.d.ts +3 -4
- package/dist/web.index.js +5 -8
- package/dist/web.index.mjs +4 -6
- package/package.json +1 -1
- package/types.d.ts +21 -3
- package/dist/types.d-D_Cze-FV.d.mts +0 -32
- package/dist/types.d-D_Cze-FV.d.ts +0 -32
package/dist/node.index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NodeRuntime, J as JsonAuthTokenExpiry, R as RuntimeWiseAlgorithmMap, G as GenerateKeyPair
|
|
1
|
+
import { N as NodeRuntime, J as JsonAuthTokenExpiry, R as RuntimeWiseAlgorithmMap, G as GenerateKeyPair } from './types.d-B-9YA5rY.mjs';
|
|
2
2
|
|
|
3
3
|
declare class NodeCryptoModule<R extends NodeRuntime> {
|
|
4
4
|
private dev;
|
|
@@ -22,14 +22,13 @@ declare const JAT: <R extends NodeRuntime>({ runtime, dev }?: {
|
|
|
22
22
|
runtime?: R;
|
|
23
23
|
dev?: boolean;
|
|
24
24
|
}) => NodeCryptoModule<R>;
|
|
25
|
-
declare const getSupportedAlgorithm: () => AlgorithmDetails[];
|
|
26
25
|
declare const P2KG: {
|
|
27
26
|
generateKeyPair: (options?: {
|
|
28
|
-
runtime?: "web";
|
|
27
|
+
runtime?: "web" | "node";
|
|
29
28
|
dev?: boolean;
|
|
30
29
|
}) => Promise<GenerateKeyPair>;
|
|
31
30
|
generatePublicKey: (privateKeyPem: string, options?: {
|
|
32
|
-
runtime?: "web";
|
|
31
|
+
runtime?: "web" | "node";
|
|
33
32
|
dev?: boolean;
|
|
34
33
|
}) => Promise<string>;
|
|
35
34
|
};
|
|
@@ -40,14 +39,14 @@ declare const jsonauthtoken: {
|
|
|
40
39
|
}) => NodeCryptoModule<R>;
|
|
41
40
|
P2KG: {
|
|
42
41
|
generateKeyPair: (options?: {
|
|
43
|
-
runtime?: "web";
|
|
42
|
+
runtime?: "web" | "node";
|
|
44
43
|
dev?: boolean;
|
|
45
44
|
}) => Promise<GenerateKeyPair>;
|
|
46
45
|
generatePublicKey: (privateKeyPem: string, options?: {
|
|
47
|
-
runtime?: "web";
|
|
46
|
+
runtime?: "web" | "node";
|
|
48
47
|
dev?: boolean;
|
|
49
48
|
}) => Promise<string>;
|
|
50
49
|
};
|
|
51
50
|
};
|
|
52
51
|
|
|
53
|
-
export { JAT, NodeCryptoModule, P2KG, jsonauthtoken as default
|
|
52
|
+
export { JAT, NodeCryptoModule, P2KG, jsonauthtoken as default };
|
package/dist/node.index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as NodeRuntime, J as JsonAuthTokenExpiry, R as RuntimeWiseAlgorithmMap, G as GenerateKeyPair
|
|
1
|
+
import { N as NodeRuntime, J as JsonAuthTokenExpiry, R as RuntimeWiseAlgorithmMap, G as GenerateKeyPair } from './types.d-B-9YA5rY.js';
|
|
2
2
|
|
|
3
3
|
declare class NodeCryptoModule<R extends NodeRuntime> {
|
|
4
4
|
private dev;
|
|
@@ -22,14 +22,13 @@ declare const JAT: <R extends NodeRuntime>({ runtime, dev }?: {
|
|
|
22
22
|
runtime?: R;
|
|
23
23
|
dev?: boolean;
|
|
24
24
|
}) => NodeCryptoModule<R>;
|
|
25
|
-
declare const getSupportedAlgorithm: () => AlgorithmDetails[];
|
|
26
25
|
declare const P2KG: {
|
|
27
26
|
generateKeyPair: (options?: {
|
|
28
|
-
runtime?: "web";
|
|
27
|
+
runtime?: "web" | "node";
|
|
29
28
|
dev?: boolean;
|
|
30
29
|
}) => Promise<GenerateKeyPair>;
|
|
31
30
|
generatePublicKey: (privateKeyPem: string, options?: {
|
|
32
|
-
runtime?: "web";
|
|
31
|
+
runtime?: "web" | "node";
|
|
33
32
|
dev?: boolean;
|
|
34
33
|
}) => Promise<string>;
|
|
35
34
|
};
|
|
@@ -40,14 +39,14 @@ declare const jsonauthtoken: {
|
|
|
40
39
|
}) => NodeCryptoModule<R>;
|
|
41
40
|
P2KG: {
|
|
42
41
|
generateKeyPair: (options?: {
|
|
43
|
-
runtime?: "web";
|
|
42
|
+
runtime?: "web" | "node";
|
|
44
43
|
dev?: boolean;
|
|
45
44
|
}) => Promise<GenerateKeyPair>;
|
|
46
45
|
generatePublicKey: (privateKeyPem: string, options?: {
|
|
47
|
-
runtime?: "web";
|
|
46
|
+
runtime?: "web" | "node";
|
|
48
47
|
dev?: boolean;
|
|
49
48
|
}) => Promise<string>;
|
|
50
49
|
};
|
|
51
50
|
};
|
|
52
51
|
|
|
53
|
-
export { JAT, NodeCryptoModule, P2KG, jsonauthtoken as default
|
|
52
|
+
export { JAT, NodeCryptoModule, P2KG, jsonauthtoken as default };
|
package/dist/node.index.js
CHANGED
|
@@ -32,8 +32,7 @@ __export(node_index_exports, {
|
|
|
32
32
|
JAT: () => JAT,
|
|
33
33
|
NodeCryptoModule: () => NodeCryptoModule,
|
|
34
34
|
P2KG: () => P2KG,
|
|
35
|
-
default: () => node_index_default
|
|
36
|
-
getSupportedAlgorithm: () => getSupportedAlgorithm
|
|
35
|
+
default: () => node_index_default
|
|
37
36
|
});
|
|
38
37
|
module.exports = __toCommonJS(node_index_exports);
|
|
39
38
|
|
|
@@ -492,7 +491,11 @@ var NodeCrypto = class {
|
|
|
492
491
|
type: "pkcs8"
|
|
493
492
|
});
|
|
494
493
|
const publicKeyObject = import_crypto.default.createPublicKey(privateKeyObject);
|
|
495
|
-
|
|
494
|
+
const key = publicKeyObject.export({ type: "spki", format: "pem" });
|
|
495
|
+
if (typeof key !== "string") {
|
|
496
|
+
return key.toString("utf-8");
|
|
497
|
+
}
|
|
498
|
+
return key;
|
|
496
499
|
}
|
|
497
500
|
_rsaPrivatePublicKeyGeneration() {
|
|
498
501
|
const { publicKey, privateKey } = import_crypto.default.generateKeyPairSync("rsa", {
|
|
@@ -708,10 +711,16 @@ var PrivatePublicKeyGeneration = class {
|
|
|
708
711
|
}
|
|
709
712
|
finalRuntime = runtime;
|
|
710
713
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
714
|
+
print({ dev: development, color: "green" }, "Current Runtime for Key Generation: ", finalRuntime);
|
|
715
|
+
if (runtime === "node") {
|
|
716
|
+
const { privateKey, publicKey } = await this.node.rsaPrivatePublicKeyGeneration();
|
|
717
|
+
print({ dev: development, color: "green" }, { privateKey, publicKey });
|
|
718
|
+
return { privateKey, publicKey };
|
|
719
|
+
} else {
|
|
720
|
+
const { privateKey, publicKey } = await this.web.rsaPrivatePublicKeyGeneration();
|
|
721
|
+
print({ dev: development, color: "green" }, { privateKey, publicKey });
|
|
722
|
+
return { privateKey, publicKey };
|
|
723
|
+
}
|
|
715
724
|
} catch (error) {
|
|
716
725
|
print({ dev: development, color: "red" }, error);
|
|
717
726
|
throw error;
|
|
@@ -723,14 +732,20 @@ var PrivatePublicKeyGeneration = class {
|
|
|
723
732
|
try {
|
|
724
733
|
if (runtime) {
|
|
725
734
|
if (!NODE_RUNTIME.includes(runtime)) {
|
|
726
|
-
throw new Error("Unsupported runtime");
|
|
735
|
+
throw new Error("Unsupported runtime (please select runtime 'web' or 'node')");
|
|
727
736
|
}
|
|
728
737
|
finalRuntime = runtime;
|
|
729
738
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
739
|
+
print({ dev: development, color: "green" }, "Current Runtime for Key Generation: ", finalRuntime);
|
|
740
|
+
if (runtime === "node") {
|
|
741
|
+
const publicKey = await this.node.rsaPublicKeyGeneration(privateKeyPem);
|
|
742
|
+
print({ dev: development, color: "green" }, publicKey);
|
|
743
|
+
return publicKey;
|
|
744
|
+
} else {
|
|
745
|
+
const publicKey = await this.web.rsaPublicKeyGeneration(privateKeyPem);
|
|
746
|
+
print({ dev: development, color: "green" }, publicKey);
|
|
747
|
+
return publicKey;
|
|
748
|
+
}
|
|
734
749
|
} catch (error) {
|
|
735
750
|
print({ dev: development, color: "red" }, error);
|
|
736
751
|
throw error;
|
|
@@ -747,8 +762,6 @@ var generatePublicKey = (privateKeyPem, options) => {
|
|
|
747
762
|
return p2kgObject.generatePublicKey(privateKeyPem, runtime, dev);
|
|
748
763
|
};
|
|
749
764
|
var JAT = ({ runtime, dev } = {}) => new NodeCryptoModule({ runtime, dev });
|
|
750
|
-
var getSupportedAlgorithm = () => SUPPORTED_ALGORITHM["web"];
|
|
751
|
-
var jat = JAT({});
|
|
752
765
|
var P2KG = {
|
|
753
766
|
generateKeyPair,
|
|
754
767
|
generatePublicKey
|
|
@@ -762,6 +775,5 @@ var node_index_default = jsonauthtoken;
|
|
|
762
775
|
0 && (module.exports = {
|
|
763
776
|
JAT,
|
|
764
777
|
NodeCryptoModule,
|
|
765
|
-
P2KG
|
|
766
|
-
getSupportedAlgorithm
|
|
778
|
+
P2KG
|
|
767
779
|
});
|
package/dist/node.index.mjs
CHANGED
|
@@ -453,7 +453,11 @@ var NodeCrypto = class {
|
|
|
453
453
|
type: "pkcs8"
|
|
454
454
|
});
|
|
455
455
|
const publicKeyObject = crypto2.createPublicKey(privateKeyObject);
|
|
456
|
-
|
|
456
|
+
const key = publicKeyObject.export({ type: "spki", format: "pem" });
|
|
457
|
+
if (typeof key !== "string") {
|
|
458
|
+
return key.toString("utf-8");
|
|
459
|
+
}
|
|
460
|
+
return key;
|
|
457
461
|
}
|
|
458
462
|
_rsaPrivatePublicKeyGeneration() {
|
|
459
463
|
const { publicKey, privateKey } = crypto2.generateKeyPairSync("rsa", {
|
|
@@ -669,10 +673,16 @@ var PrivatePublicKeyGeneration = class {
|
|
|
669
673
|
}
|
|
670
674
|
finalRuntime = runtime;
|
|
671
675
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
+
print({ dev: development, color: "green" }, "Current Runtime for Key Generation: ", finalRuntime);
|
|
677
|
+
if (runtime === "node") {
|
|
678
|
+
const { privateKey, publicKey } = await this.node.rsaPrivatePublicKeyGeneration();
|
|
679
|
+
print({ dev: development, color: "green" }, { privateKey, publicKey });
|
|
680
|
+
return { privateKey, publicKey };
|
|
681
|
+
} else {
|
|
682
|
+
const { privateKey, publicKey } = await this.web.rsaPrivatePublicKeyGeneration();
|
|
683
|
+
print({ dev: development, color: "green" }, { privateKey, publicKey });
|
|
684
|
+
return { privateKey, publicKey };
|
|
685
|
+
}
|
|
676
686
|
} catch (error) {
|
|
677
687
|
print({ dev: development, color: "red" }, error);
|
|
678
688
|
throw error;
|
|
@@ -684,14 +694,20 @@ var PrivatePublicKeyGeneration = class {
|
|
|
684
694
|
try {
|
|
685
695
|
if (runtime) {
|
|
686
696
|
if (!NODE_RUNTIME.includes(runtime)) {
|
|
687
|
-
throw new Error("Unsupported runtime");
|
|
697
|
+
throw new Error("Unsupported runtime (please select runtime 'web' or 'node')");
|
|
688
698
|
}
|
|
689
699
|
finalRuntime = runtime;
|
|
690
700
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
701
|
+
print({ dev: development, color: "green" }, "Current Runtime for Key Generation: ", finalRuntime);
|
|
702
|
+
if (runtime === "node") {
|
|
703
|
+
const publicKey = await this.node.rsaPublicKeyGeneration(privateKeyPem);
|
|
704
|
+
print({ dev: development, color: "green" }, publicKey);
|
|
705
|
+
return publicKey;
|
|
706
|
+
} else {
|
|
707
|
+
const publicKey = await this.web.rsaPublicKeyGeneration(privateKeyPem);
|
|
708
|
+
print({ dev: development, color: "green" }, publicKey);
|
|
709
|
+
return publicKey;
|
|
710
|
+
}
|
|
695
711
|
} catch (error) {
|
|
696
712
|
print({ dev: development, color: "red" }, error);
|
|
697
713
|
throw error;
|
|
@@ -708,8 +724,6 @@ var generatePublicKey = (privateKeyPem, options) => {
|
|
|
708
724
|
return p2kgObject.generatePublicKey(privateKeyPem, runtime, dev);
|
|
709
725
|
};
|
|
710
726
|
var JAT = ({ runtime, dev } = {}) => new NodeCryptoModule({ runtime, dev });
|
|
711
|
-
var getSupportedAlgorithm = () => SUPPORTED_ALGORITHM["web"];
|
|
712
|
-
var jat = JAT({});
|
|
713
727
|
var P2KG = {
|
|
714
728
|
generateKeyPair,
|
|
715
729
|
generatePublicKey
|
|
@@ -723,6 +737,5 @@ export {
|
|
|
723
737
|
JAT,
|
|
724
738
|
NodeCryptoModule,
|
|
725
739
|
P2KG,
|
|
726
|
-
node_index_default as default
|
|
727
|
-
getSupportedAlgorithm
|
|
740
|
+
node_index_default as default
|
|
728
741
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//timeformat type
|
|
2
|
+
type TimeUnit = 'S' | 'MIN' | 'H' | 'D' | 'M' | 'Y';
|
|
3
|
+
type ExpirationString = `${number}${TimeUnit}` | `${number}${Lowercase<TimeUnit>}`;
|
|
4
|
+
type JsonAuthTokenExpiry = number | ExpirationString;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
interface GenerateKeyPair {
|
|
9
|
+
privateKey: string
|
|
10
|
+
publicKey: string
|
|
11
|
+
}
|
|
12
|
+
type NodeRuntime = 'node' | 'web'
|
|
13
|
+
|
|
14
|
+
interface RuntimeWiseAlgorithmMap {
|
|
15
|
+
node: 'AES-256-GCM' | 'RSA+A256GCM'
|
|
16
|
+
web: 'AES-GCM' | 'RSA+AES-GCM'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type { GenerateKeyPair as G, JsonAuthTokenExpiry as J, NodeRuntime as N, RuntimeWiseAlgorithmMap as R };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//timeformat type
|
|
2
|
+
type TimeUnit = 'S' | 'MIN' | 'H' | 'D' | 'M' | 'Y';
|
|
3
|
+
type ExpirationString = `${number}${TimeUnit}` | `${number}${Lowercase<TimeUnit>}`;
|
|
4
|
+
type JsonAuthTokenExpiry = number | ExpirationString;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
interface GenerateKeyPair {
|
|
9
|
+
privateKey: string
|
|
10
|
+
publicKey: string
|
|
11
|
+
}
|
|
12
|
+
type NodeRuntime = 'node' | 'web'
|
|
13
|
+
|
|
14
|
+
interface RuntimeWiseAlgorithmMap {
|
|
15
|
+
node: 'AES-256-GCM' | 'RSA+A256GCM'
|
|
16
|
+
web: 'AES-GCM' | 'RSA+AES-GCM'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type { GenerateKeyPair as G, JsonAuthTokenExpiry as J, NodeRuntime as N, RuntimeWiseAlgorithmMap as R };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
export declare function JAT<T extends { runtime: 'web' | 'node'; dev?: boolean }>({ runtime, dev }?: T): T extends { runtime: 'node' } ? NodeJATInstance : WebJATInstance;
|
|
3
|
+
|
|
1
4
|
export interface WebJATInstance {
|
|
2
5
|
create: ({ key, exp, algo }: { key: string, exp: JsonAuthTokenExpiry, algo: RuntimeWiseAlgorithmMap['web'] }, payload: any) => Promise<string>
|
|
3
6
|
verify: <T>(token: string, key: string) => Promise<T>
|
|
@@ -8,9 +11,24 @@ export interface NodeJATInstance {
|
|
|
8
11
|
verify: <T>(token: string, key: string) => Promise<T>
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
export declare
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
export declare const P2KG: {
|
|
15
|
+
generateKeyPair: typeof generateKeyPair;
|
|
16
|
+
generatePublicKey: typeof generatePublicKey;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
declare const jsonauthtoken: {
|
|
20
|
+
JAT: typeof JAT;
|
|
21
|
+
P2KG: typeof P2KG;
|
|
22
|
+
};
|
|
23
|
+
export default jsonauthtoken
|
|
24
|
+
|
|
25
|
+
declare function generateKeyPair({ runtime, dev }?: { runtime?: 'web' | 'node'; dev?: boolean }): Promise<GenerateKeyPair>
|
|
26
|
+
declare function generatePublicKey(privateKeyPem: string, { runtime, dev }?: { runtime?: 'web' | 'node'; dev?: boolean }): Promise<string>
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
14
32
|
|
|
15
33
|
|
|
16
34
|
//timeformat type
|
package/dist/web.index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { J as JsonAuthTokenExpiry, R as RuntimeWiseAlgorithmMap, G as GenerateKeyPair } from './types.d-B-9YA5rY.mjs';
|
|
2
2
|
|
|
3
|
-
declare class WebCryptoModule
|
|
3
|
+
declare class WebCryptoModule {
|
|
4
4
|
private dev;
|
|
5
5
|
private runtime;
|
|
6
6
|
private web;
|
|
@@ -21,7 +21,6 @@ declare const JAT: ({ runtime, dev }?: {
|
|
|
21
21
|
runtime?: "web";
|
|
22
22
|
dev?: boolean;
|
|
23
23
|
}) => WebCryptoModule;
|
|
24
|
-
declare const getSupportedAlgorithm: () => AlgorithmDetails[];
|
|
25
24
|
declare const P2KG: {
|
|
26
25
|
generateKeyPair: (options?: {
|
|
27
26
|
runtime?: "web";
|
|
@@ -49,4 +48,4 @@ declare const jsonauthtoken: {
|
|
|
49
48
|
};
|
|
50
49
|
};
|
|
51
50
|
|
|
52
|
-
export { JAT, P2KG, jsonauthtoken as default
|
|
51
|
+
export { JAT, P2KG, jsonauthtoken as default };
|
package/dist/web.index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { J as JsonAuthTokenExpiry, R as RuntimeWiseAlgorithmMap, G as GenerateKeyPair } from './types.d-B-9YA5rY.js';
|
|
2
2
|
|
|
3
|
-
declare class WebCryptoModule
|
|
3
|
+
declare class WebCryptoModule {
|
|
4
4
|
private dev;
|
|
5
5
|
private runtime;
|
|
6
6
|
private web;
|
|
@@ -21,7 +21,6 @@ declare const JAT: ({ runtime, dev }?: {
|
|
|
21
21
|
runtime?: "web";
|
|
22
22
|
dev?: boolean;
|
|
23
23
|
}) => WebCryptoModule;
|
|
24
|
-
declare const getSupportedAlgorithm: () => AlgorithmDetails[];
|
|
25
24
|
declare const P2KG: {
|
|
26
25
|
generateKeyPair: (options?: {
|
|
27
26
|
runtime?: "web";
|
|
@@ -49,4 +48,4 @@ declare const jsonauthtoken: {
|
|
|
49
48
|
};
|
|
50
49
|
};
|
|
51
50
|
|
|
52
|
-
export { JAT, P2KG, jsonauthtoken as default
|
|
51
|
+
export { JAT, P2KG, jsonauthtoken as default };
|
package/dist/web.index.js
CHANGED
|
@@ -21,8 +21,7 @@ var web_index_exports = {};
|
|
|
21
21
|
__export(web_index_exports, {
|
|
22
22
|
JAT: () => JAT,
|
|
23
23
|
P2KG: () => P2KG,
|
|
24
|
-
default: () => web_index_default
|
|
25
|
-
getSupportedAlgorithm: () => getSupportedAlgorithm
|
|
24
|
+
default: () => web_index_default
|
|
26
25
|
});
|
|
27
26
|
module.exports = __toCommonJS(web_index_exports);
|
|
28
27
|
|
|
@@ -451,7 +450,7 @@ var WebCryptoModule = class {
|
|
|
451
450
|
try {
|
|
452
451
|
if (dev) this.dev = true;
|
|
453
452
|
if (runtime && !WEB_RUNTIME.includes(runtime)) {
|
|
454
|
-
throw new Error("Unsupported runtime");
|
|
453
|
+
throw new Error("Unsupported runtime (please select runtime 'web')");
|
|
455
454
|
}
|
|
456
455
|
this.runtime = "web";
|
|
457
456
|
print({ dev: this.dev }, "Current Runtime: ", this.runtime);
|
|
@@ -543,7 +542,7 @@ var PrivatePublicKeyGeneration = class {
|
|
|
543
542
|
finalRuntime = runtime;
|
|
544
543
|
}
|
|
545
544
|
const { privateKey, publicKey } = await this.web.rsaPrivatePublicKeyGeneration();
|
|
546
|
-
print({ dev: development, color: "green" }, "Current Runtime: ", finalRuntime);
|
|
545
|
+
print({ dev: development, color: "green" }, "Current Runtime for Key Generation: ", finalRuntime);
|
|
547
546
|
print({ dev: development, color: "green" }, { privateKey, publicKey });
|
|
548
547
|
return { privateKey, publicKey };
|
|
549
548
|
} catch (error) {
|
|
@@ -562,7 +561,7 @@ var PrivatePublicKeyGeneration = class {
|
|
|
562
561
|
finalRuntime = runtime;
|
|
563
562
|
}
|
|
564
563
|
const publicKey = await this.web.rsaPublicKeyGeneration(privateKeyPem);
|
|
565
|
-
print({ dev: development, color: "green" }, "Current Runtime: ", finalRuntime);
|
|
564
|
+
print({ dev: development, color: "green" }, "Current Runtime for Key Generation: ", finalRuntime);
|
|
566
565
|
print({ dev: development, color: "green" }, publicKey);
|
|
567
566
|
return publicKey;
|
|
568
567
|
} catch (error) {
|
|
@@ -581,7 +580,6 @@ var generatePublicKey = (privateKeyPem, options) => {
|
|
|
581
580
|
return p2kgObject.generatePublicKey(privateKeyPem, runtime, dev);
|
|
582
581
|
};
|
|
583
582
|
var JAT = ({ runtime, dev } = {}) => new WebCryptoModule({ runtime, dev });
|
|
584
|
-
var getSupportedAlgorithm = () => SUPPORTED_ALGORITHM["web"];
|
|
585
583
|
var P2KG = {
|
|
586
584
|
generateKeyPair,
|
|
587
585
|
generatePublicKey
|
|
@@ -594,6 +592,5 @@ var web_index_default = jsonauthtoken;
|
|
|
594
592
|
// Annotate the CommonJS export names for ESM import in node:
|
|
595
593
|
0 && (module.exports = {
|
|
596
594
|
JAT,
|
|
597
|
-
P2KG
|
|
598
|
-
getSupportedAlgorithm
|
|
595
|
+
P2KG
|
|
599
596
|
});
|
package/dist/web.index.mjs
CHANGED
|
@@ -423,7 +423,7 @@ var WebCryptoModule = class {
|
|
|
423
423
|
try {
|
|
424
424
|
if (dev) this.dev = true;
|
|
425
425
|
if (runtime && !WEB_RUNTIME.includes(runtime)) {
|
|
426
|
-
throw new Error("Unsupported runtime");
|
|
426
|
+
throw new Error("Unsupported runtime (please select runtime 'web')");
|
|
427
427
|
}
|
|
428
428
|
this.runtime = "web";
|
|
429
429
|
print({ dev: this.dev }, "Current Runtime: ", this.runtime);
|
|
@@ -515,7 +515,7 @@ var PrivatePublicKeyGeneration = class {
|
|
|
515
515
|
finalRuntime = runtime;
|
|
516
516
|
}
|
|
517
517
|
const { privateKey, publicKey } = await this.web.rsaPrivatePublicKeyGeneration();
|
|
518
|
-
print({ dev: development, color: "green" }, "Current Runtime: ", finalRuntime);
|
|
518
|
+
print({ dev: development, color: "green" }, "Current Runtime for Key Generation: ", finalRuntime);
|
|
519
519
|
print({ dev: development, color: "green" }, { privateKey, publicKey });
|
|
520
520
|
return { privateKey, publicKey };
|
|
521
521
|
} catch (error) {
|
|
@@ -534,7 +534,7 @@ var PrivatePublicKeyGeneration = class {
|
|
|
534
534
|
finalRuntime = runtime;
|
|
535
535
|
}
|
|
536
536
|
const publicKey = await this.web.rsaPublicKeyGeneration(privateKeyPem);
|
|
537
|
-
print({ dev: development, color: "green" }, "Current Runtime: ", finalRuntime);
|
|
537
|
+
print({ dev: development, color: "green" }, "Current Runtime for Key Generation: ", finalRuntime);
|
|
538
538
|
print({ dev: development, color: "green" }, publicKey);
|
|
539
539
|
return publicKey;
|
|
540
540
|
} catch (error) {
|
|
@@ -553,7 +553,6 @@ var generatePublicKey = (privateKeyPem, options) => {
|
|
|
553
553
|
return p2kgObject.generatePublicKey(privateKeyPem, runtime, dev);
|
|
554
554
|
};
|
|
555
555
|
var JAT = ({ runtime, dev } = {}) => new WebCryptoModule({ runtime, dev });
|
|
556
|
-
var getSupportedAlgorithm = () => SUPPORTED_ALGORITHM["web"];
|
|
557
556
|
var P2KG = {
|
|
558
557
|
generateKeyPair,
|
|
559
558
|
generatePublicKey
|
|
@@ -566,6 +565,5 @@ var web_index_default = jsonauthtoken;
|
|
|
566
565
|
export {
|
|
567
566
|
JAT,
|
|
568
567
|
P2KG,
|
|
569
|
-
web_index_default as default
|
|
570
|
-
getSupportedAlgorithm
|
|
568
|
+
web_index_default as default
|
|
571
569
|
};
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
export declare function JAT<T extends { runtime: 'web' | 'node'; dev?: boolean }>({ runtime, dev }?: T): T extends { runtime: 'node' } ? NodeJATInstance : WebJATInstance;
|
|
3
|
+
|
|
1
4
|
export interface WebJATInstance {
|
|
2
5
|
create: ({ key, exp, algo }: { key: string, exp: JsonAuthTokenExpiry, algo: RuntimeWiseAlgorithmMap['web'] }, payload: any) => Promise<string>
|
|
3
6
|
verify: <T>(token: string, key: string) => Promise<T>
|
|
@@ -8,9 +11,24 @@ export interface NodeJATInstance {
|
|
|
8
11
|
verify: <T>(token: string, key: string) => Promise<T>
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
export declare
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
export declare const P2KG: {
|
|
15
|
+
generateKeyPair: typeof generateKeyPair;
|
|
16
|
+
generatePublicKey: typeof generatePublicKey;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
declare const jsonauthtoken: {
|
|
20
|
+
JAT: typeof JAT;
|
|
21
|
+
P2KG: typeof P2KG;
|
|
22
|
+
};
|
|
23
|
+
export default jsonauthtoken
|
|
24
|
+
|
|
25
|
+
declare function generateKeyPair({ runtime, dev }?: { runtime?: 'web' | 'node'; dev?: boolean }): Promise<GenerateKeyPair>
|
|
26
|
+
declare function generatePublicKey(privateKeyPem: string, { runtime, dev }?: { runtime?: 'web' | 'node'; dev?: boolean }): Promise<string>
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
14
32
|
|
|
15
33
|
|
|
16
34
|
//timeformat type
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
interface WebJATInstance {
|
|
2
|
-
create: ({ key, exp, algo }: { key: string, exp: JsonAuthTokenExpiry, algo: RuntimeWiseAlgorithmMap['web'] }, payload: any) => Promise<string>
|
|
3
|
-
verify: <T>(token: string, key: string) => Promise<T>
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//timeformat type
|
|
8
|
-
type TimeUnit = 'S' | 'MIN' | 'H' | 'D' | 'M' | 'Y';
|
|
9
|
-
type ExpirationString = `${number}${TimeUnit}` | `${number}${Lowercase<TimeUnit>}`;
|
|
10
|
-
type JsonAuthTokenExpiry = number | ExpirationString;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
interface GenerateKeyPair {
|
|
15
|
-
privateKey: string
|
|
16
|
-
publicKey: string
|
|
17
|
-
}
|
|
18
|
-
type EncryptionAlgorithmType = 'symmetric' | 'asymmetric';
|
|
19
|
-
type NodeRuntime = 'node' | 'web'
|
|
20
|
-
|
|
21
|
-
interface AlgorithmDetails {
|
|
22
|
-
name: string;
|
|
23
|
-
value: string
|
|
24
|
-
type: EncryptionAlgorithmType;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface RuntimeWiseAlgorithmMap {
|
|
28
|
-
node: 'AES-256-GCM' | 'RSA+A256GCM'
|
|
29
|
-
web: 'AES-GCM' | 'RSA+AES-GCM'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type { AlgorithmDetails as A, GenerateKeyPair as G, JsonAuthTokenExpiry as J, NodeRuntime as N, RuntimeWiseAlgorithmMap as R, WebJATInstance as W };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
interface WebJATInstance {
|
|
2
|
-
create: ({ key, exp, algo }: { key: string, exp: JsonAuthTokenExpiry, algo: RuntimeWiseAlgorithmMap['web'] }, payload: any) => Promise<string>
|
|
3
|
-
verify: <T>(token: string, key: string) => Promise<T>
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//timeformat type
|
|
8
|
-
type TimeUnit = 'S' | 'MIN' | 'H' | 'D' | 'M' | 'Y';
|
|
9
|
-
type ExpirationString = `${number}${TimeUnit}` | `${number}${Lowercase<TimeUnit>}`;
|
|
10
|
-
type JsonAuthTokenExpiry = number | ExpirationString;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
interface GenerateKeyPair {
|
|
15
|
-
privateKey: string
|
|
16
|
-
publicKey: string
|
|
17
|
-
}
|
|
18
|
-
type EncryptionAlgorithmType = 'symmetric' | 'asymmetric';
|
|
19
|
-
type NodeRuntime = 'node' | 'web'
|
|
20
|
-
|
|
21
|
-
interface AlgorithmDetails {
|
|
22
|
-
name: string;
|
|
23
|
-
value: string
|
|
24
|
-
type: EncryptionAlgorithmType;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface RuntimeWiseAlgorithmMap {
|
|
28
|
-
node: 'AES-256-GCM' | 'RSA+A256GCM'
|
|
29
|
-
web: 'AES-GCM' | 'RSA+AES-GCM'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type { AlgorithmDetails as A, GenerateKeyPair as G, JsonAuthTokenExpiry as J, NodeRuntime as N, RuntimeWiseAlgorithmMap as R, WebJATInstance as W };
|