Skip to content

Fix pairing PSK flow and add QR code pairing - #212

Merged
maximmaxim345 merged 8 commits into
mainfrom
fix/pairing-psk-flow
Oct 28, 2026
Merged

maximmaxim345 merged 8 commits into
mainfrom
fix/pairing-psk-flow

Conversation

@maximmaxim345

@maximmaxim345 maximmaxim345 commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

What does this implement/fix?

Pairing with a pairing token skipped client/pair-init before client/pair-finalize, which the spec requires, so a spec compliant server would reject it. Pairing again with the same server also kept the old record next to the new one. Both are fixed.

The bare pairing PSK is no longer part of the public API. pairingPsk is removed from SendspinPlayer, SendspinCore and loadSendspinClientIdentity(), and rotatePairingPsk() now returns the new pairing token.

Apps that can show a QR code can now offer the dynamic pairing code as one with pairingCodeFormats: ['digits', 'qr_code']. When the server picks it, onPairingCode receives a pairing token and format set to "qr_code", and the app renders it with a QR library of its choice. The sample player shows this. I tested it against aiosendspin, which paired with the token decoded from the sample player's QR code.

Related issue or spec PR (if applicable):

Types of changes

  • Bugfix (non-breaking change which fixes an issue): bugfix
  • New feature (non-breaking change which adds functionality): new-feature
  • Enhancement to an existing feature: enhancement
  • Breaking change (changes the public API or the protocol in a way that is not backwards compatible): breaking-change
  • Refactor (no behavior change): refactor
  • Documentation only: documentation
  • Maintenance / chore: maintenance
  • CI / workflow change: ci
  • Dependencies bump: dependencies

Compliant servers treated the lone `client/pair-finalize` as a sequence
violation and closed the connection, so pairing with the pairing token
failed.
Re-pairing added a second record next to the old one, so the old PSK
still opened a connection to that server and records piled up.
`pairingPsk` is removed from `SendspinPlayer`, `SendspinCore` and
`loadSendspinClientIdentity()`, and `rotatePairingPsk()` returns the
new pairing token. The bare PSK lacks the client key a server needs to
pair.
@maximmaxim345
maximmaxim345 requested a balanced review from Copilot October 28, 2026 09:28
@github-actions github-actions Bot added the breaking-change Changes the public API or the protocol in a way that is not backwards compatible label Oct 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The started callback fires while Pairing-PSK is still idle, causing synchronous cancelPairing() calls to be ignored and the attempt to continue.

1 open issue
What changed in this PR

This PR corrects pairing-token handling in the Sendspin SDK and adds optional QR-code pairing, with corresponding sample-player controls and documentation. It also makes a breaking API change by exposing pairing tokens instead of bare pairing PSKs.

Changes:

  • Send client/pair-init before PSK finalization and replace existing credentials for the same server.
  • Add QR-format negotiation, code derivation, token encoding, and sample rendering.
  • Remove public pairingPsk access and make rotatePairingPsk() return a pairing token.
File Description
tests/​unit/​pairing.test.ts Test PSK sequencing, credential replacement, and QR pairing.
tests/​unit/​noise/​psk.test.ts Verify persisted replacement of server credentials.
tests/​unit/​noise/​pairing-token.test.ts Add a version 1 token reference vector.
tests/​unit/​core-encryption.test.ts Adapt encryption tests to token-only public access.
tests/​unit/​client-identity.test.ts Update identity tests for the removed PSK field.
tests/​helpers/​known-violations.ts Remove the resolved PSK sequencing violation.
src/​types.ts Define pairing-format configuration and callback metadata.
src/​index.ts Forward format options and update the public pairing API.
src/​core/​pake/​pin.ts Derive 24-byte QR pairing codes.
src/​core/​pairing.ts Implement QR pairing and revise PSK attempt handling.
src/​core/​noise/​psk.ts Replace long-term credentials by server ID.
src/​core/​noise/​pairing-token.ts Share token encoding and support version 1 tokens.
src/​core/​core.ts Wire format options and return tokens on rotation.
src/​client-identity.ts Remove bare PSKs from identity results.
README.md Document QR pairing and token-based API usage.
public/​app.js Persist QR preferences and render pairing QR codes.
index.html Add QR display and configuration controls.

Review effort: Balanced

Comment thread src/core/pairing.ts Resolved
# Conflicts:
#	src/core/pairing.ts
#	tests/helpers/known-violations.ts
#	tests/unit/pairing.test.ts
An app calling cancelPairing() from its started callback was ignored, since the attempt was still idle.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The QR code has only a half-module white border instead of the required four-module quiet zone, making scanning unreliable against the sample player’s dark background.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread public/app.js Resolved
The 2-pixel margin left half a module of white border, and scanners need four modules.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Independent interoperability review is needed because QR pairing changes PAKE inputs and wire-token format, while the specification was unavailable and the added test uses the same implementation for both peers.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@maximmaxim345
maximmaxim345 merged commit fa82dd1 into main Oct 28, 2026
5 checks passed
@maximmaxim345
maximmaxim345 deleted the fix/pairing-psk-flow branch October 28, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Changes the public API or the protocol in a way that is not backwards compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants