Ed25519 signatures
This page documents the Ed25519-specific signing and verification functions from sign.c.
They use either serialized message bytes or a precomputed 32-byte digest and produce or verify Sui-formatted Ed25519 signatures.
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_out[97], const uint8_t* message, const size_t message_len, const uint8_t seed[32])
Parameters
| Name | Type | Description |
|---|---|---|
sui_sig_out | uint8_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 | const uint8_t* | Serialized transaction message bytes to sign. |
message_len | size_t | Length of the message in bytes. |
seed | const uint8_t[32] | Raw 32-byte Ed25519 seed used to derive the keypair for signature generation. |
Returns
0on success.-1on fail.
Example usage
Given:
- 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
uint8_t sui_sig[97]; // Output buffer for the Sui signature
int status = microsui_sign_ed25519(sui_sig, message, message_len, seed);
if (status == 0)
// Signature is now stored in sui_sig
microsui_sign_ed25519_from_digest
Description
Sign a precomputed 32-byte digest with Ed25519 and assemble the result in the Sui signature format:
[0x00 scheme | 64-byte Ed25519 signature | 32-byte public key].
The secret key must be the 64-byte Ed25519 key produced by key-pair derivation; it is distinct from the 32-byte seed. This function signs the digest as provided and does not calculate the transaction intent digest.
void microsui_sign_ed25519_from_digest(uint8_t sui_sig_out[97], const uint8_t digest[32], const uint8_t secret_key[64], const uint8_t public_key[32])
Parameters
| Name | Type | Description |
|---|---|---|
sui_sig_out | uint8_t[97] | Output buffer for the Sui-formatted Ed25519 signature |
digest | const uint8_t[32] | Precomputed 32-byte digest to sign |
secret_key | const uint8_t[64] | 64-byte Ed25519 secret key derived from a seed |
public_key | const uint8_t[32] | 32-byte Ed25519 public key included in the signature |
Returns
- No return value. The signature is written to
sui_sig_out.
Example usage
Given a 32-byte digest and a matching Ed25519 secret/public key pair:
uint8_t digest[32] = {0}; // Replace with the digest to sign
uint8_t secret_key[64] = {0}; // Replace with the derived Ed25519 secret key
uint8_t public_key[32] = {0}; // Replace with its matching public key
uint8_t sui_sig[97];
microsui_sign_ed25519_from_digest(sui_sig, digest, secret_key, public_key);
microsui_sign_ed25519_with_keys
Description
Sign serialized transaction bytes with Ed25519 using an already-derived 64-byte secret key and 32-byte public key. The function adds Sui's three-byte intent prefix, computes a BLAKE2b-256 digest, signs it, and writes a Sui-formatted signature to the output buffer.
This function does not check that the supplied public key corresponds to the secret key. The caller must provide a matching key pair.
void microsui_sign_ed25519_with_keys(uint8_t sui_sig_out[97], const uint8_t* message, const size_t message_len, const uint8_t secret_key[64], const uint8_t public_key[32])
Parameters
| Name | Type | Description |
|---|---|---|
sui_sig_out | uint8_t[97] | Output buffer for the Sui-formatted Ed25519 signature |
message | const uint8_t* | Serialized transaction bytes to sign |
message_len | size_t | Length of message in bytes |
secret_key | const uint8_t[64] | 64-byte Ed25519 secret key derived from a seed |
public_key | const uint8_t[32] | Matching 32-byte Ed25519 public key |
Returns
- No return value. The signature is written to
sui_sig_out.
Example usage
Given serialized transaction bytes and a matching, already-derived Ed25519 key pair:
const uint8_t message[] = {0x00, 0x01, 0x02, 0x03}; // Replace with serialized transaction bytes
const size_t message_len = sizeof(message);
const uint8_t secret_key[64] = {0}; // Replace with the derived Ed25519 secret key
const uint8_t public_key[32] = {0}; // Replace with its matching public key
uint8_t sui_sig[97];
microsui_sign_ed25519_with_keys(sui_sig, message, message_len, secret_key, public_key);
microsui_verify_signature_ed25519
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
| Name | Type | Description |
|---|---|---|
sui_sig | uint8_t[97] | Input Ed25519 Sui signature to verify. |
message | const uint8_t* | Serialized message bytes corresponding to the signature. |
message_len | size_t | Length of the message in bytes. |
Returns
0if the signature is valid.-1if 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:
const uint8_t message[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
const size_t message_len = sizeof(message);
uint8_t sui_ed25519_sig[97] = {0}; // Replace with the Ed25519 Sui signature to verify
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_verify_signature_ed25519_from_digest
Description
Verify a Sui-formatted Ed25519 signature against a precomputed 32-byte digest. The function uses the public key embedded in the signature and does not calculate the message or intent digest itself.
int microsui_verify_signature_ed25519_from_digest(uint8_t sui_sig[97], const uint8_t digest[32])
Parameters
| Name | Type | Description |
|---|---|---|
sui_sig | uint8_t[97] | Sui-formatted Ed25519 signature to verify |
digest | const uint8_t[32] | Precomputed 32-byte digest to verify against |
Returns
0if the signature is valid for the digest.-1if the signature scheme byte is not Ed25519 (0x00).-2if signature verification fails.
Example usage
Given a Sui Ed25519 signature and the 32-byte digest corresponding to its signed message:
uint8_t sui_sig[97] = {0}; // Replace with the signature to verify
const uint8_t digest[32] = {0}; // Replace with the precomputed digest
int verification = microsui_verify_signature_ed25519_from_digest(sui_sig, digest);
if (verification == 0)
// Signature is valid for the digest
microsui_verify_signature_ed25519_with_public_key
Description
Verify a Sui-formatted Ed25519 signature against serialized message bytes and an expected public key. The function verifies the signature using the key embedded in the signature, then compares that key with the caller-provided public key.
int microsui_verify_signature_ed25519_with_public_key(uint8_t sui_sig[97], const uint8_t* message, const size_t message_len, uint8_t public_key[32])
Parameters
| Name | Type | Description |
|---|---|---|
sui_sig | uint8_t[97] | Sui-formatted Ed25519 signature to verify |
message | const uint8_t* | Serialized message bytes corresponding to the signature |
message_len | size_t | Length of message in bytes |
public_key | uint8_t[32] | Expected 32-byte public key to compare with the embedded key |
Returns
0if the signature is valid and the embedded public key matchespublic_key.-1if the signature scheme byte is not Ed25519 (0x00).-2if signature verification fails.-3if the embedded public key does not matchpublic_key.
Example usage
Given a Sui Ed25519 signature, its serialized message, and the expected public key:
uint8_t sui_sig[97] = {0}; // Replace with the 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 Ed25519 public key
int verification = microsui_verify_signature_ed25519_with_public_key(
sui_sig, message, message_len, expected_public_key);
if (verification == 0)
// Signature is valid and its embedded public key matches
microsui_verify_signature_ed25519_with_public_key_from_digest
Description
Verify a Sui-formatted Ed25519 signature against a precomputed 32-byte digest and an expected public key. The function verifies the signature using the key embedded in the signature, then compares that key with the caller-provided public key.
int microsui_verify_signature_ed25519_with_public_key_from_digest(uint8_t sui_sig[97], const uint8_t digest[32], uint8_t public_key[32])
Parameters
| Name | Type | Description |
|---|---|---|
sui_sig | uint8_t[97] | Sui-formatted Ed25519 signature to verify |
digest | const uint8_t[32] | Precomputed 32-byte digest to verify against |
public_key | uint8_t[32] | Expected 32-byte public key to compare with the embedded key |
Returns
0if the signature is valid and the embedded public key matchespublic_key.-1if the signature scheme byte is not Ed25519 (0x00).-2if signature verification fails.-3if the embedded public key does not matchpublic_key.
Example usage
Given a Sui Ed25519 signature, its precomputed digest, and the expected public key:
uint8_t sui_sig[97] = {0}; // Replace with the signature to verify
const uint8_t digest[32] = {0}; // Replace with the precomputed digest
uint8_t expected_public_key[32] = {0}; // Replace with the expected Ed25519 public key
int verification = microsui_verify_signature_ed25519_with_public_key_from_digest(
sui_sig, digest, expected_public_key);
if (verification == 0)
// Signature is valid and its embedded public key matches