Skip to main content

createRangeProof

Creates a "range proof" demonstrating that a secret value (value) lies within a specific minimum (minValue) and maximum (maxValue) range, without revealing the value itself.

For example, this is the cryptographic way of saying, "My device's temperature reading is between 20 and 30 degrees, but I won't tell you the exact value."

Parameters

ParameterTypeDescription
valueint64_tThe secret value whose range is to be proven.
minValueint64_tThe minimum allowed value (inclusive).
maxValueint64_tThe maximum allowed value (inclusive).
secretconst String&A secret key used to secure the proof.
outProofRangeProof&Output: A RangeProof structure containing the generated proof data.

Return Value

  • bool: Returns true if the proof was created successfully, false otherwise.

Example Code (main.cpp)

#include <Arduino.h>
#include "Infratic-lib.h" // Assume RangeProof 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=== createRangeProof Example ===");

int64_t secretValue = 42;
int64_t minRange = 0;
int64_t maxRange = 100;
String mySecret = "rangeProofSecret123";
RangeProof proof; // This struct is defined in Infratic-lib.h

Serial.print("Creating proof that secret value (42) is within [0, 100]...");

if (solana.createRangeProof(secretValue, minRange, maxRange, mySecret, proof)) {
Serial.println("\n✅ Range proof created successfully!");
// The 'proof' object can now be verified using 'verifyRangeProof'.
} else {
Serial.println("\n❌ Failed to create range proof.");
}
}

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