@ajna-inc/poe-proofs
v0.2.1
Published
Zero-knowledge proofs for Time, Location, and more (POE Protocol) - React Native & Node.js
Maintainers
Readme
@ajna-inc/poe-proofs
Zero-knowledge proofs for Time and Location verification - POE Protocol compatible.
Platform Support
| Feature | React Native | Node.js | |---------|-------------|---------| | Time Proof Generation | Full | - | | Location Proof Generation | Full | - | | Proof Verification | Full | Full | | Poseidon Hashing | Full | Full | | Commitment Computation | Full | Full | | Type Definitions | Full | Full |
React Native: Full proof generation using device sensors (GPS, magnetometer) and blockchain anchoring.
Node.js: Server-side verification of proofs using snarkjs. Proof generation requires mobile device sensors.
Installation
React Native
npm install @ajna-inc/poe-proofs
# or
yarn add @ajna-inc/poe-proofsiOS
cd ios && pod installAndroid
No additional steps required. Native libraries are automatically linked.
Node.js (Verification Only)
npm install @ajna-inc/poe-proofs snarkjsUsage
React Native - Generate Proofs
import {
generateTimeProofPOE,
generateLocationProofPOE,
verifyTimeProofPOE,
} from '@ajna-inc/poe-proofs';
// Generate a time proof (anchored to Ethereum blockchain)
const timeProof = await generateTimeProofPOE({
nonce: Date.now(),
contextHash: 12345,
sessionId: 67890,
deviceTimestamp: Math.floor(Date.now() / 1000),
tolerance: 300, // 5 minutes
});
console.log(`Time proof valid: ${timeProof.isValid}`);
console.log(`Drift: ${timeProof.drift} seconds`);
console.log(`Block: #${timeProof.blockNumber}`);
// Generate a location proof (uses GPS + magnetometer + barometer)
const locationProof = await generateLocationProofPOE({
nonce: Date.now(),
contextHash: 12345,
sessionId: 67890,
latitude: 37.7749,
longitude: -122.4194,
altitudeM: 10,
gpsAccuracyM: 5,
magXUt: 22.5,
magYUt: 5.2,
magZUt: 42.1,
pressurePa: 101325,
proofTimestamp: Math.floor(Date.now() / 1000),
currentTimestamp: Math.floor(Date.now() / 1000),
magneticTolerancePercent: 30,
altitudeToleranceM: 50,
});
console.log(`Location proof valid: ${locationProof.isValid}`);
console.log(`Confidence: ${locationProof.confidenceScore}%`);Node.js - Verify Proofs
// Import from the package (auto-detects Node.js environment)
import { verifyTimeProofPOE, verifyLocationProofPOE } from '@ajna-inc/poe-proofs';
// Or explicitly import the Node.js module
import { verifyTimeProofPOE } from '@ajna-inc/poe-proofs/node';
// Verify a time proof received from mobile
const isValid = await verifyTimeProofPOE(
proofJson, // JSON string from mobile
publicInputs, // Array of public input strings
'./time_proof.vkey.json' // Path to verification key (optional, bundled by default)
);
console.log(`Proof valid: ${isValid}`);
// Verify a location proof
const locationValid = await verifyLocationProofPOE(
proofJson,
publicInputs,
'./location_proof.vkey.json'
);Utility Functions (Both Platforms)
import {
hash2,
hash3,
computeCommitment,
generateNonce,
DOMAIN_TAGS,
} from '@ajna-inc/poe-proofs';
// Poseidon hashing (BN254 field)
const hash = hash2(BigInt(1), BigInt(2));
// Generate secure nonce
const nonce = generateNonce();
// Compute domain-separated commitment
const commit = computeCommitment(DOMAIN_TAGS.NONCE, nonce);API Reference
Proof Generation (React Native Only)
generateTimeProofPOE(input)
Generate a Groth16 time proof anchored to Ethereum blockchain.
interface TimeProofInputNew {
nonce: number;
contextHash: number;
sessionId: number;
deviceTimestamp: number;
tolerance: number;
}generateLocationProofPOE(input)
Generate a Groth16 location proof with magnetic field validation.
interface LocationProofInputNew {
nonce: number;
contextHash: number;
sessionId: number;
latitude: number; // GPS latitude (-90 to 90)
longitude: number; // GPS longitude (-180 to 180)
altitudeM: number; // Altitude in meters
gpsAccuracyM: number; // GPS accuracy in meters
magXUt: number; // Magnetometer X (microtesla)
magYUt: number; // Magnetometer Y (microtesla)
magZUt: number; // Magnetometer Z (microtesla)
pressurePa: number; // Barometric pressure (Pascals)
proofTimestamp: number;
currentTimestamp: number;
magneticTolerancePercent: number;
altitudeToleranceM: number;
}Verification (Both Platforms)
verifyTimeProofPOE(proofJson, publicInputs, vkeyPath?)
Verify a time proof. On React Native, uses native MoPro. On Node.js, uses snarkjs.
verifyLocationProofPOE(proofJson, publicInputs, vkeyPath?)
Verify a location proof.
Hashing & Commitments
hash2(a, b) / hash3(a, b, c)
Poseidon hash functions (BN254 field, matches circomlib).
computeCommitment(domain, value)
Compute domain-separated Poseidon commitment.
DOMAIN_TAGS
Domain separation tags for different commitment types:
NONCE,CONTEXT,SESSION,COORDS,MAGNETIC,ALTITUDE,TIMESTAMPS
Utilities
generateNonce() / generateNonceNumber()
Generate cryptographically secure nonces.
scaleCoordinate(coord) / scaleAltitude(meters) / scaleMagnetic(nT)
Scale values for circuit compatibility.
formatAsPOEMessage(proof, programId, messageId)
Format proof as POE DIDComm message.
toSnarkjsFormat(proof)
Convert proof to snarkjs-compatible format.
Verification Keys
Verification keys are bundled with the package:
node_modules/@ajna-inc/poe-proofs/lib/vkeys/
├── time_proof.vkey.json
└── location_proof.vkey.jsonYou can also access them via:
import timeVkey from '@ajna-inc/poe-proofs/vkeys/time_proof.vkey.json';Building from Source
Prerequisites
- Node.js 18+
- Rust (latest stable)
- Android NDK 25.1 (for Android)
- Xcode 15+ (for iOS)
Build Commands
# Install dependencies
npm install
# Build TypeScript + extract verification keys
npm run build
# Build native libraries
npm run build:native
# Run tests
npm test # Jest unit tests
npm run test:node # Node.js integration testsSecurity
- Groth16 Proofs: Zero-knowledge proofs using BN254 curve
- Poseidon Hashing: Efficient ZK-friendly hash function
- Blockchain Anchoring: Time proofs anchored to Ethereum blocks
- World Magnetic Model: Location validation against expected magnetic field
- Anti-Replay: Nonce-based replay protection
License
MIT
