Precompiles
Seismic precompiled contracts for cryptographic operations
Seismic extends the EVM with precompiled contracts for common cryptographic operations. These are available at fixed addresses and can be called from any client with a .call() method -- either a ShieldedPublicClient or a ShieldedWalletClient.
Import
import {
rng,
ecdh,
aesGcmEncrypt,
aesGcmDecrypt,
hdfk,
secp256k1Sig,
} from "seismic-viem";Overview
rng
0x...0064
Random number generation
numBytes, pers?
bigint
ecdh
0x...0065
ECDH key exchange
sk, pk
Hex (shared secret)
aesGcmEncrypt
0x...0066
AES-GCM encryption
aesKey, nonce, plaintext
Hex (ciphertext)
aesGcmDecrypt
0x...0067
AES-GCM decryption
aesKey, nonce, ciphertext
string (plaintext)
hdfk
0x...0068
HKDF key derivation
ikm
Hex (derived key)
secp256k1Sig
0x...0069
secp256k1 signing
sk, message
Signature
RNG -- Random Number Generation
Generates cryptographically secure random numbers using the TEE's CSPRNG.
Standalone Function
Parameters
numBytes
bigint | number
Yes
Number of random bytes to generate (1--32)
pers
Hex | ByteArray
No
Personalization string to seed the CSPRNG
Returns
bigint -- the generated random value.
Example
ECDH -- Elliptic Curve Diffie-Hellman
Performs an ECDH key exchange inside the TEE and returns the shared secret.
Standalone Function
Parameters
sk
Hex
Yes
32-byte secp256k1 secret key
pk
Hex
Yes
33-byte compressed secp256k1 public key
Returns
Hex -- 32-byte shared secret.
Example
AES-GCM Encrypt / Decrypt
Performs AES-GCM encryption and decryption inside the TEE.
Encrypt
Encrypt Parameters
aesKey
Hex
Yes
32-byte AES-256 key
nonce
number
Yes
Numeric nonce for AES-GCM
plaintext
string
Yes
Plaintext string to encrypt
Encrypt Returns
Hex -- the AES-GCM ciphertext.
Decrypt
Decrypt Parameters
aesKey
Hex
Yes
32-byte AES-256 key
nonce
number
Yes
Nonce used during encryption
ciphertext
Hex
Yes
Ciphertext to decrypt
Decrypt Returns
string -- the decrypted plaintext.
Full Example
HKDF -- Key Derivation
Derives a key from input key material using HKDF inside the TEE.
Standalone Function
Parameters
ikm
Hex
Yes
Input key material
Returns
Hex -- the derived key.
Example
secp256k1 Signature
Generates a secp256k1 signature inside the TEE.
Standalone Function
Parameters
sk
Hex
Yes
32-byte secp256k1 secret key
message
string
Yes
Message to sign
Returns
Signature -- a viem Signature object with r, s, and v components.
Example
Using Precompiles via Client
All precompiles are available as methods directly on ShieldedPublicClient and ShieldedWalletClient, so you can call them without importing the standalone functions.
client.rng(params)
rng(client, params)
Random number generation
client.ecdh(params)
ecdh(client, params)
ECDH key exchange
client.aesGcmEncryption(params)
aesGcmEncrypt(client, params)
AES-GCM encryption
client.aesGcmDecryption(params)
aesGcmDecrypt(client, params)
AES-GCM decryption
client.hdfk(ikm)
hdfk(client, ikm)
HKDF key derivation
client.secp256k1Signature(params)
secp256k1Sig(client, params)
secp256k1 signing
Example
Custom Precompile Pattern
Each precompile is defined as a Precompile<P, R> object with a standard interface. You can invoke any precompile directly using its object.
Precompile<P, R> Type
address
Hex
Fixed address of the precompile contract
gasCost(args)
(args: P) => bigint
Computes the gas cost for the given arguments
encodeParams(args)
(args: P) => Hex
ABI-encodes the arguments for the call
decodeResult(result)
(result: Hex) => R
Decodes the raw call result
Available Precompile Objects
rngPrecompile
Precompile<RngParams, bigint>
ecdhPrecompile
Precompile<EcdhParams, Hex>
aesGcmEncryptPrecompile
Precompile<AesGcmEncryptionParams, Hex>
aesGcmDecryptPrecompile
Precompile<AesGcmDecryptionParams, string>
hdfkPrecompile
Precompile<Hex, Hex>
secp256k1SigPrecompile
Precompile<Secp256K1SigParams, Signature>
The CallClient type accepts any client with a .call() method, so both ShieldedPublicClient and ShieldedWalletClient work with callPrecompile.
Calling via callPrecompile
callPrecompile handles gas cost calculation, parameter encoding, and result decoding automatically using the Precompile<P, R> object passed in. It throws if no data is returned, if the arguments fail validation, or if encoding/decoding fails.
See Also
Shielded Public Client -- Read-only client with precompile methods
Shielded Wallet Client -- Full-featured client with precompile methods
Encryption -- Client-side ECDH key exchange and AES-GCM encryption
Chains -- Chain configurations for Seismic networks
Last updated

