Skip to main content

signMessageRaw

Signs a given message (byte vector) using the Ed25519 algorithm with a private key provided in raw byte format. This is a lower-level version of signMessageFromBase58 that performs the signing directly without any Base58 decoding.

Parameters

ParameterTypeDescription
messageconst std::vector<uint8_t>&The byte vector containing the data to be signed.
privateKeyconst std::vector<uint8_t>&The 64-byte raw private key as a byte vector.
outSignatureuint8_t[64]An output parameter. This is a byte array where the resulting 64-byte signature will be stored.

Return Value

  • bool: Returns true if signing was successful, false if the private key size is invalid.

Example Code (main.cpp)

#include <Arduino.h>
#include "Infratic-lib.h"

// --- Settings ---
const String SOLANA_RPC_URL = "[https://api.devnet.solana.com](https://api.devnet.solana.com)";
// We first need to decode a Base58 key to get the raw bytes
const String MY_PRIVATE_KEY_BASE58 = "YOUR_PRIVATE_KEY_BASE58";

Infratic solana(SOLANA_RPC_URL);

void setup() {
Serial.begin(115200);
delay(1000);

Serial.println("\n=== Sign Message (Raw) Example ===");

// 1. Decode the Base58 private key to raw bytes
uint8_t rawPrivKeyBytes[128]; // base58Decode might require a larger buffer
size_t privLen = sizeof(rawPrivKeyBytes);
if (!base58Decode(MY_PRIVATE_KEY_BASE58, rawPrivKeyBytes, privLen) || privLen < 64) {
Serial.println("❌ Failed to decode private key from Base58.");
return;
}
// Take the first 64 bytes
std::vector<uint8_t> privateKeyVec(rawPrivKeyBytes, rawPrivKeyBytes + 64);

// 2. Prepare the message and sign
std::string message_str = "Raw signing test.";
std::vector<uint8_t> message(message_str.begin(), message_str.end());

uint8_t signature[64];

if (solana.signMessageRaw(message, privateKeyVec, signature)) {
Serial.println("✅ Message signed successfully with raw key!");
Serial.print(" -> Signature (hex): ");
for (int i = 0; i < 64; i++) {
if (signature[i] < 16) Serial.print("0");
Serial.print(signature[i], HEX);
}
Serial.println();
} else {
Serial.println("❌ Failed to sign message. Check the raw key size.");
}
}

void loop() {
// Can be left empty
}