Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,518 changes: 1,518 additions & 0 deletions crates/gitlawb-node/src/ans104.rs

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions crates/gitlawb-node/src/arweave_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! #26 Split PR 2 — three-outcome recovery policy types.
//!
//! This module owns the recovery classification policy the reviewer
//! demanded: only a trustworthy, protocol-defined absence authorizes
//! a paid re-upload. Everything else stays non-terminal.
//!
//! Deliberately narrow: the ANS-104 codec lives in `ans104`, and the
//! gateway probe, the `verify_anchor` path, and the public verify
//! endpoint are deferred until the uploader, retrieval proof, and
//! recovery consumer can be proven as one vertical slice (reviewer 2,
//! round 5). A probe against a real provider contract — same-network
//! upload/read pair, redirect-safe client, envelope-supplying read
//! API, provider-documented absence evidence — belongs in that slice,
//! not here. What ships here is the policy type plus the rule that
//! only `DefinitivelyAbsent` permits spending another upload.

/// Outcome of a gateway probe for a persisted `item_id`.
// Policy surface for the recovery slice: no construction on this
// head (the probe arrives with the provider contract); the unit
// test pins the rule meanwhile.
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProbeOutcome {
/// The persisted item was served back with a verifiable envelope
/// bound to the requested id. No re-upload allowed.
Present,
/// Trustworthy, protocol-defined proof the item was never
/// accepted. Authorizes re-upload. The exact evidence that
/// establishes this is defined by the provider contract in the
/// vertical slice that introduces the probe — never by a
/// mock-only body shape.
DefinitivelyAbsent,
/// Anything else: transport failure, oversized body, bad
/// signature, id mismatch, ambiguous gateway response. The
/// outbox stays non-terminal.
Indeterminate,
}

impl ProbeOutcome {
/// True iff the recovery code is allowed to spend another paid
/// upload request. Only `DefinitivelyAbsent` qualifies.
#[allow(dead_code)] // the recovery consumer lives in a later slice
pub fn permits_reupload(self) -> bool {
matches!(self, ProbeOutcome::DefinitivelyAbsent)
}
}

#[cfg(test)]
mod tests {
use super::*;

/// Only `DefinitivelyAbsent` authorizes a paid re-upload. This is
/// the policy the reviewer named: collapsing any ambiguous outcome
/// to absent spends a second immutable upload for the same
/// transition.
#[test]
fn only_definitively_absent_authorizes_reupload() {
assert!(!ProbeOutcome::Present.permits_reupload());
assert!(ProbeOutcome::DefinitivelyAbsent.permits_reupload());
assert!(!ProbeOutcome::Indeterminate.permits_reupload());
}
}
2 changes: 2 additions & 0 deletions crates/gitlawb-node/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod ans104;
mod api;
mod arweave;
mod arweave_v2;
mod auth;
mod bootstrap;
mod cert;
Expand Down
4 changes: 4 additions & 0 deletions crates/gitlawb-node/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ pub fn build_router(state: AppState) -> Router {
.merge(Router::new().route("/api/v1/ipfs/pins", get(ipfs::list_pins)));

// ── Arweave permanent anchors ──────────────────────────────────────────
// List endpoint only (public; issue #134 tracks surfacing
// visibility rules on list). The verify endpoint and its probe
// are deferred to the vertical slice with the uploader and a
// real provider contract (reviewer 2, #26 split 2/4 round 5).
let arweave_routes = Router::new().route("/api/v1/arweave/anchors", get(arweave::list_anchors));

// ── Bounty routes (write — require HTTP Signature) ─────────────────
Expand Down
33 changes: 33 additions & 0 deletions scripts/ans104_golden.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createData, EthereumSigner } from "arbundles";
import { createHash } from "node:crypto";
import base64url from "base64url";

const data = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-=[]{};':\",./<>?`~";
const tags = [
{ name: "tag1", value: "value1" },
{ name: "tag2", value: "value2" },
];
const anchor = "thisSentenceIs32BytesLongTrustMe";
const target = "OXcT1sVRSA5eGwt2k6Yuz8-3e3g9WJi5uSE99CWqsBs";
const signer = new EthereumSigner("8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f");

const item = createData(data, signer, { anchor, target, tags });
// Sign so the captured signature is real: `createData` alone leaves a
// zeroed placeholder, whose id is just sha256(zeros).
await item.sign(signer);
const raw = item.getRaw();
const id = item.id;

