- scripts/e2e.sh (+ scripts/e2e/*.ts): the two-node end-to-end test, now self-contained and cleaning up after itself; `make e2e`, part of `make check` - Dockerfile/.dockerignore: static Go build in a non-root alpine image, data in /data, defaults to region u1j; `make docker` - flake.nix, nix/: package (buildGoModule), dev shell, NixOS module services.allmende (hardened systemd unit that waits for `allmende-admin init`), and a NixOS VM test run by `nix flake check` - README: running a node with Docker and NixOS Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
32 lines
1.5 KiB
TypeScript
32 lines
1.5 KiB
TypeScript
// A stand-in for the browser, for the e2e script: node buyer.ts send|read <gateway> <author> <id> [secretHex]
|
|
import { buildToOwner, mailbox, newThreadSecret, openReply, threadPublic, toHex } from "../../web/src/message.ts";
|
|
import { canonicalize } from "../../web/src/jcs.ts";
|
|
|
|
const [cmd, gw, author, id, secretHex] = process.argv.slice(2) as [string, string, string, string, string?];
|
|
const now = Math.floor(Date.now() / 1000);
|
|
|
|
if (cmd === "send") {
|
|
const listing = (await (await fetch(`${gw}/api/v1/listings/${author}/${id}`)).json()) as { device: string };
|
|
const status = (await (await fetch(`${gw}/api/v1/status`)).json()) as { message_difficulty: number };
|
|
const secret = newThreadSecret();
|
|
const env = await buildToOwner({
|
|
listing: { author, id, device: listing.device },
|
|
threadSecret: secret,
|
|
text: secretHex ?? "Ist die Wohnung noch frei?",
|
|
n: 1,
|
|
now,
|
|
difficulty: status.message_difficulty,
|
|
first: true,
|
|
});
|
|
const res = await fetch(`${gw}/api/v1/messages`, { method: "POST", body: canonicalize(env) });
|
|
if (res.status !== 202) throw new Error(`post: ${res.status} ${await res.text()}`);
|
|
console.log(toHex(secret));
|
|
} else {
|
|
const secret = Uint8Array.from(Buffer.from(secretHex!, "hex"));
|
|
const envs = (await (await fetch(`${gw}/api/v1/messages?mailbox=${mailbox(threadPublic(secret))}&since=${now - 7200}`)).json()) as unknown[];
|
|
for (const e of envs) {
|
|
const r = openReply(e, secret, { author, id });
|
|
console.log(r.ok ? `OK ${r.plain.t} ${r.plain.text ?? r.plain.address}` : `BAD ${r.error}`);
|
|
}
|
|
}
|