Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

ERC-7627 proposes an interface for registering public keys, supporting multiple public-key algorithms, and exchanging encrypted messages between users.

This article explains the proposal, with additional context and examples.

You can find my other proposal articles here.

Overview

The proposal aims to standardize the exchange of encrypted messages on a blockchain. Users register their public keys and associated algorithms, then use other users' addresses to send encrypted messages. The interface defines algorithm identifiers and a way to manage user information, supporting different cryptographic schemes.

Registering public keys and algorithms

Users register their public key and the corresponding algorithm. An appropriate encryption or key-agreement scheme lets a sender encrypt a message so that the intended recipient can decrypt it.

Sending encrypted messages

The sender obtains the recipient's registered public key and encrypts the message using a compatible scheme. The recipient uses the corresponding private key to recover the plaintext. Encryption and decryption are performed outside the contract.

Managing algorithms and user information

The interface supports different public-key algorithms and user information. Applications can choose a scheme appropriate to their security requirements. Not every algorithm listed in the interface supports encryption directly: some are signature or key-agreement algorithms.

Extensibility and flexibility

The design accommodates different algorithms and user information. Adding new algorithm identifiers or fields in the future would require compatible extensions or revisions to the interface.

The proposal uses blockchain infrastructure and public-key cryptography to support confidential communication. It does not itself guarantee confidentiality: the application must implement a secure encryption scheme.

Motivation

The proposal discusses how advances in Layer 2 networks and account abstraction can make decentralized real-time communication and chat applications more practical.

Progress in Layer 2 networks

Layer 2 networks address blockchain scaling limitations. Built on top of a Layer 1, they improve transaction throughput and efficiency. Some offer short block times, reducing the delay before transactions are included and making interactive communication more practical. Inclusion time is not necessarily finality time.

Account abstraction

Account abstraction allows applications to offer more flexible authentication and transaction authorization mechanisms. Users can interact with blockchain applications without being limited to a single conventional signing workflow.

End-to-end encrypted communication

End-to-end encryption protects message contents between the sender and recipient. Intermediaries should not be able to read the plaintext, assuming the endpoints and cryptographic implementation are secure.

Asymmetric cryptography

Public-key cryptography can help establish a secure communication channel between users. Depending on the scheme, a public key can be used for encryption or to establish a shared secret, while the corresponding private key remains under its owner's control.

Standardizing decentralized, end-to-end interoperable messaging

A common interface gives developers a consistent way to integrate messaging into real-time communication and chat dApps. Interoperable protocols can enable message exchange between applications and platforms, provided they agree on the underlying encryption formats and conventions.

Together, these developments can make blockchain-based communication applications faster, more flexible, and easier to use securely.

Specification

Objectives

The proposal defines a standard smart contract interface for messaging. Its objectives include user registration, message submission, extensibility, and easier monitoring and auditing.

A standardized interface

Developers have a consistent interface for registering users' public keys and submitting messages.

Flexibility and extensibility

An enumeration of public-key algorithm identifiers and a representation of user information allow different cryptographic approaches. Future extensions can accommodate new requirements.

Message tracking events

The contract emits an event when a message is submitted. Applications can monitor message submissions and audit the recorded activity.

Custom session IDs

A custom sessionId associates related messages with a conversation, allowing applications to group and manage conversation threads.

Encrypting messages using the recipient's public key

Before submitting a message, the sender encrypts it using a suitable scheme associated with the recipient's public key. This reduces the risk of unauthorized parties reading the message contents.

These objectives provide a common foundation for messaging applications. Secure encryption, key management, and usability remain implementation responsibilities.

Interface

A contract conforming to the proposed standard must implement the following interface.

ts
pragma solidity ^0.8.0;

interface IERC7627 {

    enum PublicKeyAlgorithm { RSA, ECDSA, ED25519, DSA, DH, ECDH, X25519 }
    
    // Events

    /**
     * @dev Event emitted when a message is sent.
     * @param from The address of the sender.
     * @param to The address of the recipient.
     * @param sessionId The session ID of the message.
     * @param encryptedMessage The encrypted message.
     */
    event MessageSent(address indexed from, address indexed to, bytes32 sessionId, bytes encryptedMessage);

    /**
     * @dev Event emitted when a user updates their public key.
     * @param user The address of the user.
     * @param newPublicKey The new public key of the user.
     * @param algorithm The algorithm used for the public key.
     */
    event PublicKeyUpdated(address indexed user, bytes newPublicKey, PublicKeyAlgorithm algorithm);

