Repository navigation
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
@codex review |
|
@codex security review |
|
Cursor review failed. Remote error: |
|
Skipping Bugbot: Bugbot is disabled for this repository. Visit the Bugbot dashboard to update your settings. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Devin Review found 16 potential issues.
3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1de4f32f42
ℹ️ 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".
| VERSION: ${{ steps.version-info.outputs.version }} | ||
| IS_PRERELEASE: ${{ steps.version-info.outputs.is_prerelease }} | ||
| run: | | ||
| if [ "$GITHUB_REF" != "refs/heads/onekey" ]; then |
There was a problem hiding this comment.
P1: [Identify the production PyPI branch restriction]
The earlier comment at .github/workflows/onekeylib.yml:67 covered tag-triggered publishing. The manual path now checks for refs/heads/onekey at .github/workflows/onekeylib.yml:80. GitHub loads that check from the selected ref, and the workflow says the pypi environment has no separate approval. If that environment also permits other refs, a contributor who can write and dispatch a branch can publish an unreviewed build that users install as the official SDK.
The environment’s deployment branch policy, or an equivalent control enforced independently of the selected workflow, would settle whether only refs/heads/onekey can request production publishing credentials. No code change is requested until that policy is known. Please reply in this thread with the policy or equivalent control.
There was a problem hiding this comment.
The selected ref supplies the workflow that checks GITHUB_REF. Please provide the production pypi environment’s deployment branch policy or an equivalent independently enforced control showing that only refs/heads/onekey can obtain production publishing credentials.
Record the build's wheel and sdist with their SHA-256 before the upload, so the attestation files the publish action writes into dist/ are not taken for packages. Before uploading, every file the index already lists for this version must be one of them with the same digest; otherwise nothing is uploaded, so a re-run can only complete the same build and two builds are never mixed under one version. The final check compares the index with the recorded list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Session.close() passed the session object as a log argument, so a handler that exports record arguments could receive a V1 session and its firmware session ID. Pass the local tag instead, as the other session logs do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move only: the module becomes protocol_v2/client.py with parent-relative imports, and protocol_v2/__init__.py re-exports OneKeyClientV2, SessionV2 and REQUIRED_V2_MESSAGES, so `from onekeylib.protocol_v2 import ...` keeps working. Keeping the move apart from the split lets `git log --follow` trace the client's history. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No behavior change. OneKeyClientV2 keeps every public method and the order of every request it sends; its parts move into modules of their own: - link: message encoding over proto_link, the negotiated link state (LinkState) and the ProtocolInfo check. - requests: which requests are mid-workflow, seedless, interactive, and so on. - failures: failure replies to exceptions (failure_error). - sessions: SessionV2, the passphrase request each PassphraseSetting sends, and the checks on DeviceSession replies. - workflow: the signing exchange a session keeps reserved (WorkflowReservation), formerly three client attributes. The tests reach the reservation as client._workflow.session/.token instead of the old attributes; their assertions are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…blishing Session.close() logs only the exception type when EndSession fails: InvalidSessionError keeps the reply, which may carry the firmware session ID. The publish job runs one at a time per index, so two runs of the same version cannot both pass the preflight and mix their files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fixed the two remaining P1 workflow findings in
|
| exit 1 | ||
| fi | ||
| # PEP 440 canonical version and prerelease flag (a, b, rc, dev). | ||
| NORMALIZED_VERSION=$(python -c "import sys; from packaging.version import Version; print(Version(sys.argv[1]))" "$VERSION") |
There was a problem hiding this comment.
🟠 P1: Equivalent versions bypass build reservations
Severity: severe
For 0.1 and 0.1.0, NORMALIZED_VERSION produces separate reservations for the same PyPI release. If preflight misses a partial upload, the second build can add different files to that release.
Suggested fix:
NORMALIZED_VERSION=$(python -c "import sys; from packaging.utils import canonicalize_version; print(canonicalize_version(sys.argv[1]))" "$VERSION")
| if not isinstance(reserved, dict) or reserved != manifest: | ||
| sys.exit( | ||
| f"❌ {index_name} {norm_version} is already reserved for a different build: " | ||
| f"reserved={sorted(reserved.items()) if isinstance(reserved, dict) else reserved} " | ||
| f"vs local={sorted(manifest.items())}" | ||
| ) |
There was a problem hiding this comment.
🟠 P1: Artifact expiry strands unpublished releases
Severity: severe
If publishing stops before any upload and the build artifact expires, a fresh run cannot reproduce the reserved sdist. The reserved != manifest check blocks publishing that version even though the index is empty.
Originally reported at .github/workflows/onekeylib.yml:268-273 on commit 37458e3e29378e5c5fe3e8b321226f7ff2804c3b. The finding's code and surrounding context were verified unchanged at commit 38f84d8f572d6b7a2e74865fa99c7c23eb76386d; other code may have changed since the review.
huhuanming
left a comment
There was a problem hiding this comment.
Code review findings (excluding hardware verification, and omitting workflow P1 items already tracked in existing threads such as contents: write job isolation, equivalent version normalization, artifact expiry deadlock, and pypi environment branch policy).
| return resp.message or "" | ||
|
|
||
| @enter_context | ||
| def refresh_features(self) -> messages.Features: |
There was a problem hiding this comment.
[Medium] Missing _check_no_workflow() guard on management helpers
device_status(), ask_pin(), lock(), get_current_session(), and get_session() all call self._check_no_workflow() to prevent interleaving requests during an active SignTx/TxAck workflow. However, ping() (L226), refresh_features() (L246), ble_name (L300, which calls refresh_features()), and ensure_unlocked() (L380) do not.
If a host reads ble_name or refreshes features while a signing exchange is reserved, management requests will be sent mid-workflow and can desync the device signing state.
|
|
||
| self._features = messages.Features( | ||
| vendor="onekey.so", | ||
| major_version=info.protocol_version, |
There was a problem hiding this comment.
[Medium] client.version on V2 always reports (1, 0, 0)
major_version is populated from info.protocol_version (1) with minor_version=0, patch_version=0, so client.version reflects the protocol version rather than the firmware version. If hosts (e.g., Electrum) inspect client.version for firmware capability checks, this may be misleading—either populate the actual firmware version if available from DeviceInfo or document this limitation clearly.
| # Only the exchange this Cancel interrupts is released; a new one started | ||
| # after the Cancel was sent keeps its reservation. | ||
| token = self._workflow.token | ||
| if self.transport.is_open(): |
There was a problem hiding this comment.
[Medium] Unsynchronized check-then-act race in cancel()
cancel() checks self.transport.is_open() and calls self._raw_write(messages.Cancel()) and self._end_workflow(token) without synchronization against concurrent link closure or workflow transitions. If the active request thread closes the transport between is_open() and _raw_write(), cancel() raises TransportException instead of handling a closed link cleanly.
| if res.serialized.signature_index is not None: | ||
| idx = res.serialized.signature_index | ||
| sig = res.serialized.signature | ||
| if signatures[idx] is not None: |
There was a problem hiding this comment.
[Low] Validate signature_index bounds before indexing signatures
signatures[idx] does not check 0 <= idx < len(inputs). If a buggy/unexpected reply returns a negative signature_index, Python's negative indexing would silently write to the end of signatures instead of raising an error.
| OUTDATED_FIRMWARE_ERROR = """ | ||
| Your OneKey firmware is out of date. Update it with the following command: | ||
| onekeyctl firmware update | ||
| Or visit https://suite.onekey.io/ |
There was a problem hiding this comment.
[Low] Stale CLI command and URL in OUTDATED_FIRMWARE_ERROR
This package removes the CLI (so onekeyctl firmware update does not exist), and https://suite.onekey.io/ appears to be a leftover from replacing suite.trezor.io rather than an official OneKey domain (e.g. https://onekey.so/).
| # | ||
| # Copyright (C) SatoshiLabs and contributors | ||
| # Modifications Copyright (C) OneKey | ||
| # Modifications Copyright (C) OneKey |
There was a problem hiding this comment.
[Nit] Duplicate copyright header line
# Modifications Copyright (C) OneKey is duplicated here (and in packages/onekeylib/src/onekeylib/models.py:4-5).
| # part-way: files the index already has from this build are skipped. | ||
| - name: Publish to PyPI | ||
| if: inputs.repository == 'pypi' | ||
| uses: pypa/gh-action-pypi-publish@release/v1 |
There was a problem hiding this comment.
[Medium] Pin third-party Actions to full commit SHAs
pypa/gh-action-pypi-publish@release/v1 (and the other external actions in this workflow) are pinned to mutable branch/major tags rather than full commit SHAs. On a PyPI OIDC publish job with id-token: write, pinning to immutable commit SHAs is recommended for supply-chain hardening.
|
Addressed all remaining P1 workflow findings and @huhuanming review comments in Workflow (
|
| except TransportException: | ||
| # If the active thread closed the link concurrently between | ||
| # is_open() and _raw_write(), the device already dropped the | ||
| # exchange; treat that as cleanly cancelled. | ||
| if self.transport.is_open(): | ||
| raise |
There was a problem hiding this comment.
🟠 P1: Silent failure to send Cancel
Severity: severe
When a USB write times out or is incomplete, cancel() returns normally without confirming that it sent Cancel. write_chunk closes the link on write failure, so the closed link masks the error.
|
Fixed P1
|
This PR adds a standalone Python library in
packages/onekeylib/for planned distribution on PyPI. It is based on a trimmed-down version oftrezorlib 0.20.2, retains the LGPL-3.0 licensing materials, and supports both legacy OneKey devices (Protocol V1) and Pro 2 / Neo (Protocol V2).Changes
Minimal runtime dependencies: Keep only
libusb1andtyping_extensions. Remove support for non-Bitcoin chains, THP, Bridge, BLE, the CLI, and Trezor-specific firmware logic. Reducemessages.pyfrom 10,076 lines to 1,991.Unified device support:
WebUsbTransportandprotocol_v1.1209:4f4c) usesProtoLinkTransport(USB bulk transfers with0x5A/CRC8 framing) andprotocol_v2(main PIN and Attach PIN viaPIN_ANY, passphrases, session validation, and on-device cancellation without disconnecting).onekeylib.clientandonekeylib.btcAPIs, which includeget_public_node,get_address,sign_tx, andsign_message.Branding and licensing: Retain the LGPL-3.0
COPYINGfile and source attribution and copyright notices in file headers. Use OneKey naming consistently in identifiers, exceptions, environment variables, error messages, and links.Host API for wallet selection (Protocol V2):
device_status(),ask_pin(pin_type),lock(),get_current_session(),SessionV2.btc_test_addressandble_name, so a host such as Electrum can choose, check and relock a wallet without private attributes. The README section "Choosing and checking a wallet (Protocol V2)" describes them.Host cancellation:
client.cancel_checklets a host abandon a pending read. If the device may be showing a prompt, onekeylib sendsCancel(also instead ofButtonAck) and then closes the link. Undecodable replies raiseProtocolError.Device detection:
get_default_clientskips V1 devices that are not OneKey, andFeaturesreads the 5xx/6xx OneKey fields.Protocol V2 package layout:
onekeylib.protocol_v2is a package split by responsibility, with no behavior change:client(OneKeyClientV2),link(encoding and link negotiation),requests(request classes),failures(failure replies to exceptions),sessions(SessionV2and the passphrase request for each setting) andworkflow(the signing reservation).from onekeylib.protocol_v2 import OneKeyClientV2, SessionV2still works.Release workflow:
.github/workflows/onekeylib.ymltests and builds on pull requests that touch the package. Releases follow the npm flow (package-publish.yml): run the workflow by hand and choosepypiortestpypi. It reads the version frompyproject.toml, checks it against__version__, tests, builds and publishes with Trusted Publishing (environmentspypiandtestpypi), so no token is stored. A stable PyPI release then gets the tagonekeylib-v<version>and a GitHub release with the wheel and sdist, not marked as the repository's latest release. PEP 440 prereleases are published without a tag or release.Verification
pytest tests -q: 69 passed.flake8 --select=E9,F63,F7,F82,F401,F811 src tests: passed.python -m buildandtwine check --strict dist/*: passed.actionlinton the workflow: passed. The publish, tag and release steps run for the first time on the first release.node scripts/check-versions.js: passed. Existing JavaScript workspace packages are unaffected.This PR can be reviewed independently of the standalone Electrum ZIP plugin PR #998, which can be merged first.