From 5a9ca4b3ddba21499a44d85c9198a3b5cda329fd Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Fri, 3 Jun 2022 23:36:36 +0200 Subject: [PATCH] add payload-to-id.ts --- packages/status-js/src/utils/payload-to-id.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 packages/status-js/src/utils/payload-to-id.ts diff --git a/packages/status-js/src/utils/payload-to-id.ts b/packages/status-js/src/utils/payload-to-id.ts new file mode 100644 index 00000000..9db98a21 --- /dev/null +++ b/packages/status-js/src/utils/payload-to-id.ts @@ -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}` +}