Repository navigation
Fix pairing PSK flow and add QR code pairing - #212
Conversation
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.
There was a problem hiding this comment.
🟡 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-initbefore PSK finalization and replace existing credentials for the same server. - Add QR-format negotiation, code derivation, token encoding, and sample rendering.
- Remove public
pairingPskaccess and makerotatePairingPsk()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
# 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.
The 2-pixel margin left half a module of white border, and scanners need four modules.
There was a problem hiding this comment.
🔵 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

What does this implement/fix?
Pairing with a pairing token skipped
client/pair-initbeforeclient/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.
pairingPskis removed fromSendspinPlayer,SendspinCoreandloadSendspinClientIdentity(), androtatePairingPsk()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,onPairingCodereceives a pairing token andformatset 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
bugfixnew-featureenhancementbreaking-changerefactordocumentationmaintenancecidependencies