Files
fhe/examples/encrypted-crdt/tasks/merge-registers.ts
T
Zach Kelling 961c42e204 feat: add FHE example apps for all Pars PIPs
- data-seal: Verifiable Data Integrity Seal (PIP-0010/LP-0535)
  FHE-encrypted tamper-proof sealing with Public/ZK/Private modes,
  batch sealing, homomorphic verification

- content-provenance: AI & Media Content Provenance (PIP-0011/LP-7110)
  Model manifests, output attestation via homomorphic comparison,
  media derivation DAGs

- encrypted-crdt: Encrypted CRDT (PIP-0013/LP-6500)
  LWW-Register with FHE values, OR-Set with tag-based add/remove,
  Lamport timestamp conflict resolution, deterministic merge

- shadow-governance: Shadow Government Protocol (PIP-7010)
  Anonymous ministries, encrypted voting with homomorphic tallying,
  nullifier-based anti-fraud, quorum enforcement

Each example includes Solidity contracts, Hardhat tests, CLI tasks,
and README linking to corresponding PIP and LP specifications.
2026-02-13 14:16:46 -08:00

32 lines
1.2 KiB
TypeScript

import { task } from "hardhat/config";
task("task:merge-registers", "Merge two registers (LWW conflict resolution)")
.addParam("contract", "EncryptedCRDT contract address")
.addParam("doc", "Document ID")
.addParam("field1", "First field name")
.addParam("field2", "Second field name")
.addParam("result", "Result field name")
.setAction(async ({ contract, doc, field1, field2, result }, hre) => {
const [signer] = await hre.ethers.getSigners();
const crdt = await hre.ethers.getContractAt("EncryptedCRDT", contract);
const regId1 = hre.ethers.keccak256(
hre.ethers.solidityPacked(["string", "string"], [doc, field1])
);
const regId2 = hre.ethers.keccak256(
hre.ethers.solidityPacked(["string", "string"], [doc, field2])
);
const resultId = hre.ethers.keccak256(
hre.ethers.solidityPacked(["string", "string"], [doc, result])
);
const tx = await crdt.connect(signer).mergeRegisters(regId1, regId2, resultId);
await tx.wait();
const info = await crdt.getRegisterInfo(resultId);
console.log("Merged register:", {
timestamp: info.timestamp.toString(),
lastWriter: info.lastWriter,
});
});