From 9ef56cc59dab4a79a32d1df991e494e3cf698cd2 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 30 Jan 2026 12:34:14 +0000 Subject: [PATCH] docs(signal): improved documentation and comments - batch 3 Low Priority Fixes based on Copilot code review: 1. Clarified IdentitySaveResult.changed comment - Explicitly documents that false means "new OR unchanged" - Explains to use isNew to distinguish between cases - Documents that previousFingerprint only present when changed 2. Improved fingerprint documentation - Documents that fingerprint is 64 hex characters (full SHA-256) 3. Added comments to varint parsing - Documents that varint too long could indicate malformed/malicious message - Added comment for incomplete varint case https://claude.ai/code/session_01SWAcNuGZQmEKyBPYkBhVHg --- src/Signal/libsignal.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Signal/libsignal.ts b/src/Signal/libsignal.ts index fb35c713..9b75ecf6 100644 --- a/src/Signal/libsignal.ts +++ b/src/Signal/libsignal.ts @@ -51,13 +51,18 @@ const PREKEY_MSG_VERSION = 3 * Result of identity key save operation */ export interface IdentitySaveResult { - /** Whether the identity key changed (true) or is new/unchanged (false for unchanged) */ + /** + * Whether the identity key changed from a previous known value. + * - true: Key changed (contact reinstalled WhatsApp or switched devices) + * - false: Key is new (first contact) OR unchanged (same key as before) + * Use `isNew` to distinguish between new and unchanged cases. + */ changed: boolean /** Whether this is a new contact (first time seeing their key) */ isNew: boolean - /** Fingerprint of the previous key (if changed) */ + /** Fingerprint of the previous key (only present if changed === true) */ previousFingerprint?: string - /** Fingerprint of the current/new key */ + /** SHA-256 fingerprint of the current/new key (64 hex characters) */ currentFingerprint: string } @@ -234,10 +239,13 @@ function readVarint(buffer: Uint8Array, offset: number): { value: number; nextOf shift += 7 if (shift > 35) { // Varint too long (max 5 bytes for 32-bit) + // This could indicate a malformed or malicious message + // Caller should log this condition at debug level return undefined } } + // Incomplete varint - buffer ended before termination byte return undefined }