Skip to content

feat: add standalone Electrum plugin for Pro2 and Neo - #998

Merged
wabicai merged 58 commits into
onekeyfrom
feat/electrum-plugin
Dec 1, 2026
Merged

wabicai merged 58 commits into
onekeyfrom
feat/electrum-plugin

Conversation

@wabicai

@wabicai wabicai commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds a standalone Electrum plugin for OneKey Pro 2 and Neo in plugins/electrum/, version 0.1.0. python3 plugins/electrum/build.py builds onekey-0.1.0.zip, which users import from Electrum's plugin window (Electrum ≥ 4.8.4). The ZIP holds only Python code and icons, well below Electrum's 10 MB limit.

The plugin talks to the firmware's Protocol V2 (proto_link, USB 1209:4f4c) inside the Electrum process. It starts no Node.js process and needs only libusb1, which Electrum already bundles for hardware wallets. Older OneKey devices (Classic, Classic 1S, Mini, Touch, Pro) are not supported by this plugin.

Supported

  • Bitcoin and Testnet single-signature wallets: P2PKH, P2WPKH-P2SH and P2WPKH.
  • Sorted multisig: p2sh, p2wsh-p2sh and p2wsh, including adding one partial cosignature. Each pubkey gets an empty signature slot, as in Electrum's Trezor plugin, because firmware-pro2 indexes signatures[i] when it builds a P2SH multisig scriptSig.
  • Address display on the device, transaction signing and traditional message signing for single-signature wallets.
  • Account paths follow the firmware-pro2 Bitcoin keychain; a path the device could not sign from is refused when the wallet is created.

Wallet selection

A new wallet follows how the device is unlocked, as in Electrum's Ledger plugin: a locked device accepts either PIN (PIN_ANY), the Main PIN opens the standard wallet and an Attach PIN opens its hidden wallet. As in the Trezor plugin, a Main PIN unlock with passphrase enabled asks whether to use the standard wallet or enter a passphrase on the device. The script page has no wallet options and the passphrase is never entered on the host.

Keystores save only a public binding (serialNo, deviceId, walletType, passphraseState) and the account xpub. Firmware session IDs stay in memory. The binding and the unlock state are checked before and after every key, address and signing request, and a saved hidden wallet is reopened only after its passphrase state matches.

Electrum integration

  • Devices are labelled by their Bluetooth name (for example Neo 36B1), falling back to the serial.
  • The status bar shows the OneKey logo for each OneKey keystore, grey while the device is unpaired.
  • Electrum derives keys and addresses locally, requires full previous transactions and SIGHASH_ALL, and verifies returned signatures on a copy of the transaction before applying them.
  • Cancel, timeout and protocol errors never replay a request; a cancelled dialog keeps the device paired.

Host dependencies

Linux udev rules and Windows USB drivers are not installed by the plugin. onekey/56-onekey.rules (VID 1209, PID 4f4c) is included as a reference.

Verification

  • PYTHONPATH=plugins/electrum python -m pytest plugins/electrum/tests -q: 190 passed, 453 subtests passed.
  • Flake8 E9,F63,F7,F82 passed.
  • On a real Neo and Pro 2: device discovery, the Bluetooth name while locked, and creating a 2-of-2 multisig wallet. The P2SH multisig signing fix has not been signed on a real device yet, and hidden wallet, Attach PIN and cancel/reconnect flows still need a full device pass.

The same plugin is proposed upstream in spesmilo/electrum#11161.

@socket-security

socket-security Bot commented Nov 18, 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
Addedpypi/​libusb1@​3.4.09510010010070
Addedpypi/​pyqt6@​6.10.29810010010070
Addedpypi/​pytest@​9.2.086100100100100
Addedpypi/​flake8@​7.5.0100100100100100

View full report

Keep Electrum wallet and transaction validation in Python while using a bounded stdio helper for SDK USB, protocol and session management. Add cancellation, wallet binding, runtime integrity checks and focused regression tests.

Validation: 42 Node tests and 9 Python IPC tests passed. Real SDK/native build and Electrum security/loader tests remain dependency-DNS blocked; lint dependencies are missing. Hardware and platform validation are outstanding. Commit hooks skipped once with explicit user approval.
@wabicai
wabicai marked this pull request as ready for review November 19, 2026 07:25

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 3 potential issues.

Devin Review

