Skip to main content

sign.c (Sui Signatures)

This file implements the core signing logic for MicroSui.

It provides generic signing and verification entry points, plus an Ed25519 implementation for Sui-compatible signatures. The signing process follows the Sui specification, including intent-prefixed message hashing and Sui-formatted signature encoding.

Scheme implemented​

Additional schemes (Secp256k1, Secp256r1, MultiSig, zkLogin, Passkey) are planned and will be added incrementally.

File Location​

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


microsui_sign​

Description​

Generic signing entry point for multiple signature schemes.
Dispatches to the appropriate signing routine depending on the provided scheme identifier.
Currently only Ed25519 (0x00) is implemented.

int microsui_sign(uint8_t sui_sig_out[97], uint8_t scheme, const uint8_t* message, const size_t message_len, const uint8_t seed[32])

Parameters​

NameTypeDescription
sui_sig_outuint8_t[97]Output buffer for the generated Sui signature. Format:
• Byte 0: Scheme
• Bytes 1–64: Ed25519 signature
• Bytes 65–96: Ed25519 public key
schemeuint8_tIdentifier of the signing scheme.
Supported schemes:
- 0x00: Ed25519 (implemented)
- Others (Secp256k1, Secp256r1, Multisig, zkLogin, Passkey) are not yet implemented.
messageconst uint8_t*Serialized message bytes to sign.
message_lensize_tLength of the message in bytes.
seedconst uint8_t[32]Raw 32-byte Ed25519 seed used to derive the keypair for signature generation.

Returns​

  • 0 on success.
  • -1 on fail.

Example usage​

Given:

  • A defined scheme: 0x00 (Ed25519 scheme)
  • A message byte array and its length
  • A 32-byte Ed25519 seed named seed

You can generate a signature as follows:

const uint8_t message[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
const size_t message_len = sizeof(message);
const uint8_t seed[32] = {0}; // Replace with the Ed25519 seed
const uint8_t scheme = 0x00;
uint8_t sui_sig[97]; // Output buffer for the Sui signature

int status = microsui_sign(sui_sig, scheme, message, message_len, seed);

if (status == 0)
// Signature is now stored in sui_sig

microsui_verify_signature​

Description​

Verifies that the provided Sui-formatted signature is valid for the given serialized message.

Generic signature verification entry point for multiple signature schemes. Dispatches to the appropriate verification routine based on the scheme byte found in the provided Sui Signature (sui_sig[0]).

Currently only Ed25519 (0x00) is implemented.

int microsui_verify_signature(uint8_t sui_sig[97], const uint8_t* message, const size_t message_len)

Parameters​

NameTypeDescription
sui_siguint8_t[97]Input Sui signature to verify. Format:
• Byte 0: Scheme
• Bytes 1–64: Ed25519 signature
• Bytes 65–96: Ed25519 public key
messageconst uint8_t*Serialized message bytes corresponding to the signature.
message_lensize_tLength of the message in bytes.

Returns​

  • 0 if the signature is valid for the detected scheme.
  • -1 if the scheme is unsupported or verification fails.

Example usage​

Given:

  • A Message or Transaction bytes data message (uint8_t[] type).
  • A valid Sui Signature sui_sig (uint8_t[97] type).

You can check if as follows:

const uint8_t message[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
const size_t message_len = sizeof(message);
uint8_t sui_sig[97] = {0}; // Replace with the Sui signature to verify
int verification = microsui_verify_signature(sui_sig, message, message_len);

if (verification == 0)
// Sui-formatted signature IS VALID for the given serialized message

microsui_verify_signature_with_public_key​

Description​

Generic signature verification entry point that also checks whether the public key embedded in the Sui signature matches an expected public key. It selects the verification routine using the signature's scheme byte (sui_sig[0]).

int microsui_verify_signature_with_public_key(uint8_t sui_sig[97], const uint8_t* message, const size_t message_len, uint8_t public_key[32])

Parameters​

NameTypeDescription
sui_siguint8_t[97]Sui-formatted signature to verify
messageconst uint8_t*Serialized message bytes corresponding to the signature
message_lensize_tLength of message in bytes
public_keyuint8_t[32]Expected 32-byte public key to compare with the embedded key

Returns​

  • 0 if the signature is valid and the embedded public key matches public_key.
  • -1 if the signature scheme is unsupported.
  • -2 if signature verification fails.
  • -3 if the embedded public key does not match public_key.

Example usage​

Given a Sui signature, its serialized message, and the expected public key:

uint8_t sui_sig[97] = {0}; // Replace with the Sui signature to verify
const uint8_t message[] = {0x00, 0x01, 0x02, 0x03}; // Replace with the serialized message
const size_t message_len = sizeof(message);
uint8_t expected_public_key[32] = {0}; // Replace with the expected public key

int verification = microsui_verify_signature_with_public_key(
sui_sig, message, message_len, expected_public_key);

if (verification == 0)
// Signature is valid and its embedded public key matches

microsui_sign_message (Deprecated)​

Description​

[DEPRECATED] Use microsui_sign() or microsui_sign_ed25519() instead.
This function is kept only for backward compatibility.
Please use microsui_sign() or microsui_sign_ed25519(), which provide better compatibility and performance.

int microsui_sign_message(uint8_t sui_sig_out[97], const char* message_hex, const uint8_t seed[32]);

Parameters​

NameTypeDescription
sui_sig_outuint8_t[97]Output buffer for the generated Sui signature. Format:
• Byte 0: 0x00 (Ed25519 scheme)
• Bytes 1–64: Ed25519 signature
• Bytes 65–96: Ed25519 public key
message_hexconst char*Null-terminated string representing the message in hexadecimal (2 hex chars per byte).
seedconst uint8_t[32]Raw 32-byte Ed25519 seed used to derive the keypair for signature generation.

Returns​

  • 0 on success.
  • -1 on fail.

Example usage​

Given:

  • A hexadecimal message: "48656c6c6f2053756921" (which is "Hello Sui!")
  • A 32-byte Ed25519 seed named seed

You can generate a signature as follows:

const char* message_hex = "48656c6c6f2053756921";
const uint8_t seed[32] = {0}; // Replace with the Ed25519 seed
uint8_t sui_sig[97]; // Output buffer for the Sui signature

int status = microsui_sign_message(sui_sig, message_hex, seed);

if (status == 0)
// Signature is now stored in sui_sig