@@ -678,31 +647,14 @@ function ProjectDetails({ data, account, ready, busy, now, transact, onClose })
{current && milestoneWindow?.open && !m.submitted && isCreator && (
-
+
+
+
)}
{current && milestoneWindow?.open && m.submitted && !m.approved && contribution > 0n && (
diff --git a/src/EvidenceForm.jsx b/src/EvidenceForm.jsx
new file mode 100644
index 0000000..8fc84ba
--- /dev/null
+++ b/src/EvidenceForm.jsx
@@ -0,0 +1,146 @@
+import React, { useState } from "react";
+
+import { buildEvidencePackage, readBrowserFile } from "./ipfs.js";
+import { pinEvidence } from "./relay.js";
+import { PIN_RELAY_KEY, PIN_RELAY_URL } from "./contract.js";
+import { errorMessage } from "./utils.js";
+
+// Two-step evidence flow: package and pin locally first, then record the digest
+// on chain. The on-chain transaction only becomes available after a successful pin.
+export default function EvidenceForm({ index, ready, busy, onSubmit }) {
+ const [fileList, setFileList] = useState([]);
+ const [summary, setSummary] = useState("");
+ const [stage, setStage] = useState("idle"); // idle | packing | pinning | ready | error
+ const [packageResult, setPackageResult] = useState(null);
+ const [error, setError] = useState("");
+
+ function resetPackage() {
+ setStage("idle");
+ setPackageResult(null);
+ setError("");
+ }
+
+ function chooseFiles(event) {
+ setFileList(Array.from(event.target.files ?? []));
+ resetPackage();
+ }
+
+ async function prepare() {
+ setError("");
+ try {
+ const text = summary.trim();
+ if (!text) throw new Error("Write a summary of what you delivered.");
+ if (new TextEncoder().encode(text).length > 4000)
+ throw new Error("Summary must be 1–4000 UTF-8 bytes.");
+ if (fileList.length === 0)
+ throw new Error("Attach at least one evidence file.");
+
+ const inputs = await Promise.all(fileList.map(readBrowserFile));
+ setStage("packing");
+ const result = await buildEvidencePackage(inputs, text);
+
+ setStage("pinning");
+ const pinned = await pinEvidence(
+ PIN_RELAY_URL,
+ result.car,
+ result.digestHex,
+ PIN_RELAY_KEY,
+ );
+ setPackageResult({ ...result, pinned });
+ setStage("ready");
+ } catch (e) {
+ setError(errorMessage(e));
+ setStage("error");
+ }
+ }
+
+ async function submit(event) {
+ event.preventDefault();
+ if (stage !== "ready" || !packageResult) return;
+ await onSubmit(index, packageResult.digestHex, summary.trim());
+ }
+
+ const working = stage === "packing" || stage === "pinning";
+
+ return (
+
+
Creator’s evidence
+
{evidence}
+
+
+
+
IPFS CID
+
+
+
+
+
+
{cidText}
+
+
+
+
+
+
+
+
+ {result && (
+
+ {result.match
+ ? `✓ Match · ${result.scope} · ${result.checkedBlocks} block(s) via ${result.gateway}`
+ : `✗ Mismatch${result.reason ? ` · ${result.reason}` : ""}`}
+
+ )}
+
+ );
+}
diff --git a/src/abi/MilestoneFund.json b/src/abi/MilestoneFund.json
index b0e6c63..1d3e218 100644
--- a/src/abi/MilestoneFund.json
+++ b/src/abi/MilestoneFund.json
@@ -94,9 +94,9 @@
},
{
"indexed": false,
- "internalType": "string",
- "name": "evidenceUrl",
- "type": "string"
+ "internalType": "bytes32",
+ "name": "evidenceCid",
+ "type": "bytes32"
}
],
"name": "EvidenceSubmitted",
@@ -588,9 +588,9 @@
"type": "string"
},
{
- "internalType": "string",
- "name": "evidenceUrl",
- "type": "string"
+ "internalType": "bytes32",
+ "name": "evidenceCid",
+ "type": "bytes32"
},
{
"internalType": "uint256",
@@ -828,9 +828,9 @@
"type": "string"
},
{
- "internalType": "string",
- "name": "evidenceUrl",
- "type": "string"
+ "internalType": "bytes32",
+ "name": "evidenceCid",
+ "type": "bytes32"
}
],
"name": "submitEvidence",
diff --git a/src/contract.js b/src/contract.js
index 5ea0e3e..0bf7a86 100644
--- a/src/contract.js
+++ b/src/contract.js
@@ -48,6 +48,10 @@ export const CONFIGURED = CONFIG.configured;
export const CONFIG_ERROR = CONFIG.error;
export const ABI = abi;
+// Pin relay (Cloudflare Worker). Optional until the creator submits evidence.
+export const PIN_RELAY_URL = (import.meta.env?.VITE_PIN_RELAY_URL ?? "").trim();
+export const PIN_RELAY_KEY = (import.meta.env?.VITE_PIN_RELAY_KEY ?? "").trim();
+
// Prefer MetaMask specifically, including legacy multi-wallet injection.
export function injectedWallet() {
const injected = window.ethereum;
diff --git a/src/ipfs.js b/src/ipfs.js
new file mode 100644
index 0000000..a563284
--- /dev/null
+++ b/src/ipfs.js
@@ -0,0 +1,343 @@
+// Content-addressed evidence packaging for MilestoneFund v2.
+//
+// Evidence files plus a manifest are packed into a deterministic UnixFS directory
+// (dag-pb) entirely in the browser. Only the 32-byte SHA-256 digest is stored on
+// chain; the full CID is reconstructed with multihash prefix 0x1220 ++ digest.
+
+import { CID } from "multiformats/cid";
+import { decode as decodeDigest } from "multiformats/hashes/digest";
+import { sha256 } from "multiformats/hashes/sha2";
+import * as raw from "multiformats/codecs/raw";
+import { base58btc } from "multiformats/bases/base58";
+import { base32 } from "multiformats/bases/base32";
+import * as dagPB from "@ipld/dag-pb";
+import { CarWriter, CarReader } from "@ipld/car";
+import { UnixFS } from "ipfs-unixfs";
+
+export const EVIDENCE_SCHEMA_VERSION = 1;
+export const MANIFEST_NAME = "manifest.json";
+// Kubo-compatible leaf chunk size.
+export const DEFAULT_CHUNK_SIZE = 262144;
+
+const textEncoder = new TextEncoder();
+const textDecoder = new TextDecoder();
+const MULTIHASH_SHA256_PREFIX = new Uint8Array([0x12, 0x20]);
+
+// ---------------------------------------------------------------------------
+// Low-level byte helpers
+// ---------------------------------------------------------------------------
+
+export function utf8ByteLength(text) {
+ return textEncoder.encode(text).length;
+}
+
+function toHex(bytes) {
+ let out = "";
+ for (const b of bytes) out += b.toString(16).padStart(2, "0");
+ return out;
+}
+
+function fromHex(hex) {
+ const clean = hex.startsWith("0x") ? hex.slice(2) : hex;
+ if (clean.length % 2 !== 0) throw new Error("Invalid hex string");
+ const bytes = new Uint8Array(clean.length / 2);
+ for (let i = 0; i < bytes.length; i++)
+ bytes[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
+ return bytes;
+}
+
+function concatBytes(parts) {
+ const total = parts.reduce((n, p) => n + p.length, 0);
+ const out = new Uint8Array(total);
+ let offset = 0;
+ for (const part of parts) {
+ out.set(part, offset);
+ offset += part.length;
+ }
+ return out;
+}
+
+async function putDagPBNode(node, blocks) {
+ const bytes = dagPB.encode(node);
+ const multihash = await sha256.digest(bytes);
+ const cid = CID.create(1, dagPB.code, multihash);
+ blocks.push({ cid, bytes });
+ return { cid, bytes };
+}
+
+// A file small enough for one UnixFS node carries its bytes inline.
+function inlineFileNode(bytes) {
+ const unix = new UnixFS({ type: "file", data: bytes });
+ return dagPB.createNode(unix.marshal(), []);
+}
+
+// A large file is split into raw leaf blocks linked by one UnixFS file node.
+async function chunkedFileNode(bytes, chunkSize, blocks) {
+ const links = [];
+ const blockSizes = [];
+ for (let start = 0; start < bytes.length; start += chunkSize) {
+ const leaf = bytes.subarray(start, Math.min(start + chunkSize, bytes.length));
+ const multihash = await sha256.digest(leaf);
+ const leafCid = CID.create(1, raw.code, multihash);
+ blocks.push({ cid: leafCid, bytes: leaf });
+ links.push(dagPB.createLink("", leaf.length, leafCid));
+ blockSizes.push(BigInt(leaf.length));
+ }
+ const unix = new UnixFS({ type: "file", blockSizes });
+ return dagPB.createNode(unix.marshal(), links);
+}
+
+async function buildFile(name, bytes, chunkSize, blocks) {
+ const node =
+ bytes.length <= chunkSize
+ ? inlineFileNode(bytes)
+ : await chunkedFileNode(bytes, chunkSize, blocks);
+ const { cid, bytes: encoded } = await putDagPBNode(node, blocks);
+ return { name, size: bytes.length, cid, tsize: encoded.length };
+}
+
+function buildDirectoryNode(entries) {
+ const links = entries
+ .map((entry) => dagPB.createLink(entry.name, entry.tsize, entry.cid))
+ .sort((a, b) => (a.Name < b.Name ? -1 : a.Name > b.Name ? 1 : 0));
+ const unix = new UnixFS({ type: "directory" });
+ return dagPB.createNode(unix.marshal(), links);
+}
+
+async function writeCar(rootCid, blocks) {
+ const seen = new Set();
+ const unique = [];
+ for (const block of blocks) {
+ const key = block.cid.toString();
+ if (!seen.has(key)) {
+ seen.add(key);
+ unique.push(block);
+ }
+ }
+ const { writer, out } = CarWriter.create([rootCid]);
+ const parts = [];
+ const drain = (async () => {
+ for await (const part of out) parts.push(part);
+ })();
+ for (const block of unique) await writer.put(block);
+ await writer.close();
+ await drain;
+ return concatBytes(parts);
+}
+
+// ---------------------------------------------------------------------------
+// Public API: packaging
+// ---------------------------------------------------------------------------
+
+/**
+ * Build an evidence package.
+ * @param {Array<{name:string, bytes?:Uint8Array, arrayBuffer?:()=>Promise