Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Green 24: generate filterId by encrypt random 16 bytes + timestamp with sha256 #9

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
Account2,
} from './types'
import Sntp from '@hapi/sntp'
import { randomBytes, createHash } from 'crypto'

crypto.init('69fa4195670576c0160d660c3be36556ff8d504725be8a59b5a96509e0c994bc')

Expand Down Expand Up @@ -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[] } {
Expand Down
Loading