Comment thread plugins/electrum/helper/pin.cjs Resolved
Comment thread plugins/electrum/onekey/client.py Resolved
Comment thread plugins/electrum/onekey/onekey.py Resolved
@sidmorizon

Copy link
Copy Markdown
Contributor

@codex review

@sidmorizon

Copy link
Copy Markdown
Contributor

@codex security review

@sidmorizon

Copy link
Copy Markdown
Contributor

Cursor review failed.

Remote error: cursor_permission_denied: HTTP 403 Forbidden: Cloud Agent is not available for free users. Please upgrade to Pro.

@cursor

cursor Bot commented Nov 19, 2026

Copy link
Copy Markdown

Skipping Bugbot: Bugbot is disabled for this repository. Visit the Bugbot dashboard to update your settings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T07:36:58.093588Z fbbb5ea Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Unknown error
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sidmorizon

Copy link
Copy Markdown
Contributor

Devin Cloud review ↗

@sidmorizon

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: fbbb5ea9a2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plugins/electrum/onekey/onekey.py Resolved
Comment thread plugins/electrum/onekey/client.py Resolved
Comment thread plugins/electrum/helper/runtime.cjs Resolved
Comment thread plugins/electrum/helper/runtime.cjs Resolved
Comment thread plugins/electrum/onekey/client.py Resolved
Comment thread plugins/electrum/onekey/onekey.py Resolved
Comment thread plugins/electrum/helper/pin.cjs Resolved
Comment thread plugins/electrum/helper/runtime.cjs Resolved
Comment thread plugins/electrum/onekey/ipc.py Resolved
Comment thread plugins/electrum/onekey/client.py Resolved
…side the plugin

The plugin zip stays under Electrum's 10 MB limit. onekey-runtime carries
Node 22.21.1 for the six desktop targets and is installed next to it.
Review fixes keep the public wallet binding, use Electrum's storage
derivation, and ignore disconnects for another device. A locked Pro2/Neo
can enter the wizard before device_id exists. A new-wallet xpub fetch does
not reuse the previous selection. Closing one wallet or a cancelled call
no longer kills another live client or accepts a late success frame. SDK
dispose runs before the cancel acknowledgement. The source pin is
38f0b8c, which is already on onekey.
Comment thread plugins/electrum/onekey/ipc.py Resolved
Comment thread plugins/electrum/onekey/client.py Resolved
Comment thread plugins/electrum/onekey/client.py Resolved
Comment thread plugins/electrum/install_runtime.py Resolved
Comment thread plugins/electrum/onekey/client.py Resolved
Comment thread plugins/electrum/onekey/client.py Resolved
wabicai and others added 3 commits November 30, 2026 10:47
…cancelled

A wizard status read shared the client's dialog cancel event. Cancelling its
device dialog was treated as a lost connection, which detached the client and
dropped its wallet resume entry, and left that event set so the next operation
was cancelled at once. Each wizard read now gets its own dialog event, and
either it or the page token counts as an intentional stop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Electrum showed "OneKey Neo (OneKey Neo (NED48C04528))": the plugin label
repeated the model and exposed the serial number. DeviceInfoGet now also asks
for the coprocessor's specific info, and the client label is the Bluetooth
advertising name the user sees on the device and in the OneKey app (for
example "Neo 36B1", Pro 2 names normalized to "Pro 2 XXXX"). The serial is
the fallback label and still drives identity and wallet bindings. An invalid
name is dropped and never fails the identity read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and Ledger

Electrum's Trezor and Ledger plugins put no wallet options on the script
page. Align with them:

