Skip to content

Add EVM support to the export-and-sign signing flow - #122

Merged
andrewkmin merged 6 commits into
mainfrom
traian/export-and-sign-evm
Jul 14, 2026
Merged

Add EVM support to the export-and-sign signing flow#122
andrewkmin merged 6 commits into
mainfrom
traian/export-and-sign-evm

Conversation

@t-vila

@t-vila t-vila commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

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.

// EVM
signTransaction(
  { transaction: serializedUnsignedTxHex, type: TransactionType.Ethereum },
  address,
);
// Solana (unchanged)
signTransaction(
  { transaction: serializedTxHex, type: TransactionType.Solana },
  address,
);

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-stamper required: TransactionType.Ethereum / MessageType.Ethereum already exist. loadKeyIntoMemory is untouched — the viem account is derived lazily at sign time, so no keyFormat → curve coupling.

Tests

New EVM Signing suite in index.test.js

  • signs an EVM transaction and asserts the result recovers to the injected key's address
  • signs an EVM message (EIP-191) and asserts it recovers to the injected key's address
  • rejects an unsupported transaction type

Full suite: 39/39 passing, lint clean.

Manual testing using the updated example in tkhq/sdk#1432

Closes REQ-418

@socket-security

socket-security Bot commented Jul 6, 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
Addedviem@​2.45.09710010097100

View full report

Comment thread Dockerfile

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.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

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.

I wonder if we could just have the original Dockerfile and then have

FROM --platform=$BUILDPLATFORM node:18-bullseye-slim AS builder

for compatibility

cc @janjakubnanista

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.

Yeah lemme see what's up there

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.

@t-vila take a look at #124 and lmk if that fixes your problem - there was a bit of an issue with the docker build context (it would only affect local builds though)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 ETHEREUM branches to onSignTransaction and onSignMessage, implemented via viem (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 committed dist/ artifacts; Docker build now uses the committed export-and-sign/dist directly.

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.

Comment on lines +597 to +600
async function signEthereumTransaction(key, transactionToSign) {
const account = await getOrCreateEthereumAccount(key);
return await account.signTransaction(parseTransaction(transactionToSign));
}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 18 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • export-and-sign/package-lock.json: Generated file

Comment on lines +570 to +576
// 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"`
);
}
@andrewkmin
andrewkmin merged commit 0fb9d5e into main Jul 14, 2026
27 checks passed
@andrewkmin
andrewkmin deleted the traian/export-and-sign-evm branch July 14, 2026 20:44
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.

4 participants