Skip to main content

key_management.c (Key Management)

This file implements core key management utilities for MicroSui.

It provides deterministic helpers for deriving public keys and Sui addresses from raw Ed25519 key material, following the Sui specification. These routines handle scheme flag prefixing, public key derivation, and address hashing using BLAKE2b-256.

The functionality in this file is intentionally minimal and focused on key derivation and address generation, making it suitable for embedded and resource-constrained environments.

File Location​

Defined in microsui-lib/src/microsui_core/key_management.c


microsui_derive_sui_address_ed25519​

Description​

Derive a Sui address from a 32-byte Ed25519 public key.

Prepends the scheme flag (0x00 for Ed25519) to the public key, then computes the BLAKE2b-256 hash of the 33-byte input. The resulting 32-byte digest is the canonical Sui address.

int microsui_derive_sui_address_ed25519(uint8_t sui_address_out[32], const uint8_t pubkey[32])

Parameters​

NameTypeDescription
sui_address_outuint8_t [32]Output buffer for the 32-byte Sui address
pubkeyconst uint8_t [32]Input 32-byte Ed25519 public key

Returns​

  • 0 on success.
  • -1 if input pointers are NULL.

Example usage​

Given:

  • A defined pubkey: Public Key in Bytes format.

You can derive the key as follows:

const uint8_t pubkey[32] = {0}; // Replace with the Ed25519 public key
uint8_t sui_address_out[32]; // Output buffer for the Sui address

int status = microsui_derive_sui_address_ed25519(sui_address_out, pubkey);

if (status == 0)
// Derived Sui address is now stored in sui_address_out

microsui_derive_public_key_ed25519​

Description​

Derive a 32-byte Ed25519 public key from a 32-byte Ed25519 seed.

Generates the full 64-byte Ed25519 secret key internally, then extracts the corresponding public key.

int microsui_derive_public_key_ed25519(uint8_t public_key_out[32], const uint8_t seed[32])

Parameters​

NameTypeDescription
public_key_outuint8_t [32]Output buffer for the 32-byte public key
seedconst uint8_t [32]Input 32-byte Ed25519 seed

Returns​

  • 0 on success.
  • -1 if input pointers are NULL.

Example usage​

Given a 32-byte Ed25519 seed named seed, derive its public key as follows:

const uint8_t seed[32] = {0}; // Replace with the Ed25519 seed
uint8_t public_key[32]; // Output buffer for the public key

int status = microsui_derive_public_key_ed25519(public_key, seed);

if (status == 0)
// Derived public key is now stored in public_key

microsui_derive_keypair_ed25519​

Description​

Derive an Ed25519 key pair from a 32-byte seed. The function writes the 64-byte Ed25519 secret key and its corresponding 32-byte public key to the caller-provided output buffers.

The seed is copied internally before key generation. The caller is responsible for securely wiping secret_key_out when it is no longer needed.

int microsui_derive_keypair_ed25519(uint8_t secret_key_out[64], uint8_t public_key_out[32], const uint8_t seed[32])

Parameters​

NameTypeDescription
secret_key_outuint8_t[64]Output buffer for the 64-byte Ed25519 secret key
public_key_outuint8_t[32]Output buffer for the 32-byte Ed25519 public key
seedconst uint8_t[32]Input 32-byte Ed25519 seed

Returns​

  • 0 on success.
  • -1 if any input or output pointer is NULL.

Example usage​

Given a 32-byte Ed25519 seed, derive the key pair as follows:

const uint8_t seed[32] = {0}; // Replace with the Ed25519 seed
uint8_t secret_key[64];
uint8_t public_key[32];

int status = microsui_derive_keypair_ed25519(secret_key, public_key, seed);

if (status == 0)
// Secret and public keys are now stored in their output buffers

// Securely wipe secret_key when it is no longer needed.