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

@ -9,8 +9,9 @@ import Long from 'long';
import type { LoggerType } from '../../types/Logging';
import { strictAssert } from '../../util/assert';
import { UUID_BYTE_SIZE } from '../../types/UUID';
import { isAciString, isUntaggedPniString } from '../../types/ServiceId';
import * as Bytes from '../../Bytes';
import { UUID_BYTE_SIZE } from '../../Crypto';
import { uuidToBytes, bytesToUuid } from '../../util/uuidToBytes';
import { SignalService as Proto } from '../../protobuf';
import type {
@ -246,6 +247,14 @@ function decodeSingleResponse(
const e164 = `+${e164Long.toString()}`;
const pni = bytesToUuid(pniBytes);
const aci = bytesToUuid(aciBytes);
strictAssert(
aci === undefined || isAciString(aci),
'CDSI response has invalid ACI'
);
strictAssert(
pni === undefined || isUntaggedPniString(pni),
'CDSI response has invalid PNI'
);
resultMap.set(e164, { pni, aci });
}

View file

@ -1,7 +1,7 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { UUIDStringType } from '../../types/UUID';
import type { AciString, UntaggedPniString } from '../../types/ServiceId';
export type CDSAuthType = Readonly<{
username: string;
@ -9,15 +9,15 @@ export type CDSAuthType = Readonly<{
}>;
export type CDSResponseEntryType = Readonly<{
aci: UUIDStringType | undefined;
pni: UUIDStringType | undefined;
aci: AciString | undefined;
pni: UntaggedPniString | undefined;
}>;
export type CDSResponseType = ReadonlyMap<string, CDSResponseEntryType>;
export type CDSRequestOptionsType = Readonly<{
e164s: ReadonlyArray<string>;
acis: ReadonlyArray<UUIDStringType>;
acis: ReadonlyArray<AciString>;
accessKeys: ReadonlyArray<string>;
returnAcisWithoutUaks?: boolean;
timeout?: number;