402mob-runtime 0.2.2 → 0.3.1
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/README.md +18 -8
- package/dist/runtime/cli.js +325 -392
- package/package.json +1 -1
- package/public/wallet/app.js +73 -32
- package/public/wallet/index.html +62 -52
- package/public/wallet/style.css +3 -0
package/package.json
CHANGED
package/public/wallet/app.js
CHANGED
|
@@ -23,15 +23,18 @@ export function delegationInput(values, requestId, now = Date.now()) {
|
|
|
23
23
|
const id = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
24
24
|
if (!id.test(requestId)) throw new Error('invalid_request_id');
|
|
25
25
|
if (typeof values.name !== 'string' || !values.name || values.name.length > 80) throw new Error('invalid_agent_name');
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
for (const key of ['merchantId', 'payee', 'capability', 'maxPerPaymentUSDC', 'expiresAt']) {
|
|
26
|
+
const policy = { name: values.name };
|
|
27
|
+
for (const key of ['maxTotalUSDC', 'merchantId', 'payee', 'capability', 'maxPerPaymentUSDC', 'expiresAt']) {
|
|
29
28
|
if (values[key] !== undefined && values[key] !== '') policy[key] = values[key];
|
|
30
29
|
}
|
|
31
30
|
if (policy.merchantId !== undefined && !id.test(policy.merchantId)) throw new Error('invalid_merchant_id');
|
|
32
31
|
if (policy.payee !== undefined && (!/^0x[0-9a-f]{40}$/i.test(policy.payee) || /^0x0{40}$/i.test(policy.payee))) throw new Error('invalid_payee');
|
|
33
32
|
if (policy.capability !== undefined && !['text-statistics-v1', 'prepared-artifact-v1'].includes(policy.capability)) throw new Error('unsupported_capability');
|
|
34
|
-
if (policy.
|
|
33
|
+
if (policy.maxTotalUSDC !== undefined) amount(policy.maxTotalUSDC);
|
|
34
|
+
if (policy.maxPerPaymentUSDC !== undefined) {
|
|
35
|
+
const perPayment = amount(policy.maxPerPaymentUSDC);
|
|
36
|
+
if (policy.maxTotalUSDC !== undefined && perPayment > amount(policy.maxTotalUSDC)) throw new Error('delegation_limit_invalid');
|
|
37
|
+
}
|
|
35
38
|
if (policy.expiresAt !== undefined) {
|
|
36
39
|
const expiry = new Date(policy.expiresAt);
|
|
37
40
|
if (!Number.isFinite(expiry.getTime()) || expiry.getTime() <= now) throw new Error('delegation_expired');
|
|
@@ -43,16 +46,18 @@ export function delegationInput(values, requestId, now = Date.now()) {
|
|
|
43
46
|
if (typeof document !== 'undefined') {
|
|
44
47
|
const $ = id => document.getElementById(id);
|
|
45
48
|
let gateway = 'http://127.0.0.1:4032', session = null, state = null, epoch = 0, pending = null, sent = false, refreshing = null;
|
|
46
|
-
let budgetTarget = null, budgetPending = null;
|
|
49
|
+
let budgetTarget = null, budgetPending = null, agentConnection = null;
|
|
47
50
|
let customer = null, fundingReview = null, fundingEpoch = null, fundingMemory = null;
|
|
48
51
|
let fundingJournal;
|
|
49
52
|
try { fundingJournal = new FundingJournal(window.sessionStorage); } catch { fundingJournal = new FundingJournal(null); }
|
|
50
53
|
const messages = {
|
|
51
54
|
local_gateway_required: 'Use the signer URL on localhost or 127.0.0.1, including its port.',
|
|
55
|
+
signer_incompatible: 'This endpoint does not identify a Base USDC owner signer. Check the local runtime URL. No pairing code was submitted.',
|
|
56
|
+
signer_upgrade_required: 'This signer uses the earlier wallet interface. Upgrade the runtime using the same wallet directory, or open its local console below. The pairing code has not been used.',
|
|
52
57
|
pairing_invalid_or_expired: 'This pairing link was used or expired. Press Enter in the signer terminal for a fresh link.',
|
|
53
58
|
owner_session_required: 'The owner session expired. Open a fresh pairing link from your signer.',
|
|
54
59
|
wallet_response_unreadable: 'The signer’s response was incomplete. Refresh state, or recover the same delegation request.',
|
|
55
|
-
schema_mismatch: 'The signer rejected the fields.
|
|
60
|
+
schema_mismatch: 'The signer rejected the fields. Name-only connections need runtime 0.3.0 or later; upgrade and restart with the same wallet directory. Check any optional fields before retrying.',
|
|
56
61
|
invalid_amount: 'Use a positive USDC amount with at most six decimal places; no commas or exponent notation.',
|
|
57
62
|
delegation_limit_invalid: 'The per-payment limit must fit this agent’s total limit, and that total must fit the wallet’s lifetime limit.',
|
|
58
63
|
delegation_expired: 'Choose an expiry in the future.', invalid_payee: 'Enter a nonzero Base receiving address.',
|
|
@@ -66,7 +71,8 @@ if (typeof document !== 'undefined') {
|
|
|
66
71
|
function notice(message, error = false) { $('notice').textContent = message; $('notice').dataset.error = String(error); }
|
|
67
72
|
function fail(error) { if (error.message !== 'session_changed') notice(messages[error.message] || error.message, true); }
|
|
68
73
|
function clear() {
|
|
69
|
-
|
|
74
|
+
$('signer-upgrade').hidden = true; $('legacy-console').removeAttribute('href');
|
|
75
|
+
budgetTarget = null; budgetPending = null; agentConnection = null; $('agent-connection').value = ''; $('connection-secret').open = false; $('budget-form').hidden = true; $('agent-setup').hidden = true; $('agent-setup-command').textContent = ''; $('agent-next-command').textContent = '';
|
|
70
76
|
epoch++; session = null; state = null; pending = null; sent = false; refreshing = null;
|
|
71
77
|
$('connection').hidden = false; $('create-wallet').hidden = true; $('owner-panels').hidden = true;
|
|
72
78
|
$('wallet').hidden = true; $('permissions-prerequisite').hidden = false; $('activity-link').hidden = true;
|
|
@@ -100,16 +106,30 @@ if (typeof document !== 'undefined') {
|
|
|
100
106
|
}
|
|
101
107
|
function element(tag, text, className) { const n = document.createElement(tag); n.textContent = text; if (className) n.className = className; return n; }
|
|
102
108
|
function button(text, action) { const b = element('button', text); b.type = 'button'; b.addEventListener('click', async () => { b.disabled = true; try { await action(); } catch (e) { fail(e); } finally { b.disabled = false; } }); return b; }
|
|
103
|
-
function
|
|
109
|
+
function showConnection(credential) {
|
|
104
110
|
if (!/^mobrt_[0-9a-f]{64}$/.test(credential.token)) throw new Error('invalid_credential_response');
|
|
111
|
+
agentConnection = { id: credential.id, token: credential.token, gateway: localGateway(credential.gateway) };
|
|
112
|
+
$('agent-connection').value = JSON.stringify(agentConnection, null, 2);
|
|
113
|
+
$('connection-secret').open = false; $('agent-setup').hidden = false;
|
|
114
|
+
$('agent-setup-command').textContent = '402mob-runtime buyer check';
|
|
115
|
+
$('agent-next-command').textContent = '402mob-runtime buyer workers\n402mob-runtime buyer resources';
|
|
116
|
+
}
|
|
117
|
+
function download(credential) {
|
|
105
118
|
const url = URL.createObjectURL(new Blob([JSON.stringify(credential, null, 2) + '\n'], { type: 'application/json' }));
|
|
106
119
|
const a = document.createElement('a'); a.href = url; a.download = '402mob-agent-' + credential.id + '.json';
|
|
107
|
-
$('agent-setup').hidden = false; $('agent-setup-command').textContent = 'chmod 600 /absolute/private/' + a.download + '\n402mob-runtime buyer check --credential /absolute/private/' + a.download;
|
|
108
|
-
$('agent-next-command').textContent = '402mob-runtime buyer workers --credential /absolute/private/' + a.download + '\n402mob-runtime buyer resources --credential /absolute/private/' + a.download;
|
|
109
120
|
document.body.append(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
110
121
|
}
|
|
122
|
+
$('copy-agent-connection').addEventListener('click', async () => {
|
|
123
|
+
if (!agentConnection) return;
|
|
124
|
+
try { await navigator.clipboard.writeText(JSON.stringify(agentConnection, null, 2)); notice('Private connection copied. Pass it only to your agent.'); }
|
|
125
|
+
catch { $('connection-secret').open = true; $('agent-connection').select(); notice('Copy the private connection shown below.'); }
|
|
126
|
+
});
|
|
127
|
+
$('download-agent-connection').addEventListener('click', () => { if (agentConnection) download(agentConnection); });
|
|
111
128
|
function render(data) {
|
|
112
129
|
state = data; $('connection').hidden = true; $('refresh').hidden = false; $('disconnect').hidden = false;
|
|
130
|
+
if (agentConnection && data.delegations.some(d => d.id === agentConnection.id && d.state === 'revoked')) {
|
|
131
|
+
agentConnection = null; $('agent-connection').value = ''; $('agent-setup').hidden = true;
|
|
132
|
+
}
|
|
113
133
|
$('create-wallet').hidden = data.initialized; $('owner-panels').hidden = !data.initialized;
|
|
114
134
|
$('wallet').hidden = !data.initialized; $('permissions-prerequisite').hidden = data.initialized; $('activity-link').hidden = !data.initialized;
|
|
115
135
|
renderCustomer();
|
|
@@ -122,12 +142,12 @@ if (typeof document !== 'undefined') {
|
|
|
122
142
|
for (const d of data.delegations) {
|
|
123
143
|
const row = element('article', '', 'record'); row.append(element('h3', d.policy.name + ' / ' + d.state));
|
|
124
144
|
row.append(element('p', 'Merchant: ' + (d.policy.merchantId || 'agent chooses') + ' · Recipient: ' + (d.policy.payee || 'seller payout')));
|
|
125
|
-
row.append(element('p', '
|
|
126
|
-
row.append(element('p', 'Spent: ' + formatUSDC(d.spentAtomic) + ' ·
|
|
145
|
+
row.append(element('p', 'Spending: ' + (d.policy.maxTotalUSDC ? d.policy.maxTotalUSDC + ' USDC lifetime' : 'available wallet balance, including later deposits') + ' · Per payment: ' + (d.policy.maxPerPaymentUSDC || 'no extra limit') + ' · Expires: ' + (d.policy.expiresAt ? new Date(d.policy.expiresAt).toLocaleString() : 'never')));
|
|
146
|
+
row.append(element('p', 'Spent: ' + formatUSDC(d.spentAtomic) + ' · Pending: ' + formatUSDC(d.reservedAtomic) + (d.remainingAtomic === null ? '' : ' · Limit left: ' + formatUSDC(d.remainingAtomic)) + ' USDC'));
|
|
127
147
|
row.append(element('p', 'Service: ' + (d.policy.capability || 'all supported services') + ' · Delegation ID: ' + d.id));
|
|
128
148
|
const controls = element('div', '', 'actions');
|
|
129
|
-
if (d.credentialRecoverable) controls.append(button(d.state === 'expired' ? '
|
|
130
|
-
if (d.state === 'active') controls.append(button('
|
|
149
|
+
if (d.credentialRecoverable) controls.append(button(d.state === 'expired' ? 'Recovery connection' : 'Agent connection', async () => { showConnection(await api('/api/delegations/' + d.id + '/credential', {})); notice('Existing connection ready. Its permissions are unchanged.'); }));
|
|
150
|
+
if (d.state === 'active') controls.append(button('Optional limit', () => openBudget(d)));
|
|
131
151
|
if (d.state !== 'revoked') controls.append(button('Revoke spending', async () => { if (!window.confirm('Revoke new spending for ' + d.policy.name + '? Existing signed payments may still settle.')) return; render(await api('/api/delegations/' + d.id + '/revoke', {})); notice('New authorizations revoked. Existing payments and recovery records are retained.'); }));
|
|
132
152
|
row.append(controls); $('delegation-list').append(row);
|
|
133
153
|
}
|
|
@@ -162,8 +182,26 @@ if (typeof document !== 'undefined') {
|
|
|
162
182
|
event.preventDefault(); const b = event.submitter; b.disabled = true;
|
|
163
183
|
try {
|
|
164
184
|
gateway = localGateway($('gateway').value.trim()); epoch++;
|
|
165
|
-
|
|
166
|
-
|
|
185
|
+
$('signer-upgrade').hidden = true; $('legacy-console').removeAttribute('href');
|
|
186
|
+
const code = $('pair-code').value.trim();
|
|
187
|
+
const health = await api('/api/healthz', undefined, false);
|
|
188
|
+
if (health?.protocol !== '402mob.owner-wallet-web.v1' || health.network !== 'eip155:8453' || typeof health.asset !== 'string' || health.asset.toLowerCase() !== USDC.toLowerCase()) throw new Error('signer_incompatible');
|
|
189
|
+
if (health.consoleProtocol !== '402mob.wallet-console.v2') {
|
|
190
|
+
// Leave the one-use code untouched so the matching local console can still pair.
|
|
191
|
+
const fallback = new URL(gateway + '/');
|
|
192
|
+
if (/^mobpair_[0-9a-f]{64}$/.test(code)) fallback.hash = new URLSearchParams({ gateway, pair: code }).toString();
|
|
193
|
+
$('legacy-console').href = fallback.href; $('signer-upgrade').hidden = false;
|
|
194
|
+
throw new Error('signer_upgrade_required');
|
|
195
|
+
}
|
|
196
|
+
session = await api('/api/session', { code }, false); $('pair-code').value = '';
|
|
197
|
+
// Retain usable session controls even if the first state or create response is lost.
|
|
198
|
+
$('connection').hidden = true; $('refresh').hidden = false; $('disconnect').hidden = false;
|
|
199
|
+
const opened = await api('/api/state'); render(opened);
|
|
200
|
+
if (!opened.initialized) {
|
|
201
|
+
try { render(await api('/api/wallet', {})); }
|
|
202
|
+
catch (error) { if (error.message !== 'wallet_already_exists') throw error; }
|
|
203
|
+
}
|
|
204
|
+
notice('Agent wallet connected. Session expires ' + new Date(session.expiresAt).toLocaleTimeString() + '.'); await refresh();
|
|
167
205
|
} catch (e) { fail(e); } finally { b.disabled = false; }
|
|
168
206
|
});
|
|
169
207
|
$('create-form').addEventListener('submit', async event => { event.preventDefault(); const b = event.submitter; b.disabled = true;
|
|
@@ -172,11 +210,11 @@ if (typeof document !== 'undefined') {
|
|
|
172
210
|
});
|
|
173
211
|
function openBudget(delegation) {
|
|
174
212
|
if (budgetPending) { notice('Recover the pending budget update before preparing another.', true); return; }
|
|
175
|
-
budgetTarget = delegation ? { id: delegation.id, expected: delegation.policy.maxTotalUSDC } : { id: null, expected: state.walletLimitUSDC };
|
|
176
|
-
$('budget-title').textContent = delegation ? '
|
|
213
|
+
budgetTarget = delegation ? { id: delegation.id, expected: delegation.policy.maxTotalUSDC ?? null } : { id: null, expected: state.walletLimitUSDC };
|
|
214
|
+
$('budget-title').textContent = delegation ? 'Optional spending limit for ' + delegation.policy.name : 'Optional wallet limit';
|
|
177
215
|
$('budget-amount').value = ''; $('budget-amount').disabled = false; $('budget-submit').textContent = 'Review and apply'; $('budget-cancel').hidden = false;
|
|
178
|
-
$('budget-help').textContent =
|
|
179
|
-
$('budget-form').hidden = false;
|
|
216
|
+
$('budget-help').textContent = 'Leave empty to remove this limit. A new limit includes past spending and pending payments; an existing limit can be increased or removed.';
|
|
217
|
+
$('wallet-controls').open = true; $('budget-form').hidden = false;
|
|
180
218
|
}
|
|
181
219
|
$('edit-wallet-limit').addEventListener('click', () => openBudget(null));
|
|
182
220
|
$('budget-cancel').addEventListener('click', () => { if (!budgetPending) { budgetTarget = null; $('budget-form').hidden = true; } });
|
|
@@ -185,8 +223,8 @@ if (typeof document !== 'undefined') {
|
|
|
185
223
|
try {
|
|
186
224
|
if (!budgetPending) {
|
|
187
225
|
const next = $('budget-amount').value.trim() || null; if (next !== null) amount(next);
|
|
188
|
-
if (budgetTarget.id &&
|
|
189
|
-
if (!window.confirm((budgetTarget.id ? 'Set this agent’s
|
|
226
|
+
if (budgetTarget.id && next !== null && budgetTarget.expected !== null && amount(next) < amount(budgetTarget.expected)) throw new Error('delegation_limit_invalid');
|
|
227
|
+
if (!window.confirm((budgetTarget.id ? 'Set this agent’s lifetime spending limit to ' : 'Set the shared lifetime ceiling to ') + (next === null ? 'no extra ceiling' : next + ' USDC') + '? Existing spending and pending payments remain recorded.')) return;
|
|
190
228
|
budgetPending = { path: budgetTarget.id ? '/api/delegations/' + budgetTarget.id + '/allocation' : '/api/wallet/limit', body: { requestId: crypto.randomUUID(), maxTotalUSDC: next, ...(budgetTarget.id ? { expectedMaxTotalUSDC: budgetTarget.expected } : { expectedLimitUSDC: budgetTarget.expected }) } };
|
|
191
229
|
}
|
|
192
230
|
$('budget-amount').disabled = true; $('budget-cancel').hidden = true;
|
|
@@ -211,18 +249,21 @@ if (typeof document !== 'undefined') {
|
|
|
211
249
|
try {
|
|
212
250
|
pending = delegationInput({ name: $('agent-name').value.trim(), merchantId: $('merchant-id').value.trim(), payee: $('payee').value.trim(),
|
|
213
251
|
capability: $('capability').value, maxPerPaymentUSDC: $('per-payment').value.trim(), maxTotalUSDC: $('total-limit').value.trim(), expiresAt: $('expires').value }, crypto.randomUUID());
|
|
214
|
-
if (state.walletLimitUSDC !== null && amount(pending.policy.maxTotalUSDC) > amount(state.walletLimitUSDC)) throw new Error('delegation_limit_invalid');
|
|
252
|
+
if (state.walletLimitUSDC !== null && pending.policy.maxTotalUSDC && amount(pending.policy.maxTotalUSDC) > amount(state.walletLimitUSDC)) throw new Error('delegation_limit_invalid');
|
|
215
253
|
sent = false; $('review-terms').replaceChildren();
|
|
216
|
-
for (const [label, value] of Object.entries({ Agent: pending.policy.name,
|
|
217
|
-
|
|
218
|
-
|
|
254
|
+
for (const [label, value] of Object.entries({ Agent: pending.policy.name, Spending: pending.policy.maxTotalUSDC ? pending.policy.maxTotalUSDC + ' USDC lifetime' : 'Available wallet balance, including future deposits',
|
|
255
|
+
...(state.walletLimitUSDC !== null ? { 'Wallet limit': state.walletLimitUSDC + ' USDC lifetime' } : {}),
|
|
256
|
+
...(pending.policy.merchantId ? { Merchant: pending.policy.merchantId } : {}), ...(pending.policy.payee ? { Recipient: pending.policy.payee } : {}),
|
|
257
|
+
...(pending.policy.capability ? { Service: pending.policy.capability } : {}), ...(pending.policy.maxPerPaymentUSDC ? { 'Per payment': pending.policy.maxPerPaymentUSDC + ' USDC' } : {}),
|
|
258
|
+
...(pending.policy.expiresAt ? { Expiry: pending.policy.expiresAt } : {}) })) $('review-terms').append(element('dt', label), element('dd', value));
|
|
259
|
+
$('grant-form').hidden = true; $('grant-review').hidden = false; $('cancel-grant').hidden = false; $('confirm-grant').textContent = 'Connect agent'; $('grant-recovery').textContent = '';
|
|
219
260
|
} catch (e) { pending = null; fail(e); }
|
|
220
261
|
});
|
|
221
262
|
$('cancel-grant').addEventListener('click', () => { if (sent) return; pending = null; $('grant-review').hidden = true; $('grant-form').hidden = false; });
|
|
222
263
|
$('confirm-grant').addEventListener('click', async () => {
|
|
223
264
|
if (!pending) return; const b = $('confirm-grant'); b.disabled = true; sent = true; $('cancel-grant').hidden = true;
|
|
224
|
-
try {
|
|
225
|
-
notice('Agent
|
|
265
|
+
try { showConnection(await api('/api/delegations', pending)); pending = null; sent = false; $('grant-review').hidden = true; $('grant-form').hidden = false; $('grant-form').reset();
|
|
266
|
+
notice('Agent connection ready. Copy it to your agent; file export is optional.'); await refresh(); }
|
|
226
267
|
catch (e) {
|
|
227
268
|
if (e.message === 'session_changed') return;
|
|
228
269
|
// Explicit rejection or confirmed revocation unlocks editing. Unknown outcomes retain the exact request.
|
|
@@ -230,7 +271,7 @@ if (typeof document !== 'undefined') {
|
|
|
230
271
|
if (pending && rejected) {
|
|
231
272
|
pending = null; sent = false; $('grant-review').hidden = true; $('grant-form').hidden = false; $('cancel-grant').hidden = false;
|
|
232
273
|
$('grant-recovery').textContent = '';
|
|
233
|
-
} else if (pending) { b.textContent = 'Recover same
|
|
274
|
+
} else if (pending) { b.textContent = 'Recover same connection'; $('grant-recovery').textContent = 'Keep this request: ' + pending.requestId + '. Retry recovers the same delegation. After reloading, inspect the delegation list before creating another.'; }
|
|
234
275
|
fail(e);
|
|
235
276
|
}
|
|
236
277
|
finally { b.disabled = false; }
|
|
@@ -287,7 +328,7 @@ if (typeof document !== 'undefined') {
|
|
|
287
328
|
$('browser-wallet-switch').hidden = !connected || s.chainId === BASE_CHAIN;
|
|
288
329
|
if (fundingReview && (fundingReview !== customer?.review || fundingEpoch !== epoch)) fundingReview = null;
|
|
289
330
|
$('funding-review').hidden = !fundingReview;
|
|
290
|
-
$('funding-target').textContent = state?.initialized ? state.wallet.address : '
|
|
331
|
+
$('funding-target').textContent = state?.initialized ? state.wallet.address : 'Open the agent wallet in step 02.';
|
|
291
332
|
let record = fundingMemory;
|
|
292
333
|
try { record ||= fundingJournal.read(); } catch (error) { customerFail(error); }
|
|
293
334
|
$('funding-form').hidden = !connected || !state?.initialized || !session || s.chainId !== BASE_CHAIN || Boolean(fundingReview) || Boolean(record);
|
|
@@ -336,7 +377,7 @@ if (typeof document !== 'undefined') {
|
|
|
336
377
|
if (current !== epoch || wallet !== customer) throw new Error('session_changed');
|
|
337
378
|
fundingReview = review; fundingEpoch = current;
|
|
338
379
|
$('funding-review-terms').textContent = formatUSDC(review.amountAtomic) + ' USDC on Base\nFrom wallet: ' + review.from + '\nTo agent wallet: ' + review.to + '\nUSDC contract: ' + USDC;
|
|
339
|
-
customerNotice('Review this deposit, then confirm its transaction in your wallet.
|
|
380
|
+
customerNotice('Review this deposit, then confirm its transaction in your wallet. Optional spending limits remain in effect.'); renderCustomer();
|
|
340
381
|
} catch (error) { customerFail(error); } finally { event.submitter.disabled = false; }
|
|
341
382
|
});
|
|
342
383
|
$('funding-edit').addEventListener('click', () => { if (customer?.busy) return; fundingReview = null; renderCustomer(); });
|
|
@@ -371,7 +412,7 @@ if (typeof document !== 'undefined') {
|
|
|
371
412
|
const fragment = new URLSearchParams(location.hash.slice(1));
|
|
372
413
|
if (fragment.has('pair') || fragment.has('gateway')) {
|
|
373
414
|
history.replaceState(null, '', location.pathname + location.search);
|
|
374
|
-
try { gateway = localGateway(fragment.get('gateway') || gateway); $('gateway').value = gateway; $('pair-code').value = fragment.get('pair') || ''; notice('Pairing
|
|
415
|
+
try { gateway = localGateway(fragment.get('gateway') || gateway); $('gateway').value = gateway; $('pair-code').value = fragment.get('pair') || ''; $('connection-manual').open = !$('pair-code').value; notice('Pairing details loaded. Click Open agent wallet to continue.'); } catch (e) { fail(e); }
|
|
375
416
|
} else { $('gateway').value = initialGateway(location.href); }
|
|
376
417
|
setInterval(() => { if (session && Date.parse(session.expiresAt) <= Date.now()) { clear(); notice(messages.owner_session_required, true); } else if (session && !document.hidden) void refresh(); }, 30000);
|
|
377
418
|
}
|
package/public/wallet/index.html
CHANGED
|
@@ -4,101 +4,111 @@
|
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
6
|
<meta name="referrer" content="no-referrer">
|
|
7
|
-
<meta name="description" content="Manage an owner-controlled Base USDC wallet and
|
|
7
|
+
<meta name="description" content="Manage an owner-controlled Base USDC wallet and connect an agent with optional spending limits.">
|
|
8
8
|
<title>402Mob / USDC wallet</title>
|
|
9
9
|
<link rel="icon" type="image/svg+xml" href="./favicon.svg">
|
|
10
|
-
<link rel="stylesheet" href="./style.css?v=
|
|
11
|
-
<script type="module" src="./app.js?v=
|
|
10
|
+
<link rel="stylesheet" href="./style.css?v=5">
|
|
11
|
+
<script type="module" src="./app.js?v=10"></script>
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<a class="skip" href="#main">Skip to wallet</a>
|
|
15
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="#
|
|
16
|
+
<nav aria-label="Wallet navigation"><a href="#customer-wallet">01 / Your wallet</a><a href="#agent-wallet">02 / Agent wallet</a><a href="#permissions">03 / Connect agent</a><a id="activity-link" href="#activity" hidden>Activity</a><a href="https://evidence.contact/web-wallet.md">Guide ↗</a></nav>
|
|
17
17
|
<main id="main">
|
|
18
|
-
<div class="toolbar"><div><p class="eyebrow">OWNER CONSOLE</p><h1>USDC for your agent</h1><p>
|
|
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>--
|
|
20
|
-
<p id="notice" role="status" aria-live="polite">
|
|
18
|
+
<div class="toolbar"><div><p class="eyebrow">OWNER CONSOLE</p><h1>USDC for your agent</h1><p>Connect your wallet, send USDC to the agent wallet, and give your agent a connection token.</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>-- agent purchases --></span> SELLER</code></pre></figure>
|
|
20
|
+
<p id="notice" role="status" aria-live="polite">Connect your wallet below. Open the local runtime link to create or reopen the agent wallet.</p>
|
|
21
|
+
<section id="customer-wallet" class="panel" aria-labelledby="customer-title">
|
|
22
|
+
<div class="section-head"><h2 id="customer-title">01 / Your wallet</h2><span class="tag">FROM YOUR WALLET</span></div>
|
|
23
|
+
<p>Connect a browser wallet to send USDC on Base. The agent uses a separate wallet; it cannot spend from this connected account.</p>
|
|
24
|
+
<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>
|
|
25
|
+
<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>
|
|
26
|
+
<div id="customer-connected" hidden>
|
|
27
|
+
<div class="customer-details"><code id="customer-address"></code><span id="customer-network"></span><strong id="customer-usdc">—</strong></div>
|
|
28
|
+
<p id="customer-gas" class="note"></p>
|
|
29
|
+
<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>
|
|
30
|
+
</div>
|
|
31
|
+
</section>
|
|
21
32
|
<div id="agent-wallet">
|
|
22
33
|
<section id="connection" class="panel" aria-labelledby="connection-title">
|
|
23
|
-
<h2 id="connection-title">
|
|
24
|
-
<p>The local
|
|
25
|
-
<
|
|
26
|
-
|
|
34
|
+
<h2 id="connection-title">02 / Open the agent wallet</h2>
|
|
35
|
+
<p>The local runtime keeps the agent wallet's key on your computer. Opening it creates a wallet if needed; existing wallets stay unchanged.</p>
|
|
36
|
+
<details id="runtime-start" class="optional-restrictions"><summary>Start the local runtime</summary>
|
|
37
|
+
<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:</p>
|
|
38
|
+
<pre><code>402mob-runtime wallet web \
|
|
27
39
|
--dir "$HOME/.local/share/402mob/runtime-owner"</code></pre>
|
|
28
|
-
|
|
40
|
+
<p>Open the link printed in that terminal. Use its local console link if your browser blocks localhost access.</p>
|
|
41
|
+
</details>
|
|
42
|
+
<div id="signer-upgrade" class="review" hidden><p>The new connection flow needs an updated runtime. Keep the same wallet directory when upgrading.</p><div class="actions"><a href="https://evidence.contact/agent-runtime.md#upgrade-from-02x" target="_blank" rel="noopener noreferrer">Upgrade instructions</a><a id="legacy-console" target="_blank" rel="noopener noreferrer">Open this signer's local console</a></div></div>
|
|
29
43
|
<form id="connect-form" autocomplete="off">
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
<details id="connection-manual" class="optional-restrictions" open><summary>Pairing details</summary>
|
|
45
|
+
<label>Local runtime URL<input id="gateway" type="url" value="http://127.0.0.1:4032" required spellcheck="false"></label>
|
|
46
|
+
<label>Pairing code<input id="pair-code" type="password" autocomplete="off" required spellcheck="false" placeholder="mobpair_…"></label>
|
|
47
|
+
</details>
|
|
48
|
+
<button class="primary" type="submit">Open agent wallet</button>
|
|
33
49
|
</form>
|
|
34
|
-
<p class="note">
|
|
50
|
+
<p class="note">The runtime link fills these details. Pairing codes last five minutes; press Enter in the runtime terminal for a new link.</p>
|
|
35
51
|
</section>
|
|
36
52
|
<section id="create-wallet" class="panel" hidden aria-labelledby="create-title">
|
|
37
|
-
<h2 id="create-title">
|
|
38
|
-
<
|
|
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>
|
|
53
|
+
<h2 id="create-title">02 / Create the agent wallet</h2>
|
|
54
|
+
<form id="create-form"><details class="optional-restrictions"><summary>Optional wallet limit</summary><label>Total spending ceiling · USDC<input id="wallet-limit" type="text" inputmode="decimal" placeholder="No limit" autocomplete="off"></label></details><button class="primary" type="submit">Create wallet</button></form>
|
|
42
55
|
</section>
|
|
43
56
|
<section id="wallet" class="panel" hidden aria-labelledby="wallet-title">
|
|
44
|
-
<div class="section-head"><h2 id="wallet-title">
|
|
45
|
-
<div class="
|
|
57
|
+
<div class="section-head"><h2 id="wallet-title">02 / Agent wallet</h2><span id="connection-state" class="tag">SIGNER CONNECTED</span></div>
|
|
58
|
+
<div class="wallet-balance"><span>BALANCE ON BASE</span><strong id="balance">—</strong><span>USDC</span></div>
|
|
46
59
|
<p id="balance-time" class="note">Balance has not been read.</p>
|
|
47
60
|
<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
|
|
61
|
+
<details id="wallet-controls" class="optional-restrictions"><summary>Wallet limits and accounting</summary><div class="metrics"><div><span>PENDING</span><strong id="reserved">—</strong></div><div><span>SPENT</span><strong id="spent">—</strong></div><div><span>LIMIT LEFT</span><strong id="remaining">—</strong></div></div><button id="edit-wallet-limit" type="button">Change wallet limit</button>
|
|
49
62
|
<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
63
|
<p id="wallet-context" class="note"></p>
|
|
51
|
-
<p class="note">
|
|
64
|
+
<p class="note">Pending payments reserve USDC until resolved. An optional lifetime limit includes past spending and reservations.</p></details>
|
|
65
|
+
<p class="note">Deposit destination: <code id="funding-target">Open the agent wallet in step 02.</code></p>
|
|
66
|
+
<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>
|
|
67
|
+
<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. Connected agents without a spending limit can use this deposit. Any limits you set remain in effect.</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>
|
|
68
|
+
|
|
69
|
+
|
|
52
70
|
</section>
|
|
71
|
+
<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">Keep this tab open until the deposit is resolved. Check the same transaction; do not send it again while its outcome is unknown.</p></div>
|
|
53
72
|
</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
73
|
<div id="permissions">
|
|
70
|
-
<p id="permissions-prerequisite" class="note setup-prerequisite">03 /
|
|
74
|
+
<p id="permissions-prerequisite" class="note setup-prerequisite">03 / Open the agent wallet to connect an agent.</p>
|
|
71
75
|
<div id="owner-panels" hidden>
|
|
72
76
|
<section id="delegations" class="panel" aria-labelledby="delegations-title">
|
|
73
|
-
<div class="section-head"><h2 id="delegations-title">03 /
|
|
74
|
-
<p>
|
|
77
|
+
<div class="section-head"><h2 id="delegations-title">03 / Connect your agent</h2><span class="tag">PRIVATE CONNECTION</span></div>
|
|
78
|
+
<p>By default, the agent can spend available USDC in this wallet, including future deposits. Set a limit only if you need one. You can revoke access at any time.</p>
|
|
75
79
|
<form id="grant-form" autocomplete="off">
|
|
76
80
|
<div class="form-grid">
|
|
77
|
-
<label>Name for this agent<input id="agent-name" required maxlength="80" placeholder="
|
|
78
|
-
<label>Allocate · USDC<input id="total-limit" required inputmode="decimal" placeholder="0.10"></label>
|
|
81
|
+
<label>Name for this agent<input id="agent-name" required maxlength="80" value="Agent" placeholder="Agent name"></label>
|
|
79
82
|
</div>
|
|
80
|
-
<details class="optional-restrictions"><summary>Optional
|
|
83
|
+
<details class="optional-restrictions"><summary>Optional limits and restrictions</summary>
|
|
81
84
|
<div class="form-grid">
|
|
85
|
+
<label>Total lifetime limit · USDC<input id="total-limit" inputmode="decimal" placeholder="Use available wallet balance"></label>
|
|
82
86
|
<label>Only this seller<input id="merchant-id" spellcheck="false" placeholder="Any seller · or enter a merchant UUID"></label>
|
|
83
87
|
<label>Only this receiving address<input id="payee" spellcheck="false" placeholder="Any seller payout · or enter 0x…"></label>
|
|
84
88
|
<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="
|
|
89
|
+
<label>Per-payment limit · USDC<input id="per-payment" inputmode="decimal" placeholder="No per-payment limit"></label>
|
|
86
90
|
<label>Expiry · your local time<input id="expires" type="datetime-local"></label>
|
|
87
91
|
</div>
|
|
88
92
|
<div class="actions"><button id="inspect-merchant" type="button">Inspect seller</button><span id="merchant-info" class="note"></span></div>
|
|
89
93
|
<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
94
|
</details>
|
|
91
|
-
<button class="primary" type="submit">Review
|
|
95
|
+
<button class="primary" type="submit">Review connection</button>
|
|
92
96
|
</form>
|
|
93
|
-
<div id="grant-review" class="review" hidden><h3>
|
|
94
|
-
<p class="note">Keep
|
|
95
|
-
<div id="agent-setup" class="review" hidden><h3>
|
|
97
|
+
<div id="grant-review" class="review" hidden><h3>Confirm agent access</h3><dl id="review-terms"></dl><p>This authorizes purchases from the agent wallet. It does not give the agent access to your connected browser wallet.</p><div class="actions"><button id="confirm-grant" class="primary" type="button">Connect agent</button><button id="cancel-grant" type="button">Edit terms</button></div><p id="grant-recovery" class="note"></p></div>
|
|
98
|
+
<p class="note">Keep the connection private. Agents share the wallet balance. Revoking access stops new purchases; already signed payments may still settle.</p>
|
|
99
|
+
<div id="agent-setup" class="review" hidden><h3>Agent connection ready</h3>
|
|
100
|
+
<p>Give this private connection to your agent on the runtime's host. No configuration file is required.</p>
|
|
101
|
+
<div class="actions"><button id="copy-agent-connection" type="button" class="primary">Copy agent connection</button><button id="download-agent-connection" type="button">Export JSON (optional)</button></div>
|
|
102
|
+
<details id="connection-secret" class="optional-restrictions"><summary>View connection</summary><label>Private connection JSON<textarea id="agent-connection" readonly rows="6" spellcheck="false"></textarea></label></details>
|
|
103
|
+
<p class="note">The agent uses <code>token</code> as its bearer credential and <code>gateway</code> as its local API URL. For the CLI, load these into <code>MOB_RUNTIME_TOKEN</code> and <code>MOB_RUNTIME_GATEWAY</code> through the agent's environment or secret manager.</p>
|
|
104
|
+
<pre><code id="agent-setup-command"></code></pre><pre><code id="agent-next-command"></code></pre>
|
|
105
|
+
</div>
|
|
96
106
|
<div id="delegation-list" class="records" aria-live="polite"></div>
|
|
97
107
|
</section>
|
|
98
108
|
<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
109
|
</div>
|
|
100
110
|
</div>
|
|
101
111
|
</main>
|
|
102
|
-
<footer><span>Base USDC
|
|
112
|
+
<footer><span>Base USDC · local keys · optional spending limits</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
113
|
</body>
|
|
104
114
|
</html>
|
package/public/wallet/style.css
CHANGED
|
@@ -8,3 +8,6 @@ form{display:grid;gap:16px;max-width:920px}label{display:flex;flex-direction:col
|
|
|
8
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
9
|
|
|
10
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}
|
|
11
|
+
|
|
12
|
+
/* One source, one destination, then the agent connection. */
|
|
13
|
+
header,nav,main,footer{padding-inline:max(5%,calc((100% - 960px)/2))}header{min-height:72px}main{padding-block:24px 40px}.panel{padding:22px;margin-top:18px}.panel p{margin-block:10px}.toolbar p{max-width:650px}textarea{width:100%;resize:vertical;background:#050505;color:var(--fg);border:1px solid #363636;padding:12px;font:12px/1.6 monospace}.wallet-balance{display:flex;gap:12px;align-items:baseline;border-block:1px solid var(--line);padding:14px 0}.wallet-balance span{font:11px monospace;color:var(--muted)}.wallet-balance strong{font:30px monospace}.metrics{grid-template-columns:repeat(3,minmax(0,1fr));border:0}.metrics strong{font-size:18px}.optional-restrictions{margin-block:14px}.optional-restrictions>summary{cursor:pointer;color:var(--accent);font:12px/1.7 monospace}.optional-restrictions[open]>summary{margin-bottom:14px}.optional-restrictions label+label{margin-top:12px}#grant-form>.form-grid{grid-template-columns:minmax(0,360px)}#agent-setup pre{margin-bottom:0}#agent-setup textarea:focus-visible{outline:2px solid var(--accent)}#wallet-context{overflow-wrap:anywhere}#connection form{margin-top:14px}.receive{padding-block:12px}.wallet-flow{margin-block:18px}#customer-wallet .actions label{min-width:220px}@media(max-width:700px){.panel{padding:16px}.wallet-balance{flex-wrap:wrap}.wallet-balance strong{font-size:26px}.metrics{grid-template-columns:1fr 1fr}nav{gap:10px 18px}#customer-wallet .actions label{min-width:0;width:100%}}
|