mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-10 04:19:32 +00:00
feat: move to noble hash scrypt impl
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
export function constantTimeEqual(
|
||||
a: ArrayBuffer,
|
||||
a: ArrayBuffer | Uint8Array,
|
||||
b: ArrayBuffer | Uint8Array,
|
||||
): boolean {
|
||||
const aBuffer = new Uint8Array(a);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { scrypt } from "node:crypto";
|
||||
import { decodeHex, encodeHex } from "oslo/encoding";
|
||||
import { constantTimeEqual } from "./buffer";
|
||||
|
||||
import { scryptAsync } from "@noble/hashes/scrypt";
|
||||
const config = {
|
||||
N: 16384,
|
||||
r: 16,
|
||||
@@ -9,28 +8,12 @@ const config = {
|
||||
dkLen: 64,
|
||||
};
|
||||
|
||||
async function generateKey(
|
||||
password: string,
|
||||
salt: string,
|
||||
): Promise<ArrayBuffer> {
|
||||
return await new Promise<ArrayBuffer>((resolve, reject) => {
|
||||
scrypt(
|
||||
password.normalize("NFKC"),
|
||||
salt!,
|
||||
config.dkLen,
|
||||
{
|
||||
async function generateKey(password: string, salt: string) {
|
||||
return await scryptAsync(password.normalize("NFKC"), salt, {
|
||||
N: config.N,
|
||||
p: config.p,
|
||||
r: config.r,
|
||||
// errors when 128 * N * r > `maxmem` (approximately)
|
||||
maxmem: 128 * config.N * config.r * 2,
|
||||
},
|
||||
(err, buff) => {
|
||||
if (err) return reject(err);
|
||||
// @ts-ignore
|
||||
return resolve(buff);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user