402mob-runtime 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +56 -2
- package/THIRD-PARTY-NOTICES.txt +1993 -0
- package/bin/402mob-runtime +2 -0
- package/dist/runtime/cli.js +66380 -0
- package/package.json +28 -4
- package/public/wallet/app.js +377 -0
- package/public/wallet/browser-wallet.js +212 -0
- package/public/wallet/favicon.svg +4 -0
- package/public/wallet/index.html +104 -0
- package/public/wallet/metamask.js +2 -0
- package/public/wallet/style.css +10 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
export const USDC = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
|
|
2
|
+
export const BASE_CHAIN = '0x2105';
|
|
3
|
+
const FUNDING_KEY = '402mob.wallet.funding.v1';
|
|
4
|
+
const TRANSFER_TOPIC = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
|
5
|
+
const fail = code => { throw new Error(code); };
|
|
6
|
+
const evmAddress = value => typeof value === 'string' && /^0x[0-9a-f]{40}$/i.test(value) && !/^0x0{40}$/i.test(value) ? value.toLowerCase() : fail('invalid_wallet_address');
|
|
7
|
+
const quantity = value => typeof value === 'string' && /^0x[0-9a-f]{1,64}$/i.test(value) ? BigInt(value) : fail('invalid_wallet_response');
|
|
8
|
+
const chain = value => '0x' + quantity(value).toString(16);
|
|
9
|
+
const account = values => Array.isArray(values) && values.length ? evmAddress(values[0]) : null;
|
|
10
|
+
const word = value => value.replace(/^0x/i, '').padStart(64, '0');
|
|
11
|
+
export function fundingAtomic(value) {
|
|
12
|
+
if (!/^(?!0(?:\.0{1,6})?$)(0|[1-9][0-9]{0,5})(\.[0-9]{1,6})?$/.test(value)) fail('invalid_amount');
|
|
13
|
+
const [whole, fraction = ''] = value.split('.'); return BigInt(whole) * 1000000n + BigInt(fraction.padEnd(6, '0'));
|
|
14
|
+
}
|
|
15
|
+
export function fundingTransaction(from, to, atomic) {
|
|
16
|
+
from = evmAddress(from); to = evmAddress(to);
|
|
17
|
+
if (from === to || !/^[1-9][0-9]{0,11}$/.test(atomic)) fail('invalid_funding_terms');
|
|
18
|
+
return { from, to: USDC, value: '0x0', chainId: BASE_CHAIN, data: '0xa9059cbb' + word(to) + word(BigInt(atomic).toString(16)) };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Provider names are unverified display text. Never load icons or use names to route funds. */
|
|
22
|
+
export function discoverBrowserWallets(target, changed = () => {}) {
|
|
23
|
+
const found = new Map(), legacyIds = new WeakMap(); let sequence = 0;
|
|
24
|
+
const usable = provider => { try { return provider && typeof provider.request === 'function'; } catch { return false; } };
|
|
25
|
+
const announce = event => {
|
|
26
|
+
try {
|
|
27
|
+
const { info, provider } = event.detail;
|
|
28
|
+
if (typeof info.uuid !== 'string' || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(info.uuid) ||
|
|
29
|
+
typeof info.name !== 'string' || typeof info.rdns !== 'string' || !usable(provider) || found.size >= 10) return;
|
|
30
|
+
const id = info.uuid.toLowerCase();
|
|
31
|
+
if ([...found.values()].some(entry => entry.provider === provider) || found.has(id)) return;
|
|
32
|
+
const name = info.name.replace(/[\u0000-\u001f\u007f\u202a-\u202e\u2066-\u2069]/g, '').trim().slice(0, 64) || 'Browser wallet';
|
|
33
|
+
found.set(id, { id, name, provider, pendingRequestIsRejection: info.rdns === 'io.metamask' }); changed();
|
|
34
|
+
} catch { /* Ignore malformed announcements without invoking the provider. */ }
|
|
35
|
+
};
|
|
36
|
+
target.addEventListener('eip6963:announceProvider', announce);
|
|
37
|
+
const list = () => {
|
|
38
|
+
const entries = [...found.values()], seen = new Set(entries.map(entry => entry.provider));
|
|
39
|
+
let injected = [];
|
|
40
|
+
try { injected = Array.isArray(target.ethereum?.providers) ? target.ethereum.providers : [target.ethereum]; } catch { /* Other announced wallets remain usable. */ }
|
|
41
|
+
for (const provider of injected.slice(0, 10)) {
|
|
42
|
+
if (!usable(provider) || seen.has(provider)) continue;
|
|
43
|
+
if (!legacyIds.has(provider)) legacyIds.set(provider, 'legacy-' + sequence++);
|
|
44
|
+
// Legacy injection has no reliable brand identity or provider-specific error contract.
|
|
45
|
+
entries.push({ id: legacyIds.get(provider), name: 'Browser wallet (legacy)', provider, pendingRequestIsRejection: false }); seen.add(provider);
|
|
46
|
+
}
|
|
47
|
+
return entries;
|
|
48
|
+
};
|
|
49
|
+
return { list, scan: () => { target.dispatchEvent(new Event('eip6963:requestProvider')); changed(); },
|
|
50
|
+
stop: () => target.removeEventListener('eip6963:announceProvider', announce) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Non-secret, tab-scoped intent journal. No signer key or owner/agent bearer token is stored. */
|
|
54
|
+
export class FundingJournal {
|
|
55
|
+
constructor(storage) { this.storage = storage; }
|
|
56
|
+
read() {
|
|
57
|
+
let raw; try { raw = this.storage.getItem(FUNDING_KEY); } catch { return fail('funding_storage_unavailable'); }
|
|
58
|
+
if (!raw) return null;
|
|
59
|
+
try {
|
|
60
|
+
const r = JSON.parse(raw);
|
|
61
|
+
if (![1, 2].includes(r.version) || !/^[0-9a-f-]{36}$/i.test(r.id) || r.asset !== USDC || r.chainId !== BASE_CHAIN ||
|
|
62
|
+
!['unknown', 'submitted', 'confirming', 'confirmed', 'reverted', 'cancelled'].includes(r.status) || !Number.isSafeInteger(r.createdAt) ||
|
|
63
|
+
!(r.hash === null || /^0x[0-9a-f]{64}$/i.test(r.hash))) throw Error();
|
|
64
|
+
if (r.version === 2) { quantity(r.nonce); quantity(r.startBlock); }
|
|
65
|
+
fundingTransaction(r.from, r.to, r.amountAtomic); return r;
|
|
66
|
+
} catch { return fail('funding_record_invalid'); }
|
|
67
|
+
}
|
|
68
|
+
write(record) {
|
|
69
|
+
try { const raw = JSON.stringify(record); this.storage.setItem(FUNDING_KEY, raw); if (this.storage.getItem(FUNDING_KEY) !== raw) throw Error(); }
|
|
70
|
+
catch { fail('funding_storage_unavailable'); }
|
|
71
|
+
}
|
|
72
|
+
clear() { try { this.storage.removeItem(FUNDING_KEY); if (this.storage.getItem(FUNDING_KEY) !== null) throw Error(); } catch { fail('funding_storage_unavailable'); } }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The selected browser wallet holds the customer key. This adapter can only fund the selected agent address in Base USDC. */
|
|
76
|
+
export class BrowserWallet {
|
|
77
|
+
constructor(provider, journal, changed = () => {}, options = {}) {
|
|
78
|
+
this.pendingRequestIsRejection = options.pendingRequestIsRejection === true;
|
|
79
|
+
this.provider = provider; this.journal = journal; this.changed = changed; this.revision = 0; this.generation = 0; this.closed = false;
|
|
80
|
+
this.state = { account: null, chainId: null, usdcAtomic: null, ethAtomic: null }; this.review = null; this.busy = false;
|
|
81
|
+
this.listeners = { accountsChanged: values => this.update({ account: account(values) }), chainChanged: value => this.update({ chainId: chain(value) }),
|
|
82
|
+
disconnect: () => this.update({ account: null, chainId: null }) };
|
|
83
|
+
for (const [name, fn] of Object.entries(this.listeners)) {
|
|
84
|
+
const guarded = value => { if (!this.closed) { try { fn(value); } catch { this.update({ account: null, chainId: null }); } } };
|
|
85
|
+
this.listeners[name] = guarded; this.provider.on?.(name, guarded);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
update(values) { this.revision++; this.review = null; this.state = { ...this.state, ...values, usdcAtomic: null, ethAtomic: null }; this.changed(); }
|
|
89
|
+
assertCurrent(revision, generation = this.generation) { if (this.closed || revision !== this.revision || generation !== this.generation) fail('browser_wallet_changed'); }
|
|
90
|
+
async identity() { return { account: account(await this.provider.request({ method: 'eth_accounts' })), chainId: chain(await this.provider.request({ method: 'eth_chainId' })) }; }
|
|
91
|
+
async connect() {
|
|
92
|
+
const generation = this.generation;
|
|
93
|
+
await this.provider.request({ method: 'eth_requestAccounts' });
|
|
94
|
+
if (this.closed || generation !== this.generation) fail('browser_wallet_changed');
|
|
95
|
+
await this.refresh(); if (!this.state.account) fail('browser_wallet_account_required'); return this.state;
|
|
96
|
+
}
|
|
97
|
+
async refresh() {
|
|
98
|
+
const revision = this.revision, generation = this.generation;
|
|
99
|
+
const identity = await this.identity(); this.assertCurrent(revision, generation);
|
|
100
|
+
if (identity.account !== this.state.account || identity.chainId !== this.state.chainId) this.update(identity);
|
|
101
|
+
else { this.state = { ...identity, usdcAtomic: null, ethAtomic: null }; this.changed(); }
|
|
102
|
+
if (!identity.account || identity.chainId !== BASE_CHAIN) return this.state;
|
|
103
|
+
const current = this.revision;
|
|
104
|
+
const [usdc, eth] = await Promise.all([
|
|
105
|
+
this.provider.request({ method: 'eth_call', params: [{ to: USDC, data: '0x70a08231' + word(identity.account) }, 'latest'] }),
|
|
106
|
+
this.provider.request({ method: 'eth_getBalance', params: [identity.account, 'latest'] }),
|
|
107
|
+
]);
|
|
108
|
+
const after = await this.identity(); this.assertCurrent(current, generation);
|
|
109
|
+
if (after.account !== identity.account || after.chainId !== BASE_CHAIN) { this.update(after); fail('browser_wallet_changed'); }
|
|
110
|
+
this.state = { ...identity, usdcAtomic: quantity(usdc).toString(), ethAtomic: quantity(eth).toString() }; this.changed(); return this.state;
|
|
111
|
+
}
|
|
112
|
+
async switchBase() {
|
|
113
|
+
const generation = this.generation;
|
|
114
|
+
try { await this.provider.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: BASE_CHAIN }] }); }
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (error.code !== 4902 || this.closed || generation !== this.generation) throw error;
|
|
117
|
+
await this.provider.request({ method: 'wallet_addEthereumChain', params: [{ chainId: BASE_CHAIN, chainName: 'Base', nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, rpcUrls: ['https://mainnet.base.org'], blockExplorerUrls: ['https://basescan.org'] }] });
|
|
118
|
+
if (this.closed || generation !== this.generation) fail('browser_wallet_changed');
|
|
119
|
+
await this.provider.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: BASE_CHAIN }] });
|
|
120
|
+
}
|
|
121
|
+
if (this.closed || generation !== this.generation) fail('browser_wallet_changed');
|
|
122
|
+
return this.refresh();
|
|
123
|
+
}
|
|
124
|
+
async prepareFunding(to, value) {
|
|
125
|
+
if (this.busy || this.journal.read()) fail('funding_record_exists');
|
|
126
|
+
this.review = null; const amountAtomic = fundingAtomic(value).toString();
|
|
127
|
+
await this.refresh();
|
|
128
|
+
if (!this.state.account || this.state.chainId !== BASE_CHAIN) fail('browser_wallet_base_required');
|
|
129
|
+
const tx = fundingTransaction(this.state.account, to, amountAtomic);
|
|
130
|
+
if (BigInt(this.state.usdcAtomic) < BigInt(amountAtomic)) fail('browser_wallet_usdc_insufficient');
|
|
131
|
+
if (BigInt(this.state.ethAtomic) === 0n) fail('browser_wallet_gas_required');
|
|
132
|
+
return this.review = Object.freeze({ id: crypto.randomUUID(), from: tx.from, to: evmAddress(to), amountAtomic, revision: this.revision, preparedAt: Date.now() });
|
|
133
|
+
}
|
|
134
|
+
async sendFunding(review, verifyRecipient) {
|
|
135
|
+
if (this.busy || !review || review !== this.review || this.journal.read()) fail('funding_review_required');
|
|
136
|
+
this.busy = true;
|
|
137
|
+
try {
|
|
138
|
+
this.assertCurrent(review.revision);
|
|
139
|
+
if (Date.now() - review.preparedAt > 120000) fail('funding_review_expired');
|
|
140
|
+
await this.refresh(); this.assertCurrent(review.revision);
|
|
141
|
+
if (this.state.account !== review.from || this.state.chainId !== BASE_CHAIN) fail('browser_wallet_changed');
|
|
142
|
+
if (BigInt(this.state.usdcAtomic) < BigInt(review.amountAtomic)) fail('browser_wallet_usdc_insufficient');
|
|
143
|
+
if (BigInt(this.state.ethAtomic) === 0n) fail('browser_wallet_gas_required');
|
|
144
|
+
const recipient = evmAddress(await verifyRecipient()); this.assertCurrent(review.revision);
|
|
145
|
+
if (recipient !== review.to) fail('funding_recipient_changed');
|
|
146
|
+
const startBlock = chain(await this.provider.request({ method: 'eth_blockNumber' }));
|
|
147
|
+
const nonce = chain(await this.provider.request({ method: 'eth_getTransactionCount', params: [review.from, 'pending'] }));
|
|
148
|
+
this.assertCurrent(review.revision);
|
|
149
|
+
if (Date.now() - review.preparedAt > 120000) fail('funding_review_expired');
|
|
150
|
+
const tx = { ...fundingTransaction(review.from, review.to, review.amountAtomic), nonce };
|
|
151
|
+
const record = { version: 2, id: review.id, from: review.from, to: review.to, amountAtomic: review.amountAtomic, asset: USDC, chainId: BASE_CHAIN, nonce, startBlock, createdAt: Date.now(), status: 'unknown', hash: null };
|
|
152
|
+
// Persist intent before invoking the wallet. Unknown results must never trigger an automatic second send.
|
|
153
|
+
this.journal.write(record); this.review = null; this.changed();
|
|
154
|
+
let hash;
|
|
155
|
+
try { hash = await this.provider.request({ method: 'eth_sendTransaction', params: [tx] }); }
|
|
156
|
+
catch (error) { if (error.code === 4001 || error.code === 4200 || error.code === -32002 && this.pendingRequestIsRejection) this.journal.clear(); else fail('funding_outcome_unknown'); throw error; }
|
|
157
|
+
if (typeof hash !== 'string' || !/^0x[0-9a-f]{64}$/i.test(hash)) fail('funding_outcome_unknown');
|
|
158
|
+
const submitted = { ...record, status: 'submitted', hash };
|
|
159
|
+
// Keep the hash available to the caller even if storage fails after broadcast.
|
|
160
|
+
try { this.journal.write(submitted); } catch { const e = new Error('funding_hash_not_saved'); e.record = submitted; throw e; }
|
|
161
|
+
return submitted;
|
|
162
|
+
} finally { this.busy = false; this.changed(); }
|
|
163
|
+
}
|
|
164
|
+
async checkFunding(hashInput) {
|
|
165
|
+
if (this.busy) fail('funding_request_pending');
|
|
166
|
+
this.busy = true;
|
|
167
|
+
try {
|
|
168
|
+
const record = this.journal.read(); if (!record) fail('funding_record_missing');
|
|
169
|
+
const hash = hashInput || record.hash;
|
|
170
|
+
if (typeof hash !== 'string' || !/^0x[0-9a-f]{64}$/i.test(hash)) fail('funding_hash_required');
|
|
171
|
+
// Old records have no nonce/broadcast boundary. Their original returned hash is the only safe anchor.
|
|
172
|
+
if (record.version === 1 && (!record.hash || hash.toLowerCase() !== record.hash.toLowerCase())) fail('funding_legacy_recovery_required');
|
|
173
|
+
const revision = this.revision;
|
|
174
|
+
if (chain(await this.provider.request({ method: 'eth_chainId' })) !== BASE_CHAIN) fail('browser_wallet_base_required');
|
|
175
|
+
const tx = await this.provider.request({ method: 'eth_getTransactionByHash', params: [hash] });
|
|
176
|
+
const expected = fundingTransaction(record.from, record.to, record.amountAtomic);
|
|
177
|
+
if (!tx) fail('funding_transaction_unavailable');
|
|
178
|
+
if ((tx.hash && tx.hash.toLowerCase() !== hash.toLowerCase()) || evmAddress(tx.from) !== expected.from ||
|
|
179
|
+
quantity(tx.value) !== 0n || (tx.chainId && chain(tx.chainId) !== BASE_CHAIN)) fail('funding_transaction_mismatch');
|
|
180
|
+
if (record.version === 2 && quantity(tx.nonce) !== quantity(record.nonce)) fail('funding_nonce_mismatch');
|
|
181
|
+
const transfer = evmAddress(tx.to) === USDC.toLowerCase() && tx.input?.toLowerCase() === expected.data;
|
|
182
|
+
const cancellation = record.version === 2 && evmAddress(tx.to) === expected.from && tx.input === '0x';
|
|
183
|
+
if (!transfer && !cancellation) fail('funding_transaction_mismatch');
|
|
184
|
+
const receipt = await this.provider.request({ method: 'eth_getTransactionReceipt', params: [hash] });
|
|
185
|
+
let status = 'submitted';
|
|
186
|
+
if (receipt) {
|
|
187
|
+
if (receipt.transactionHash?.toLowerCase() !== hash.toLowerCase()) fail('funding_transaction_mismatch');
|
|
188
|
+
if (record.version === 2 && quantity(receipt.blockNumber) <= quantity(record.startBlock)) fail('funding_transaction_predates_intent');
|
|
189
|
+
if (receipt.status === '0x0') status = 'reverted';
|
|
190
|
+
else if (receipt.status === '0x1' && cancellation) status = 'cancelled';
|
|
191
|
+
else if (receipt.status === '0x1') {
|
|
192
|
+
const matches = receipt.logs?.filter(log => log.address?.toLowerCase() === USDC.toLowerCase() &&
|
|
193
|
+
log.topics?.length === 3 && log.topics[0]?.toLowerCase() === TRANSFER_TOPIC &&
|
|
194
|
+
log.topics[1]?.toLowerCase() === '0x' + word(record.from) && log.topics[2]?.toLowerCase() === '0x' + word(record.to) &&
|
|
195
|
+
log.data?.toLowerCase() === '0x' + word(BigInt(record.amountAtomic).toString(16)));
|
|
196
|
+
if (matches?.length !== 1) fail('funding_transfer_mismatch');
|
|
197
|
+
status = 'confirmed';
|
|
198
|
+
} else fail('invalid_wallet_response');
|
|
199
|
+
const tip = quantity(await this.provider.request({ method: 'eth_blockNumber' }));
|
|
200
|
+
if (tip < quantity(receipt.blockNumber) + 2n) status = 'confirming';
|
|
201
|
+
}
|
|
202
|
+
if (chain(await this.provider.request({ method: 'eth_chainId' })) !== BASE_CHAIN) fail('browser_wallet_base_required');
|
|
203
|
+
this.assertCurrent(revision);
|
|
204
|
+
if (this.journal.read()?.id !== record.id) fail('funding_record_changed');
|
|
205
|
+
const next = { ...record, hash, status }; this.journal.write(next); this.changed(); return next;
|
|
206
|
+
} finally { this.busy = false; this.changed(); }
|
|
207
|
+
}
|
|
208
|
+
disconnect() {
|
|
209
|
+
this.closed = true; this.generation++; this.update({ account: null, chainId: null });
|
|
210
|
+
for (const [name, fn] of Object.entries(this.listeners)) this.provider.removeListener?.(name, fn);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
|
2
|
+
<rect width="64" height="64" rx="9" fill="#101216"/>
|
|
3
|
+
<text x="32" y="43" fill="#e5e7eb" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="25" font-weight="700" letter-spacing="-2" text-anchor="middle">EC</text>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<meta name="referrer" content="no-referrer">
|
|
7
|
+
<meta name="description" content="Manage an owner-controlled Base USDC wallet and delegate bounded spending to an agent.">
|
|
8
|
+
<title>402Mob / USDC wallet</title>
|
|
9
|
+
<link rel="icon" type="image/svg+xml" href="./favicon.svg">
|
|
10
|
+
<link rel="stylesheet" href="./style.css?v=4">
|
|
11
|
+
<script type="module" src="./app.js?v=8"></script>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<a class="skip" href="#main">Skip to wallet</a>
|
|
15
|
+
<header><a class="brand" href="https://evidence.contact/"><span class="mark">[EC]</span><span>402MOB / WALLET<small>OWNER-CONTROLLED SIGNER</small></span></a><span class="tag">BASE / USDC</span></header>
|
|
16
|
+
<nav aria-label="Wallet navigation"><a href="#agent-wallet">01 / Agent wallet</a><a href="#customer-wallet">02 / Add USDC</a><a href="#permissions">03 / Spending permissions</a><a id="activity-link" href="#activity" hidden>Activity</a><a href="https://evidence.contact/web-wallet.md">Guide ↗</a></nav>
|
|
17
|
+
<main id="main">
|
|
18
|
+
<div class="toolbar"><div><p class="eyebrow">OWNER CONSOLE</p><h1>USDC for your agent</h1><p>Fund a separate agent wallet and allocate USDC to an agent. Add spending restrictions when you need them.</p></div><div class="actions"><button id="refresh" type="button" hidden>Refresh</button><button id="disconnect" type="button" hidden>Disconnect signer</button></div></div>
|
|
19
|
+
<figure class="wallet-flow"><figcaption id="funds-flow-caption">WHERE USDC GOES</figcaption><pre tabindex="0" role="region" aria-labelledby="funds-flow-caption"><code>YOUR WALLET <span>-- deposit --></span> AGENT WALLET <span>-- permitted purchase --></span> SELLER</code></pre></figure>
|
|
20
|
+
<p id="notice" role="status" aria-live="polite">Start your local signer, then open its pairing link.</p>
|
|
21
|
+
<div id="agent-wallet">
|
|
22
|
+
<section id="connection" class="panel" aria-labelledby="connection-title">
|
|
23
|
+
<h2 id="connection-title">01 / Open your agent wallet</h2>
|
|
24
|
+
<p>The local signer is the program that holds the agent wallet's key on your computer and enforces its spending limits.</p>
|
|
25
|
+
<p><a href="https://evidence.contact/agent-runtime.md#install-the-runtime" target="_blank" rel="noopener noreferrer">Install with npm or direct download</a>, then run this command on the same computer as this browser:</p>
|
|
26
|
+
<pre><code>402mob-runtime wallet web \
|
|
27
|
+
--dir "$HOME/.local/share/402mob/runtime-owner"</code></pre>
|
|
28
|
+
<p>Open the link it prints, then click <strong>Connect signer</strong>. You can also enter its five-minute pairing code below. If your browser blocks localhost access, use the local console link printed by the same command.</p>
|
|
29
|
+
<form id="connect-form" autocomplete="off">
|
|
30
|
+
<label>Local signer URL<input id="gateway" type="url" value="http://127.0.0.1:4032" required spellcheck="false"></label>
|
|
31
|
+
<label>Pairing code<input id="pair-code" type="password" autocomplete="off" required spellcheck="false" placeholder="mobpair_…"></label>
|
|
32
|
+
<button class="primary" type="submit">Connect signer</button>
|
|
33
|
+
</form>
|
|
34
|
+
<p class="note">Allow your browser's localhost connection when prompted. Pairing uses a one-use code; owner sessions expire after one hour. No wallet key is sent to this website.</p>
|
|
35
|
+
</section>
|
|
36
|
+
<section id="create-wallet" class="panel" hidden aria-labelledby="create-title">
|
|
37
|
+
<h2 id="create-title">01 / Create your agent wallet</h2>
|
|
38
|
+
<p>Your signer will generate and retain the key in its private directory. Creation does not move money.</p>
|
|
39
|
+
<form id="create-form"><label>Optional shared spending ceiling · USDC<input id="wallet-limit" type="text" inputmode="decimal" placeholder="No extra ceiling" autocomplete="off" aria-describedby="wallet-limit-help"></label><button class="primary" type="submit">Create wallet</button></form>
|
|
40
|
+
<p id="wallet-limit-help" class="note">Leave empty to use only each agent’s allocation and available funds. An optional ceiling limits total lifetime spending across agents.</p>
|
|
41
|
+
<p class="note">Existing ceilings are retained. Owner budget updates preserve spent and pending amounts. Retain the same signer directory for recovery.</p>
|
|
42
|
+
</section>
|
|
43
|
+
<section id="wallet" class="panel" hidden aria-labelledby="wallet-title">
|
|
44
|
+
<div class="section-head"><h2 id="wallet-title">01 / Agent wallet</h2><span id="connection-state" class="tag">SIGNER CONNECTED</span></div>
|
|
45
|
+
<div class="metrics"><div><span>USDC BALANCE</span><strong id="balance">—</strong></div><div><span>RESERVED FOR PAYMENTS</span><strong id="reserved">—</strong></div><div><span>SPENT BY AGENTS</span><strong id="spent">—</strong></div><div><span>SPENDING LIMIT LEFT</span><strong id="remaining">—</strong></div></div>
|
|
46
|
+
<p id="balance-time" class="note">Balance has not been read.</p>
|
|
47
|
+
<div class="receive"><div><h3>Receive USDC on Base</h3><code id="wallet-address"></code><p class="note">Send native USDC on Base to this address. USDC contract: <code>0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913</code>.</p></div><button id="copy-address" type="button">Copy address</button></div>
|
|
48
|
+
<button id="edit-wallet-limit" type="button">Change shared ceiling</button>
|
|
49
|
+
<form id="budget-form" class="review" hidden><h3 id="budget-title"></h3><label id="budget-label">New total · USDC<input id="budget-amount" inputmode="decimal" autocomplete="off"></label><p id="budget-help" class="note"></p><div class="actions"><button id="budget-submit" type="submit">Review and apply</button><button id="budget-cancel" type="button">Cancel</button></div></form>
|
|
50
|
+
<p id="wallet-context" class="note"></p>
|
|
51
|
+
<p class="note">Reserved amounts cover payments that have not been resolved. Spending limit left is the lifetime limit minus spent and reserved amounts; the USDC balance is shown separately. Funding and delegation do not pay a seller.</p>
|
|
52
|
+
</section>
|
|
53
|
+
</div>
|
|
54
|
+
<section id="customer-wallet" class="panel" aria-labelledby="customer-title">
|
|
55
|
+
<div class="section-head"><h2 id="customer-title">02 / Add USDC</h2><span class="tag">FROM YOUR WALLET</span></div>
|
|
56
|
+
<p>Choose a compatible Ethereum wallet extension and deposit Base USDC into the agent wallet. Your browser wallet keeps its key; the agent spends from its separate wallet.</p>
|
|
57
|
+
<div class="actions"><label>Browser wallet<select id="browser-wallet-select"><option value="">Detecting wallets…</option></select></label><button id="browser-wallet-connect" type="button">Connect wallet</button><button id="browser-wallet-scan" type="button">Scan again</button><button id="browser-wallet-disconnect" type="button" hidden>Disconnect wallet</button></div>
|
|
58
|
+
<p id="customer-notice" class="note" role="status" aria-live="polite">Connection requests account access only. Each deposit requires a separate confirmation in your wallet.</p>
|
|
59
|
+
<div id="customer-connected" hidden>
|
|
60
|
+
<div class="customer-details"><code id="customer-address"></code><span id="customer-network"></span><strong id="customer-usdc">—</strong></div>
|
|
61
|
+
<p id="customer-gas" class="note"></p>
|
|
62
|
+
<div class="actions"><button id="browser-wallet-refresh" type="button">Refresh wallet balance</button><button id="browser-wallet-switch" type="button" hidden>Switch to Base</button></div>
|
|
63
|
+
</div>
|
|
64
|
+
<p class="note">Deposit destination: <code id="funding-target">Complete step 01 to see your agent wallet's address.</code></p>
|
|
65
|
+
<form id="funding-form" hidden autocomplete="off"><label>Deposit · USDC<input id="funding-amount" required inputmode="decimal" placeholder="0.10"></label><button type="submit">Review deposit</button></form>
|
|
66
|
+
<div id="funding-review" class="review" hidden><h3>Review the transfer</h3><pre id="funding-review-terms"></pre><p>Your wallet will request a Base USDC transfer and show its gas fee in ETH. This deposit does not raise the wallet's lifetime spending limit or grant an agent permission to spend.</p><div class="actions"><button id="funding-confirm" type="button" class="primary">Confirm in your wallet</button><button id="funding-edit" type="button">Edit deposit</button></div></div>
|
|
67
|
+
<div id="funding-record" class="review" hidden><h3>Funding record</h3><p id="funding-record-text"></p><code id="funding-record-hash"></code><label id="funding-hash-input" hidden>Original or replacement hash from your wallet activity (optional if saved)<input id="funding-hash" placeholder="0x…" spellcheck="false"></label><div class="actions"><button id="funding-check" type="button">Check same transaction</button><button id="funding-new" type="button" hidden>Start another deposit</button></div><p class="note">This tab retains the sender, recipient, amount, nonce, starting block and transaction hash for recovery. Pending or unknown transfers are never automatically sent again. If your wallet returned no hash, inspect its activity before closing this tab.</p></div>
|
|
68
|
+
</section>
|
|
69
|
+
<div id="permissions">
|
|
70
|
+
<p id="permissions-prerequisite" class="note setup-prerequisite">03 / Spending permissions will appear after you open your agent wallet.</p>
|
|
71
|
+
<div id="owner-panels" hidden>
|
|
72
|
+
<section id="delegations" class="panel" aria-labelledby="delegations-title">
|
|
73
|
+
<div class="section-head"><h2 id="delegations-title">03 / Set agent spending permissions</h2><span class="tag">DELEGATION</span></div>
|
|
74
|
+
<p>Give the agent a USDC allocation. By default it chooses sellers and can spend that amount without a per-payment limit or expiry. Optional restrictions narrow this permission; the wallet key stays on your computer.</p>
|
|
75
|
+
<form id="grant-form" autocomplete="off">
|
|
76
|
+
<div class="form-grid">
|
|
77
|
+
<label>Name for this agent<input id="agent-name" required maxlength="80" placeholder="Research buyer"></label>
|
|
78
|
+
<label>Allocate · USDC<input id="total-limit" required inputmode="decimal" placeholder="0.10"></label>
|
|
79
|
+
</div>
|
|
80
|
+
<details class="optional-restrictions"><summary>Optional spending restrictions</summary>
|
|
81
|
+
<div class="form-grid">
|
|
82
|
+
<label>Only this seller<input id="merchant-id" spellcheck="false" placeholder="Any seller · or enter a merchant UUID"></label>
|
|
83
|
+
<label>Only this receiving address<input id="payee" spellcheck="false" placeholder="Any seller payout · or enter 0x…"></label>
|
|
84
|
+
<label>Only this service<select id="capability"><option value="">All supported services</option><option value="prepared-artifact-v1">Prepared artifacts / prepared-artifact-v1</option><option value="text-statistics-v1">Text statistics / text-statistics-v1</option></select></label>
|
|
85
|
+
<label>Per-payment limit · USDC<input id="per-payment" inputmode="decimal" placeholder="Up to remaining allocation"></label>
|
|
86
|
+
<label>Expiry · your local time<input id="expires" type="datetime-local"></label>
|
|
87
|
+
</div>
|
|
88
|
+
<div class="actions"><button id="inspect-merchant" type="button">Inspect seller</button><span id="merchant-info" class="note"></span></div>
|
|
89
|
+
<p class="note">Leave a field empty to omit that restriction. Inspect seller fills its current payout address; this also restricts the recipient if kept.</p>
|
|
90
|
+
</details>
|
|
91
|
+
<button class="primary" type="submit">Review delegation</button>
|
|
92
|
+
</form>
|
|
93
|
+
<div id="grant-review" class="review" hidden><h3>Review this agent's spending permission</h3><dl id="review-terms"></dl><p>This permits the agent to authorize USDC payments within these terms. Funds remain in the agent wallet until spent.</p><div class="actions"><button id="confirm-grant" class="primary" type="button">Authorize and download credential</button><button id="cancel-grant" type="button">Edit terms</button></div><p id="grant-recovery" class="note"></p></div>
|
|
94
|
+
<p class="note">Keep downloaded credentials in the agent's secret store. Each delegation has its own allocation; all delegations also share the wallet's lifetime limit. Revocation blocks new authorizations. A payment already signed may still settle.</p>
|
|
95
|
+
<div id="agent-setup" class="review" hidden><h3>Connect the agent</h3><p>Move the downloaded credential into the agent’s private storage with access to this signer’s local task API. Run from the repository:</p><pre><code id="agent-setup-command"></code></pre><p>The check reads the current policy and spendable estimate without making a payment. Then discover a worker or prepared resource:</p><pre><code id="agent-next-command"></code></pre></div>
|
|
96
|
+
<div id="delegation-list" class="records" aria-live="polite"></div>
|
|
97
|
+
</section>
|
|
98
|
+
<section id="activity" class="panel" aria-labelledby="activity-title"><div class="section-head"><h2 id="activity-title">Recent agent work</h2><span class="tag">LATEST 50 LOCAL JOBS</span></div><p>The buyer runtime keeps the same task and payment across retries. Activity here covers this signer’s runtime jobs, not every transfer on the wallet.</p><div id="activity-list" class="records" aria-live="polite"></div></section>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
</main>
|
|
102
|
+
<footer><span>Base USDC only · spending policy enforced by the owner’s signer</span><a href="https://evidence.contact/web-wallet.md">Wallet guide ↗</a><a href="https://evidence.contact/agent-runtime.md">Agent runtime ↗</a><a href="https://evidence.contact/">evidence.contact ↗</a></footer>
|
|
103
|
+
</body>
|
|
104
|
+
</html>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
:root{color-scheme:dark;--bg:#050505;--panel:#0a0a0a;--line:#292929;--fg:#e5e5e5;--muted:#969696;--accent:#b5c2d0;font:14px/1.6 Arial,Helvetica,sans-serif;background:var(--bg);color:var(--fg)}
|
|
2
|
+
*{box-sizing:border-box}body{margin:0}[hidden]{display:none!important}a{color:inherit;text-underline-offset:4px}button,input,select{font:inherit}button{cursor:pointer;border:1px solid #484848;color:var(--fg);background:#101010;padding:9px 14px}button:hover{border-color:var(--accent)}button:disabled{opacity:.5;cursor:wait}button.primary{background:#d2d2d2;color:#090909;border-color:#d2d2d2}button:focus-visible,a:focus-visible,input:focus-visible,select:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
|
|
3
|
+
header,nav,main,footer{padding-inline:max(5%,calc((100% - 1180px)/2))}header{display:flex;align-items:center;justify-content:space-between;gap:20px;min-height:88px;border-bottom:1px solid var(--line)}.brand{display:flex;align-items:center;gap:16px;font:12px/1.5 monospace;letter-spacing:1px;text-decoration:none}.brand small{display:block;color:var(--muted);font-size:9px}.mark{font-size:28px;color:var(--accent)}nav{display:flex;flex-wrap:wrap;gap:14px 28px;padding-block:14px;border-bottom:1px solid var(--line);font:11px/1.6 monospace}nav a{text-decoration:none}main{padding-block:32px 50px}footer{display:flex;flex-wrap:wrap;gap:14px 24px;padding-block:22px;border-top:1px solid var(--line);font-size:12px;color:var(--muted)}
|
|
4
|
+
h1{font-size:24px;font-weight:500;letter-spacing:-.5px;margin:6px 0}h2{font:500 15px/1.5 monospace;margin:0 0 16px}h3{font-size:14px;font-weight:500;margin:0 0 10px}p{max-width:860px;color:#aaa}.eyebrow,.tag{font:10px/1.6 monospace;color:var(--accent);letter-spacing:.6px}.note{font-size:12px;color:var(--muted);line-height:1.7}.toolbar,.section-head,.actions,.receive{display:flex;align-items:center;justify-content:space-between;gap:16px;flex-wrap:wrap}.toolbar{align-items:flex-start}.actions{justify-content:flex-start}.section-head h2{margin:0}.section-head{margin-bottom:18px}.panel{border:1px solid var(--line);background:var(--panel);padding:24px;margin-top:24px}.panel:target{border-color:#646e7b}#notice{padding:12px 16px;background:#101010;border-left:2px solid var(--accent);max-width:none;overflow-wrap:anywhere}#notice[data-error=true]{border-left-color:#d39883;color:#dfb8a8}
|
|
5
|
+
form{display:grid;gap:16px;max-width:920px}label{display:flex;flex-direction:column;gap:7px;font-size:12px;color:var(--muted)}input,select{min-width:0;width:100%;background:#050505;color:var(--fg);padding:10px 12px;border:1px solid #363636;border-radius:0}form>button{justify-self:start}.form-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}.metrics{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:18px;border-block:1px solid var(--line);padding-block:20px}.metrics span{display:block;color:var(--muted);font:10px/1.5 monospace}.metrics strong{display:block;font:400 26px/1.7 monospace;overflow-wrap:anywhere}.receive{padding-top:14px;align-items:flex-start}.receive>div{min-width:0}code{font:12px/1.8 monospace;overflow-wrap:anywhere}pre{overflow:auto;white-space:pre;background:#050505;border:1px solid var(--line);padding:16px}pre code{white-space:pre;overflow-wrap:normal}.review{border:1px solid #626e7c;background:#101316;padding:20px;margin-top:18px}dl{display:grid;grid-template-columns:140px 1fr;gap:7px 16px;font-size:13px}dt{color:var(--muted)}dd{margin:0;overflow-wrap:anywhere}.records{margin-top:24px}.record{padding:18px 0;border-top:1px solid var(--line)}.record p{margin:7px 0;font-size:12px;overflow-wrap:anywhere}.record h3{overflow-wrap:anywhere}.record .actions{margin-top:12px}.record button{font-size:12px}.skip{position:absolute;left:-10000px}.skip:focus{left:10px;top:10px;background:#111;padding:10px}
|
|
6
|
+
@media(max-width:700px){header{gap:12px}.tag{font-size:9px}.toolbar h1{font-size:21px}.panel{padding:18px}.metrics{grid-template-columns:repeat(2,minmax(0,1fr))}.form-grid{grid-template-columns:1fr}dl{grid-template-columns:1fr;gap:3px}dd{margin-bottom:8px}.metrics strong{font-size:22px}}
|
|
7
|
+
.customer-details{display:flex;flex-wrap:wrap;align-items:center;gap:12px 24px;padding-block:14px;border-block:1px solid var(--line)}.customer-details code{overflow-wrap:anywhere;min-width:0}.customer-details strong{font:18px monospace}#customer-notice[data-error=true]{color:#dfb8a8}#funding-form{margin-top:18px;max-width:380px}#funding-record .actions{margin-top:14px}#funding-review-terms{white-space:pre-wrap;overflow-wrap:anywhere}#funding-record-hash{display:block;overflow-wrap:anywhere}
|
|
8
|
+
.wallet-flow{margin:24px 0}.wallet-flow figcaption{font:10px/1.6 monospace;letter-spacing:.6px;color:var(--muted)}.wallet-flow pre{margin:8px 0;background:none;border:0;border-block:1px solid var(--line);padding:16px 0}.wallet-flow code{color:var(--fg)}.wallet-flow span{color:var(--accent)}.setup-prerequisite{margin:24px 0;padding-block:16px;border-block:1px solid var(--line)}#agent-wallet,#customer-wallet,#permissions,#activity{scroll-margin-top:20px}#customer-wallet .actions{align-items:flex-end}.panel>p{line-height:1.7}.panel>p:first-of-type{margin-top:14px}#wallet-limit-help{margin-bottom:0}
|
|
9
|
+
|
|
10
|
+
.optional-restrictions{margin:1rem 0;border-top:1px solid #36383c;border-bottom:1px solid #36383c;padding:.8rem 0}.optional-restrictions summary{cursor:pointer;color:#c8cbd0}.optional-restrictions[open] summary{margin-bottom:1rem}
|