Skip to content

Commit 833da05

Browse files
committed
chore: formatting
1 parent 52b5f8a commit 833da05

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

example/src/tests/hash/hash_tests.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
createHash,
99
getHashes,
1010
type Encoding,
11+
keccak256,
1112
} from 'react-native-quick-crypto';
1213
import { expect } from 'chai';
1314
import { test } from '../util';
@@ -37,33 +38,37 @@ test(SUITE, 'check openssl version', () => {
3738
expect(() => {
3839
// Create a hash to trigger OpenSSL initialization
3940
const hash = createHash('sha256');
40-
41+
4142
// Get OpenSSL version directly from the hash object
4243
const version = hash.getOpenSSLVersion();
4344
console.log('OpenSSL Version:', version);
4445
}).to.not.throw();
4546
});
4647

4748
test(SUITE, 'keccak256 function using provider-aware API', () => {
48-
const { keccak256 } = require('react-native-quick-crypto');
49-
5049
// Test with a simple string
5150
const result1 = keccak256('test');
52-
expect(result1.toString('hex')).to.equal('9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658');
53-
51+
expect(result1.toString('hex')).to.equal(
52+
'9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658',
53+
);
54+
5455
// Test with empty string
5556
const result2 = keccak256('');
56-
expect(result2.toString('hex')).to.equal('c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470');
57-
57+
expect(result2.toString('hex')).to.equal(
58+
'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
59+
);
60+
5861
// Test with Buffer
5962
const result3 = keccak256(Buffer.from('hello world'));
60-
expect(result3.toString('hex')).to.equal('47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad');
61-
63+
expect(result3.toString('hex')).to.equal(
64+
'47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad',
65+
);
66+
6267
// Verify the result is 32 bytes (256 bits)
6368
expect(result1.length).to.equal(32);
6469
expect(result2.length).to.equal(32);
6570
expect(result3.length).to.equal(32);
66-
71+
6772
// Test that it's different from SHA3-256 (they should be different)
6873
const sha3Hash = createHash('SHA3-256').update('test').digest();
6974
expect(result1.toString('hex')).to.not.equal(sha3Hash.toString('hex'));

packages/react-native-quick-crypto/src/hash.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class HashUtils {
1111
return this.native.getSupportedHashAlgorithms();
1212
}
1313
public static keccak256(data: BinaryLike): Buffer {
14-
const nativeDigest = this.native.keccak256(binaryLikeToArrayBuffer(data, 'utf8'));
14+
const nativeDigest = this.native.keccak256(
15+
binaryLikeToArrayBuffer(data, 'utf8'),
16+
);
1517
return Buffer.from(nativeDigest);
1618
}
1719
}
@@ -180,7 +182,9 @@ class Hash extends Stream.Transform {
180182
* @returns Buffer containing the KECCAK-256 hash
181183
*/
182184
keccak256(data: BinaryLike): Buffer {
183-
const nativeDigest = this.native.keccak256(binaryLikeToArrayBuffer(data, 'utf8'));
185+
const nativeDigest = this.native.keccak256(
186+
binaryLikeToArrayBuffer(data, 'utf8'),
187+
);
184188
return Buffer.from(nativeDigest);
185189
}
186190

0 commit comments

Comments
 (0)