Improve conversion between typed arrays
This commit is contained in:
parent
5d035dff86
commit
5453d10572
2 changed files with 12 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue