Skip to main content

sign.c (Signatures)

This file implements the core signing logic for MicroSui.

It provides a generic signing interface (microsui_sign) and concrete implementations for Sui-compatible signature schemes. The signing process follows the Sui specification, including intent-prefixed message hashing and Sui-formatted signature encoding.

Currently, only the Ed25519 scheme is 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 scheme, uint8_t sui_sig[97], const uint8_t* message, const size_t message_len, const uint8_t private_key[32])

Parameters

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

Returns

  • 0 on success.
  • -1 on fail.

Example usage

Given:

  • A defined scheme: 0x00 (Ed25519 scheme)
  • A bytes array message: [0x00, 0x01, 0x02, 0x03, 0x04, 0x05] (message_len = 6)
  • A 32-byte Ed25519 private key

You can generate a signature as follows:

uint8_t sui_sig[97];  // Placeholder for the Sui signature. We initialize it empty

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

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

microsui_sign_ed25519

Description

Sign a Sui Transaction message using Ed25519 and produce a Sui-formatted signature.
Builds the "message with intent" (prefix + tx bytes), digests it with BLAKE2b, signs the digest with Ed25519, and encodes the result in the Sui signature format (scheme byte + 64-byte Ed25519 signature + 32-byte public key).

int microsui_sign_ed25519(uint8_t sui_sig[97], const uint8_t* message, const size_t message_len, const uint8_t private_key[32])

Parameters

NameTypeDescription
sui_siguint8_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
messageconst uint8_t*Message to sign in hexadecimal bytes format
message_lensize_tLength of the message.
private_keyconst uint8_t[32]Raw 32-byte Ed25519 private key used for signature generation.

Returns

  • 0 on success.
  • -1 on fail.

Example usage

Given:

  • A bytes array message: [0x00, 0x01, 0x02, 0x03, 0x04, 0x05] (message_len = 6)
  • A 32-byte Ed25519 private key

You can generate a signature as follows:

uint8_t sui_sig[97];  // We initialize it empty

int status = microsui_sign_ed25519(sui_sig, message, message_len, private_key);

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]Output buffer for the generated Sui signature. Format:
• Byte 0: 0x00 (Ed25519 scheme)
• Bytes 1–64: Ed25519 signature
• Bytes 65–96: Ed25519 public key
messageconst uint8_t*Message to sign in hexadecimal bytes format
message_lensize_tLength of the message.

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:

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

Description

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

Expects a Sui signature encoded as: [0x00 scheme | 64-byte Ed25519 signature | 32-byte public key]

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

Parameters

NameTypeDescription
sui_siguint8_t[97]Output buffer for the generated Ed25519 Sui signature.
messageconst uint8_t*Message to sign in hexadecimal bytes format
message_lensize_tLength of the message.

Returns

  • 0 if the signature is valid.
  • -1 if the signature is invalid or the scheme byte is not Ed25519 (0x00).

Example usage

Given:

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

You can check if as follows:

int verification = microsui_verify_signature_ed25519(sui_ed25519_sig, message, message_len);

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

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[97], const char* message_hex, const uint8_t private_key[32]);

Parameters

NameTypeDescription
sui_siguint8_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).
private_keyconst uint8_t[32]Raw 32-byte Ed25519 private key used 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 private key

You can generate a signature as follows:

uint8_t sui_sig[97];  // We initialize it empty

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

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