Introduce Service Id Types

Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
Fedor Indutny 2023-08-10 18:43:33 +02:00 committed by Jamie Kyle
parent 414c0a58d3
commit 366b875fd2
269 changed files with 5832 additions and 5550 deletions

View file

@ -5,7 +5,7 @@ import { get, throttle } from 'lodash';
import type { WebAPIType } from './textsecure/WebAPI';
import * as log from './logging/log';
import type { UUIDStringType } from './types/UUID';
import type { AciString } from './types/ServiceId';
import { parseIntOrThrow } from './util/parseIntOrThrow';
import { SECOND, HOUR } from './util/durations';
import * as Bytes from './Bytes';
@ -162,18 +162,18 @@ export function getValue(name: ConfigKeyType): string | undefined {
export function isBucketValueEnabled(
name: ConfigKeyType,
e164: string | undefined,
uuid: UUIDStringType | undefined
aci: AciString | undefined
): boolean {
return innerIsBucketValueEnabled(name, getValue(name), e164, uuid);
return innerIsBucketValueEnabled(name, getValue(name), e164, aci);
}
export function innerIsBucketValueEnabled(
name: ConfigKeyType,
flagValue: unknown,
e164: string | undefined,
uuid: UUIDStringType | undefined
aci: AciString | undefined
): boolean {
if (e164 == null || uuid == null) {
if (e164 == null || aci == null) {
return false;
}
@ -191,7 +191,7 @@ export function innerIsBucketValueEnabled(
return false;
}
const bucketValue = getBucketValue(uuid, name);
const bucketValue = getBucketValue(aci, name);
return bucketValue < remoteConfigValue;
}
@ -230,10 +230,10 @@ export function getCountryCodeValue(
return wildcard;
}
export function getBucketValue(uuid: UUIDStringType, flagName: string): number {
export function getBucketValue(aci: AciString, flagName: string): number {
const hashInput = Bytes.concatenate([
Bytes.fromString(`${flagName}.`),
uuidToBytes(uuid),
uuidToBytes(aci),
]);
const hashResult = window.SignalContext.crypto.hash(
HashType.size256,