diff --git a/ts/services/backups/export.preload.ts b/ts/services/backups/export.preload.ts index 25d2966fdd..370ac44700 100644 --- a/ts/services/backups/export.preload.ts +++ b/ts/services/backups/export.preload.ts @@ -28,6 +28,7 @@ import { getStickerPacksForBackup } from '../../types/Stickers.preload.js'; import { isPniString, isServiceIdString, + type PniString, type AciString, type ServiceIdString, } from '../../types/ServiceId.std.js'; @@ -1240,11 +1241,9 @@ export class BackupExportStream extends Readable { const maybePni = convo.pni ?? convo.serviceId; const aci = isAciString(convo.serviceId) - ? Aci.parseFromServiceIdString(convo.serviceId).getRawUuidBytes() - : null; - const pni = isPniString(maybePni) - ? Pni.parseFromServiceIdString(maybePni).getRawUuidBytes() + ? this.#aciToBytes(convo.serviceId) : null; + const pni = isPniString(maybePni) ? this.#pniToRawBytes(maybePni) : null; const e164 = convo.e164 ? BigInt(convo.e164) : null; strictAssert( @@ -1935,8 +1934,14 @@ export class BackupExportStream extends Readable { return null; } + /** For fields explicitly marked as PNI (validator will expect 16 bytes) */ + #pniToRawBytes(pni: PniString | string): Uint8Array { + return Pni.parseFromServiceIdString(pni).getRawUuidBytes(); + } + + /** For fields that can accept either ACI or PNI bytes */ #serviceIdToBytes(serviceId: ServiceIdString): Uint8Array { - return ServiceId.parseFromServiceIdString(serviceId).getRawUuidBytes(); + return ServiceId.parseFromServiceIdString(serviceId).getServiceIdBinary(); } async #toChatItemFromNonBubble( @@ -2840,7 +2845,7 @@ export class BackupExportStream extends Readable { ? this.#aciToBytes(detail.serviceId) : null, inviteePni: isPniString(detail.serviceId) - ? this.#serviceIdToBytes(detail.serviceId) + ? this.#pniToRawBytes(detail.serviceId) : null, }, ],