Skip to content

Commit

Permalink
Debug import bug
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Mar 5, 2024
1 parent 6ae82e7 commit 255352a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions benchmark/bug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { scrypt } = require('../scrypt.js');
let start = Date.now();
scrypt('password', 'salt', { N: 2 ** 15, r: 8, p: 1, dkLen: 32 })
let end = Date.now();
console.log(end - start, 'ms');
12 changes: 9 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
// Makes the utils un-importable in browsers without a bundler.
// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
import { crypto } from '@noble/hashes/crypto';
import { isBytes, bytes as abytes } from './_assert.js';
import { bytes as abytes } from './_assert.js';
// export { isBytes } from './_assert.js';
// We can't reuse isBytes from _assert, because somehow this causes huge perf issues
export function isBytes(a: unknown): a is Uint8Array {
return (
a instanceof Uint8Array ||
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')
);
}

// prettier-ignore
export type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |
Expand Down Expand Up @@ -38,8 +46,6 @@ export const byteSwap = (word: number) =>
// Conditionally byte swap if on a big-endian platform
export const byteSwapIfBE = isLE ? (n: number) => n : (n: number) => byteSwap(n);

export { isBytes };

// In place byte swap for Uint32Array
export function byteSwap32(arr: Uint32Array) {
for (let i = 0; i < arr.length; i++) {
Expand Down

0 comments on commit 255352a

Please sign in to comment.