Skip to content

Commit 7965b17

Browse files
committed
Expose scrypt onProgress callback. Closes gh-7.
1 parent fdd5f18 commit 7965b17

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/scrypt.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import {
2-
scrypt as _scrypt,
3-
scryptAsync as _scryptAsync
4-
} from "@noble/hashes/scrypt";
1+
import { scrypt as _sync, scryptAsync as _async } from "@noble/hashes/scrypt";
52
import { assertBytes } from "./utils";
63

4+
type OnProgressCallback = (progress: number) => void;
5+
76
export async function scrypt(
87
password: Uint8Array,
98
salt: Uint8Array,
109
n: number,
1110
p: number,
1211
r: number,
13-
dkLen: number
12+
dkLen: number,
13+
onProgress?: OnProgressCallback
1414
): Promise<Uint8Array> {
1515
assertBytes(password);
1616
assertBytes(salt);
17-
return _scryptAsync(password, salt, { N: n, r, p, dkLen });
17+
return _async(password, salt, { N: n, r, p, dkLen, onProgress });
1818
}
1919

2020
export function scryptSync(
@@ -23,9 +23,10 @@ export function scryptSync(
2323
n: number,
2424
p: number,
2525
r: number,
26-
dkLen: number
26+
dkLen: number,
27+
onProgress?: OnProgressCallback
2728
): Uint8Array {
2829
assertBytes(password);
2930
assertBytes(salt);
30-
return _scrypt(password, salt, { N: n, r, p, dkLen });
31+
return _sync(password, salt, { N: n, r, p, dkLen, onProgress });
3132
}

0 commit comments

Comments
 (0)