1- "use strict ";
2- const assert = require ( "node:assert" ) ;
3- const { randomBytes , timingSafeEqual } = require ( "node:crypto" ) ;
4- const { promisify } = require ( "node:util" ) ;
5- const { deserialize, serialize } = require ( "@phc/format" ) ;
6- const gypBuild = require ( "node-gyp-build" ) ;
1+ import assert from "node:assert ";
2+ import { randomBytes , timingSafeEqual } from "node:crypto" ;
3+ import { fileURLToPath } from "node:url" ;
4+ import { promisify } from "node:util" ;
5+ import { deserialize , serialize } from "@phc/format" ;
6+ import gypBuild from "node-gyp-build" ;
77
88const { hash : _hash } = gypBuild ( fileURLToPath ( new URL ( "." , import . meta. url ) ) ) ;
99
@@ -12,8 +12,12 @@ const bindingsHash = promisify(_hash);
1212/** @type {(size: number) => Promise<Buffer> } */
1313const generateSalt = promisify ( randomBytes ) ;
1414
15- /** @enum {0 | 1 | 2} */
16- const types = Object . freeze ( { argon2d : 0 , argon2i : 1 , argon2id : 2 } ) ;
15+ export const argon2d = 0 ;
16+ export const argon2i = 1 ;
17+ export const argon2id = 2 ;
18+
19+ /** @enum {argon2i | argon2d | argon2id} */
20+ const types = Object . freeze ( { argon2d, argon2i, argon2id } ) ;
1721
1822/** @enum {'argon2d' | 'argon2i' | 'argon2id'} */
1923const names = Object . freeze ( {
@@ -74,7 +78,7 @@ export const limits = Object.freeze({
7478 * @param {Options & { raw?: boolean } } options
7579 * @returns {Promise<Buffer | string> }
7680 */
77- async function hash ( plain , options ) {
81+ export async function hash ( plain , options ) {
7882 const { raw, salt, saltLength, ...rest } = { ...defaults , ...options } ;
7983
8084 for ( const [ key , { min, max } ] of Object . entries ( limits ) ) {
@@ -115,7 +119,7 @@ async function hash(plain, options) {
115119 * @param {Options } [options] The current parameters for Argon2
116120 * @return {boolean } `true` if the digest parameters do not match the parameters in `options`, otherwise `false`
117121 */
118- function needsRehash ( digest , options ) {
122+ export function needsRehash ( digest , options ) {
119123 const { memoryCost, timeCost, version } = { ...defaults , ...options } ;
120124
121125 const {
@@ -132,7 +136,7 @@ function needsRehash(digest, options) {
132136 * @param {Options } [options] The current parameters for Argon2
133137 * @return {Promise<boolean> } `true` if the digest parameters matches the hash generated from `plain`, otherwise `false`
134138 */
135- async function verify ( digest , plain , options ) {
139+ export async function verify ( digest , plain , options ) {
136140 const {
137141 id,
138142 version = 0x10 ,
@@ -160,5 +164,3 @@ async function verify(digest, plain, options) {
160164 )
161165 ) ;
162166}
163-
164- module . exports = { defaults, hash, needsRehash, verify, ...types } ;
0 commit comments