verifyDataCommitment
Verifies a previously created cryptographic commitment (originalCommitment) against revealed data. This is the second step in commit-reveal schemes.
The function recalculates the commitment hash using the provided data, secret, nonce, and timestamp. If the recalculated hash exactly matches the originalCommitment, it proves that the revealed data is authentic and hasn't been tampered with.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | const String& | The revealed data to be verified. |
secret | const String& | The secret key originally used to create the commitment. |
nonce | const String& | The nonce originally used for the commitment. |
timestamp | uint64_t | The timestamp originally used for the commitment. |
originalCommitment | const String& | The previously generated commitment hash to compare against. |
Return Value
bool: Returnstrueif the data and parameters match the commitment,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=== verifyDataCommitment Example ===");
// Assume these values were obtained from a previous call to 'createDataCommitment'.
String revealedData = "sensor_reading:25.5C";
String mySecret = "myUltraSecureSecretKey123";
String originalNonce = "a1b2c3d4e5f6"; // Example nonce
uint64_t originalTimestamp = 1678886400; // Example timestamp
String originalCommitment = "2b9a7a59d6f0d36f5e8d9c12b4c7d0a3a1b2c3d4e5f67890a1b2c3d4e5f67890"; // Example commitment hash
// 1. Successful Verification Scenario
Serial.println("Test 1: Attempting successful verification...");
bool isVerified = solana.verifyDataCommitment(revealedData, mySecret, originalNonce, originalTimestamp, originalCommitment);
if (isVerified) {
Serial.println("✅ SUCCESS: Data matches the commitment!");
} else {
Serial.println("❌ ERROR: Data or parameters do not match the commitment.");
}
// 2. Failed Verification Scenario (Tampered Data)
Serial.println("\nTest 2: Attempting failed verification with tampered data...");
String tamperedData = "sensor_reading:99.9C"; // Data has been changed
isVerified = solana.verifyDataCommitment(tamperedData, mySecret, originalNonce, originalTimestamp, originalCommitment);
if (isVerified) {
Serial.println("❌ ERROR: Verification should have failed!");
} else {
Serial.println("✅ SUCCESS: Tampered data was correctly rejected.");
}
}
void loop() {
// Can be left empty
}