keyecdh

On-chain elliptic-curve Diffie-Hellman key exchange

Compute a shared key with the ECDH precompile at 0x65.

Overview

ecdh() and async_ecdh() take a PrivateKey and a CompressedPublicKey and return a Bytes32 shared key.

The on-chain precompile performs ECDH and an HKDF derivation step, so the returned Bytes32 is ready to use as an AES key.

Signature

def ecdh(
    w3: Web3,
    *,
    sk: PrivateKey,
    pk: CompressedPublicKey,
) -> Bytes32

async def async_ecdh(
    w3: AsyncWeb3,
    *,
    sk: PrivateKey,
    pk: CompressedPublicKey,
) -> Bytes32

Parameters

Parameter
Type
Required
Description

w3

Web3 / AsyncWeb3

Yes

Connected Seismic client

sk

Yes

Local 32-byte private key

pk

Yes

Peer compressed public key (33 bytes)

Returns

Type
Description

Derived shared key

Examples

Two-Party Key Exchange

Use Shared Key for AES-GCM

Async Usage

Gas Cost

Fixed cost: 3120.

Notes

  • Input layout is sk(32) || pk(33).

  • Invalid keys cause the call to fail.

  • Keep private keys out of logs and telemetry.

See Also

Last updated