feat(win): support authenticated PIN pairing - #135
Conversation
Relationship to #134I noticed #134 after preparing and testing this PR. There is meaningful overlap, so I want to acknowledge that work and clarify why this PR exists separately. #134 takes the broader approach of exposing This PR addresses a narrower missing capability: pairing devices that require the application to provide a PIN. The PIN is collected by the consuming application and passed to WinRT through There is no device- or application-specific behavior in this implementation:
Why #134 does not currently cover this use caseAt its current head, #134 explicitly rejects ceremonies requiring a PIN or password. In particular, it does not pass a caller-provided value to Microsoft describes custom pairing as application-participated pairing: for https://learn.microsoft.com/en-us/uwp/api/windows.devices.enumeration.devicepairingkinds https://learn.microsoft.com/en-us/windows/uwp/devices-sensors/pair-devices I also noticed what appears to be an enum-value mismatch in #134. Its JavaScript constants currently use:
The documented WinRT values are:
Unless there is an intended translation layer that I missed, passing the current JavaScript values directly into the native WinRT enum would select different or undefined ceremonies. For example, the exported There is also an important behavioral distinction around Possible way forwardI do not intend this PR to dismiss or compete with #134. That PR contains useful work around exposing pairing kinds, protection levels, validation, documentation, and tests. If the maintainers prefer #134’s generalized API, I am happy to adapt this implementation so the two approaches converge—for example, by extending a common options object with pairing kinds, protection level, and an optional caller-provided PIN. The important requirements for this PR are:
I wanted to document the relationship explicitly so the two PRs can be evaluated or combined without duplicating work. |
|
please rebase |
9cff35a to
9d632e5
Compare
Extend the Windows pairing API with optional caller-provided PINs while preserving ConfirmOnly behavior for callers without pairing options and compatibility with the established native PIN call shape. Expose PairOptions through Noble and Peripheral callback and async APIs, add paired-state helpers, and derive the required WinRT custom pairing kinds and authenticated protection level for PIN entry and PIN confirmation. Keep PIN values out of logs and retain existing error handling on unsupported platforms. Document the platform behavior and cover legacy delegation, PIN forwarding, pairing state, async APIs, and Peripheral delegation with regression tests.
Windows delivers the advertising packet and its scan response as separate watcher events. The follow-up can contain Complete Local Name while omitting the service UUID that matched the initial packet, so applying the service filter independently discarded the name update. Keep follow-up packets only for addresses already accepted into the device map. Unmatched devices remain filtered, while an existing peripheral can consume the complete advertised name and emit an updated discovery event.
9d632e5 to
537f4a6
Compare
|
done |
Extend the existing Windows pairing API with optional caller-provided PINs while preserving the current ConfirmOnly behavior for callers that do not pass pairing options.
Expose PairOptions through the Noble and Peripheral callback and async APIs, and add isPaired helpers so applications can avoid prompting users when WinRT already reports a durable bond. Bindings without pairing-state support continue to report false, and unsupported-platform pairing retains its existing deterministic error behavior.
On WinRT, accept ProvidePin requests with the supplied value and accept ConfirmPinMatch only when the displayed PIN matches. PIN-based requests require EncryptionAndAuthentication; calls without a PIN continue to request ConfirmOnly with Encryption exactly as before. Keep PIN values out of logging and retain the existing pairing result and exception handling paths.
Document the platform behavior and add regression coverage for legacy callback signatures, no-option delegation, PIN forwarding, paired-state queries, async options, and Peripheral delegation.