Skip to content

feat(pro2): add auto-detected Protocol V2 over WebUSB and BLE#773

Draft
wabicai wants to merge 254 commits into
onekeyfrom
feat/pro2-usb-ble
Draft

feat(pro2): add auto-detected Protocol V2 over WebUSB and BLE#773
wabicai wants to merge 254 commits into
onekeyfrom
feat/pro2-usb-ble

Conversation

@wabicai

@wabicai wabicai commented Apr 24, 2026

Copy link
Copy Markdown
Member

Summary

  • Add Pro2 Protocol V2 support for WebUSB and Electron BLE with connection-time active probing.
  • Stop using PID/productName/descriptor as the protocol switch; transports send GetProtoVersion after connect and fall back to Protocol V1 on timeout or failure.
  • Keep desktop-web-ble as the default Electron BLE entry. desktop-web-ble-pro2 is now only a compatibility alias that maps to the same auto-detect transport.
  • Update Pro2 runtime schema and generated TypeScript types from firmware-pro2 so Filesystem*, DevFirmwareUpdate, and DevReboot are available through typed calls.
  • Update Pro2 firmware update flow so resource, bootloader, and firmware files all enter DevFirmwareUpdate.targets.
  • Refresh architecture, transport, protocol, and Claude entry docs for the V1/V2 split, active probing, schema routing, and Pro2 file/update flows.

Architecture

Protocol split

  • Protocol V1: existing Classic / Mini / Touch / Pro devices; supports USB and BLE; initializes with Initialize -> Features.
  • Protocol V2: Pro2; supports USB and BLE; initializes through GetProtoVersion probing and Ping.

Transport behavior

  • TransportManager configures both messages.json and messages-pro2.json when the transport supports Protocol V2.
  • WebUSB discovers interface/endpoints from USB descriptors, but protocol selection is based only on the GetProtoVersion device response.
  • Electron BLE connects/subscribes first, then probes V2. If probing fails, it keeps the legacy V1 BLE packet flow.
  • Device.acquire() reads the detected protocol through getProtocolType() and stores it on originalDescriptor.protocolType before initialization.

Pro2 initialization and update

  • Pro2 skips legacy Initialize/GetFeatures; SDK verifies the link with Ping and synthesizes minimal Features with stable device_id, serial_no, and onekey_serial_no.
  • Pro2 file/update APIs use FilesystemDirMake, FilesystemFileWrite, DevFirmwareUpdate, and DevReboot from the generated Pro2 type surface.
  • DevFirmwareUpdate.targets includes resource, bootloader, and firmware targets explicitly.

Review Findings Addressed

  • Shared PID no longer causes V1 WebUSB devices to be forced into V2 framing.
  • Pro2 WebUSB synthetic features now preserve a stable connectId/uuid source.
  • hd-transport tests now import Protocol V1 from serialization/protocol-v1.
  • Resource and bootloader uploads are included in Pro2 firmware update targets.
  • Pro2 messages are generated into the runtime JSON and TypeScript MessageType union.

Firmware Pro2 Source

  • Submodule: submodules/firmware-pro2
  • Branch source: origin/dev_romloader_split
  • Commit: 504b8752bba68c289769c320cf27d1a7bfcbfed4
  • Commit date: 2026-04-23 14:57:42 +0800

main/dev do not currently provide the required latest Pro2 schema surface used here, especially the Filesystem* and DevFirmwareUpdate messages.

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.md
  • yarn --cwd packages/hd-transport-web-device build
  • yarn --cwd packages/hd-common-connect-sdk build
  • yarn --cwd packages/hd-transport test --runInBand
  • yarn --cwd packages/hd-transport build
  • yarn --cwd packages/core build
  • NODE_OPTIONS=--max-old-space-size=8192 yarn lint --quiet
  • git diff --check

Hardware Validation Still Needed

  • Real Pro2 WebUSB smoke test for GetProtoVersion, Ping, file write, and firmware update.
  • Real Pro2 Electron BLE smoke test for auto-detect V2, fallback safety, and multi-chunk file write.
  • Legacy V1 WebUSB/BLE smoke test with Mini/Touch/Pro to confirm V2 probe fallback in real hardware.

@revan-zhang

revan-zhang commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Snyk checks have failed. 1 issues have been found so far.

Status Scan Engine Critical High Medium Low Total (1)
Open Source Security 0 0 0 0 0 issues
Licenses 0 1 0 0 1 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@socket-security

socket-security Bot commented Apr 24, 2026

Copy link
Copy Markdown

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.

View full report

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
wabicai force-pushed the feat/pro2-usb-ble branch from 312143a to 90bd1bd Compare April 27, 2026 07:24
@wabicai wabicai changed the title feat(pro2): WebUSB + BLE transport with Proto Link protocol feat(pro2): add auto-detected Protocol V2 over WebUSB and BLE Apr 27, 2026
@socket-security

socket-security Bot commented May 11, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​@​onekeyfe/​hd-common-connect-sdk@​1.1.15 ⏵ 1.1.26-alpha.881 +31008196100
Addedpypi/​pyusb@​1.3.198100100100100
Addedpypi/​libusb-package@​1.0.30.0100100100100100

View full report

wabicai and others added 23 commits June 5, 2026 17:33
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>
wabicai added 30 commits July 17, 2026 16:33
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.

2 participants