Improve conversion between typed arrays

This commit is contained in:
Fedor Indutny
2022-02-22 17:05:53 -08:00
committed by GitHub
parent 5d035dff86
commit 5453d10572
2 changed files with 12 additions and 1 deletions

View File

@@ -35,7 +35,12 @@ export type EncryptedAttachment = {
// Generate a number between zero and 16383
export function generateRegistrationId(): number {
const id = new Uint16Array(getRandomBytes(2))[0];
const bytes = getRandomBytes(2);
const id = new Uint16Array(
bytes.buffer,
bytes.byteOffset,
bytes.byteLength / 2
)[0];
// eslint-disable-next-line no-bitwise
return id & 0x3fff;