createDataCommitment
Creates a cryptographic commitment to hide data, using the original data and a secret key. This is the first step in commit-reveal schemes.
The generated outCommitment hash does not reveal any information about the original data. The outNonce (number used once) and outTimestamp ensure the commitment is unique and protected against replay attacks.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | const String& | The original data to be committed/hidden. |
secret | const String& | A secret key used to secure the commitment. |
outCommitment | String& | Output: The resulting commitment hash (hex format). |
outNonce | String& | Output: The randomly generated nonce used for the commitment. |
outTimestamp | uint64_t& | Output: The timestamp used for the commitment. |
Return Value
bool: Returnstrueif the commitment was created successfully,falseotherwise.
Example Code (main.cpp)
#include <Arduino.h>
#include "Infratic-lib.h"
// This function does not require network connectivity.
Infratic solana(""); // RPC URL not needed
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("\n=== createDataCommitment Example ===");
String dataToCommit = "sensor_reading:25.5C";
String mySecret = "myUltraSecureSecretKey123";
String commitment;
String nonce;
uint64_t timestamp;
if (solana.createDataCommitment(dataToCommit, mySecret, commitment, nonce, timestamp)) {
Serial.println("✅ Data commitment created successfully!");
Serial.println(" -> Data: " + dataToCommit);
Serial.println(" -> Secret: " + mySecret);
Serial.println("-------------------------------------");
Serial.println(" -> Commitment: " + commitment);
Serial.println(" -> Nonce: " + nonce);
Serial.print(" -> Timestamp: ");
Serial.println((unsigned long)timestamp);
Serial.println("\nYou can now send this 'Commitment' value on-chain.");
} else {
Serial.println("❌ Failed to create data commitment.");
}
}
void loop() {
// Can be left empty
}