lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

order_terms_oracle.mjs (2577B)


      1 // Independent ECMAScript canonicalization/SHA-256 oracle for the closed
      2 // ASCII-key command profile. This consumes synthetic fixture inputs only,
      3 // never Rust writer output, source authority or product data.
      4 import { createHash } from "node:crypto";
      5 import { readFileSync } from "node:fs";
      6 
      7 const source = readFileSync(new URL("../fixtures/order_acceptance.v1.json", import.meta.url));
      8 const inputs = JSON.parse(source).cases;
      9 const canonical = value => {
     10   if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
     11   if (value !== null && typeof value === "object") {
     12     return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`;
     13   }
     14   return JSON.stringify(value);
     15 };
     16 const hash = (domain, value) => createHash("sha256").update(domain, "utf8").update(canonical(value), "utf8").digest("hex");
     17 const cases = inputs.map((original, index) => {
     18   const context = structuredClone(original.wire.context);
     19   context.operation_id = (index ? "52" : "51").repeat(32);
     20   context.expected.agreement = "40".repeat(32);
     21   context.expected.seller_sequence = "1";
     22   context.expected.buyer_head = "32".repeat(32);
     23   context.correlation_id = index ? "replacement 🥬 observer" : null;
     24   context.approval = null;
     25   const wire = { type: "orders.install_terms", context, input: {
     26     proposal: "31".repeat(32), authorization: "32".repeat(32),
     27     terms_digest: original.wire.input.terms_digest,
     28     allocation: structuredClone(original.wire.input.allocation),
     29   }};
     30   const intent = structuredClone(wire);
     31   delete intent.context.approval;
     32   delete intent.context.correlation_id;
     33   const approval = hash("radroots.approval.v1\0", intent);
     34   if (index) wire.context.approval = { intent_digest: approval, scope: "orders.install_terms", expires_at: "190" };
     35   const semantic = structuredClone(wire);
     36   delete semantic.context.correlation_id;
     37   return { name: index ? "explicit_with_approval" : "automatic_without_approval", wire,
     38     protected_canonical_utf8: canonical(wire), semantic_canonical_utf8: canonical(semantic),
     39     command_digest: hash("radroots.command.v1\0", semantic), approval_intent_digest: approval };
     40 });
     41 process.stdout.write(JSON.stringify({ schema: "radroots.terms_installation_commands.v1",
     42   provenance: "Synthetic command inputs; independent ECMAScript ASCII-key canonicalization and Node SHA-256. No Rust writer or actual authority is used.",
     43   producer: `Node.js ${process.versions.node}`,
     44   source_context_fixture_sha256: createHash("sha256").update(source).digest("hex"), cases }, null, 2) + "\n");