Documentation
    Preparing search index...

    Class HashManager<KnownHashers>

    HashManager implements the manager/builder pattern to create a use multiple hashing algorithm without self managing hash instance.

    const manager = new HashManager({
    default: 'argon',
    list: {
    argon: () => new ArgonDriver(),
    bcrypt: () => new BcryptDriver(),
    }
    })

    Type Parameters

    Implements

    Index

    Constructors

    Properties

    config: { default?: keyof KnownHashers; list: KnownHashers }

    Configuration object containing default hasher and list of available hashers

    Methods

    • Use one of the registered hashers to hash values.

      manager.use() // returns default hasher
      manager.use('argon')

      Type Parameters

      • Hasher extends string | number | symbol

      Parameters

      • Optionalhasher: Hasher

        The name of the hasher to use, defaults to the configured default

      Returns Hash

      Hash instance for the specified hasher

    • Enable fake hash drivers to disable actual hashing for testing

      Returns void

    • Restore normal hashing behavior by disabling fake mode

      Returns void

    • Check if the value is a valid hash. This method just checks for the formatting of the hash

      Parameters

      • value: string

        The value to check

      Returns boolean

      True if the value is a valid hash format

    • Hash plain text value using the default hasher

      Parameters

      • value: string

        The plain text value to hash

      Returns Promise<string>

      Promise resolving to the hashed value

    • Verify the plain text value against an existing hash

      Parameters

      • hashedValue: string

        The hashed value to verify against

      • plainValue: string

        The plain text value to verify

      Returns Promise<boolean>

      Promise resolving to true if verification succeeds

    • Find if the hash value needs a rehash or not.

      Parameters

      • hashedValue: string

        The hashed value to check

      Returns boolean

      True if the hash needs to be rehashed

    • Assert the plain value passes the hash verification

      Parameters

      • hashedValue: string

        The hashed value to verify against

      • plainValue: string

        The plain text value to verify

      Returns Promise<void>

      Promise that resolves if verification passes, throws if it fails

    • Assert the plain value fails the hash verification

      Parameters

      • hashedValue: string

        The hashed value to verify against

      • plainValue: string

        The plain text value to verify

      Returns Promise<void>

      Promise that resolves if verification fails, throws if it passes