11import rnqc from 'react-native-quick-crypto' ;
22// @ts -expect-error - crypto-browserify is not typed
33import 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' ;
67import type { BenchFn } from '../../types/benchmarks' ;
78import { Bench } from 'tinybench' ;
89import { text1MB , text8MB , buffer1MB , buffer8MB } from '../testData' ;
910
1011const hmacKey = 'test-key-for-hmac-benchmarks' ;
12+ const hmacKeyBytes = utf8ToBytes ( hmacKey ) ;
1113
1214const 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 ) ;
0 commit comments