eleven / ocho Public

Clone
git clone https://amadan.net/eleven/ocho

Plain git — no account needed to clone.

Download

Download this file

1#!/usr/bin/env node
2// 🤖 Append one entry to a ledger stream (issue #1224) — the generic CLI over
3// tools/ledgerstream.mjs. The payload is JSON on stdin; the chain (prev-hash
4// fingerprints) is maintained for you.
5//
6// echo '{"note":"hello"}' | node tools/ledger-append.mjs <ledger> --writer "Full Name"
7//
8// Reads need no credentials (the bucket is public-read); the write uses the
9// ambient AWS profile — the scoped status-ledger-writer key or your own.
10// Verify any stream end-to-end with tools/ledger-verify.mjs.
11import { append } from "./ledgerstream.mjs";
12
13const args = process.argv.slice(2);
14const ledger = args.find((a) => !a.startsWith("--"));
15const wi = args.indexOf("--writer");
16const writer = wi >= 0 ? args[wi + 1] : null;
17if (!ledger || !writer || !/^[a-z][a-z0-9-]*$/.test(ledger)) {
18 console.error('usage: echo \'{"…"}\' | node tools/ledger-append.mjs <ledger> --writer "Full Name"');
19 process.exit(1);
20}
21
22const stdin = [];
23for await (const chunk of process.stdin) stdin.push(chunk);
24const payload = JSON.parse(Buffer.concat(stdin).toString("utf8"));
25
26const head = await append(ledger, writer, new Date().toISOString(), payload);
27console.log(ledger + ": entry " + head.count + " appended, head " + head.head_sha256.slice(0, 12) + "…");
28