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. |
| 11 | import { append } from "./ledgerstream.mjs"; |
| 12 | |
| 13 | const args = process.argv.slice(2); |
| 14 | const ledger = args.find((a) => !a.startsWith("--")); |
| 15 | const wi = args.indexOf("--writer"); |
| 16 | const writer = wi >= 0 ? args[wi + 1] : null; |
| 17 | if (!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 | |
| 22 | const stdin = []; |
| 23 | for await (const chunk of process.stdin) stdin.push(chunk); |
| 24 | const payload = JSON.parse(Buffer.concat(stdin).toString("utf8")); |
| 25 | |
| 26 | const head = await append(ledger, writer, new Date().toISOString(), payload); |
| 27 | console.log(ledger + ": entry " + head.count + " appended, head " + head.head_sha256.slice(0, 12) + "…"); |
| 28 | |