Skip to content

Commit 1192400

Browse files
feat: implement isValidHash method
1 parent 1162da7 commit 1192400

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/helpers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import { BinaryLike, createHash } from "crypto";
22

3-
export const hash = (data: BinaryLike): string => createHash('sha256').update(data).digest('hex')
3+
export const hash = (data: BinaryLike): string => createHash('sha256').update(data).digest('hex')
4+
5+
export const isValidHash = ({ hash, difficulty, prefix }: { hash: string, difficulty: number, prefix: string }): boolean => {
6+
const check = prefix.repeat(difficulty)
7+
8+
return hash.startsWith(check)
9+
}

0 commit comments

Comments
 (0)