Remove support for E164-based numbers
This commit is contained in:
parent
aa03ac36bc
commit
0ce593bf0d
17 changed files with 469 additions and 916 deletions
|
@ -5,30 +5,24 @@ import { PublicKey, Fingerprint } from '@signalapp/libsignal-client';
|
|||
import type { ConversationType } from '../state/ducks/conversations';
|
||||
|
||||
import { assertDev } from './assert';
|
||||
import { isNotNil } from './isNotNil';
|
||||
import { missingCaseError } from './missingCaseError';
|
||||
import { uuidToBytes } from './uuidToBytes';
|
||||
import * as log from '../logging/log';
|
||||
import * as Bytes from '../Bytes';
|
||||
import type { SafetyNumberType } from '../types/safetyNumber';
|
||||
import { SafetyNumberIdentifierType } from '../types/safetyNumber';
|
||||
import { isAciString } from './isAciString';
|
||||
|
||||
const ITERATION_COUNT = 5200;
|
||||
const E164_VERSION = 1;
|
||||
const SERVICE_ID_VERSION = 2;
|
||||
|
||||
// Number of digits in a safety number block
|
||||
const BLOCK_SIZE = 5;
|
||||
|
||||
export async function generateSafetyNumbers(
|
||||
export async function generateSafetyNumber(
|
||||
contact: ConversationType
|
||||
): Promise<ReadonlyArray<SafetyNumberType>> {
|
||||
): Promise<SafetyNumberType> {
|
||||
const logId = `generateSafetyNumbers(${contact.id})`;
|
||||
log.info(`${logId}: starting`);
|
||||
|
||||
const { storage } = window.textsecure;
|
||||
const ourNumber = storage.user.getNumber();
|
||||
const ourAci = storage.user.getCheckedAci();
|
||||
|
||||
const us = storage.protocol.getIdentityRecord(ourAci);
|
||||
|
@ -53,55 +47,24 @@ export async function generateSafetyNumbers(
|
|||
const ourKey = PublicKey.deserialize(Buffer.from(ourKeyBuffer));
|
||||
const theirKey = PublicKey.deserialize(Buffer.from(theirKeyBuffer));
|
||||
|
||||
const identifierTypes = [
|
||||
SafetyNumberIdentifierType.ACIIdentifier,
|
||||
SafetyNumberIdentifierType.E164Identifier,
|
||||
];
|
||||
assertDev(theirAci, 'Should have their serviceId');
|
||||
const fingerprint = Fingerprint.new(
|
||||
ITERATION_COUNT,
|
||||
SERVICE_ID_VERSION,
|
||||
Buffer.from(uuidToBytes(ourAci)),
|
||||
ourKey,
|
||||
Buffer.from(uuidToBytes(theirAci)),
|
||||
theirKey
|
||||
);
|
||||
|
||||
return identifierTypes
|
||||
.map(identifierType => {
|
||||
let fingerprint: Fingerprint;
|
||||
if (identifierType === SafetyNumberIdentifierType.E164Identifier) {
|
||||
if (!contact.e164) {
|
||||
log.error(
|
||||
`${logId}: Attempted to generate security number for contact with no e164`
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
const securityNumber = fingerprint.displayableFingerprint().toString();
|
||||
|
||||
assertDev(ourNumber, 'Should have our number');
|
||||
fingerprint = Fingerprint.new(
|
||||
ITERATION_COUNT,
|
||||
E164_VERSION,
|
||||
Buffer.from(Bytes.fromString(ourNumber)),
|
||||
ourKey,
|
||||
Buffer.from(Bytes.fromString(contact.e164)),
|
||||
theirKey
|
||||
);
|
||||
} else if (identifierType === SafetyNumberIdentifierType.ACIIdentifier) {
|
||||
assertDev(theirAci, 'Should have their serviceId');
|
||||
fingerprint = Fingerprint.new(
|
||||
ITERATION_COUNT,
|
||||
SERVICE_ID_VERSION,
|
||||
Buffer.from(uuidToBytes(ourAci)),
|
||||
ourKey,
|
||||
Buffer.from(uuidToBytes(theirAci)),
|
||||
theirKey
|
||||
);
|
||||
} else {
|
||||
throw missingCaseError(identifierType);
|
||||
}
|
||||
const numberBlocks = [];
|
||||
for (let i = 0; i < securityNumber.length; i += BLOCK_SIZE) {
|
||||
numberBlocks.push(securityNumber.substring(i, i + BLOCK_SIZE));
|
||||
}
|
||||
|
||||
const securityNumber = fingerprint.displayableFingerprint().toString();
|
||||
const qrData = fingerprint.scannableFingerprint().toBuffer();
|
||||
|
||||
const numberBlocks = [];
|
||||
for (let i = 0; i < securityNumber.length; i += BLOCK_SIZE) {
|
||||
numberBlocks.push(securityNumber.substring(i, i + BLOCK_SIZE));
|
||||
}
|
||||
|
||||
const qrData = fingerprint.scannableFingerprint().toBuffer();
|
||||
|
||||
return { identifierType, numberBlocks, qrData };
|
||||
})
|
||||
.filter(isNotNil);
|
||||
return { numberBlocks, qrData };
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue