15 lines
517 B
TypeScript
15 lines
517 B
TypeScript
|
|
/**
|
||
|
|
* Client-side msgId helper. Mirrors `@shade/inbox-server/msg-id` but lives
|
||
|
|
* in this package so client code doesn't need to import the server bundle.
|
||
|
|
*
|
||
|
|
* `msgId = lowercase-hex( sha256(ciphertext) )`
|
||
|
|
*/
|
||
|
|
export async function computeMsgId(ciphertext: Uint8Array): Promise<string> {
|
||
|
|
const buf = await globalThis.crypto.subtle.digest(
|
||
|
|
'SHA-256',
|
||
|
|
ciphertext as unknown as ArrayBuffer,
|
||
|
|
);
|
||
|
|
const arr = new Uint8Array(buf);
|
||
|
|
return Array.from(arr, (b) => b.toString(16).padStart(2, '0')).join('');
|
||
|
|
}
|