    // Functions

    /**
     * @dev Function to update a user's public key.
     * @param _publicKey The public key of the user.
     * @param _algorithm The algorithm used for the public key.
     */
    function updatePublicKey(bytes calldata _publicKey, PublicKeyAlgorithm _algorithm) external;

    /**
     * @dev Function to send an encrypted message from one user to another.
     * @param _to The address of the recipient.
     * @param _sessionId The session ID of the message.
     * @param _encryptedMessage The encrypted message.
     */
    function sendMessage(address _to, bytes32 _sessionId, bytes calldata _encryptedMessage) external;

    /**
     * @dev Function to retrieve a user's public key and algorithm.
     * @param _user The address of the user.
     * @return publicKey The public key of the user.
     * @return algorithm The algorithm used for the public key.
     */
    function getUserPublicKey(address _user) external view returns (bytes memory publicKey, PublicKeyAlgorithm algorithm);
}

PublicKeyAlgorithm

javascript
enum PublicKeyAlgorithm { RSA, ECDSA, ED25519, DSA, DH, ECDH, X25519 }

Overview

An enumeration identifying supported public-key algorithms.

Details

The PublicKeyAlgorithm enum identifies the algorithms supported by the contract interface. Users select an identifier corresponding to their public key.

Values

  • RSA
    • A widely used public-key cryptosystem.
  • ECDSA
    • Elliptic Curve Digital Signature Algorithm.
  • ED25519
    • A signature scheme based on EdDSA.
  • DSA
    • Digital Signature Algorithm.
  • DH
    • Diffie–Hellman key agreement.
  • ECDH
    • Elliptic Curve Diffie–Hellman key agreement.
  • X25519
    • An elliptic-curve key-agreement function.

MessageSent

javascript
event MessageSent(address indexed from, address indexed to, bytes32 sessionId, bytes encryptedMessage);

Overview

An event emitted when a message is submitted.

Details

The MessageSent event records message submission on the blockchain, allowing applications to track and audit it. The message payload is encrypted, and a session ID associates it with a conversation. Sender and recipient addresses and session identifiers remain visible.

Parameters

  • from
    • The sender's address.
  • to
    • The recipient's address.
  • sessionId
    • The identifier of the session associated with the message.
  • encryptedMessage
    • The encrypted message contents.

PublicKeyUpdated

javascript
event PublicKeyUpdated(address indexed user, bytes newPublicKey, PublicKeyAlgorithm algorithm);

Overview

An event emitted when a user updates their public key.

Details

The PublicKeyUpdated event records changes to a user's public key on the blockchain, allowing observers to track the history of key updates. The event includes the associated algorithm identifier.

Parameters

  • user
    • The address of the user updating their key.
  • newPublicKey
    • The new public key.
  • algorithm
    • The algorithm associated with the public key.

updatePublicKey

javascript
function updatePublicKey(bytes calldata _publicKey, PublicKeyAlgorithm _algorithm) external;

Overview

Updates a user's public key.

Details

This externally callable function lets users replace their public key and its associated algorithm. The update can be recorded on the blockchain through the corresponding event.

Parameters

  • _publicKey
    • The replacement public key.
  • _algorithm
    • The algorithm associated with the replacement key.

sendMessage

javascript
function sendMessage(address _to, bytes32 _sessionId, bytes calldata _encryptedMessage) external;

Overview

Submits an encrypted message from one user to another.

Details

The sendMessage function accepts an encrypted message intended for a recipient. The session ID associates it with a conversation. The caller must encrypt the message before submission; the function does not encrypt plaintext.

Parameters

  • _to
    • The recipient's address.
  • _sessionId
    • The identifier of the session associated with the message.
  • _encryptedMessage
    • The encrypted message to submit.

getUserPublicKey

javascript
function getUserPublicKey(address _user) external view returns (bytes memory publicKey, PublicKeyAlgorithm algorithm);

Overview

Retrieves a user's public key and its associated algorithm.

Details

The getUserPublicKey function returns both the registered public key and the algorithm identifier. It is a read-only function that external applications can use to obtain information about a recipient's key.

Parameters

  • _user
    • The address of the user whose key and algorithm are requested.

Return values

  • publicKey
    • The specified user's public key.
  • algorithm
    • The algorithm associated with the public key.

Additional considerations

The proposal describes how a standardized encrypted messaging interface could address security and transparency concerns in blockchain-based communication.

