From aa909689202f28cdc6a6de9efd29f3572b75be59 Mon Sep 17 00:00:00 2001 From: Do Minh Khai Date: Fri, 12 Apr 2024 11:43:51 +0700 Subject: [PATCH] generate filterId by encrypt random 16 bytes + timestamp with sha256 --- src/utils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 9101fb0b..e4b429fb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -31,6 +31,7 @@ import { Account2, } from './types' import Sntp from '@hapi/sntp' +import { randomBytes, createHash } from 'crypto' crypto.init('69fa4195670576c0160d660c3be36556ff8d504725be8a59b5a96509e0c994bc') @@ -1037,8 +1038,9 @@ export async function getTransactionReceipt(hash: string) { */ export function getFilterId(): string { - // todo: use a better way to generate filter id - return '0x' + Math.round(Math.random() * 1000000000).toString(16) + return '0x' + createHash('sha256') + .update(randomBytes(16).toString('hex') + Date.now()) + .digest('hex') } export function parseFilterDetails(filter: Filter): { address: string; topics: string[] } {