feat(pro2): add auto-detected Protocol V2 over WebUSB and BLE#773
Draft
wabicai wants to merge 254 commits into
Draft
feat(pro2): add auto-detected Protocol V2 over WebUSB and BLE#773wabicai wants to merge 254 commits into
wabicai wants to merge 254 commits into
Conversation
Contributor
⛔ Snyk checks have failed. 1 issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
All alerts resolved. Learn more about Socket for GitHub. This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
wabicai
added a commit
that referenced
this pull request
Apr 27, 2026
The PR #773 lint job failed in `pinentry.test.ts` with `Cannot use import statement outside a module` because the hd-cli package was missing jest.config.js. Other workspaces (hd-transport, core, hwk-ledger-*) already inherit the root preset that wires up babel-jest + @babel/preset-typescript; hd-cli was the only one running plain Jest defaults, so any TS test file failed to parse. Mirror the existing pattern: preset → root jest.config.js, testEnvironment → node, ignore dist/. Local `yarn test` in hd-cli now passes 23/23 (pinentry parser tests). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
wabicai
added a commit
that referenced
this pull request
Apr 27, 2026
- `packages/hd-cli/jest.config.js`: add the workspace's missing jest config so unit tests can transform TypeScript. Mirrors the pattern used by hd-transport / core / hwk-ledger-* (preset → root jest.config.js, testEnvironment → node, ignore dist/). Fixes the PR #773 lint job, which was failing in `pinentry.test.ts` with `Cannot use import statement outside a module` because Jest was running with bare defaults. - `pinentry.ts` / `pinentry.test.ts`: small refactor to the Assuan parser surface — same observable behavior, less code. - `sdk.ts`: minor cleanup that drifted in alongside. - `hwk-adapter-core/src/__tests__/core-types.test.ts`: keep the Pro2 device-type addition compiling under the existing test expectations. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
wabicai
force-pushed
the
feat/pro2-usb-ble
branch
from
April 27, 2026 07:24
312143a to
90bd1bd
Compare
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Pro2 debug page (`expo-playground/app/routes/pro2-debug.tsx`):
- Wire-level testing tool that talks to Pro2 over WebUSB directly,
bypassing the SDK transport stack. Used to isolate protocol-frame
/ CRC / message-encoding bugs from the SDK plumbing.
- Four tabs:
* Ping — connection sanity check
* File System — DirList, PathInfoQuery, FileRead, FileWrite,
FileDelete, DirMake, DirRemove, FixPermission
* Firmware — single-target FirmwareUpdate with manual target_id /
path / reboot_on_success controls
* Reboot — sends Reboot { reboot_type: Normal/Boardloader/BootLoader }
- Carries its own minimal protobuf encoder/decoder for the Pro2
message subset; deliberately does not depend on the SDK so it
remains usable as a fault-isolation tool when the SDK is broken.
Static WebUSB test page (`expo-playground/public/webusb_test.html`):
- Single-file HTML harness for the same Pro2 protocol (predates the
React debug page). Kept under `public/` so Vercel serves it without
a route. Useful for cross-browser / cross-machine debugging where
setting up the playground app is overkill.
Vercel deployment:
- `vercel.json` at repo root; root `package.json` carries the build
glue. Lets us deploy the playground (including pro2-debug and
webusb_test.html) under a stable preview URL for the firmware team
to test against without local toolchain setup.
Sidebar + entry client tweaks add the pro2-debug route to the
playground navigation.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds Pro2 connection paths and firmware-update entry to the example app, so end-to-end Pro2 SDK flows can be exercised from a real UI (not just the wire-level pro2-debug page). - `deviceConnectAtoms.ts` / `hardwareInstance.ts`: track and route the new `desktop-web-ble-pro2` env alongside the existing webusb / desktop-web-ble options. Default to `desktop-web-ble-pro2` when running inside Electron so Pro2 BLE is the path most users land on. - `DeviceList.tsx` / `FirmwareScreen/index.tsx`: connection-type picker on both home and firmware-update screens; the picker triggers a transport switch that requires an app restart in some envs (the underlying transport instance is a singleton). Firmware-update screen shows the V3 entry for both Pro and Pro2; Pro2 path renders as "Firmware Update V3 (Pro2 Protocol V2)". - Minor cleanups in `passphraseTest/TestSessionCountView.tsx` and `views/SLIP39TestScreen.tsx` that drifted in alongside the Pro2 work. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- `docs/transport.md`: rewritten end to end. Side-by-side comparison of Protocol V1 (`##` header, 64-byte chunked, requires Initialize handshake) vs Protocol V2 (`0x5A` framing, single-frame up to 2200 bytes, no handshake, CRC8 validated). Wire format diagrams, schema selection rules, PID-based detection, architecture layers. - `docs/pro2-protocol.md`: new deep dive on Protocol V2 framing (Proto Link headers, channel/attr/seq fields, CRC8 algorithm), Pro2 message catalog (60000-series IDs), WebUSB and BLE I/O specifics including BLE notification reassembly and channel routing through the BLE coprocessor's UART bridge. - `OneKey_Pro2_Deep_Dive.md`: high-level Pro2 architecture notes (storage layout, secure-element targets, firmware partition map) for engineers onboarding to the Pro2 stack. - `CLAUDE.md`: minor refresh of repo-wide instructions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- `packages/hd-cli/jest.config.js`: add the workspace's missing jest config so unit tests can transform TypeScript. Mirrors the pattern used by hd-transport / core / hwk-ledger-* (preset → root jest.config.js, testEnvironment → node, ignore dist/). Fixes the PR #773 lint job, which was failing in `pinentry.test.ts` with `Cannot use import statement outside a module` because Jest was running with bare defaults. - `pinentry.ts` / `pinentry.test.ts`: small refactor to the Assuan parser surface — same observable behavior, less code. - `sdk.ts`: minor cleanup that drifted in alongside. - `hwk-adapter-core/src/__tests__/core-types.test.ts`: keep the Pro2 device-type addition compiling under the existing test expectations. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GetProtoVersionafter connect and fall back to Protocol V1 on timeout or failure.desktop-web-bleas the default Electron BLE entry.desktop-web-ble-pro2is now only a compatibility alias that maps to the same auto-detect transport.firmware-pro2soFilesystem*,DevFirmwareUpdate, andDevRebootare available through typed calls.DevFirmwareUpdate.targets.Architecture
Protocol split
Initialize -> Features.GetProtoVersionprobing andPing.Transport behavior
TransportManagerconfigures bothmessages.jsonandmessages-pro2.jsonwhen the transport supports Protocol V2.GetProtoVersiondevice response.Device.acquire()reads the detected protocol throughgetProtocolType()and stores it onoriginalDescriptor.protocolTypebefore initialization.Pro2 initialization and update
Initialize/GetFeatures; SDK verifies the link withPingand synthesizes minimalFeatureswith stabledevice_id,serial_no, andonekey_serial_no.FilesystemDirMake,FilesystemFileWrite,DevFirmwareUpdate, andDevRebootfrom the generated Pro2 type surface.DevFirmwareUpdate.targetsincludes resource, bootloader, and firmware targets explicitly.Review Findings Addressed
hd-transporttests now import Protocol V1 fromserialization/protocol-v1.MessageTypeunion.Firmware Pro2 Source
submodules/firmware-pro2origin/dev_romloader_split504b8752bba68c289769c320cf27d1a7bfcbfed42026-04-23 14:57:42 +0800main/devdo not currently provide the required latest Pro2 schema surface used here, especially theFilesystem*andDevFirmwareUpdatemessages.Docs
CLAUDE.md: Claude / Agent workflow entry, task routing, Pro2 caveats, and verification commands.docs/README.md: local documentation hierarchy and maintenance rules.docs/architecture.md: SDK layering, V1/V2 ownership, active protocol detection, Device/TransportManager responsibilities.docs/transport.md: WebUSB/BLE probing flow, schema routing, Pro2 firmware update flow, compatibility boundaries.docs/pro2-protocol.md: Protocol V2 frame format, protobuf payload, message IDs, WebUSB/BLE behavior, file write and firmware update messages.Test Plan
yarn prettier --write README.md docs/README.md CLAUDE.md docs/architecture.md docs/transport.md docs/pro2-protocol.mdyarn --cwd packages/hd-transport-web-device buildyarn --cwd packages/hd-common-connect-sdk buildyarn --cwd packages/hd-transport test --runInBandyarn --cwd packages/hd-transport buildyarn --cwd packages/core buildNODE_OPTIONS=--max-old-space-size=8192 yarn lint --quietgit diff --checkHardware Validation Still Needed
GetProtoVersion,Ping, file write, and firmware update.