Skip to content

Commit 57347e2

Browse files
committed
fix: resolve issue with topic not being computed correctly
1 parent 7325a1f commit 57347e2

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ node_modules
77
coverage
88
.vscode
99
.DS_Store
10+
.idea

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ethereum-bloom-filters",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Ability to test bloom filters for ethereum.",
55
"main": "dist/index.js",
66
"scripts": {

src/index.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ describe('isTopicInBloom', () => {
257257
),
258258
).toEqual(false);
259259
});
260+
261+
it('should return true if topic is not in bloom', () => {
262+
expect(
263+
isTopicInBloom(
264+
"0x00000000000000000000008000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000044000200000000000000000002000000000000000000000040000000000000000000000000000020000000000000000000800000000000800000000000800000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000808002000000000400000000000000000000000060000000000000000000000000000000000000000000000100000000000002000000",
265+
"0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb"
266+
),
267+
).toEqual(true);
268+
});
260269
});
261270

262271
describe('isTopic', () => {

src/utils.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { keccak_256 } from '@noble/hashes/sha3';
2+
import { bytesToHex as toHex } from '@noble/hashes/utils';
23

34
/**
45
* Keccak256 hash
@@ -27,14 +28,7 @@ export const padLeft = (value: string, chars: number) => {
2728
* @param bytes The bytes
2829
*/
2930
export function bytesToHex(bytes: Uint8Array): string {
30-
const hex: string[] = [];
31-
32-
for (let i = 0; i < bytes.length; i++) {
33-
hex.push((bytes[i] >>> 4).toString(16));
34-
hex.push((bytes[i] & 0xf).toString(16));
35-
}
36-
37-
return `0x${hex.join('').replace(/^0+/, '')}`;
31+
return "0x" + toHex(bytes);
3832
}
3933

4034
/**

web-scripts/1.2.0/ethereum-bloom-filters-1.2.0.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)