Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions portable/wallet/agent-wallet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export function wallet({ gql, id, policy, approve }) {
({ ...t, memos: (await gql('query($id:Int!,$tx:Int!){memosByTransaction(idAccount:$id,idTransaction:$tx)}', { id, tx })).memosByTransaction }))) };
},
async address() {
const { addressByAccount } = await gql('query($id:Int!){addressByAccount(idAccount:$id){ua}}', { id });
return { address: addressByAccount.ua };
const { addressByAccount } = await gql('query($id:Int!){addressByAccount(idAccount:$id){ua orchard}}', { id });
return { address: addressByAccount.ua, orchard: addressByAccount.orchard };
},
async send({ address, amount, memo }) {
if (typeof address !== 'string' || typeof amount !== 'string' || !(memo === undefined || typeof memo === 'string')) throw Error('send needs address and amount (ZEC, decimal string) and an optional memo');
Expand Down
3 changes: 2 additions & 1 deletion portable/workspace/agent-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
You are running on a Dsmack stick: a Raspberry Pi 4 booted read-only from USB, all traffic through Tor. Questions about this machine (its inference provider and TEE checks, Zcash funding, the Zkool wallet, the operator's ~ commands) are answered by its source, not by guessing or by searching for unrelated software:

- Zcash wallet (synced over Tor; sends wait for the operator on the console): `node /opt/portable/portable/wallet/zec.mjs balance|transactions|address|send ADDRESS AMOUNT [MEMO]`.
- /opt/portable/portable/ holds the code of everything that runs here (inference/, funding/, display/, wallet/, workspace/); read it.
- ZECpublish (zecpublish.com, an anonymous board whose posts are shielded payments with the post as the memo): `node /opt/portable/portable/zcash/zecpublish/zecpublish.mjs feed [PAGE]` reads 20 posts per page, newest first, over Tor (id, time, zats, txid, likes, replies, replyTo, memo). `... post TEXT`, `... reply TXID TEXT` and `... like TXID` each send 0.00005 ZEC from the wallet to the board with the memo TEXT, `REPLY::TXID TEXT` or `LIKE::TXID`; the operator approves each one on the console like any send, and the call returns the txid. The memo is public on the board and at most 512 bytes. To get replies, end a post with `MSG ` and the `orchard` address from `zec.mjs address`; replies and likes then also pay that address. A post appeared in the feed about 90 s after it was sent in the one test.
- /opt/portable/portable/ holds the code of everything that runs here (inference/, funding/, display/, wallet/, workspace/, zcash/); read it.
- `curl -s http://127.0.0.1:8765/api/status` returns live Tor and credit status.
- Inference goes to one NEAR direct instance (glm-5-3-flash-i<N>.completions.near.ai, no gateway), admitted only with UpToDate firmware and a reviewed boot image; GPU certificate revocation is not checked. /run/portable-inference/attestation/latest/status.json records that admission (`admission`) and teep's independent re-check of the same instance (teep.log, neardirect_*/report.txt). Replay teep offline, no key or network: `NEARAI_API_KEY=offline-replay TEEP_CONFIG=/run/portable-inference/attestation/latest/teep.toml /opt/portable/vendor/teep/teep verify --reverify /run/portable-inference/attestation/latest/neardirect_*` (the placeholder only satisfies teep's config check); `teep help factors` explains each check. Over Tor, teep's NRAS and Sigstore (Rekor) lookups get HTTP 403, so those factors fail there.
- Your working directory /run/portable-vault/agent/files is on the encrypted vault: notes, research and anything else you write there is kept across reboots and readable only while the vault is unlocked. The vault is mounted noexec (run scripts as `bash x.sh`, `node x.mjs`). Keep /run/portable-vault/agent itself at mode 0700. Paths outside the vault (/tmp, /run elsewhere) are RAM and gone at power-off.
Expand Down
2 changes: 1 addition & 1 deletion portable/workspace/pi-wallet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function walletTools(Type, socket = WALLET_SOCKET) {
return [
tool('wallet_balance', 'Wallet balance', 'Sync the Zcash wallet over Tor and return its balance in ZEC by pool, the synced height and the spend policy (approve: every payment needs the operator; cap: payments under the caps go without asking).', none, 'balance'),
tool('wallet_transactions', 'Wallet transactions', 'Sync the Zcash wallet over Tor and list its 20 latest transactions (txid, height, time, value and fee in ZEC, memos).', none, 'transactions'),
tool('wallet_address', 'Wallet address', 'Return the wallet\'s unified receive address.', none, 'address'),
tool('wallet_address', 'Wallet address', 'Return the wallet\'s unified receive address and its Orchard-only unified address (`orchard`, the one to give after MSG on ZECpublish).', none, 'address'),
tool('wallet_send', 'Wallet send', 'Pay ZEC from the wallet. The wallet service decides by its policy whether the operator must approve on the console (they see amount, fee, destination and memo and press y or n); the call waits for that decision. Returns the txid, or an error such as a refusal or insufficient funds.',
Type.Object({
address: Type.String({ description: 'Zcash destination address' }),
Expand Down
54 changes: 54 additions & 0 deletions portable/zcash/zecpublish/zecpublish.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT
// ZECpublish (zecpublish.com) for the agent: zecpublish feed [PAGE] | post TEXT | reply TXID TEXT | like TXID
// A post is a shielded payment to the board with the post as its memo, sent by the agent wallet (the operator approves it).
// The feed has no API: it is a Next.js server action whose ID changes with each site deploy, so it is read from the site's JS.
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
import { pathToFileURL } from 'node:url';
import { walletCall } from '../../workspace/pi-wallet.mjs';

export const SITE = 'https://zecpublish.com';
// The Sapling receiver of the board's UA: Orchard sends go out as Ironwood, which the board's scanner predates.
export const BOARD = 'zs14zjwshdjrscw08rnynpwntrhu27ee0x5ema7z23sdvnmakmlhjpuv776enqetcjyz4eazjrt5gu';
export const AMOUNT = '0.00005';
const run = promisify(execFile);

// curl, not fetch: fetch's fixed 10 s connect timeout is too short for some Tor circuits.
async function text(url, { method = 'GET', body, headers = {} } = {}) {
const args = ['-sS', '--fail-with-body', '--max-time', '120', '-X', method, ...Object.entries(headers).flatMap(([k, v]) => ['-H', `${k}: ${v}`]), url];
const { stdout } = await run('curl', body === undefined ? args : [...args, '--data-binary', body], { maxBuffer: 1 << 24 });
return stdout;
}

// The feed action is the actions module's default export: `.ZP=(0,x.$)("<id>")` in one of the board page's chunks.
export function feedAction(chunks) {
const ids = [...new Set(chunks.flatMap(js => [...js.matchAll(/\.ZP=\(0,[\w$]+\.\$\)\("([0-9a-f]{40})"\)/g)].map(m => m[1])))];
if (ids.length !== 1) throw Error(`expected one feed action in the site's JS, found ${ids.length}: ${ids.join(' ')}`);
return ids[0];
}

export function posts(rsc) {
const line = rsc.split('\n').find(l => l.includes('{"posts":'));
if (!line) throw Error(`no posts in the feed answer: ${rsc.slice(0, 300)}`);
return JSON.parse(line.slice(line.indexOf(':') + 1)).posts.map(p =>
({ id: p.id, time: new Date(Number(p.datetime)).toISOString(), zats: p.amount, txid: p.txid, likes: p.likes, replies: p.reply_count, replyTo: p.reply_to_post, memo: p.memo }));
}

export async function feed(page = 1) {
const html = await text(`${SITE}/z/all`);
const chunks = await Promise.all([...new Set(html.match(/\/_next\/static\/chunks\/[^"]+\.js/g))].map(c => text(SITE + c)));
const action = feedAction(chunks);
return posts(await text(`${SITE}/z/all`, { method: 'POST', body: JSON.stringify([{ pageParam: page, limit: 20 }]),
headers: { 'Next-Action': action, Accept: 'text/x-component', 'Content-Type': 'text/plain;charset=UTF-8' } }));
}

export const memo = (op, a, b) => ({ post: a, reply: `REPLY::${a} ${b}`, like: `LIKE::${a}` })[op];

const usage = 'usage: zecpublish feed [PAGE] | post TEXT | reply TXID TEXT | like TXID';
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
const [op, a, b] = process.argv.slice(2);
const ok = op === 'feed' ? a === undefined || /^\d+$/.test(a) : op === 'post' ? a : op === 'reply' ? /^[0-9a-f]{64}$/.test(a ?? '') && b : op === 'like' && /^[0-9a-f]{64}$/.test(a ?? '');
if (!ok) { console.error(usage); process.exit(2); }
const out = op === 'feed' ? await feed(Number(a ?? 1)) : await walletCall({ op: 'send', address: BOARD, amount: AMOUNT, memo: memo(op, a, b) });
console.log(JSON.stringify(out, null, 1));
}
26 changes: 26 additions & 0 deletions portable/zcash/zecpublish/zecpublish.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
import test from 'node:test';
import assert from 'node:assert/strict';
import { feedAction, posts, memo } from './zecpublish.mjs';

const A = '03bb05e9a53248af4397aff82fd77a28831d4403', B = '7061bd1e519bde10840b4b5c9309e95cceb678c3';
// Shape of the minified actions module in the site's chunk (Next.js 14).
const chunk = `{9923:function(e,t,n){var r=n(8064),i=(0,r.$)("${B}");t.ZP=(0,r.$)("${A}")}}`;

test('feedAction finds the default-export action and refuses none or several', () => {
assert.equal(feedAction(['x', chunk, chunk]), A);
assert.throws(() => feedAction(['x']), /found 0/);
assert.throws(() => feedAction([chunk, chunk.replace(A, B)]), /found 2/);
});

test('posts reads the RSC answer', () => {
const rsc = `0:["$@1",["build",null]]\n1:{"posts":[{"id":62,"memo":"hi MSG u1x","datetime":"1793141543000","amount":5000,"txid":"aa","likes":0,"reply_zaddr":"u1x","reply_to_post":null,"reply_count":0}]}\n`;
assert.deepEqual(posts(rsc), [{ id: 62, time: '2026-10-27T22:52:23.000Z', zats: 5000, txid: 'aa', likes: 0, replies: 0, replyTo: null, memo: 'hi MSG u1x' }]);
assert.throws(() => posts('0:["$@1"]'), /no posts/);
});

test('memos follow the board format', () => {
assert.equal(memo('post', 'hello'), 'hello');
assert.equal(memo('reply', 'ab', 'yes'), 'REPLY::ab yes');
assert.equal(memo('like', 'ab'), 'LIKE::ab');
});