Skip to content

prekeys, remote signal: keep companion device identities - #69

Open
purpshell wants to merge 3 commits into
mainfrom
feat/prekey-device-identity
Open

purpshell wants to merge 3 commits into
mainfrom
feat/prekey-device-identity

Conversation

@purpshell

@purpshell purpshell commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Prekey responses include a <device-identity> element (serialized ADVSignedDeviceIdentity) for companion devices. It sits beside the identity key, as WhatsApp Web's own parser reads it (Cellar bundle whatsapp-1054794655, WASmaxInPreKeysDeviceSuccessMixin.js:20 and WASmaxInPreKeysDeviceIdentityMixin.js:3-6). HyperMeow dropped it.

  • fetchPreKeys now keeps the bytes. It reads them beside the identity key, or inside a <keys> wrapper.
  • DangerousInternals().FetchPreKeysWithIdentityNoError returns each bundle with its device identity (FetchedPreKey). A headless (shadow) client fetches through its relay, which returns bundles only, so DeviceIdentity is nil there.
  • FetchPreKeysNoError and the other existing calls are unchanged.
  • A remote-keyed client forwards a pkmsg's <device-identity>, the child of <message> beside its <enc>, in the new RemoteReceive.DeviceIdentity. Other payload kinds leave it nil.
  • A remote-keyed client's retry receipt handling forwards the <device-identity> from the receipt's <keys> in the new RemoteResend.DeviceIdentity, next to Bundle. It's nil without keys. WhatsApp Web passes the retry bundle's device identity into session setup the same way (Cellar whatsapp-1054794655, WAWebProcessRetryKeyBundle.js:150-171).

Polymorfa's runner needs both directions to relay a companion's device identity to an external Signal service. That service verifies the device against the account's pinned identity before encrypting to it or decrypting its prekey messages.

Verification

  • go test -count=1 . passes, including two new tests. TestPreKeyDeviceIdentity covers the identity beside the key, inside <keys>, absent and empty. TestRemoteReceiveForwardsPreKeyDeviceIdentity checks that a pkmsg forwards it and a msg does not. TestRemoteRetryReceiptForwardsItsKeysDeviceIdentity checks a retry receipt built in the layout retry.go sends. It fails without the fix.
  • go vet ./... is clean.
  • Not exercised: a live prekey fetch or receive from a real account.

Checklist

Summary by CodeRabbit

  • New Features
    • Prekey fetch results now include each device’s identity information when available. Relay-fetched results continue to provide bundles without identity information.
    • Remote decryption forwards device identity information with prekey message requests, and retry requests forward identity information from retry receipts.

The prekey response carries a <device-identity> (serialized
ADVSignedDeviceIdentity) for companion devices, beside the identity key.
fetchPreKeys now keeps it, and DangerousInternals gains
FetchPreKeysWithIdentityNoError, which returns it with each bundle so a
caller can verify a companion against its account before encrypting.
Existing fetch calls are unchanged.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds device-identity bytes to fetched prekey results and remote Signal receive and resend requests. It extracts identities from prekey responses, pkmsg stanzas, and retry receipts. Tests cover extraction and forwarding.

Changes: Device identity propagation

Layer / File(s) Summary
Prekey identity extraction and fetch results
prekeys.go, internals.go, prekeys_device_identity_test.go
Prekey responses retain nonempty device-identity bytes from the response or its keys child. The fetch method returns each bundle with its identity. Relay results contain bundles without identity bytes. Tests cover extraction from direct and nested response nodes, and absent or empty values.
Remote receive identity forwarding
remote_signal.go, remote_signal_test.go
RemoteReceive carries device-identity bytes for pkmsg messages. Other encrypted message types do not include them. Tests cover forwarding for pkmsg and omission for msg.
Retry resend identity forwarding
remote_signal.go, remote_signal_test.go
RemoteResend carries device-identity bytes from retry receipts containing keys. The test also checks the parsed key bundle’s registration ID.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant EncryptedStanza
  participant decryptMessagesRemote
  participant messageDeviceIdentity
  participant RemoteSignalStore
  EncryptedStanza->>decryptMessagesRemote: Provide encrypted stanza
  decryptMessagesRemote->>messageDeviceIdentity: Extract identity for pkmsg
  messageDeviceIdentity-->>decryptMessagesRemote: Return nonempty identity bytes
  decryptMessagesRemote->>RemoteSignalStore: Send RemoteReceive with DeviceIdentity
Loading

Possibly related PRs

  • polymorfa/hypermeow#48: Introduces the RemoteReceive and RemoteResend contracts that this change extends with device-identity fields.

Suggested reviewers: tulir

Merge Risk: Minimal · up to 88c3b

This change retains companion-device identities from prekey fetches and forwards them in remote receive and resend requests. The additions are optional and backward compatible, and tests cover the new paths. No merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two areas the change touches (prekeys and remote signal) and the core behavior (keeping companion device identities). The raw summary and PR objectives confirm that fetchPreKeys no…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template's checklist, and it states the change, the affected APIs, the verification steps, and what was not tested. It explains the reason for the change (keepin…
Full details: Title check

Explanation

The title names the two areas the change touches (prekeys and remote signal) and the core behavior (keeping companion device identities). The raw summary and PR objectives confirm that fetchPreKeys now retains the device-identity bytes and that RemoteReceive and RemoteResend forward them. The title is specific and concise, and it does not list files.

Full details: Description check

Explanation

The description follows the repository template's checklist, and it states the change, the affected APIs, the verification steps, and what was not tested. It explains the reason for the change (keeping companion device identities for a remote Signal service) and identifies the new fields and functions. The template has only a contributing-guidelines checklist, which the author marked as complete, so the template requirements are met.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 6d77b8e4-7cb8-4406-84d0-5529ebb92ea4
Commits

Reviewing files that changed from the base of the PR and between 4792d8d and 88c3b21.

Files selected for processing: 2

  • remote_signal.go
  • remote_signal_test.go

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T06:59:15.378105Z 88c3b21 Manual request
🔒 Security Review ✅ Completed 2026-11-17T07:01:50.984963Z 88c3b21 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@purpshell

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 48af73edf3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 48af73edf3

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

A prekey message from a companion device carries <device-identity>
beside its <enc>. Pass it to the remote Signal store in
RemoteReceive.DeviceIdentity so it can verify the sender against its
account before decrypting.
@purpshell purpshell changed the title prekeys: keep each bundle's device identity prekeys, remote signal: keep companion device identities Nov 16, 2026
@purpshell

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 4792d8dfc2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 4792d8dfc2

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

A retry receipt's <keys> carry the requester's <device-identity> beside
its identity key. The remote path parsed the bundle but dropped it, so a
remote Signal store that verifies companions refused every companion
retry that brought fresh keys. Carry it in RemoteResend.DeviceIdentity.
@purpshell

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 88c3b217ff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 88c3b217ff

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant