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_pubkey_to_sui_address
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_pubkey_to_sui_address(const uint8_t pubkey[32], uint8_t sui_address_out[32])
Parameters
| Name | Type | Description |
|---|---|---|
pubkey | const uint8_t [32] | 32-byte Ed25519 public key |
sui_address_out | uint8_t [32] | Output buffer for the 32-byte Sui address |
Returns
0on success.-1if input pointers are NULL.
Example usage
Given:
- A defined
pubkey: Public Key in Bytes format.
You can derive the key as follows:
uint8_t sui_address_out[32]; // We initialize it empty
int status = microsui_pubkey_to_sui_address(pubkey, sui_address_out);
if (status == 0)
// Derived Sui address is now stored in sui_address_out
get_public_key_from_private_key
Description
Derive a 32-byte Ed25519 public key from a 32-byte private key seed.
Generates the full 64-byte Ed25519 secret key internally, then extracts the corresponding public key.
int get_public_key_from_private_key(const uint8_t private_key[32], uint8_t public_key[32])
Parameters
| Name | Type | Description |
|---|---|---|
private_key | const uint8_t [32] | 32-byte Ed25519 private key seed |
public_key | uint8_t [32] | Output buffer for the 32-byte public key |
Returns
0on success.-1if input pointers are NULL.
Example usage
Given:
- A defined
private_key: Private/Secret Key in Bytes format.
You can derive the key as follows:
uint8_t public_key[32]; // We initialize it empty
int status = get_public_key_from_private_key(private_key, public_key);
if (status == 0)
// Decoded key is now stored in private_key