Interface ICryptoHelper

Interface that should follow a class to implement a crypto helper.

It's useful because we have different implementations in browser and NodeJS.

interface ICryptoHelper {
    generateCodeVerifier: (() => Promise<string>);
    getCodeChallenge: ((code, method) => Promise<string>);
    getValidationHash: ((value) => Promise<string>);
    isValidHash: ((value, hash) => Promise<boolean>);
}

Properties

generateCodeVerifier: (() => Promise<string>)

Generate a cryptographic-safe value suitable for PKCE.

Type declaration

    • (): Promise<string>
    • Returns Promise<string>

Returns

A code verifier to use for PKCE.

See

PKCE

getCodeChallenge: ((code, method) => Promise<string>)

Generate a code challenge from a code verifier for PKCE.

Type declaration

    • (code, method): Promise<string>
    • Parameters

      • code: string

        The code verifier.

      • method: "plain" | "S256"

        The hashing method. Can either be plain or S256. For maximum security, prefer S256.

      Returns Promise<string>

Returns

A code challenge to use for PKCE.

See

PKCE

getValidationHash: ((value) => Promise<string>)

Return the validation hash of a value.

Useful to check the validity c_hash and at_hash claims.

Type declaration

    • (value): Promise<string>
    • Parameters

      • value: string

        The value to hash.

      Returns Promise<string>

Returns

The hashed value.

isValidHash: ((value, hash) => Promise<boolean>)

Check if a hash corresponds to the provided value.

Useful to check the validity c_hash and at_hash claims.

Type declaration

    • (value, hash): Promise<boolean>
    • Parameters

      • value: string

        The plain value to challenge.

      • hash: string

        The hash to compare with.

      Returns Promise<boolean>

Returns

If the hash is valid.