1
60%
MIT
Bucklescript bindings for the argon2 module

BuckleScript Bindings for Argon2

Based on node-argon2.

Install

npm install @leeor/bs-argon2 --save

API

The Argon2.hash type

To promote security of the generated hashes, a special type is used to represent the output of the hashing functions. This should be used for protecting at the type level against leakage and usage of these values in sensitive areas (such as code that is used by both client and server).

hash

Hash a string or a Node.Buffer.t returning an Argon2.hash.

  • RE
  • ML
type hashInput =
  | String(string)
  | Buffer(Node.Buffer.t);

let hash:
  (
    ~hashLength: int=?,
    ~timeCost: int=?,
    ~memoryCost: int=?,
    ~parallelism: int=?,
    ~type_: hashMode=?,
    ~version: version=?,
    ~salt: Node.Buffer.t=?,
    ~saltLength: int=?,
    ~associatedData: Node.Buffer.t=?,
    hashInput
  ) =>
  Js.Promise.t(hash);
958: <UNKNOWN SYNTAX ERROR>

hashRaw

Hash a string or a Node.Buffer.t returning a Node.Buffer.t.

  • RE
  • ML
type hashInput =
  | String(string)
  | Buffer(Node.Buffer.t);

let hashRaw:
  (
    ~hashLength: int=?,
    ~timeCost: int=?,
    ~memoryCost: int=?,
    ~parallelism: int=?,
    ~type_: hashMode=?,
    ~version: version=?,
    ~salt: Node.Buffer.t=?,
    ~saltLength: int=?,
    ~associatedData: Node.Buffer.t=?,
    hashInput
  ) =>
  Js.Promise.t(Node.Buffer.t);
958: <UNKNOWN SYNTAX ERROR>

needsRehash

Return whether the hash needs to be recomputed due to changed options/version.

  • RE
  • ML
let needsRehash:
  (~timeCost: int=?, ~memoryCost: int=?, ~version: version=?, hash) =>
  bool;
958: <UNKNOWN SYNTAX ERROR>

verify

Verify a given string or Node.Buffer.t against a previously generated hash.

  • RE
  • ML
type hashInput =
  | String(string)
  | Buffer(Node.Buffer.t);

let verify: (hash, hashInput) => Js.Promise.t(bool);
958: <UNKNOWN SYNTAX ERROR>

Js.Json.t Enconding/decoding

Use the following two functions when (de)serializing generated hashes:

  • RE
  • ML
let hashToJson: hash => Js.Json.t;
let jsonToHash: Js.Json.t => hash;
958: <UNKNOWN SYNTAX ERROR>

Note: in its current implementation, jsonToHash will raise an exception if the decoding fails.