- A new wallet follows how the device is unlocked (Ledger, whose PIN-bound
  passphrase matches OneKey's Attach PIN): a locked device accepts either
  PIN, the Main PIN opens the standard wallet and an Attach PIN its hidden
  wallet. The wizard no longer forces the Main PIN.
- A Main PIN unlock with passphrase enabled asks, as Trezor does, whether to
  use the standard wallet or enter a passphrase on the device. The passphrase
  is still never entered on the host.
- The script page loses its hidden/Attach PIN checkboxes, the background
  device probe and the Refresh button. The Testnet legacy multisig default
  stays.

Saved wallets and hardware-encrypted files keep their existing recovery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread plugins/electrum/onekey/client.py Resolved
wabicai and others added 3 commits November 30, 2026 12:13
New wallets follow the device unlock, so nothing requests the "attach" open
mode any more. Remove it from the device session and the helper's mode
check, together with its ATTACH_PIN_DISABLED error. An Attach PIN wallet is
still opened through PIN_ANY ("current"), and saved Attach PIN wallets
recover as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Electrum swaps each hardware signer's status bar icon between icon_unpaired
and icon_paired. Both pointed at the same file, so the icon never showed
whether that signer's device was connected. Like Trezor and Ledger, use a
grey variant while unpaired.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…an sign

firmware-pro2 builds the P2SH multisig scriptSig with
signatures[signature_index] and does not pad the list, unlike the witness
path. Without the slots the device failed every legacy multisig spend, and
the plugin reported SDK_FAILED. Send one empty slot per pubkey, as
Electrum's Trezor plugin does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wabicai and others added 2 commits December 1, 2026 15:00
…o over Protocol V1

The plugin now drives the older OneKey devices itself instead of leaving
them to Electrum's Trezor plugin:

- USB: enumerate the WebUSB interface (64-byte interrupt endpoints) on
  1209:53C1, 1209:4F4B and 534C:0001 next to the Pro 2 / Neo bulk interface.
- LinkV1: "?##" + type + length framing behind the same exchange() contract,
  so xpub, address, signing and message signing stay shared with V2.
- SessionV1: PIN always on the device (BixinPinInputOnDevice for Classic,
  Classic 1S, Mini and Pure; Touch and Pro prompt themselves), passphrase on
  the device or the empty standard passphrase. Hidden wallets are identified
  by GetPassphraseState, or the testnet m/44'/1'/0'/0/0 address on firmware
  without it, as in the JS SDK. Sessions resume through Initialize.
- Identity from V1 Features: serial, model and Bluetooth name with the JS
  SDK's fallbacks. A OneKey in Trezor-compatible mode is accepted by its
  OneKey fields; a real Trezor on the same ids is refused.
- Classic needs about 1.7 s for GetFeatures, so V1 discovery probes get 5 s.

Also replace the "1K" status bar icon with the OneKey logo (grey while
unpaired) and add the V1 ids to the udev rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Classic left inside another host's prompt, or woken from idle, answers
nothing until it receives a Cancel, so discovery skipped it. Send Cancel
when the V1 link opens and drop the reply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread plugins/electrum/onekey/device.py Resolved
Comment thread plugins/electrum/onekey/device.py Resolved
Comment thread plugins/electrum/onekey/device.py Resolved
Comment thread plugins/electrum/onekey/usb.py Resolved
Comment thread plugins/electrum/onekey/link.py Resolved
wabicai and others added 4 commits December 1, 2026 17:04
Revert the Protocol V1 support for Classic, Classic 1S, Mini, Pure, Touch
and Pro (6c23a8d, 8d17776). The plugin stays on Pro 2 and Neo. The OneKey
logo status bar icon from 6c23a8d is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e resume ids to the USB claim

- New keystores open with a "new" mode that refuses a device already unlocked
  with an Attach PIN before the wizard step (ATTACH_PIN_ACTIVE). The user
  locks it and enters the intended PIN in the PIN_ANY prompt, so a hidden
  account is never bound without being chosen. Storage unlock still follows
  the current unlock.
- A cached wallet resume id is used only on the USB claim that obtained it.
  On a new claim the path may lead to another device, so the session is
  re-established through the identity checks without sending the old id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e PIN for new wallets

A device unlocked with an Attach PIN before the wizard step was not unlocked
for this wallet. Instead of refusing it, lock the device and ask for the PIN
with PIN_ANY: the Main PIN adds the standard wallet and an Attach PIN its
hidden wallet. Storage unlock still uses the current unlock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zy2000-star
zy2000-star previously approved these changes Dec 1, 2026
Electrum Plugin CI built and size-checked onekey-<version>.zip but discarded
it. Upload it with its SHA-256 as "onekey-<version>-<sha8>", and allow a
manual run (workflow_dispatch) to build one on demand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread .github/workflows/electrum-plugin.yml Resolved
build.py prints an absolute path, so the .sha256 named the runner's path and
`sha256sum -c` failed next to the downloaded ZIP. Hash from the output
directory with the basename.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wabicai
wabicai merged commit 0ce9770 into onekey Dec 1, 2026
14 checks passed
@wabicai
wabicai deleted the feat/electrum-plugin branch December 1, 2026 10:04
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.

6 participants