Make 1 the minimum registration ID
This commit is contained in:
28
ts/Crypto.ts
28
ts/Crypto.ts
@@ -34,17 +34,8 @@ export type EncryptedAttachment = {
|
||||
digest: Uint8Array;
|
||||
};
|
||||
|
||||
// Generate a number between zero and 16383
|
||||
export function generateRegistrationId(): number {
|
||||
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;
|
||||
return randomInt(1, 16383);
|
||||
}
|
||||
|
||||
export function deriveStickerPackKey(packKey: Uint8Array): Uint8Array {
|
||||
@@ -342,16 +333,6 @@ export function sha256(data: Uint8Array): Uint8Array {
|
||||
|
||||
// Utility
|
||||
|
||||
export function getRandomValue(low: number, high: number): number {
|
||||
const diff = high - low;
|
||||
const bytes = getRandomBytes(1);
|
||||
|
||||
// Because high and low are inclusive
|
||||
const mod = diff + 1;
|
||||
|
||||
return (bytes[0] % mod) + low;
|
||||
}
|
||||
|
||||
export function getZeroes(n: number): Uint8Array {
|
||||
return new Uint8Array(n);
|
||||
}
|
||||
@@ -683,6 +664,13 @@ export function decrypt(
|
||||
return crypto.decrypt(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an integer between `min` and `max`, inclusive.
|
||||
*/
|
||||
export function randomInt(min: number, max: number): number {
|
||||
return crypto.randomInt(min, max + 1);
|
||||
}
|
||||
|
||||
export function getRandomBytes(size: number): Uint8Array {
|
||||
return crypto.getRandomBytes(size);
|
||||
}
|
||||
|
Reference in New Issue
Block a user