Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

typescript definition #13

Open
Oloompa opened this issue Mar 11, 2020 · 0 comments
Open

typescript definition #13

Oloompa opened this issue Mar 11, 2020 · 0 comments

Comments

@Oloompa
Copy link

Oloompa commented Mar 11, 2020

please add typescript definition

currently i made a custom one in my own project using upash. If it can help:

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

declare module "upash" {
    type PHCstring = string;

    namespace Upash {
        /**
         * Installs a compatible password hashing function.
         */
        function install(
            name: string,
            algorithm: {
                hash(
                    password: string,
                    options?: { [key: string]: any }
                ): Promise<PHCstring>;
                verify(
                    phcString: PHCstring,
                    password: string
                ): Promise<boolean>;
            }
        ): void;

        /**
         * Gets the list of the installed password hashing functions.
         */
        function list(): string[];

        /**
         * Uninstalls a password hashing function previously installed.
         */
        function uninstall(name: string): void;

        /**
         * Selects manually which password hashing function to use. You can call hash and verify on the object returned.
         */
        function use(
            name: string
        ): {
            hash: typeof hash;
            verify: typeof verify;
        };

        /**
         * Returns the name of the algorithm that has generated the hash string.
         */
        function which(name: PHCstring): 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 = Upash;
}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant