Skip to content

Add OneKey device support #826

Open
wabicai wants to merge 3 commits intobitcoin-core:masterfrom
wabicai:feature/onekey-hwi-sidecar
Open

Add OneKey device support #826
wabicai wants to merge 3 commits intobitcoin-core:masterfrom
wabicai:feature/onekey-hwi-sidecar

Conversation

@wabicai
Copy link

@wabicai wabicai commented Feb 25, 2026

Summary

This PR adds native OneKey support to HWI and wires it into simulator-backed tests/CI.

Compared with the original revision, the current implementation no longer tries to extend the generic trezorlib.client logic directly. Instead, OneKey-specific behavior is isolated on the OneKey side in hwilib.devices.onekey and hwilib.devices.onekeylib.

Main changes:

  • add hwilib.devices.onekey as the HWI entrypoint for OneKey devices
  • add hwilib.devices.onekeylib/* to keep OneKey-specific model/profile/transport/client compatibility logic out of generic Trezor code
  • detect OneKey devices by USB IDs and OneKey product/vendor markers
  • exclude OneKey transports from trezor.enumerate() so Trezor enumeration is not polluted
  • support model-aware behavior for legacy-style and core-style OneKey devices
  • add simulator coverage for both OneKey Pro and OneKey Classic 1S
  • add CI build/install/test wiring for OneKey simulators
  • slim simulator artifacts to the minimum runtime paths needed by CI
  • add OneKey udev rules, device docs, and Qt passphrase-toggle exposure

Reviewer Guide

If you want to review this efficiently, the main areas are:

  1. Device implementation
  • hwilib/devices/onekey.py
  • hwilib/devices/onekeylib/protocol.py
  • hwilib/devices/onekeylib/features.py
  • hwilib/devices/onekeylib/transport.py
  • hwilib/devices/onekeylib/client.py

What to check:

  • OneKey-specific behavior is contained on the OneKey side
  • model/profile normalization is correct for Pro vs Classic 1S
  • transport/device detection does not interfere with Trezor enumeration
  • simulator paths still use the vendored Trezor message/transport stack safely
  1. Emulator / test integration
  • test/test_onekey.py
  • test/run_tests.py
  • test/setup_environment.sh
  • test/data/onekey-firmware-build.patch
  • test/data/onekey-classic1s-emulator.patch

What to check:

  • HWI can boot and talk to both simulators
  • test coverage is aligned with the current reviewer request for simulator-backed validation
  • firmware patches are scoped to emulator/debug/test enablement rather than changing production behavior
  1. CI wiring
  • .github/actions/build-sim/action.yml
  • .github/actions/install-sim/action.yml
  • .github/sim-build-map.json
  • .github/workflows/ci.yml
  • .github/workflows/device-test.yml
  • .github/workflows/prepare-sim-matrices.yml

What to check:

  • OneKey simulator build/install/test matrix is correctly wired
  • artifact contents are minimized but still sufficient to boot the emulators in CI

Firmware Snapshots Used By CI

To keep CI reproducible, simulator builds use pinned firmware snapshots:

  • OneKey Pro: 3bb8767e55f88005830880d4f797e91d4077ee01
  • OneKey Classic 1S: ee01f0114fd18dbdf3da3ee8de5dec9b391f1bc8

The HWI test harness currently applies two local patches when building these snapshots:

  • test/data/onekey-firmware-build.patch
  • test/data/onekey-classic1s-emulator.patch

These patches are there to make the current pinned emulator builds reliable under automated HWI tests and CI packaging. They are not intended as production firmware changes.

Validation

Local validation completed for the current revision:

  • python -m unittest test_onekey -> passed (Ran 14 tests, OK)
  • test/run_tests.py --onekey-classic1s --interface=library --device-only -> passed (Ran 24 tests, OK)
  • OneKey Pro smoke checks passed for library, cli, and stdin
  • OneKey Classic 1S smoke checks passed for library, cli, and stdin
  • minimal CI artifact contents were verified locally for both Pro and Classic 1S emulator startup

Smoke coverage included at least:

  • enumerate
  • getmasterxpub

Notes

  • This PR still reuses the vendored Trezor transport/message stack, but OneKey-specific client/profile handling now lives in OneKey-owned code paths instead of generic Trezor client code.
  • The current reviewer request on the upstream PR was specifically about simulator integration and simulator-backed testing, so this revision focuses on that path explicitly.

@wabicai
Copy link
Author

wabicai commented Feb 25, 2026

Added follow-up updates in 7f1b7be:

  • Added unit tests for OneKey helper detection and Trezor-side OneKey transport filtering (test/test_onekey.py).
  • Added a short support-matrix note in docs clarifying OneKey currently follows the Trezor transport/command path.

Validation:

  • python -m unittest test.test_onekey
  • python -m flake8 hwilib/devices/onekey.py hwilib/devices/trezor.py test/test_onekey.py

There is still no public OneKey emulator for CI end-to-end flows, so device-flow verification remains manual for now.

@wabicai
Copy link
Author

wabicai commented Feb 28, 2026

@achow101 could you review this PR?

@wabicai wabicai changed the title Add OneKey device support via Trezor transport path Add OneKey device support Feb 28, 2026
@wabicai
Copy link
Author

wabicai commented Mar 4, 2026

@Sjors Could you take a look for this PR?

@achow101
Copy link
Member

achow101 commented Mar 5, 2026

A simulator/emulator is required for new devices, and must be tested via CI.

@wabicai wabicai marked this pull request as draft March 16, 2026 03:28
@wabicai wabicai force-pushed the feature/onekey-hwi-sidecar branch from 3f445ff to cbf86fe Compare March 17, 2026 02:54
@wabicai wabicai marked this pull request as ready for review March 20, 2026 08:49
@wabicai
Copy link
Author

wabicai commented Mar 20, 2026

A simulator/emulator is required for new devices, and must be tested via CI. @achow101

I have already integrated the simulator and other components in my local repository. Please review again.

https://github.com/wabicai/HWI/actions/runs/23335510061

wabicai added 3 commits March 23, 2026 22:32
Add OneKey device support to HWI, covering all OneKey models
(Pro, Classic, Classic 1S, Mini, Touch, Pure).

- hwilib/devices/onekey.py: Full HWI device interface including
  enumerate, get_pubkey_at_path, get_master_xpub, sign_tx,
  sign_message, display_singlesig/multisig_address, setup/wipe/restore
- hwilib/devices/onekeylib/: OneKey-specific client library with
  protocol profiles, DebugLink support, transport layer, and
  feature detection per model
- hwilib/udev/51-usb-onekey.rules: Linux udev rules for OneKey USB
- docs/devices/index.rst: Documentation reference
24 test cases per model covering enumerate, fingerprint detection,
getdescriptors, getkeypool, signtx (single + multisig), displayaddress
(single + multisig + descriptor), signmessage, getxpub, and label.

OneKey Pro emulator patch (onekey-pro-firmware-build.patch):
- Skip boot_animation + lvgl_tick in emulator (direct config.unlock)
- StatusBar stub to avoid LVGL widget creation crashes
- _emu_confirm() guards on UI confirm functions (confirm_output,
  confirm_total, confirm_signverify, confirm_action, confirm_blob,
  show_address, show_popup, etc.) to skip LVGL screen creation
- Simplified dispatch_debuglink_decision for LVGL compatibility
- loop.close() cleanup fix for _paused dict entries

OneKey Classic 1S emulator patch (onekey-classic1s-emulator.patch):
- DebugLink button_request fix for address display flow
- Emulator guards for layoutSignMessage and fsm_layoutAddress
- cryptoMultisigPubkeyIndex leaf pubkey fallback
- signing_sign_ecdsa hdnode_fill_public_key fix

Test infrastructure:
- SIGALRM-based 30s PINGPING timeout for reliable emulator startup
- supports_idle_auto_press=True for Pro DebugLink auto-confirm
- ONEKEY_UDP_PORT environment variable for emulator communication
- sim-builder-onekey: builds both Pro and Classic 1S emulators
- test-onekey-pro: 24 test jobs (4 Python versions × 6 interfaces)
- test-onekey-classic1s: 24 test jobs
- install-sim: Xvfb setup for Pro's SDL display, apt dependencies
- sim-build-map: onekey-pro and onekey-classic1s archive definitions
- prepare-sim-matrices: onekey family matrix generation
- device-test: 60-minute timeout for OneKey Pro (comparable to Trezor T)
@wabicai wabicai force-pushed the feature/onekey-hwi-sidecar branch from cf144b9 to 09e7ba4 Compare March 23, 2026 14:34
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.

3 participants