Offline Sign (Get Signature)
The simplest and most powerful example we can find in microsui-lib is the ability to generate Sui-compatible Ed25519 signatures.
Using MicroSui, we can sign messages both for validation purposes and for completing transactions.
⚠️ This operation DOES NOT REQUIRE an internet connection. However, if generating the message to be signed requires network access, you must ensure that your microcontroller or development board includes an HTTP stack to reach the Sui API endpoints. Alternatively, the message to be signed can be generated externally and then passed to the device for signing.
SDK way (adaptation for ArduinoIDE)
✅ Fully compatible with Arduino IDE on supported platforms.
This is the most developer-friendly approach, similar to what you may find in the Mysten Labs SDKs.
const char* privateKey = "suiprivkey1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq509duq";
const char* messageToSign = "48656c6c6f2053756921"; // which is "Hello Sui!"
// Create the keypair object
MicroSuiEd25519 keypair = SuiKeypair_fromSecretKey(sui_private_key_bech32);
Serial.print(F(" DONE! - Created KeyPair - userAddress: ")); Serial.println(keypair.toSuiAddress(&keypair));
// Generate the Signature with the message and the keypair
SuiSignature sig = keypair.signTransaction(&keypair, message_string);
Serial.println(F(" DONE! - Created Signature!"));
Serial.println(F("\n --- Signature Result ---"));
if (sig.signature)
Serial.print(F(" Signature in BASE64 format: ")); Serial.println(sig.signature);
if (sig.bytes) {
Serial.print(F(" Signature in Bytes format: "));
for (int i = 0; i < 97; i++) {
Serial.print(F("%02x", sig.bytes[i]));
}
}
Serial.print(F("\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.
const char* private_key_bech32 = "suiprivkey1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq509duq";
const char* message_hex = "48656c6c6f2053756921"; // which is "Hello Sui!"
// 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
uint8_t sui_sig[97];
microsui_sign_ed25519(sui_sig, message, message_len, private_key);
// Printing the Sui Signature in hex format
char sui_sig_hex[195]; // 2 hex chars per byte + null terminator
bytes_to_hex(sui_sig, 97, sui_sig_hex); // 97 bytes is the length of a Sui Signature
printf(" Sui Signature (97 bytes): %s\n", sui_sig_hex);