add payload-to-id.ts

This commit is contained in:
Felicio Mununga 2022-06-03 23:36:36 +02:00
parent 0bf7d05344
commit 7bebcc9d30
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
1 changed files with 12 additions and 0 deletions

View File

@ -0,0 +1,12 @@
import { keccak256 } from 'ethereum-cryptography/keccak'
import { bytesToHex } from 'ethereum-cryptography/utils'
export function payloadToId(
publicKey: Uint8Array,
payload: Uint8Array
): string {
const hash = keccak256(new Uint8Array([...publicKey, ...payload]))
const hex = bytesToHex(hash)
return `0x${hex}`
}