// `item.signature` is base64url(rawSignature). Decode and sha256.
const sigBytes = base64url.toBuffer(item.signature);
const idCheck = base64url.encode(createHash("sha256").update(sigBytes).digest());
if (idCheck !== id) {
console.error(`MISMATCH: id=${id} sha256(sig)=${idCheck}`);
process.exit(1);
}

console.log("id =", id);
console.log("signature_b64=", item.signature);
console.log("signature_len=", sigBytes.length);
console.log("binary_len =", raw.length);
console.log("binary_hex =", raw.toString("hex"));
40 changes: 40 additions & 0 deletions scripts/ans104_golden_ed25519.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { createData, SolanaSigner } from "arbundles";
import bs58 from "bs58";
import { getPublicKey } from "@noble/ed25519";
import { createHash } from "node:crypto";
import base64url from "base64url";

// Deterministic Ed25519 keypair from seed 0x01 * 32.
const seed = Buffer.alloc(32, 0x01);
const pub = await getPublicKey(seed);
const secret64 = Buffer.concat([seed, Buffer.from(pub)]);
const signer = new SolanaSigner(bs58.encode(secret64));

const data = "hello gitlawb ed25519 golden";
const tags = [
{ name: "App-Name", value: "gitlawb" },
{ name: "Schema", value: "gitlawb/ref-update/v1" },
];

const item = createData(data, signer, { tags });
await item.sign(signer);
const raw = Buffer.from(item.getRaw());
const id = item.id;
const sigBytes = base64url.toBuffer(item.signature);
const idCheck = base64url.encode(createHash("sha256").update(sigBytes).digest());
if (idCheck !== id) {
console.error(`MISMATCH: id=${id} sha256(sig)=${idCheck}`);
process.exit(1);
}
const sigData = await item.getSignatureData();
console.log("id =", id);
console.log("signature_b64=", item.signature);
console.log("signature_len=", sigBytes.length);
console.log("owner_b64 =", item.owner);
console.log("owner_len =", base64url.toBuffer(item.owner).length);
console.log("sigtype =", item.signatureType);
console.log("binary_len =", raw.length);
console.log("binary_hex =", raw.toString("hex"));
console.log("deephash_hex =", Buffer.from(sigData).toString("hex"));
console.log("data_b64 =", base64url.encode(Buffer.from(data)));
console.log("isValid =", await item.isValid());
37 changes: 37 additions & 0 deletions scripts/ans104_golden_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ANS-104 golden vectors, captured from arbundles 0.10.x.

Ed25519 vector (the interop pin used by
`ans104::tests::dataitem_matches_arbundles_golden_vector`):
captured by = scripts/ans104_golden_ed25519.mjs (deterministic seed
0x01 * 32 via SolanaSigner, sigtype 2, `await item.sign`)
data = "hello gitlawb ed25519 golden"
tags = [{name:"App-Name",value:"gitlawb"},
{name:"Schema",value:"gitlawb/ref-update/v1"}]
target = absent
anchor = absent

Outputs:
signature_type = 2 (Ed25519)
signature_len = 64 bytes
owner_len = 32 bytes
binary_len = 192 bytes
id = SGrcBs-ITTyzvd7eIB5kk2GdBWoxB_iTi9iJ6KOe_RE (base64url of sha256(signature))
deephash_hex = f15c82431767f14ac9e66ab8e995a8cd08e094be3773245163b53c12feb50aefc55d9f8c1098fabcfbf11a462706d347
(arbundles `getSignatureData` 8-element fold)

binary_hex:
0200da41825fd44ca3b2705af18fce86ed6d04d0204331965d9af5d5cb1a740fcc6587ee81501b1d7928c54c0f174fde8893560d785db4d988a3161113b10a2028038a88e3dd7409f195fd52db2d3cba5d72ca6709bf1d94121bf3748801b40f6f5c00000200000000000000300000000000000004104170702d4e616d650e6769746c6177620c536368656d612a6769746c6177622f7265662d7570646174652f76310068656c6c6f206769746c617762206564323535313920676f6c64656e

The Rust side will:
1. Parse binary via DataItem::from_binary (signature_type, signature,
owner, target, anchor, tags, data).
2. Compute deep_hash via DataItem::deep_hash (the 8-element arbundles
fold) and compare to deephash_hex above.
3. Verify the Ed25519 signature via DataItem::verify_data_item WITHOUT
re-signing.
4. Assert sha256(signature_bytes) base64url-encodes to the captured id.
5. Assert to_binary round-trips byte-exact (signature slot preserved).

Legacy Ethereum script (scripts/ans104_golden.mjs) now signs before
capture as well; its output is illustrative only — the node verifies
Ed25519 (sigtype 2) on the verify path.
Loading
Loading