Skip to content

Commit 1a73b4c

Browse files
committed
fix(benchmarks): align @noble/hashes imports with v2 API
v2.x of @noble/hashes uses an explicit exports map requiring `.js` suffixes on subpath imports, and `hmac()`/`sha256()` no longer accept string inputs. Update the benchmarks to pass UTF-8 encoded bytes for the string-input variants.
1 parent 524c4ad commit 1a73b4c

6 files changed

Lines changed: 18 additions & 15 deletions

File tree

example/src/benchmarks/blake3/blake3.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import rnqc from 'react-native-quick-crypto';
2-
import { blake3 as nobleBlake3 } from '@noble/hashes/blake3';
2+
import { blake3 as nobleBlake3 } from '@noble/hashes/blake3.js';
33
import type { BenchFn } from '../../types/benchmarks';
44
import { Bench } from 'tinybench';
55

example/src/benchmarks/hash/hash.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import rnqc from 'react-native-quick-crypto';
2-
import { sha256 } from '@noble/hashes/sha2';
2+
import { sha256 } from '@noble/hashes/sha2.js';
3+
import { utf8ToBytes } from '@noble/hashes/utils.js';
34
// @ts-expect-error - crypto-browserify is not typed
45
import browserify from 'crypto-browserify';
56
import type { BenchFn } from '../../types/benchmarks';
@@ -21,7 +22,7 @@ const hash_sha256_8mb_string: BenchFn = () => {
2122
hash.digest('hex');
2223
})
2324
.add('@noble/hashes/sha256', () => {
24-
sha256(text8MB);
25+
sha256(utf8ToBytes(text8MB));
2526
})
2627
.add('browserify', () => {
2728
const hash = browserify.createHash('sha256');
@@ -47,7 +48,7 @@ const hash_sha256_1mb_string: BenchFn = () => {
4748
hash.digest('hex');
4849
})
4950
.add('@noble/hashes/sha256', () => {
50-
sha256(text1MB);
51+
sha256(utf8ToBytes(text1MB));
5152
})
5253
.add('browserify', () => {
5354
const hash = browserify.createHash('sha256');

example/src/benchmarks/hkdf/hkdf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import rnqc, { Buffer } from 'react-native-quick-crypto';
2-
import { hkdf } from '@noble/hashes/hkdf';
3-
import { sha256 } from '@noble/hashes/sha2';
2+
import { hkdf } from '@noble/hashes/hkdf.js';
3+
import { sha256 } from '@noble/hashes/sha2.js';
44
import type { BenchFn } from '../../types/benchmarks';
55
import { Bench } from 'tinybench';
66

example/src/benchmarks/hmac/hmac.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import rnqc from 'react-native-quick-crypto';
22
// @ts-expect-error - crypto-browserify is not typed
33
import browserify from 'crypto-browserify';
4-
import { hmac } from '@noble/hashes/hmac';
5-
import { sha256 } from '@noble/hashes/sha2';
4+
import { hmac } from '@noble/hashes/hmac.js';
5+
import { sha256 } from '@noble/hashes/sha2.js';
6+
import { utf8ToBytes } from '@noble/hashes/utils.js';
67
import type { BenchFn } from '../../types/benchmarks';
78
import { Bench } from 'tinybench';
89
import { text1MB, text8MB, buffer1MB, buffer8MB } from '../testData';
910

1011
const hmacKey = 'test-key-for-hmac-benchmarks';
12+
const hmacKeyBytes = utf8ToBytes(hmacKey);
1113

1214
const hmac_sha256_8mb_string: BenchFn = () => {
1315
const bench = new Bench({
@@ -24,7 +26,7 @@ const hmac_sha256_8mb_string: BenchFn = () => {
2426
h.digest('hex');
2527
})
2628
.add('@noble/hashes/hmac', () => {
27-
hmac(sha256, hmacKey, text8MB);
29+
hmac(sha256, hmacKeyBytes, utf8ToBytes(text8MB));
2830
})
2931
.add('browserify', () => {
3032
const h = browserify.createHmac('sha256', hmacKey);
@@ -50,7 +52,7 @@ const hmac_sha256_1mb_string: BenchFn = () => {
5052
h.digest('hex');
5153
})
5254
.add('@noble/hashes/hmac', () => {
53-
hmac(sha256, hmacKey, text1MB);
55+
hmac(sha256, hmacKeyBytes, utf8ToBytes(text1MB));
5456
})
5557
.add('browserify', () => {
5658
const h = browserify.createHmac('sha256', hmacKey);
@@ -76,7 +78,7 @@ const hmac_sha256_8mb_buffer: BenchFn = () => {
7678
h.digest('hex');
7779
})
7880
.add('@noble/hashes/hmac', () => {
79-
hmac(sha256, hmacKey, buffer8MB);
81+
hmac(sha256, hmacKeyBytes, buffer8MB);
8082
})
8183
.add('browserify', () => {
8284
const h = browserify.createHmac('sha256', hmacKey);
@@ -102,7 +104,7 @@ const hmac_sha256_1mb_buffer: BenchFn = () => {
102104
h.digest('hex');
103105
})
104106
.add('@noble/hashes/hmac', () => {
105-
hmac(sha256, hmacKey, buffer1MB);
107+
hmac(sha256, hmacKeyBytes, buffer1MB);
106108
})
107109
.add('browserify', () => {
108110
const h = browserify.createHmac('sha256', hmacKey);

example/src/benchmarks/pbkdf2/pbkdf2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import rnqc from 'react-native-quick-crypto';
2-
import * as noble from '@noble/hashes/pbkdf2';
3-
import { sha256 } from '@noble/hashes/sha2';
2+
import * as noble from '@noble/hashes/pbkdf2.js';
3+
import { sha256 } from '@noble/hashes/sha2.js';
44
// @ts-expect-error - crypto-browserify is not typed
55
import browserify from 'crypto-browserify';
66
import type { BenchFn } from '../../types/benchmarks';

example/src/benchmarks/scrypt/scrypt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import rnqc from 'react-native-quick-crypto';
2-
import * as noble from '@noble/hashes/scrypt';
2+
import * as noble from '@noble/hashes/scrypt.js';
33
import type { BenchFn } from '../../types/benchmarks';
44
import { Bench } from 'tinybench';
55

0 commit comments

Comments
 (0)