|
8 | 8 | createHash,
|
9 | 9 | getHashes,
|
10 | 10 | type Encoding,
|
| 11 | + keccak256, |
11 | 12 | } from 'react-native-quick-crypto';
|
12 | 13 | import { expect } from 'chai';
|
13 | 14 | import { test } from '../util';
|
@@ -37,33 +38,37 @@ test(SUITE, 'check openssl version', () => {
|
37 | 38 | expect(() => {
|
38 | 39 | // Create a hash to trigger OpenSSL initialization
|
39 | 40 | const hash = createHash('sha256');
|
40 |
| - |
| 41 | + |
41 | 42 | // Get OpenSSL version directly from the hash object
|
42 | 43 | const version = hash.getOpenSSLVersion();
|
43 | 44 | console.log('OpenSSL Version:', version);
|
44 | 45 | }).to.not.throw();
|
45 | 46 | });
|
46 | 47 |
|
47 | 48 | test(SUITE, 'keccak256 function using provider-aware API', () => {
|
48 |
| - const { keccak256 } = require('react-native-quick-crypto'); |
49 |
| - |
50 | 49 | // Test with a simple string
|
51 | 50 | const result1 = keccak256('test');
|
52 |
| - expect(result1.toString('hex')).to.equal('9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658'); |
53 |
| - |
| 51 | + expect(result1.toString('hex')).to.equal( |
| 52 | + '9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658', |
| 53 | + ); |
| 54 | + |
54 | 55 | // Test with empty string
|
55 | 56 | const result2 = keccak256('');
|
56 |
| - expect(result2.toString('hex')).to.equal('c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'); |
57 |
| - |
| 57 | + expect(result2.toString('hex')).to.equal( |
| 58 | + 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470', |
| 59 | + ); |
| 60 | + |
58 | 61 | // Test with Buffer
|
59 | 62 | 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 | + |
62 | 67 | // Verify the result is 32 bytes (256 bits)
|
63 | 68 | expect(result1.length).to.equal(32);
|
64 | 69 | expect(result2.length).to.equal(32);
|
65 | 70 | expect(result3.length).to.equal(32);
|
66 |
| - |
| 71 | + |
67 | 72 | // Test that it's different from SHA3-256 (they should be different)
|
68 | 73 | const sha3Hash = createHash('SHA3-256').update('test').digest();
|
69 | 74 | expect(result1.toString('hex')).to.not.equal(sha3Hash.toString('hex'));
|
|
0 commit comments