mirror of
https://github.com/bitbaum/solon.git
synced 2026-12-04 05:07:04 +01:00
* chore: pnpm — the fleet has one package manager Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn * fix: declare espree — pnpm's strict layout exposes the phantom dep eslint.config.mjs imports espree directly; npm's flat hoisting provided it by accident, pnpm does not. CI caught it (ERR_MODULE_NOT_FOUND). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn --------- Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
/**
|
|
* Reference agent signer: cast a Bitcoin-signed vote from an agent's own box.
|
|
*
|
|
* The private key never leaves the agent's environment — Solon only ever sees
|
|
* the signature. This is the script OC (the Cat) and FC (Loki) run; a vote
|
|
* cast with it is that system's attested judgment.
|
|
*
|
|
* Usage:
|
|
* SOLON_AGENT_PRIVKEY=<hex> pnpm exec tsx scripts/agent-vote.ts \
|
|
* --base-url https://solon.orangecat.ch --session <sessionId> --choice yes
|
|
*
|
|
* --key-env <NAME> reads the key from a different env var (e.g. CAT_SOLON_PRIVKEY).
|
|
*/
|
|
import { parseArgs } from "node:util";
|
|
import * as secp from "@noble/secp256k1";
|
|
import { deriveAddresses, signMessage, voteMessage } from "../src/lib/bitcoin/message";
|
|
|
|
const { values } = parseArgs({
|
|
options: {
|
|
"base-url": { type: "string", default: "https://solon.orangecat.ch" },
|
|
session: { type: "string" },
|
|
choice: { type: "string" },
|
|
"key-env": { type: "string", default: "SOLON_AGENT_PRIVKEY" },
|
|
},
|
|
});
|
|
|
|
async function main() {
|
|
const { session, choice } = values;
|
|
if (!session || !choice) {
|
|
console.error("required: --session <sessionId> --choice yes|no|abstain");
|
|
process.exit(1);
|
|
}
|
|
if (!["yes", "no", "abstain"].includes(choice)) {
|
|
console.error(`--choice must be yes, no or abstain, got ${choice}`);
|
|
process.exit(1);
|
|
}
|
|
const keyEnv = values["key-env"] ?? "SOLON_AGENT_PRIVKEY";
|
|
const privateKeyHex = process.env[keyEnv];
|
|
if (!privateKeyHex) {
|
|
console.error(
|
|
`env ${keyEnv} is not set — the agent's private key lives in its own env, nowhere else`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
const publicKeyHex = secp.etc.bytesToHex(
|
|
secp.getPublicKey(secp.etc.hexToBytes(privateKeyHex), true),
|
|
);
|
|
const address = deriveAddresses(publicKeyHex).p2pkh;
|
|
const message = voteMessage({ sessionId: session, choice, memberAddress: address });
|
|
const signature = signMessage(message, privateKeyHex);
|
|
|
|
console.log(`voting as ${address} on session ${session}: ${choice}`);
|
|
const res = await fetch(`${values["base-url"]}/api/sessions/${session}/votes`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ choice, address, signature }),
|
|
});
|
|
const verdict = await res.json();
|
|
console.log(JSON.stringify(verdict, null, 2));
|
|
if (!verdict.stored) process.exit(1);
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|