Docs
chromia.com

crypto

On this page

The crypto namespace provides cryptographic functions for hashing, key management, signing, and Ethereum operations. For complete API documentation, see the Standard Library crypto reference.

Overview

The crypto namespace includes:

Key functions

Example: Verify a signature

Rell
val pubkey = x'036d6caac248af96f6afa7f904f550253a0f3ef3f5aa2fe6838a95b216691468e2';
val message = x'DEADBEEF';
val signature = x'8ac02f17b508815fa9495177395925e41fd7db595ad35e54a56be6284e5b8e08...';

val ok = crypto.verify_signature(message, pubkey, signature);
print(ok); // prints "true"

Example: Ethereum signing and recovery

Rell
val privkey = x'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f';
val pubkey = crypto.privkey_to_pubkey(privkey);

val hash = 'Hello'.to_bytes();
val (r, s, rec_id) = crypto.eth_sign(hash, privkey);

val recovered_pubkey = x'04' + crypto.eth_ecrecover(r, s, rec_id, hash);
require(recovered_pubkey == pubkey);