createBatchCommitments
Creates commitments for a list of data items (dataList) in a single batch operation, using a shared secret. This is more efficient than calling createDataCommitment individually for each item.
It populates the outCommitments vector with ZKCommitment structures, each containing its own commitment hash, nonce, and timestamp.
Parameters
| Parameter | Type | Description |
|---|---|---|
dataList | const std::vector<String>& | The list of data strings to commit in batch. |
secret | const String& | The shared secret key to use for all commitments in the batch. |
outCommitments | std::vector<ZKCommitment>& | Output: A vector populated with the generated ZKCommitment structures. |
Return Value
bool: Returnstrueif the batch operation was successful.
Example Code (main.cpp)
#include <Arduino.h>
#include <vector>
#include "Infratic-lib.h" // Assume ZKCommitment struct is defined here
// This function does not require network connectivity.
Infratic solana(""); // RPC URL not needed
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("\n=== createBatchCommitments Example ===");
std::vector<String> dataList;
dataList.push_back("BatchData_1");
dataList.push_back("BatchData_2");
dataList.push_back("BatchData_3");
String sharedSecret = "batchSecretKey";
std::vector<ZKCommitment> commitments; // ZKCommitment defined in Infratic-lib.h
if (solana.createBatchCommitments(dataList, sharedSecret, commitments)) {
Serial.println("✅ Batch commitments created successfully!");
Serial.printf(" -> Generated %d commitments in total.\n", commitments.size());
// (Assuming ZKCommitment struct has these members)
// for (size_t i = 0; i < commitments.size(); ++i) {
// Serial.printf(" Commitment %d: %s\n", i, commitments[i].commitment.c_str());
// }
} else {
Serial.println("❌ Failed to create batch commitments.");
}
}
void loop() {
// Can be left empty
}