simonepri / phc-argon2

🔒 Node.JS Argon2 password hashing algorithm following the PHC string format.
MIT License
17 stars 6 forks source link

support typescript #10

Open zuohuadong opened 5 years ago

awhitford commented 4 years ago

Inspired by https://github.com/simonepri/upash/issues/13, you could try this:

/// <reference types="node" />

declare module "@phc/argon2" {
  type PHCstring = string;

  namespace Argon2 {
    /**
     * Gets the list of all identifiers supported by this hashing function.
     */
    function identifiers(): string[];

    /**
     * Computes the hash string of the given password in the PHC format using argon2 package.
     * @returns a hash with the PHC string format (see https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md)
     */
    function hash(
      password: string,
      options?: { [key: string]: any }
    ): Promise<PHCstring>;

    /**
     * Determines whether or not the hash stored inside the PHC formatted string matches the hash generated for the password provided.
     */
    function verify(phcString: PHCstring, password: string): Promise<boolean>;
  }

  export = Argon2;
}