mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
17 lines
324 B
TypeScript
17 lines
324 B
TypeScript
/** Get POW difficulty from a Nostr hex ID. */
|
|
export function getPow(hex: string): number {
|
|
let count = 0
|
|
|
|
for (let i = 0; i < hex.length; i++) {
|
|
const nibble = parseInt(hex[i], 16)
|
|
if (nibble === 0) {
|
|
count += 4
|
|
} else {
|
|
count += Math.clz32(nibble) - 28
|
|
break
|
|
}
|
|
}
|
|
|
|
return count
|
|
}
|