@twin.org/web 0.0.1-next.9 → 0.0.2-next.3
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/cjs/index.cjs +298 -94
- package/dist/esm/index.mjs +299 -96
- package/dist/types/index.d.ts +3 -1
- package/dist/types/models/IJwk.d.ts +2 -58
- package/dist/types/models/IJwtHeader.d.ts +2 -18
- package/dist/types/models/IJwtPayload.d.ts +2 -33
- package/dist/types/models/jwkCryptoKey.d.ts +4 -0
- package/dist/types/models/mimeTypes.d.ts +8 -0
- package/dist/types/utils/fetchHelper.d.ts +7 -0
- package/dist/types/utils/jwk.d.ts +41 -0
- package/dist/types/utils/jws.d.ts +22 -0
- package/dist/types/utils/jwt.d.ts +67 -29
- package/docs/changelog.md +480 -1
- package/docs/reference/classes/FetchError.md +16 -8
- package/docs/reference/classes/FetchHelper.md +104 -28
- package/docs/reference/classes/Jwk.md +129 -0
- package/docs/reference/classes/Jws.md +81 -0
- package/docs/reference/classes/Jwt.md +261 -105
- package/docs/reference/classes/MimeTypeHelper.md +9 -5
- package/docs/reference/index.md +3 -2
- package/docs/reference/interfaces/IHttpHeaders.md +1 -1
- package/docs/reference/interfaces/IJwk.md +2 -106
- package/docs/reference/interfaces/IJwtHeader.md +5 -23
- package/docs/reference/interfaces/IJwtPayload.md +5 -55
- package/docs/reference/type-aliases/HeaderTypes.md +1 -1
- package/docs/reference/type-aliases/HttpMethod.md +1 -1
- package/docs/reference/type-aliases/HttpStatusCode.md +1 -1
- package/docs/reference/type-aliases/JwkCryptoKey.md +5 -0
- package/docs/reference/type-aliases/MimeTypes.md +1 -1
- package/docs/reference/variables/MimeTypes.md +12 -0
- package/locales/en.json +11 -1
- package/package.json +7 -6
- package/dist/types/models/jwtAlgorithms.d.ts +0 -17
- package/docs/reference/type-aliases/JwtAlgorithms.md +0 -5
- package/docs/reference/variables/JwtAlgorithms.md +0 -19
|
@@ -1,37 +1,6 @@
|
|
|
1
|
+
import type { JWTPayload } from "jose";
|
|
1
2
|
/**
|
|
2
3
|
* The fields in a JSON Web Token payload.
|
|
3
4
|
*/
|
|
4
|
-
export interface IJwtPayload {
|
|
5
|
-
/**
|
|
6
|
-
* Additional fields in the payload.
|
|
7
|
-
*/
|
|
8
|
-
[key: string]: unknown;
|
|
9
|
-
/**
|
|
10
|
-
* The issuer of the token.
|
|
11
|
-
*/
|
|
12
|
-
iss?: string;
|
|
13
|
-
/**
|
|
14
|
-
* The subject of the token.
|
|
15
|
-
*/
|
|
16
|
-
sub?: string;
|
|
17
|
-
/**
|
|
18
|
-
* The audience of the token.
|
|
19
|
-
*/
|
|
20
|
-
aud?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The expiration time of the token.
|
|
23
|
-
*/
|
|
24
|
-
exp?: number;
|
|
25
|
-
/**
|
|
26
|
-
* The not before time of the token.
|
|
27
|
-
*/
|
|
28
|
-
nbf?: number;
|
|
29
|
-
/**
|
|
30
|
-
* The issued at time of the token.
|
|
31
|
-
*/
|
|
32
|
-
iat?: number;
|
|
33
|
-
/**
|
|
34
|
-
* The JWT ID.
|
|
35
|
-
*/
|
|
36
|
-
jti?: string;
|
|
5
|
+
export interface IJwtPayload extends JWTPayload {
|
|
37
6
|
}
|
|
@@ -22,6 +22,10 @@ export declare const MimeTypes: {
|
|
|
22
22
|
* JSON-LD - application/ld+json
|
|
23
23
|
*/
|
|
24
24
|
readonly JsonLd: "application/ld+json";
|
|
25
|
+
/**
|
|
26
|
+
* JWT - application/jwt
|
|
27
|
+
*/
|
|
28
|
+
readonly Jwt: "application/jwt";
|
|
25
29
|
/**
|
|
26
30
|
* XML - application/xml
|
|
27
31
|
*/
|
|
@@ -34,6 +38,10 @@ export declare const MimeTypes: {
|
|
|
34
38
|
* Application GZIP - application/gzip
|
|
35
39
|
*/
|
|
36
40
|
readonly Gzip: "application/gzip";
|
|
41
|
+
/**
|
|
42
|
+
* Application deflate - application/zlib
|
|
43
|
+
*/
|
|
44
|
+
readonly Zlib: "application/zlib";
|
|
37
45
|
/**
|
|
38
46
|
* Application BZIP2 - application/x-bzip2
|
|
39
47
|
*/
|
|
@@ -44,6 +44,13 @@ export declare class FetchHelper {
|
|
|
44
44
|
* @returns The cache entry if it exists.
|
|
45
45
|
*/
|
|
46
46
|
static getCacheEntry<T>(url: string): Promise<T | undefined>;
|
|
47
|
+
/**
|
|
48
|
+
* Set a cache entry.
|
|
49
|
+
* @param url The url for the request.
|
|
50
|
+
* @param value The value to cache.
|
|
51
|
+
* @returns The cache entry if it exists.
|
|
52
|
+
*/
|
|
53
|
+
static setCacheEntry<T>(url: string, value: T): Promise<void>;
|
|
47
54
|
/**
|
|
48
55
|
* Remove a cache entry.
|
|
49
56
|
* @param url The url for the request.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { IJwk } from "../models/IJwk";
|
|
2
|
+
import type { JwkCryptoKey } from "../models/jwkCryptoKey";
|
|
3
|
+
/**
|
|
4
|
+
* Class to handle JSON Web Keys.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Jwk {
|
|
7
|
+
/**
|
|
8
|
+
* Convert the JWK to a crypto key.
|
|
9
|
+
* @param jwk The JWK to convert.
|
|
10
|
+
* @param alg The alg to be used, defaults to jwk.alg.
|
|
11
|
+
* @returns The crypto key.
|
|
12
|
+
*/
|
|
13
|
+
static toCryptoKey(jwk: IJwk, alg?: string): Promise<JwkCryptoKey>;
|
|
14
|
+
/**
|
|
15
|
+
* Convert the Ed25519 private key to a crypto key.
|
|
16
|
+
* @param privateKey The private key to use.
|
|
17
|
+
* @returns The crypto key.
|
|
18
|
+
*/
|
|
19
|
+
static fromEd25519Private(privateKey: Uint8Array): Promise<IJwk>;
|
|
20
|
+
/**
|
|
21
|
+
* Convert the Ed25519 public key to a crypto key.
|
|
22
|
+
* @param publicKey The private key to use.
|
|
23
|
+
* @returns The crypto key.
|
|
24
|
+
*/
|
|
25
|
+
static fromEd25519Public(publicKey: Uint8Array): Promise<IJwk>;
|
|
26
|
+
/**
|
|
27
|
+
* Convert the JWK to raw keys.
|
|
28
|
+
* @param jwk The JWK to convert to raw.
|
|
29
|
+
* @returns The crypto key.
|
|
30
|
+
*/
|
|
31
|
+
static toRaw(jwk: IJwk): Promise<{
|
|
32
|
+
publicKey?: Uint8Array;
|
|
33
|
+
privateKey?: Uint8Array;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Generate a KID for the JWK.
|
|
37
|
+
* @param jwk The JWK to generate a KID for.
|
|
38
|
+
* @returns The KID.
|
|
39
|
+
*/
|
|
40
|
+
static generateKid(jwk: IJwk): Promise<string>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { JwkCryptoKey } from "../models/jwkCryptoKey";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle JSON Web Signatures.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Jws {
|
|
6
|
+
/**
|
|
7
|
+
* Create a signature.
|
|
8
|
+
* @param privateKey The private key to use.
|
|
9
|
+
* @param hash The hash to sign.
|
|
10
|
+
* @param algOverride An optional algorithm override.
|
|
11
|
+
* @returns The signature.
|
|
12
|
+
*/
|
|
13
|
+
static create(privateKey: JwkCryptoKey, hash: Uint8Array, algOverride?: string): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Verify a signature.
|
|
16
|
+
* @param jws The signature to verify.
|
|
17
|
+
* @param publicKey The public key to verify the signature with.
|
|
18
|
+
* @param hash The hash to verify.
|
|
19
|
+
* @returns True if the signature was verified.
|
|
20
|
+
*/
|
|
21
|
+
static verify(jws: string, publicKey: JwkCryptoKey, hash: Uint8Array): Promise<boolean>;
|
|
22
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { IJwtHeader } from "../models/IJwtHeader";
|
|
2
2
|
import type { IJwtPayload } from "../models/IJwtPayload";
|
|
3
|
-
import {
|
|
3
|
+
import type { JwkCryptoKey } from "../models/jwkCryptoKey";
|
|
4
4
|
/**
|
|
5
|
-
* Class to
|
|
5
|
+
* Class to handle JSON Web Tokens.
|
|
6
6
|
*/
|
|
7
7
|
export declare class Jwt {
|
|
8
8
|
/**
|
|
@@ -12,7 +12,7 @@ export declare class Jwt {
|
|
|
12
12
|
* @param key The key for signing the token, can be omitted if a signer is provided.
|
|
13
13
|
* @returns The encoded token.
|
|
14
14
|
*/
|
|
15
|
-
static encode<
|
|
15
|
+
static encode<T extends IJwtHeader, U extends IJwtPayload>(header: T, payload: U, key: JwkCryptoKey): Promise<string>;
|
|
16
16
|
/**
|
|
17
17
|
* Encode a token.
|
|
18
18
|
* @param header The header to encode.
|
|
@@ -20,15 +20,15 @@ export declare class Jwt {
|
|
|
20
20
|
* @param signer Custom signer method.
|
|
21
21
|
* @returns The encoded token.
|
|
22
22
|
*/
|
|
23
|
-
static encodeWithSigner<
|
|
23
|
+
static encodeWithSigner<T extends IJwtHeader, U extends IJwtPayload>(header: T, payload: U, signer: (header: IJwtHeader, payload: IJwtPayload, key: JwkCryptoKey | undefined) => Promise<string>): Promise<string>;
|
|
24
24
|
/**
|
|
25
25
|
* Decode a token.
|
|
26
26
|
* @param token The token to decode.
|
|
27
27
|
* @returns The decoded payload.
|
|
28
28
|
*/
|
|
29
|
-
static decode<
|
|
30
|
-
header?:
|
|
31
|
-
payload?:
|
|
29
|
+
static decode<T extends IJwtHeader, U extends IJwtPayload>(token: string): Promise<{
|
|
30
|
+
header?: T;
|
|
31
|
+
payload?: U;
|
|
32
32
|
signature?: Uint8Array;
|
|
33
33
|
}>;
|
|
34
34
|
/**
|
|
@@ -37,11 +37,9 @@ export declare class Jwt {
|
|
|
37
37
|
* @param key The key for verifying the token
|
|
38
38
|
* @returns The decoded payload.
|
|
39
39
|
*/
|
|
40
|
-
static verify<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
payload?: T;
|
|
44
|
-
signature?: Uint8Array;
|
|
40
|
+
static verify<T extends IJwtHeader, U extends IJwtPayload>(token: string, key: JwkCryptoKey): Promise<{
|
|
41
|
+
header: T;
|
|
42
|
+
payload: U;
|
|
45
43
|
}>;
|
|
46
44
|
/**
|
|
47
45
|
* Verify a token.
|
|
@@ -49,37 +47,77 @@ export declare class Jwt {
|
|
|
49
47
|
* @param verifier Custom verification method.
|
|
50
48
|
* @returns The decoded payload.
|
|
51
49
|
*/
|
|
52
|
-
static verifyWithVerifier<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
static verifyWithVerifier<T extends IJwtHeader, U extends IJwtPayload>(token: string, verifier: (token: string, key: JwkCryptoKey | undefined) => Promise<{
|
|
51
|
+
header: T;
|
|
52
|
+
payload: U;
|
|
53
|
+
}>): Promise<{
|
|
54
|
+
header: T;
|
|
55
|
+
payload: U;
|
|
57
56
|
}>;
|
|
58
57
|
/**
|
|
59
58
|
* Verify a token by parts.
|
|
60
|
-
* @param
|
|
61
|
-
* @param payload The payload to verify.
|
|
62
|
-
* @param signature The signature to verify.
|
|
59
|
+
* @param token The token to verify.
|
|
63
60
|
* @param key The key for verifying the token, if not provided no verification occurs.
|
|
64
61
|
* @param verifier Custom verification method.
|
|
65
62
|
* @returns True if the parts are verified.
|
|
66
63
|
*/
|
|
67
|
-
static verifySignature<
|
|
64
|
+
static verifySignature<T extends IJwtHeader, U extends IJwtPayload>(token: string, key?: JwkCryptoKey, verifier?: (token: string, key: JwkCryptoKey | undefined) => Promise<{
|
|
65
|
+
header: T;
|
|
66
|
+
payload: U;
|
|
67
|
+
}>): Promise<{
|
|
68
|
+
header: T;
|
|
69
|
+
payload: U;
|
|
70
|
+
}>;
|
|
68
71
|
/**
|
|
69
72
|
* The default signer for the JWT.
|
|
70
|
-
* @param
|
|
71
|
-
* @param key The key to sign with.
|
|
73
|
+
* @param header The header to sign.
|
|
72
74
|
* @param payload The payload to sign.
|
|
75
|
+
* @param key The optional key to sign with.
|
|
73
76
|
* @returns The signature.
|
|
74
77
|
*/
|
|
75
|
-
static defaultSigner(
|
|
78
|
+
static defaultSigner(header: IJwtHeader, payload: IJwtPayload, key: JwkCryptoKey | undefined): Promise<string>;
|
|
76
79
|
/**
|
|
77
80
|
* The default verifier for the JWT.
|
|
78
|
-
* @param
|
|
81
|
+
* @param token The token to verify.
|
|
79
82
|
* @param key The key to verify with.
|
|
80
|
-
* @
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
* @returns The header and payload if verification successful.
|
|
84
|
+
*/
|
|
85
|
+
static defaultVerifier<T extends IJwtHeader, U extends IJwtPayload>(token: string, key: JwkCryptoKey | undefined): Promise<{
|
|
86
|
+
header: T;
|
|
87
|
+
payload: U;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Create bytes for signing from header and payload.
|
|
91
|
+
* @param header The header.
|
|
92
|
+
* @param payload The payload.
|
|
93
|
+
* @returns The bytes to sign.
|
|
94
|
+
*/
|
|
95
|
+
static toSigningBytes<T extends IJwtHeader, U extends IJwtPayload>(header: T, payload: U): Uint8Array;
|
|
96
|
+
/**
|
|
97
|
+
* Create header and payload from signing bytes.
|
|
98
|
+
* @param signingBytes The signing bytes from a token.
|
|
99
|
+
* @returns The header and payload.
|
|
100
|
+
* @throws If the signing bytes are invalid
|
|
101
|
+
*/
|
|
102
|
+
static fromSigningBytes<T extends IJwtHeader, U extends IJwtPayload>(signingBytes: Uint8Array): {
|
|
103
|
+
header: T;
|
|
104
|
+
payload: U;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Convert signed bytes and signature bytes to token.
|
|
108
|
+
* @param signingBytes The signed bytes.
|
|
109
|
+
* @param signature The signature.
|
|
110
|
+
* @returns The token.
|
|
111
|
+
*/
|
|
112
|
+
static tokenFromBytes(signingBytes: Uint8Array, signature: Uint8Array): string;
|
|
113
|
+
/**
|
|
114
|
+
* Convert the token to signing bytes and signature bytes.
|
|
115
|
+
* @param token The token to convert to bytes.
|
|
116
|
+
* @returns The decoded bytes.
|
|
117
|
+
* @throws If the token is invalid.
|
|
83
118
|
*/
|
|
84
|
-
static
|
|
119
|
+
static tokenToBytes(token: string): {
|
|
120
|
+
signingBytes: Uint8Array;
|
|
121
|
+
signature: Uint8Array;
|
|
122
|
+
};
|
|
85
123
|
}
|