|
| 1 | +export type JsonObject = { |
| 2 | + [Key in string]?: JsonValue; |
| 3 | +}; |
| 4 | +export type JsonArray = JsonValue[]; |
| 5 | +export type JsonPrimitive = string | number | boolean | null; |
| 6 | +export type JsonValue = JsonPrimitive | JsonObject | JsonArray; |
| 7 | +/** |
| 8 | + * @ignore |
| 9 | + */ |
| 10 | +export type CryptoKey = Extract<Awaited<ReturnType<typeof crypto.subtle.generateKey>>, { |
| 11 | + type: string; |
| 12 | +}>; |
| 13 | +/** |
| 14 | + * Supported JWS `alg` Algorithm identifiers. |
| 15 | + * |
| 16 | + * @example CryptoKey algorithm for the ES256 JWS Algorithm Identifier |
| 17 | + * |
| 18 | + * ```ts |
| 19 | + * interface ES256Algorithm extends EcKeyAlgorithm { |
| 20 | + * name: 'ECDSA' |
| 21 | + * namedCurve: 'P-256' |
| 22 | + * } |
| 23 | + * ``` |
| 24 | + * |
| 25 | + * @example CryptoKey algorithm for the Ed25519 JWS Algorithm Identifier |
| 26 | + * |
| 27 | + * ```ts |
| 28 | + * interface Ed25519Algorithm extends Algorithm { |
| 29 | + * name: 'Ed25519' |
| 30 | + * } |
| 31 | + * ``` |
| 32 | + * |
| 33 | + * @example CryptoKey algorithm for the PS256 JWS Algorithm Identifier |
| 34 | + * |
| 35 | + * ```ts |
| 36 | + * interface PS256Algorithm extends RsaHashedKeyAlgorithm { |
| 37 | + * name: 'RSA-PSS' |
| 38 | + * hash: { name: 'SHA-256' } |
| 39 | + * } |
| 40 | + * ``` |
| 41 | + * |
| 42 | + * @example CryptoKey algorithm for the RS256 JWS Algorithm Identifier |
| 43 | + * |
| 44 | + * ```ts |
| 45 | + * interface RS56Algorithm extends RsaHashedKeyAlgorithm { |
| 46 | + * name: 'RSASSA-PKCS1-v1_5' |
| 47 | + * hash: { name: 'SHA-256' } |
| 48 | + * } |
| 49 | + * ``` |
| 50 | + */ |
| 51 | +export type JWSAlgorithm = 'ES256' | 'Ed25519' | 'RS256' | 'PS256'; |
| 52 | +/** |
| 53 | + * @ignore |
| 54 | + */ |
| 55 | +export interface CryptoKeyPair { |
| 56 | + privateKey: CryptoKey; |
| 57 | + publicKey: CryptoKey; |
| 58 | +} |
| 59 | +export interface KeyPair extends CryptoKeyPair { |
| 60 | + /** |
| 61 | + * Private CryptoKey instance to sign the DPoP Proof JWT with. |
| 62 | + * |
| 63 | + * Its algorithm must be compatible with a supported {@link JWSAlgorithm JWS `alg` Algorithm}. |
| 64 | + */ |
| 65 | + privateKey: CryptoKey; |
| 66 | + /** |
| 67 | + * The public CryptoKey instance corresponding to {@link KeyPair.privateKey} |
| 68 | + */ |
| 69 | + publicKey: CryptoKey; |
| 70 | +} |
| 71 | +/** |
| 72 | + * Generates a unique DPoP Proof JWT. |
| 73 | + * |
| 74 | + * @param keypair |
| 75 | + * @param htu The HTTP URI (without query and fragment parts) of the request |
| 76 | + * @param htm The HTTP method of the request |
| 77 | + * @param nonce Server-provided nonce. |
| 78 | + * @param accessToken Access token's value (When making protected resource requests). |
| 79 | + * @param additional Any additional claims. |
| 80 | + */ |
| 81 | +export declare function generateProof(keypair: KeyPair, htu: string, htm: string, nonce?: string, accessToken?: string, additional?: Record<string, JsonValue>): Promise<string>; |
| 82 | +export interface GenerateKeyPairOptions { |
| 83 | + /** |
| 84 | + * Indicates whether or not the private key may be exported. Default is `false`. |
| 85 | + */ |
| 86 | + extractable?: boolean; |
| 87 | +} |
| 88 | +/** |
| 89 | + * Generates a {@link KeyPair} for a given JWS `alg` Algorithm identifier. |
| 90 | + * |
| 91 | + * @param alg Supported JWS `alg` Algorithm identifier. |
| 92 | + */ |
| 93 | +export declare function generateKeyPair(alg: JWSAlgorithm, options?: GenerateKeyPairOptions): Promise<KeyPair>; |
| 94 | +/** |
| 95 | + * Calculates the JWK Thumbprint of the DPoP public key using the SHA-256 hash function for use as |
| 96 | + * the optional `dpop_jkt` authorization request parameter. |
| 97 | + */ |
| 98 | +export declare function calculateThumbprint(publicKey: CryptoKey): Promise<string>; |
0 commit comments