1 |
|
2 |
|
3 |
|
4 |
|
5 | export declare class InvalidHmacError extends Error {
|
6 | constructor(message?: any);
|
7 | }
|
8 | /**
|
9 | * Generate a new TWT from a payload and signature
|
10 | * @param payload - Payload
|
11 | * @param secret - Secret
|
12 | * @example
|
13 | * // returns "hello5112055c05f944f85755efc5cd8970e194e9f45b"
|
14 | * sign("hello", "secret");
|
15 | */
|
16 | export declare const sign: (payload: string, secret: string, length?: number, algorithm?: string) => string;
|
17 | /**
|
18 | * Verify a TWT using its secret
|
19 | * @param twt - TWT
|
20 | * @param secret - Secret
|
21 | * @example
|
22 | * // returns "hello"
|
23 | * verify("hello5112055c05f944f85755efc5cd8970e194e9f45b", "secret");
|
24 | * @example
|
25 | * // Throws an InvalidHmacError
|
26 | * verify("hello-this-is-not-the-correct-hmac", "secret");
|
27 | * @example
|
28 | * // Throws an InvalidHmacError
|
29 | * verify("hello5112055c05f944f85755efc5cd8970e194e9f45b", "incorrect-secret");
|
30 | */
|
31 | export declare const verify: (twt: string, secret: string, length?: number, algorithm?: string) => string;
|
32 | /**
|
33 | * Decode a TWT **without** verifying it (not recommended)
|
34 | * @param twt - TWT
|
35 | * @example
|
36 | * // returns "hello"
|
37 | * decode("hello5112055c05f944f85755efc5cd8970e194e9f45b");
|
38 | * @example
|
39 | * // returns "hello"
|
40 | * decode("hellothis-is-not-the-correct-hmac");
|
41 | */
|
42 | export declare const decode: (twt: string, length?: number) => string;
|
43 | /**
|
44 | * Validate a TWT **without** verifying it
|
45 | * @param twt - TWT
|
46 | * @example
|
47 | * // returns true
|
48 | * decode("hello5112055c05f944f85755efc5cd8970e194e9f45b");
|
49 | * @example
|
50 | * // returns false
|
51 | * decode("hellothis-is-not-32-characters");
|
52 | * // returns true
|
53 | * decode("hellothis-is-32-characters-abcdefghijklmnopqr");
|
54 | */
|
55 | export declare const validate: (twt: string, length?: number) => boolean;
|