Repository navigation
feat: hardware wallet emulators - #560
montelaidev wants to merge 84 commits into
Conversation
…ages - @metamask/speculos: Speculos emulator lifecycle, transport, and device interaction - Speculos class with start/stop lifecycle (auto-detect Docker vs native) - SpeculosClient for TCP APDU and REST API communication - ApduBridge WebSocket HID relay for browser E2E testing - DockerManager and ProcessManager for container/native binary lifecycle - DeviceInteraction handlers for button (Nano) and touch (Stax/Flex) - WebHID mock script for browser injection - Bundled ELF apps (nanosp, nanox, stax, flex), NVRAM, docker-compose.yml - @metamask/speculos-up: Binary downloader for native Speculos - ensureBinary() with SHA-256 checksum verification - Platform detection (linux-x64, linux-arm64, darwin-arm64) - CLI entry point for standalone setup
- Add explicit return types to all arrow functions and callbacks - Replace negated conditions with positive equivalents - Fix JSDoc param names and descriptions for fingerTap/fingerSwipe/connectWithResilience - Replace void IIFEs with proper async method extraction (apdu-bridge #handleMessage) - Use nullish coalescing assignment (??=) where appropriate - Wrap async callbacks in void-safe wrappers for setTimeout (no-misused-promises) - Replace resolves.toBeUndefined patterns with direct await + assertion - Add toThrow messages and increase timeouts for delay-based tests - Use type assertions instead of non-null assertions for Record lookups - Remove unused imports and suppress inherent Node.js rule violations in tests - Prune eslint-suppressions.json to only permanent suppressions
|
Caution MetaMask internal reviewing guidelines:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@metamaskbot publish-preview |
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions (from the Expand for full list of packages and versions. |
Spike browser scripts named test.js are picked up by jest's default testMatch and fail with 'document is not defined' in the node environment.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 5 potential issues.
There are 6 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit de887b2. Configure here.
bumble's android_netsim transport imports google.protobuf at runtime; grpcio does not pull it in transitively, so fresh virtualenvs failed at import time. Also refresh yarn.lock with the @metamask/eth-sig-util@8.2.0 entry for the already-committed hw-emulator dependency.
…idable The hard-coded 30s APDU fuse raced the E2E device-approval automation (adaptive button-press flows can take ~50s worst case), killing signing exchanges mid-approval. Default raised to 120s; override with SPECULOS_APDU_TIMEOUT.
Forward deletion only — prior history is left untouched.
…hon/ and tests/python/ Aligns the package layout with standard Python conventions: the setuptools/hatch package dir becomes python/speculos_ble, pytest testpaths become tests/python, and the Dockerfile COPY, package.json files/scripts, README, and SpeculosBleRunner path resolution are updated accordingly. No functional changes; venv location (.venv) and the speculos_ble package name are unchanged.
- speculos-up: resolve the package root via package.json so bundled archives and checksum verification work in the published cjs/mjs build (the extensionless ./utils specifier never resolves against dist) - speculos-up: fall back to sourceDir when Dirent.parentPath is unavailable - hw-emulator: run the native Speculos process from the bundled nvram/ directory so --load-nvram finds main_nvram.bin - require Node >=26 for the speculos packages - add regression tests and CHANGELOG entries Also folds in incidental repo maintenance from yarn lint:fix (README merge-marker cleanup, tsconfig/package.json formatting, lockfile dedupe).
….parentPath installBinaries() now derives each entry path from the `sourceDir` argument (the directory the entries were read from) instead of the `Dirent.parentPath` property, which is only populated on newer runtimes. Uses only APIs supported on Node 22+.
…forgery' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ease Pin actions/checkout, actions/setup-python, actions/upload-artifact and actions/download-artifact to commit SHAs (blanket pinning policy). Replace softprops/action-gh-release with the GitHub CLI (gh release create / gh release upload), matching the MetaMask convention — no third-party action is used to publish release assets.
…t/hw-emulators-master
…forgery' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Prevent the GITHUB_TOKEN from being persisted in the local git config, since no step in this workflow pushes via git credentials.
…t/hw-emulators-master
- Drop --experimental-vm-modules from the jest scripts: main removed it in #696 because requiring the ESM-only @metamask/eth-sig-util v10 throws ERR_REQUIRE_ESM under it, which failed every test suite that imports it. - Align devDependency ranges with the monorepo so `yarn constraints` passes, bump @metamask/eth-sig-util to ^10.0.0, and dedupe the lockfile. - Remove an unnecessary type assertion that eslint flags in extract.ts. - Make two hw-emulator tests host-independent: match a closed port by error code (a reset arrives as "socket hang up") and connect to a free port instead of the default APDU port a running emulator may hold. - Pack the hardlink fixture with sync: true; tar's async pending-link path could end the gzip stream twice and fail the run with an unhandled ZlibError. - Changelogs: link entries to #560, let auto-changelog order the Unreleased sections, and drop the keyring-eth-trezor entry that landed in the released [11.0.1] section (the IN_TEST change never existed on main).
- Rebuild the linux-amd64 and linux-arm64 archives from the 0.27.8 PyPI release and regenerate bundled/checksums.json. - Point the default version, build scripts, CI workflow, and docs at 0.27.8. - Fix the release build for 0.27: it moved imports into speculos/__init__.py, so build against a launcher shim, bundle backports.tarfile for pkg_resources, and smoke-test the binary with --help (Docker, native, and CI paths). - Keep the hw-emulator Docker image on 0.25.13: no later version tag is published on ghcr.io/ledgerhq/speculos.
- hw-emulator: ethereumjs 10, secp256k1 5, ethereum-cryptography 3, keystone BC-UR 0.23, zxing 0.23, ws 8.23, uuid 11, plus latest dev tooling (jest 30, TypeScript 5.9, typedoc 0.28). - speculos-up: tar 8 with extract migrated to the Promise API, plus the same dev tooling set. - Vendor the Ledger HID framing helper removed in @ledgerhq/devices v8 and cover it with tests. - Allow the resulting version skew via ALLOWED_INCONSISTENT_DEPENDENCIES and scope the tar resolution so node-gyp/cacache stay on patched tar 7. - @metamask/utils and uuid stay on their latest dual-format versions (v12+ is ESM-only).
…y/bip39 @metamask/bip39 was last published in 2022. ethereum-cryptography is already a direct dependency, and its `bip39` subpath re-exports `mnemonicToSeedSync` from @scure/bip39, so this drops one dependency without changing the seed derivation.

This PR introduces hardware wallet emulators to be used in clients for e2e testing. In this initial release, it only includes the ledger speculos emulator
Examples
Note
Medium Risk
Large new E2E stack (HID/APDU bridge, signing flow timing, Docker/process lifecycle) affects how Ledger flows are tested but does not change production keyring or auth code paths.
Overview
Adds Ledger Speculos–based hardware wallet emulation for client E2E tests via two new packages and release tooling.
@metamask/hw-emulatorexposescreateEmulator()with Docker (default off Linux) and native Linux modes, bundled Ethereum ELF apps and NVRAM,SpeculosClient/DockerManager/ProcessManager, screen automation for Nano and touch devices, and anApduBridgeplus injectable WebHID mock script so browser tests can talk to Speculos without real devices. Native start can resolve the Speculos binary through optional@metamask/speculos-up. Docker compose wiring now honors custom ports, seed, and display via env vars.@metamask/speculos-upinstalls managed Linux Speculos binaries (bundled archives with SHA-256 checks, GitHub release fallback, cache,mm-speculos-upCLI). Maintainers getbuild-speculos.yml(tagspeculos-v*) and local Docker/native build scripts for linux-amd64/arm64 archives.The monorepo README, root TypeScript project references, and
.gitignore(dist-build/,.worktrees/) are updated to include the new packages.Reviewed by Cursor Bugbot for commit de887b2. Bugbot is set up for automated code reviews on this repo. Configure here.