Validating a Sui Signature for a given message
Verifies that the provided Sui-formatted signature is valid for the given serialized message.
Currently only Ed25519 (0x00) is implemented in signature validations.
note
✅ Compatible across all microcontroller implementations and IDEs.
SDK way (adaptation for ArduinoIDE)
✅ Fully compatible with ArduinoIDE on supported platforms.
Serial.print(F("\n\t This demo shows how to validate a Sui Signature. (Signature is generated here too)\n"));
const char* private_key = "suiprivkey1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq509duq";
const char* message1_string = "0001020304050607080910";
const char* message2_string = "00020406081012141a1c1e";
// Create a keypair from a given secret key in Bech32 format
MicroSuiEd25519 keypair = SuiKeypair_fromSecretKey(private_key);
// Create two transactions with the prebuilted TxBytes
MicroSuiTransaction tx1 = SuiTransaction_setPrebuiltTxBytes(message1_string);
MicroSuiTransaction tx2 = SuiTransaction_setPrebuiltTxBytes(message2_string);
Serial.print(F("\n\t Signing the Transaction Message1 with the keypair...\n\n"));
SuiSignature sig = keypair.signTransaction(&keypair, message1_string);
Serial.print(F(" Signature in base64: %s\n", sig.signature));
Serial.print(F" Signature in bytes: "));
for (int i = 0; i < 97; i++) {
Serial.print(F("%02x", sig.bytes[i]));
}
Serial.print(F("\n\n"));
// Signature validation must be correct for Message 1 and failed for Message 2
Serial.print(F("\t Signature validation must be correct for Message 1 and failed for Message 2\n"));
// Validation with message 1 (correct)
int verification_result_1 = microsui_verify_signature(sig.bytes, tx1.tx_bytes.data, tx1.tx_bytes.length);
if(verification_result_1 == 0)
Serial.print(F("\t - Signature Verification is CORRECT for Message 1 -- OK\n"));
// Validation with message 2 (must fail)
int verification_result_2 = microsui_verify_signature(sig.bytes, tx2.tx_bytes.data, tx2.tx_bytes.length);
if(verification_result_2 == -1)
Serial.print(F("\t - Signature Verification is FAILED for Message 2 -- OK\n"));
Core functions way
✅ Fully compatible with any IDE and any microcontroller, offering full control and customization for developers.
This method is recommended for 8-bit microcontrollers or other memory-constrained environments.
printf("\n\t This demo shows how to validate a Sui Signature. (Signature is generated here too)\n");
const char *private_key_bech32 = "suiprivkey1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq509duq";
const char* message_hex = "00000200080065cd1d0000000000202e3d52393c9035afd1ef38abd7fce2dad71f0e276b522fb274f4e14d1df974720202000101000001010300000000010100d79a4c7a655aa80cf92069bbac9666705f1d7181ff9c2d59efbc7e6ec4c3379d0180dc491e55e7caabfcdd1b0f538928d8d54107b9c1def3ed0baa3aa5106ba8674f0dd01400000000204b7e9da00f30cd1edf4d40710213c15a862e1fc175f2edb2b2c870c8559d65cdd79a4c7a655aa80cf92069bbac9666705f1d7181ff9c2d59efbc7e6ec4c3379de80300000000000040ab3c000000000000";
// Decoding the Bech32 private key to bytes
uint8_t private_key[32];
if (microsui_decode_sui_privkey(private_key_bech32, private_key) != 0) {
printf("Invalid Bech32 private key.\n");
return -1;
}
// Converting the message from hex to bytes
size_t message_len = strlen(message_hex) / 2; // 2 hex chars = 1 byte
uint8_t message[message_len];
hex_to_bytes(message_hex, message, message_len);
// Generating the Sui Signature from the message and private key (private_key is in constant.h)
uint8_t sui_sig[97];
printf("\n\n\n Generating Signature...\n");
microsui_sign_ed25519(sui_sig, message, message_len, private_key);
printf("\t Signature created successfully\n");
// Verifying the Sui Signature
int verification_result = microsui_verify_signature(sui_sig, message, message_len);
if(verification_result == 0) {
printf("\t Signature verified successfully\n\n");
} else {
printf("\t Signature verification failed\n");
printf("\t Error code: %d\n\n", verification_result);
}