diff --git a/ts/test-electron/SignalProtocolStore_test.ts b/ts/test-electron/SignalProtocolStore_test.ts index 62fe812e98..4e1e7fdab2 100644 --- a/ts/test-electron/SignalProtocolStore_test.ts +++ b/ts/test-electron/SignalProtocolStore_test.ts @@ -48,6 +48,7 @@ const { describe('SignalProtocolStore', () => { const ourAci = generateAci(); + const ourPni = generatePni(); const theirAci = generateAci(); let store: SignalProtocolStore; let identityKey: KeyPairType; @@ -1385,6 +1386,21 @@ describe('SignalProtocolStore', () => { await store.archiveSiblingSessions(id.address, { zone }); }); + it('should not throw in archiveSession on PNI', async () => { + const id = new QualifiedAddress(ourPni, new Address(theirAci, 1)); + + await store.storeSession(id, getSessionRecord(true)); + + await store.archiveSession(id); + + const { devices, emptyServiceIds } = await store.getOpenDevices(ourPni, [ + theirAci, + ]); + + assert.deepEqual(devices, []); + assert.deepEqual(emptyServiceIds, [theirAci]); + }); + it('can be concurrently re-entered after waiting', async () => { const a = new Zone('a'); const b = new Zone('b'); diff --git a/ts/types/Address.ts b/ts/types/Address.ts index 7164cf4491..d22b49fd4f 100644 --- a/ts/types/Address.ts +++ b/ts/types/Address.ts @@ -1,15 +1,10 @@ // Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -import { strictAssert } from '../util/assert'; - import type { ServiceIdString } from './ServiceId'; -import { isServiceIdString } from './ServiceId'; export type AddressStringType = `${ServiceIdString}.${number}`; -const ADDRESS_REGEXP = /^([:0-9a-f-]+).(\d+)$/i; - export class Address { constructor( public readonly serviceId: ServiceIdString, @@ -20,15 +15,6 @@ export class Address { return `${this.serviceId}.${this.deviceId}`; } - public static parse(value: string): Address { - const match = value.match(ADDRESS_REGEXP); - strictAssert(match != null, `Invalid Address: ${value}`); - const [whole, serviceId, deviceId] = match; - strictAssert(whole === value, 'Integrity check'); - strictAssert(isServiceIdString(serviceId), 'Their service id is incorrect'); - return Address.create(serviceId, parseInt(deviceId, 10)); - } - public static create(serviceId: ServiceIdString, deviceId: number): Address { return new Address(serviceId, deviceId); } diff --git a/ts/types/QualifiedAddress.ts b/ts/types/QualifiedAddress.ts index ec82d5736f..9d7c849ca6 100644 --- a/ts/types/QualifiedAddress.ts +++ b/ts/types/QualifiedAddress.ts @@ -8,7 +8,8 @@ import { isServiceIdString } from './ServiceId'; import type { AddressStringType } from './Address'; import { Address } from './Address'; -const QUALIFIED_ADDRESS_REGEXP = /^([:0-9a-f-]+):([:0-9a-f-]+).(\d+)$/i; +const QUALIFIED_ADDRESS_REGEXP = + /^((?:PNI:)?[:0-9a-f-]+):((?:PNI:)?[:0-9a-f-]+).(\d+)$/i; export type QualifiedAddressCreateOptionsType = Readonly<{ ourServiceId: ServiceIdString;