Choosing asymmetric cryptography

Public-key cryptography can protect message confidentiality by allowing only the intended holder of the private key to decrypt an appropriately encrypted message. Integrity and authentication require a suitable authenticated encryption or signature scheme rather than asymmetric encryption alone.

Providing a unified interface

A common interface makes encrypted communication easier to integrate with smart contracts, allowing developers to build messaging systems without inventing an incompatible contract interface for every application.

Securing encrypted messaging

Applications should follow established data security practices, including authenticated encryption, to protect against eavesdropping and tampering. The contract interface alone does not enforce those practices.

Rotating public keys

Security requirements may call for periodic key rotation. The interface lets users update their public keys independently. Applications also need to account for messages encrypted under earlier keys.

Supporting different cryptographic methods

Multiple algorithm identifiers make the interface adaptable to applications with different security requirements. Applications must agree on compatible key formats and encryption procedures.

Monitoring and auditing through events

Contract events help improve observability and auditability, supporting compliance and transparency. They record activity, not proof that the ciphertext is secure or that the recipient has read a message.

Interoperability through standardization

A standardized interface makes integration across platforms easier and encourages compatible messaging implementations.

The proposal aims to improve the security and efficiency of blockchain-based communication. Whether a messaging application achieves those goals depends on its cryptographic implementation and operational practices.

Reference implementation

ts
pragma solidity ^0.8.0;

contract ERC7627 {

    enum PublicKeyAlgorithm { RSA, ECDSA, ED25519, DSA, DH, ECDH, X25519 }

    struct UserInfo {
        bytes publicKey;
        PublicKeyAlgorithm algorithm;
    }

    mapping(address => UserInfo) public pk;

    event MessageSent(address indexed from, address indexed to, bytes32 sessionId, bytes encryptedMessage);
    event PublicKeyUpdated(address indexed user, bytes newPublicKey, PublicKeyAlgorithm algorithm);

    // Function to register a user with their public key
    function updatePublicKey(bytes calldata _publicKey, PublicKeyAlgorithm _algorithm) public {
        pk[msg.sender].publicKey = _publicKey;
        pk[msg.sender].algorithm = _algorithm;
        emit PublicKeyUpdated(msg.sender, _publicKey, _algorithm);
    }

    // Function to send an encrypted message from one user to another
    function sendMessage(address _to, bytes32 _sessionId, bytes calldata _encryptedMessage) public {
        emit MessageSent(msg.sender, _to, _sessionId, _encryptedMessage);
    }

    // Function to retrieve a user's public key
    function getUserPublicKey(address _user) public view returns (bytes memory, PublicKeyAlgorithm) {
        UserInfo memory userInfo = pk[_user];
        return (userInfo.publicKey, userInfo.algorithm);
    }
}

Security considerations

The proposal discusses security considerations for implementing encrypted messaging on a blockchain.

Using secure and current cryptographic algorithms

When selecting an algorithm, follow current security guidance. Avoid schemes with known vulnerabilities or those that are no longer recommended. Review algorithm choices periodically to address emerging threats.

Encrypting messages using public-key cryptography

To protect message confidentiality, encrypt message contents using a secure scheme associated with the recipient's public key. Sending plaintext risks permanent exposure, particularly on public blockchains. Keep message contents encrypted during transmission and storage.

Key management and protection

Robust key management is essential. Private keys must remain confidential, and public-key registrations should be protected against unauthorized modification. Secure key storage, appropriate multifactor authentication, and rotation procedures can reduce the risk of key compromise. Review these processes periodically.

Auditing and monitoring

Implement monitoring and audit mechanisms for message activity and key updates. Detect unusual activity and potential security threats and respond appropriately. Record important operations and events to support incident investigation without exposing private keys or plaintext.

These considerations help prevent unauthorized access to confidential message contents when implementing and operating a blockchain-based messaging application.

Citation

Chen Liaoyuan (@chenly) cly@kip.pro, "ERC-7627: Secure Messaging Protocol [DRAFT]," Ethereum Improvement Proposals, no. 7627, February 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7627.

Conclusion

ERC-7627 provides a proposed interface for registering public keys and exchanging encrypted messages between users, with events for tracking messages and key updates. The interface leaves the actual cryptographic protocol to the applications that use it.

If you have questions, feel free to contact me on Twitter.

Twitter @cardene777

You can also find my work on the following sites.

https://chaldene.net/