Skip to content

ringconn: sm3 handshake + framing, no field decode - #48

Merged
abdulsaheel merged 2 commits into
mainfrom
feat/ringconn
Sep 5, 2026
Merged

ringconn: sm3 handshake + framing, no field decode#48
abdulsaheel merged 2 commits into
mainfrom
feat/ringconn

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

adds the RingConn (Gen 2 / Gen 2 Air / Gen 3) wire format as pure functions — SM3 auth handshake (keyed off the ring's own BLE MAC, no vendor secret), frame parsing, bulk-page slicing for both history channels.

structural only: reply tags, page lengths, record slicing. nothing inside a record is decoded — those layouts aren't verified against real hardware yet.

Summary by Sourcery

Add a pure-function RingConn protocol layer for authentication, framing, synchronization, and structural history-page parsing without decoding record contents.

New Features:

  • Add pure RingConn wire-format support for Gen 2, Gen 2 Air, and Gen 3 devices, including SM3 authentication, MAC recovery, framing, history synchronization commands, and bulk-page handling.
  • Expose RingConn protocol APIs through the package barrel.

Enhancements:

  • Keep bulk history records opaque while providing structural slicing for sleep/activity and PPG channels.
  • Support RingConn cursor conversion, reply classification, checksum validation, and outbound command construction as hardware-independent utilities.

Tests:

  • Add comprehensive unit coverage for SM3, MAC recovery, authentication responses, framing, bulk-page slicing, command layouts, and epoch conversion.

@sourcery-ai

sourcery-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces a publicly exported, hardware-independent RingConn Gen 2/2 Air/3 wire-format implementation: SM3-based authentication, framing and bulk-history record slicing, plus outbound commands, with comprehensive synthetic byte fixtures while intentionally leaving record fields undecoded and real-device behavior unverified.

Sequence diagram for the RingConn authentication and history sync flow

sequenceDiagram
    participant Host
    participant RingConn
    Host->>RingConn: ringConnCmdStatus()
    RingConn-->>Host: parseRingConnFrame(status challenge)
    Host->>Host: ringConnMacFromSystemId(systemId)
    Host->>Host: ringConnAuthResponse(mac, challenge)
    Host->>RingConn: ringConnCmdAuthResponse(response)
    Host->>RingConn: ringConnCmdSyncOpen(cursor, channel)
    RingConn-->>Host: parseRingConnFrame(sync-open reply)
    Host->>RingConn: ringConnCmdFetch()
    RingConn-->>Host: parseRingConnFrame(notification)
    alt bulk page
        Host->>Host: parseRingConnBulkPage(frame)
        Host->>RingConn: ringConnCmdAckPpg() or ringConnCmdAckActivity()
    else burst ends
        Host->>Host: ringConnEndsBurst(respid)
    end
Loading

Flow diagram for RingConn reply framing and bulk-page slicing

flowchart LR
    N[BLE notification bytes] --> P["parseRingConnFrame(value)"]
    P --> V{xorValid}
    V -->|valid| T["ringConnIsBulk(respid)"]
    V -->|invalid| R[Caller decides whether to drop or archive]
    T -->|yes| B["parseRingConnBulkPage(frame)"]
    T -->|no| E["ringConnEndsBurst(respid)"]
    B --> S[remaining count plus fixed-size raw records]
    E --> D[End current fetch burst]
Loading

File-Level Changes

Change Details Files
Adds a pure-function RingConn wire-format module covering SM3 authentication, MAC recovery, reply framing, history-page slicing, and outbound command construction.
  • Implements dependency-free SM3 hashing with padding, compression, and known-answer coverage.
  • Derives the ring MAC from System ID and generates the three-byte challenge response.
  • Parses status and XOR-trailed replies while reporting invalid trailers without discarding payloads.
  • Recognizes bulk PPG/activity pages and slices 47-byte or 23-byte records without decoding their contents.
  • Builds status, auth, sync-open, fetch, and page-ack commands with literal trailing zeros and cursor/channel fields.
lib/src/ringconn.dart
Exposes the RingConn protocol API through the package barrel.
  • Exports the new RingConn module from the public library entry point.
lib/openstrap_protocol.dart
Adds byte-level tests for the RingConn implementation and explicitly documents the hardware-validation boundary.
  • Tests SM3 against the published abc vector and boundary/determinism properties.
  • Covers MAC recovery variants, authentication response shape, frame parsing, reply classification, page slicing, command bytes, and epoch conversion.
  • Uses synthetic/self-consistent fixtures; does not validate record field layouts or authentication against captured hardware traffic.
test/ringconn_test.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 22 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 946efa27-3f8f-4bf6-b5f0-c00ffaa402b4

📥 Commits

Reviewing files that changed from the base of the PR and between b8430e4 and 4863800.

📒 Files selected for processing (3)
  • lib/openstrap_protocol.dart
  • lib/src/ringconn.dart
  • test/ringconn_test.dart

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@abdulsaheel
abdulsaheel merged commit 3eb98fe into main Sep 5, 2026
3 of 4 checks passed
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