EIPs Explained

ERC-5630 · Draft · ERC · 2022-09-07

ERC-5630: New approach for encryption / decryption

Proposes two wallet RPC methods so dApps can encrypt data to an Ethereum account's own secp256k1 key and have the wallet perform only the ECDH step needed to decrypt it.

What problem does it solve?

People often want to send a private message to an Ethereum address, or let a dApp store a secret that only the user can recover later. The obvious key to use is the one the user already has backed up: their wallet key.

An earlier, never-standardized approach (eth_getEncryptionPublicKey + eth_decrypt) reused the same secret key on a different curve (Curve25519) for encryption and hardcoded one ECIES variant. Using one key on two curves has no security proof. ERC-5630 keeps everything on secp256k1, the same curve used for signing, a combination that has been studied and is used in production elsewhere (EMV payments).

How it works

The wallet does only the sensitive part; the application does the rest of ECIES.

  • eth_getEncryptionPublicKey(account) returns the account's secp256k1 public key as a 0x-prefixed, 33-byte compressed point.
  • eth_performECDH(account, ephemeralKey) takes a compressed ephemeral public key, validates it is on the curve, multiplies it by the account's secret key, and returns the 32-byte shared secret.

To encrypt, the sender generates an ephemeral key pair, derives the shared secret with the recipient's public key, and runs ECIES locally. To decrypt, the recipient's dApp sends only the ephemeral public key to the wallet, gets the shared secret back, and finishes decryption itself. Only about 32 bytes cross the wallet boundary, and apps can choose their own ECIES variant without wallet updates.

Unless there is a reason to differ, the spec suggests: ANSI-X9.63-KDF with SHA-512, HMAC-SHA-256, AES-256-CBC, concatenated ciphertext serialization, and compressed points.

Because any signed transaction reveals the signer's public key, you can encrypt to any account that has sent at least one transaction, even without calling its wallet.

For smart-contract wallets, a contract can advertise how to encrypt to it with encryptTo(bytes plaintext, bytes32 randomness), an encryption analogue of ERC-1271.

Sample code

Calling the two methods through an EIP-1193 provider:

const account = "0x72682F2A3c160947696ac3c9CC48d290aa89549c";

// Recipient side: publish your encryption key
const pubKey: string = await window.ethereum.request({
  method: "eth_getEncryptionPublicKey",
  params: [account],
}); // "0x03ff57..." (33 bytes, compressed)

// Decrypting later: ephemeralKey comes from the ciphertext header
const sharedSecret: string = await window.ethereum.request({
  method: "eth_performECDH",
  params: [account, ephemeralKey], // ephemeralKey: compressed point, 0x-hex
});
// Feed sharedSecret into your KDF -> AES key + MAC key, then decrypt locally

Contract-side interface for encrypting to a smart account:

interface IERC5630 {
    function encryptTo(bytes memory plaintext, bytes32 randomness)
        external view returns (bytes memory ciphertext);
}

Things to know

  • Status: Draft. Wallet support is not standardized; check whether a given wallet exposes these methods before relying on them.
  • The proposal redefines the meaning of eth_getEncryptionPublicKey, which some wallets historically returned as a Curve25519 key for the older eth_decrypt flow. Ciphertexts made the old way are not decryptable with eth_performECDH.
  • Points must be compressed and validated; the spec explains why this rules out "twist attacks" on secp256k1.
  • Reusing a signing key for encryption means anyone with that key can read past messages. There is no forward secrecy on the recipient side.

#encryption #wallet #json-rpc #ecies #privacy

Details

Authors
Firn Protocol (@firnprotocol), Fried L. Trout, Weiji Guo (@weijiguo)
Status
Draft
Type
Standards Track / ERC
Created
2022-09-07

Machine-readable: Markdown · JSON