Add EVM support to the export-and-sign signing flow - #122
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
qq -- what prompted the changes to this file? I don't see any changes that would necessitate updating this dockerfile. If there are fixes to be made that aren't specific to this feature (enabling EVM support), then I'd recommend taking this out of the current PR and ticketing/tackling in a separate PR, just to decouple and reduce rollout risk
There was a problem hiding this comment.
It was actually required by this change, not sure if there's a better solution tho ?
Enabling EVM adds viem, and the docker job builds linux/amd64,linux/arm64 via buildx, so the arm64 leg runs under QEMU emulation.
The old Dockerfile built export-and-sign in-container (RUN cd export-and-sign && npm ci && npm run build), and under emulation that step dies pulling viem's dependency tree:
npm error network read ECONNRESET (errno -104)
ERROR: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c cd export-and-sign && npm ci && npm run build" did not complete successfully: exit code: 152
The fix switches export-and-sign to copy its committed dist/ — identical to how the export frame is already handled (COPY export …) — and integrity is enforced by the existing build-check (export-and-sign) job, which rebuilds and diffs against the committed dist/ on every run.
There was a problem hiding this comment.
I wonder if we could just have the original Dockerfile and then have
FROM --platform=$BUILDPLATFORM node:18-bullseye-slim AS builder
for compatibility
There was a problem hiding this comment.
Yeah lemme see what's up there
There was a problem hiding this comment.
Pull request overview
Extends the export-and-sign iframe signing flow to support EVM (Ethereum) transactions and messages in addition to the existing Solana signing, using an injected private key that remains in-memory within the iframe.
Changes:
- Adds
ETHEREUMbranches toonSignTransactionandonSignMessage, implemented viaviem(parseTransaction,privateKeyToAccount,account.signTransaction,account.signMessage). - Introduces a cached, lazily-derived Ethereum account helper (
getOrCreateEthereumAccount) and a transaction signing helper (signEthereumTransaction). - Updates dependencies (adds
viem) and refreshes committeddist/artifacts; Docker build now uses the committedexport-and-sign/distdirectly.
Reviewed changes
Copilot reviewed 4 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| export-and-sign/src/event-handlers.js | Adds EVM signing support and Ethereum account/tx signing helpers. |
| export-and-sign/package.json | Adds viem dependency. |
| export-and-sign/package-lock.json | Locks viem and transitive dependencies. |
| export-and-sign/index.test.js | Adds EVM signing test suite for tx + message signing + unsupported types. |
| export-and-sign/dist/index.html | Updates bundled asset filenames (rebuilt artifact). |
| export-and-sign/dist/bundle.c9a8b8d5055f705bd308.js | Updates webpack chunk mapping (rebuilt artifact). |
| export-and-sign/dist/bundle.6f3ad536a859e78bdbd5.js.LICENSE.txt | Adds license notice (rebuilt artifact). |
| export-and-sign/dist/bundle.6f3ad536a859e78bdbd5.js | Adds new compiled bundle (rebuilt artifact). |
| export-and-sign/dist/bundle.539e9a91965e314c7b7e.js | Removes old compiled bundle (rebuilt artifact). |
| export-and-sign/dist/bundle.52d2885ae469455328a8.js.LICENSE.txt | Updates license attributions (rebuilt artifact). |
| export-and-sign/dist/bundle.29203a225e88524b9cba.js | Updates webpack chunk mapping (rebuilt artifact). |
| Dockerfile | Stops building export-and-sign in the builder stage; copies committed dist/ into nginx image. |
Files not reviewed (1)
- export-and-sign/package-lock.json: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async function signEthereumTransaction(key, transactionToSign) { | ||
| const account = await getOrCreateEthereumAccount(key); | ||
| return await account.signTransaction(parseTransaction(transactionToSign)); | ||
| } |
| // Ethereum keys are exported in HEXADECIMAL format, where privateKey is a | ||
| // 0x-prefixed hex string — exactly what viem's privateKeyToAccount expects. | ||
| if (key.format !== "HEXADECIMAL") { | ||
| throw new Error( | ||
| `cannot sign Ethereum payload with key format "${key.format}"; expected "HEXADECIMAL"` | ||
| ); | ||
| } |
Extends the export-and-sign iframe to sign EVM transactions and messages with an injected private key, alongside the existing Solana support. Signing happens entirely in-memory inside the iframe; key material never reaches the parent page.
onSignTransaction — new ETHEREUM branch. Takes a 0x-prefixed serialized unsigned transaction, signs it, and returns the broadcast-ready serialized signed transaction (via viem parseTransaction → account.signTransaction).
onSignMessage — new ETHEREUM branch. EIP-191 personal_sign over the UTF-8 message, matching how the Solana path treats messages.
New helpers getOrCreateEthereumAccount (lazy + cached, mirrors getOrCreateKeypair) and signEthereumTransaction.
Adds viem@2.45.0.
Design note — contract is symmetric with Solana
The EVM path deliberately mirrors the Solana contract: the caller builds and serializes the unsigned transaction with whatever library it likes (ethers/viem/web3/…) and hands the iframe serialized hex; the iframe returns serialized signed hex. This keeps the iframe build-agnostic rather than coupling callers to a specific transaction-object shape.
A JSON tx-object input form can be added later as a superset (branch on 0x vs {) if we want the ergonomic alternative — not needed now.
No changes to
@turnkey/iframe-stamperrequired:TransactionType.Ethereum / MessageType.Ethereumalready exist.loadKeyIntoMemoryis untouched — the viem account is derived lazily at sign time, so nokeyFormat → curvecoupling.Tests
New
EVM Signingsuite inindex.test.jsFull suite: 39/39 passing, lint clean.
Manual testing using the updated example in tkhq/sdk#1432
Closes REQ-418