noa-receipt
Version:
NOA Agent Action Receipt — open, offline-verifiable provenance for AI-agent actions. The governance/receipt organ only; the NOA brain is separate and proprietary.
39 lines (38 loc) • 1.46 kB
JavaScript
import { canonicalize } from "./jcs.js";
import { objectCreateNull, objectGetOwnPropertyNames, getOwnPropertyDescriptor } from "./intrinsics.js";
function copyOwn(source, omit) {
const out = objectCreateNull();
const keys = objectGetOwnPropertyNames(source);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (key === omit)
continue;
const d = getOwnPropertyDescriptor(source, key);
if (d === undefined || d.get !== undefined || d.set !== undefined)
continue;
out[key] = d.value;
}
return out;
}
export function receiptHashInput(receipt) {
const src = receipt;
const out = copyOwn(src);
const chain = src["chain"];
const sig = src["sig"];
if (typeof chain !== "object" || chain === null)
throw new TypeError("receiptHashInput: receipt.chain must be an object");
if (typeof sig !== "object" || sig === null)
throw new TypeError("receiptHashInput: receipt.sig must be an object");
out["chain"] = copyOwn(chain, "hash");
out["sig"] = copyOwn(sig, "value");
return canonicalize(out);
}
export function checkpointHashInput(cp) {
const src = cp;
const out = copyOwn(src);
const sig = src["sig"];
if (typeof sig !== "object" || sig === null)
throw new TypeError("checkpointHashInput: checkpoint.sig must be an object");
out["sig"] = copyOwn(sig, "value");
return canonicalize(out);
}