@attocash/cli 0.2.2 → 0.3.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/README.md +157 -5
- package/dist/application/app.d.ts +34 -3
- package/dist/application/app.js +142 -125
- package/dist/application/operations.d.ts +3 -0
- package/dist/application/operations.js +30 -8
- package/dist/cli/cli.d.ts +1 -0
- package/dist/cli/cli.js +101 -13
- package/dist/cli/onboarding.d.ts +13 -0
- package/dist/cli/onboarding.js +99 -2
- package/dist/cli/output.js +18 -2
- package/dist/doctor/profile.js +2 -1
- package/dist/internal-marketplace.d.ts +25 -0
- package/dist/internal-marketplace.js +50 -0
- package/dist/marketplace/approval-files.d.ts +3 -0
- package/dist/marketplace/approval-files.js +97 -0
- package/dist/marketplace/approval-preview.d.ts +2 -0
- package/dist/marketplace/approval-preview.js +86 -0
- package/dist/marketplace/proof-approval.d.ts +82 -0
- package/dist/marketplace/proof-approval.js +671 -0
- package/dist/marketplace/topups.d.ts +82 -0
- package/dist/marketplace/topups.js +485 -0
- package/dist/network/batching.d.ts +2 -0
- package/dist/network/batching.js +23 -0
- package/dist/network/entry.d.ts +2 -0
- package/dist/network/entry.js +35 -0
- package/dist/network/reader.d.ts +2 -0
- package/dist/network/reader.js +125 -37
- package/dist/spending/approval.d.ts +35 -0
- package/dist/spending/approval.js +25 -0
- package/dist/spending/atto-x402.d.ts +31 -0
- package/dist/spending/atto-x402.js +174 -0
- package/dist/spending/ledger.d.ts +74 -2
- package/dist/spending/ledger.js +298 -7
- package/dist/spending/payments.d.ts +105 -5
- package/dist/spending/payments.js +795 -11
- package/dist/storage/recovery-seed.d.ts +13 -0
- package/dist/storage/recovery-seed.js +93 -0
- package/dist/storage/state.d.ts +4 -0
- package/dist/storage/state.js +32 -2
- package/dist/wallet/receive.d.ts +39 -0
- package/dist/wallet/receive.js +264 -0
- package/dist/wallet/signing.d.ts +1 -0
- package/dist/wallet/signing.js +37 -21
- package/dist/wallet/types.d.ts +1 -0
- package/node_modules/@attocash/commons-core/Kotlin-DateTime-library-kotlinx-datetime.mjs +1922 -1918
- package/node_modules/@attocash/commons-core/Kotlin-DateTime-library-kotlinx-datetime.mjs.map +1 -1
- package/node_modules/@attocash/commons-core/README.md +9 -0
- package/node_modules/@attocash/commons-core/commons-commons-core.d.mts +10 -0
- package/node_modules/@attocash/commons-core/commons-commons-core.mjs +2543 -2434
- package/node_modules/@attocash/commons-core/commons-commons-core.mjs.map +1 -1
- package/node_modules/@attocash/commons-core/kotlin-kotlin-stdlib.mjs +4695 -4227
- package/node_modules/@attocash/commons-core/kotlin-kotlin-stdlib.mjs.map +1 -1
- package/node_modules/@attocash/commons-core/kotlin_org_jetbrains_kotlin_kotlin_dom_api_compat.mjs.map +1 -1
- package/node_modules/@attocash/commons-core/kotlinx-io-kotlinx-io-bytestring.mjs +60 -60
- package/node_modules/@attocash/commons-core/kotlinx-io-kotlinx-io-bytestring.mjs.map +1 -1
- package/node_modules/@attocash/commons-core/kotlinx-io-kotlinx-io-core.mjs +651 -631
- package/node_modules/@attocash/commons-core/kotlinx-io-kotlinx-io-core.mjs.map +1 -1
- package/node_modules/@attocash/commons-core/kotlinx-serialization-kotlinx-serialization-core.mjs +2294 -2295
- package/node_modules/@attocash/commons-core/kotlinx-serialization-kotlinx-serialization-core.mjs.map +1 -1
- package/node_modules/@attocash/commons-core/kotlinx-serialization-kotlinx-serialization-json.mjs +1732 -1701
- package/node_modules/@attocash/commons-core/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -1
- package/node_modules/@attocash/commons-core/package.json +1 -1
- package/node_modules/@attocash/commons-node/commons-commons-node.d.mts +1 -0
- package/node_modules/@attocash/commons-node/commons-commons-node.mjs +873 -847
- package/node_modules/@attocash/commons-node/commons-commons-node.mjs.map +1 -1
- package/node_modules/@attocash/commons-node/kotlin-logging.mjs +109 -109
- package/node_modules/@attocash/commons-node/kotlin-logging.mjs.map +1 -1
- package/node_modules/@attocash/commons-node/kotlinx-serialization-kotlinx-serialization-json.mjs +1732 -1701
- package/node_modules/@attocash/commons-node/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -1
- package/node_modules/@attocash/commons-node/package.json +3 -3
- package/node_modules/@attocash/commons-node-remote/commons-commons-node-remote.d.mts +1 -0
- package/node_modules/@attocash/commons-node-remote/commons-commons-node-remote.mjs +674 -640
- package/node_modules/@attocash/commons-node-remote/commons-commons-node-remote.mjs.map +1 -1
- package/node_modules/@attocash/commons-node-remote/kotlin-logging.mjs +109 -109
- package/node_modules/@attocash/commons-node-remote/kotlin-logging.mjs.map +1 -1
- package/node_modules/@attocash/commons-node-remote/kotlinx-browser.mjs.map +1 -1
- package/node_modules/@attocash/commons-node-remote/kotlinx-serialization-kotlinx-serialization-json-io.mjs.map +1 -1
- package/node_modules/@attocash/commons-node-remote/kotlinx-serialization-kotlinx-serialization-json.mjs +1732 -1701
- package/node_modules/@attocash/commons-node-remote/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -1
- package/node_modules/@attocash/commons-node-remote/package.json +4 -4
- package/node_modules/@attocash/commons-transport/commons-commons-transport.d.mts +1 -0
- package/node_modules/@attocash/commons-transport/commons-commons-transport.mjs +52 -51
- package/node_modules/@attocash/commons-transport/commons-commons-transport.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/kotlinx-atomicfu.mjs +13 -13
- package/node_modules/@attocash/commons-transport/kotlinx-atomicfu.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/kotlinx-browser.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/kotlinx-coroutines-core.mjs +2639 -2608
- package/node_modules/@attocash/commons-transport/kotlinx-coroutines-core.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/kotlinx-serialization-kotlinx-serialization-json-io.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/kotlinx-serialization-kotlinx-serialization-json.mjs +1732 -1701
- package/node_modules/@attocash/commons-transport/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-client-content-negotiation.mjs +411 -196
- package/node_modules/@attocash/commons-transport/ktor-ktor-client-content-negotiation.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-client-core.mjs +2115 -1976
- package/node_modules/@attocash/commons-transport/ktor-ktor-client-core.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-events.mjs +7 -7
- package/node_modules/@attocash/commons-transport/ktor-ktor-events.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-http-cio.mjs +385 -384
- package/node_modules/@attocash/commons-transport/ktor-ktor-http-cio.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-http.mjs +1261 -1185
- package/node_modules/@attocash/commons-transport/ktor-ktor-http.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-io.mjs +668 -656
- package/node_modules/@attocash/commons-transport/ktor-ktor-io.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-openapi-schema.mjs +89 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-openapi-schema.mjs.map +1 -0
- package/node_modules/@attocash/commons-transport/ktor-ktor-serialization-kotlinx-json.mjs +9 -9
- package/node_modules/@attocash/commons-transport/ktor-ktor-serialization-kotlinx-json.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-serialization-kotlinx.mjs +120 -128
- package/node_modules/@attocash/commons-transport/ktor-ktor-serialization-kotlinx.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-serialization.mjs +46 -49
- package/node_modules/@attocash/commons-transport/ktor-ktor-serialization.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-sse.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-utils.mjs +1041 -985
- package/node_modules/@attocash/commons-transport/ktor-ktor-utils.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-websocket-serialization.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/ktor-ktor-websockets.mjs +530 -455
- package/node_modules/@attocash/commons-transport/ktor-ktor-websockets.mjs.map +1 -1
- package/node_modules/@attocash/commons-transport/package.json +4 -4
- package/node_modules/@attocash/commons-worker/commons-commons-worker.d.mts +1 -0
- package/node_modules/@attocash/commons-worker/commons-commons-worker.mjs +230 -226
- package/node_modules/@attocash/commons-worker/commons-commons-worker.mjs.map +1 -1
- package/node_modules/@attocash/commons-worker/kotlin-logging.mjs +109 -109
- package/node_modules/@attocash/commons-worker/kotlin-logging.mjs.map +1 -1
- package/node_modules/@attocash/commons-worker/kotlinx-serialization-kotlinx-serialization-json.mjs +1732 -1701
- package/node_modules/@attocash/commons-worker/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -1
- package/node_modules/@attocash/commons-worker/package.json +3 -3
- package/node_modules/@attocash/commons-worker-remote/commons-commons-worker-remote.d.mts +1 -0
- package/node_modules/@attocash/commons-worker-remote/commons-commons-worker-remote.mjs +91 -86
- package/node_modules/@attocash/commons-worker-remote/commons-commons-worker-remote.mjs.map +1 -1
- package/node_modules/@attocash/commons-worker-remote/kotlin-logging.mjs +109 -109
- package/node_modules/@attocash/commons-worker-remote/kotlin-logging.mjs.map +1 -1
- package/node_modules/@attocash/commons-worker-remote/kotlinx-browser.mjs.map +1 -1
- package/node_modules/@attocash/commons-worker-remote/kotlinx-serialization-kotlinx-serialization-json-io.mjs.map +1 -1
- package/node_modules/@attocash/commons-worker-remote/kotlinx-serialization-kotlinx-serialization-json.mjs +1732 -1701
- package/node_modules/@attocash/commons-worker-remote/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -1
- package/node_modules/@attocash/commons-worker-remote/package.json +4 -4
- package/package.json +9 -5
package/dist/application/app.js
CHANGED
|
@@ -2,26 +2,37 @@ import { PersonalLabels } from '../labels/personal.js';
|
|
|
2
2
|
import { GlobalDirectory } from '../labels/directory.js';
|
|
3
3
|
import { AddressLabels } from '../labels/presentation.js';
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
5
|
-
import { AttoMnemonic, toAttoIndex, } from '@attocash/commons-core';
|
|
5
|
+
import { AttoMnemonic, AttoPublicKey, AttoSignature, toAttoIndex, } from '@attocash/commons-core';
|
|
6
6
|
import { amountOutput, amountRaw } from '../domain/amount.js';
|
|
7
7
|
import { AttoError } from '../domain/errors.js';
|
|
8
8
|
import { NodeReader, parseAddress, publicModel } from '../network/reader.js';
|
|
9
|
+
import { resolveNodeBatchSize } from '../network/batching.js';
|
|
9
10
|
import { OsSecretStore } from '../storage/secrets.js';
|
|
10
11
|
import { StateStore } from '../storage/state.js';
|
|
11
12
|
import { resolveWalletProfile } from '../storage/profiles.js';
|
|
12
13
|
import { SpendLedger } from '../spending/ledger.js';
|
|
14
|
+
import { approvalInstructions } from '../spending/approval.js';
|
|
13
15
|
import { Payments } from '../spending/payments.js';
|
|
14
16
|
import { WalletWork } from '../wallet/work.js';
|
|
15
17
|
import { BackgroundReceiver } from '../wallet/background-receive.js';
|
|
16
18
|
import { WatchManager } from '../watches/manager.js';
|
|
17
19
|
import { AutoReceiver } from '../wallet/auto-receive.js';
|
|
20
|
+
import { WalletReceiver } from '../wallet/receive.js';
|
|
18
21
|
import { defaultSettings } from '../wallet/defaults.js';
|
|
19
22
|
import { derivedSigner, mnemonicSeed, signingWallet } from '../wallet/signing.js';
|
|
20
|
-
import {
|
|
23
|
+
import { operationFor, parseOperation } from './operations.js';
|
|
21
24
|
import { MarketData } from '../pricing/market.js';
|
|
22
25
|
import { marketTerms } from '../pricing/terms.js';
|
|
23
26
|
import { runDoctor } from '../doctor/doctor.js';
|
|
27
|
+
import { validateMarketplaceUserProofApproval, createMarketplaceProofApprovalResponse } from '../marketplace/proof-approval.js';
|
|
28
|
+
import { MarketplaceTopUpClient } from '../marketplace/topups.js';
|
|
24
29
|
const RESET_KEY = 'wallet.reset';
|
|
30
|
+
function signedMessageBytes(args) {
|
|
31
|
+
const bytes = args.messageHex !== undefined
|
|
32
|
+
? Buffer.from(args.messageHex, 'hex')
|
|
33
|
+
: Buffer.from(args.message, 'utf8');
|
|
34
|
+
return new Int8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
35
|
+
}
|
|
25
36
|
export class AttoApplication {
|
|
26
37
|
store;
|
|
27
38
|
ledger;
|
|
@@ -30,12 +41,14 @@ export class AttoApplication {
|
|
|
30
41
|
personal;
|
|
31
42
|
labels;
|
|
32
43
|
auto;
|
|
44
|
+
receiver;
|
|
33
45
|
work;
|
|
34
46
|
background;
|
|
35
47
|
receivingAllowed;
|
|
36
48
|
preparation;
|
|
37
49
|
preparationAbort = new AbortController();
|
|
38
50
|
payments;
|
|
51
|
+
topUps;
|
|
39
52
|
watchManager;
|
|
40
53
|
watchConfiguration = '';
|
|
41
54
|
watchQueue = Promise.resolve();
|
|
@@ -45,6 +58,9 @@ export class AttoApplication {
|
|
|
45
58
|
recoveryReads = 0;
|
|
46
59
|
calls = new Set();
|
|
47
60
|
mcp;
|
|
61
|
+
internalMarketplacePayment;
|
|
62
|
+
internalMarketplaceAuthorizeWrite;
|
|
63
|
+
internalMarketplaceReceiveSafety;
|
|
48
64
|
doctorAbort = new AbortController();
|
|
49
65
|
constructor(options = {}) {
|
|
50
66
|
const profile = resolveWalletProfile(options.directory);
|
|
@@ -52,6 +68,9 @@ export class AttoApplication {
|
|
|
52
68
|
try {
|
|
53
69
|
this.secrets = options.secrets ?? new OsSecretStore(profile.credentialAccount, profile.credentialService);
|
|
54
70
|
this.mcp = options.access === 'mcp';
|
|
71
|
+
this.internalMarketplacePayment = options.internalMarketplacePayment;
|
|
72
|
+
this.internalMarketplaceAuthorizeWrite = options.internalMarketplaceAuthorizeWrite;
|
|
73
|
+
this.internalMarketplaceReceiveSafety = options.internalMarketplaceReceiveSafety === true;
|
|
55
74
|
this.ledger = new SpendLedger(this.store);
|
|
56
75
|
this.personal = new PersonalLabels(this.store);
|
|
57
76
|
this.labels = new AddressLabels(this.personal, options.globalDirectory ?? new GlobalDirectory(this.store.directory));
|
|
@@ -63,14 +82,24 @@ export class AttoApplication {
|
|
|
63
82
|
this.work = new WalletWork(this.store, () => this.settings(), options.workExecution);
|
|
64
83
|
this.background = new BackgroundReceiver(this.store);
|
|
65
84
|
this.receivingAllowed = options.receivingAllowed ?? (() => true);
|
|
85
|
+
this.topUps = new MarketplaceTopUpClient(this.store, {
|
|
86
|
+
settings: () => this.settings(), addresses: () => this.addresses(), seed: () => this.seed(), mcp: this.mcp,
|
|
87
|
+
});
|
|
88
|
+
this.receiver = new WalletReceiver({
|
|
89
|
+
store: this.store, settings: () => this.settings(), address: (index, active) => this.address(index, active),
|
|
90
|
+
reader: () => this.reader(), seed: () => this.seed(), requireMcpWrite: () => this.requireMcpWrite(),
|
|
91
|
+
requireAccountAvailable: index => this.ledger.assertAccountAvailable(index), work: this.work, receivingAllowed: this.receivingAllowed,
|
|
92
|
+
internalMarketplaceReceiveSafety: this.internalMarketplaceReceiveSafety,
|
|
93
|
+
});
|
|
66
94
|
this.payments = new Payments(this.store, this.ledger, {
|
|
67
95
|
settings: () => this.settings(), addresses: () => this.addresses(), seed: () => this.seed(),
|
|
68
96
|
requireWrite: () => this.requireMcpWrite(), mcp: this.mcp,
|
|
69
|
-
|
|
97
|
+
...(this.internalMarketplaceReceiveSafety ? { requireAccountsAvailable: (indexes) => this.receiver.requireReceivesResolved(indexes) } : {}),
|
|
98
|
+
}, this.market, this.work, options.sendRetry, options.onDestination, this.topUps, this.internalMarketplacePayment);
|
|
70
99
|
this.auto = new AutoReceiver(() => ({
|
|
71
100
|
settings: !this.receivingAllowed() || (this.mcp && this.ledger.mcpAccess() !== 'spend') ? { ...this.settings(), autoReceive: false } : this.settings(),
|
|
72
101
|
addresses: this.addresses(),
|
|
73
|
-
}), (index, hash) => this.receive({ index, hash }, true), event => options.onReceiveProgress?.(this.labels.decorate(event, this.settings().network)));
|
|
102
|
+
}), (index, hash) => this.receiver.receive({ index, hash }, true), event => options.onReceiveProgress?.(this.labels.decorate(event, this.settings().network)));
|
|
74
103
|
}
|
|
75
104
|
catch (error) {
|
|
76
105
|
this.store.close();
|
|
@@ -105,6 +134,10 @@ export class AttoApplication {
|
|
|
105
134
|
if (this.mcp && this.ledger.mcpAccess() !== 'spend') {
|
|
106
135
|
throw new AttoError('MCP_READ_ONLY', 'MCP has read-only access to this wallet. Propose limits and obtain local terminal approval to enable transactions.');
|
|
107
136
|
}
|
|
137
|
+
if (this.internalMarketplaceAuthorizeWrite) {
|
|
138
|
+
this.internalMarketplaceAuthorizeWrite({ initialized: Boolean(this.identity()), identity: this.identity() ?? null,
|
|
139
|
+
settings: this.settings(), addresses: this.addresses(), mcpAccess: this.ledger.mcpAccess(), pool: this.ledger.pool() });
|
|
140
|
+
}
|
|
108
141
|
}
|
|
109
142
|
proposalWallet() {
|
|
110
143
|
return { directory: this.store.directory, walletFingerprint: this.identity()?.fingerprint ?? null, network: this.settings().network };
|
|
@@ -120,6 +153,7 @@ export class AttoApplication {
|
|
|
120
153
|
proposal: this.ledger.reviewProposal(id, this.proposalWallet()), directory: this.store.directory,
|
|
121
154
|
identity: this.identity() ?? null, network: this.settings().network,
|
|
122
155
|
policy: this.ledger.policy(), mcpAccess: this.ledger.mcpAccess(), pool: this.ledger.pool(),
|
|
156
|
+
messageSigningIndexes: this.ledger.messageSigningIndexes(),
|
|
123
157
|
}));
|
|
124
158
|
}
|
|
125
159
|
async approveLimitsProposal(id) {
|
|
@@ -340,122 +374,11 @@ export class AttoApplication {
|
|
|
340
374
|
result(transaction, status = 'published') {
|
|
341
375
|
return { status, hash: transaction.hash.toString(), transaction: publicModel(transaction) };
|
|
342
376
|
}
|
|
343
|
-
async pendingReceivable(address, hash) {
|
|
344
|
-
let found;
|
|
345
|
-
const controller = new AbortController();
|
|
346
|
-
const timer = setTimeout(() => controller.abort(), 2000);
|
|
347
|
-
try {
|
|
348
|
-
await this.reader().stream({ event: 'receivable', addresses: [address], minAmountRaw: '1' }, model => {
|
|
349
|
-
const receivable = model;
|
|
350
|
-
if (receivable.hash.toString().toUpperCase() === hash.toUpperCase()) {
|
|
351
|
-
found = receivable;
|
|
352
|
-
controller.abort();
|
|
353
|
-
}
|
|
354
|
-
}, controller.signal);
|
|
355
|
-
}
|
|
356
|
-
catch (error) {
|
|
357
|
-
if (!controller.signal.aborted)
|
|
358
|
-
throw error;
|
|
359
|
-
}
|
|
360
|
-
finally {
|
|
361
|
-
clearTimeout(timer);
|
|
362
|
-
}
|
|
363
|
-
if (!found && controller.signal.aborted) {
|
|
364
|
-
throw new AttoError('RECEIVABLE_LOOKUP_TIMEOUT', 'Checking the pending payment timed out. Retry receiving it; its absence has not been confirmed.');
|
|
365
|
-
}
|
|
366
|
-
return found;
|
|
367
|
-
}
|
|
368
|
-
async receive(request, automatic = false) {
|
|
369
|
-
if (automatic && !this.receivingAllowed())
|
|
370
|
-
throw new AttoError('AUTO_RECEIVE_DISABLED', 'Automatic receiving is stopping.');
|
|
371
|
-
const index = request.index ?? 0;
|
|
372
|
-
const operation = async () => {
|
|
373
|
-
await this.store.withWalletLock(async () => {
|
|
374
|
-
this.requireMcpWrite();
|
|
375
|
-
this.payments.requireAvailable(index);
|
|
376
|
-
});
|
|
377
|
-
if (automatic && !this.settings().autoReceive)
|
|
378
|
-
throw new AttoError('AUTO_RECEIVE_DISABLED', 'Automatic receiving is disabled.');
|
|
379
|
-
const address = this.address(index, automatic);
|
|
380
|
-
const hash = request.hash.toUpperCase();
|
|
381
|
-
const key = `receive.${this.settings().network}.${hash}`;
|
|
382
|
-
const prior = this.store.get(key);
|
|
383
|
-
if (prior && prior.index !== index)
|
|
384
|
-
throw new AttoError('WRONG_RECEIVER', 'This receivable belongs to a different address.');
|
|
385
|
-
if (prior?.result)
|
|
386
|
-
return prior.result;
|
|
387
|
-
if (prior) {
|
|
388
|
-
const transaction = await this.reader().transaction(prior.blockHash);
|
|
389
|
-
if (transaction && transaction.hash.toString() === prior.blockHash && await transaction.isValid()) {
|
|
390
|
-
const result = this.result(transaction, 'received');
|
|
391
|
-
this.store.set(key, { ...prior, result });
|
|
392
|
-
this.work.prepareConfirmed(transaction.block);
|
|
393
|
-
return result;
|
|
394
|
-
}
|
|
395
|
-
// Refresh pending state below: an unconsumed send permits retrying receive
|
|
396
|
-
// against the current frontier without risking a second debit.
|
|
397
|
-
}
|
|
398
|
-
const receivable = await this.pendingReceivable(address.address, hash);
|
|
399
|
-
if (!receivable)
|
|
400
|
-
throw new AttoError('RECEIVABLE_NOT_PENDING', 'The payment is not pending for this address; it may already have been received.');
|
|
401
|
-
if (receivable.receiverAddress.value !== address.address)
|
|
402
|
-
throw new AttoError('WRONG_RECEIVER', 'The payment belongs to a different address.');
|
|
403
|
-
if (automatic && BigInt(receivable.amount.toString()) < BigInt(this.settings().minReceiveRaw)) {
|
|
404
|
-
throw new AttoError('RECEIVABLE_BELOW_MINIMUM', 'The payment is below the current automatic receiving minimum.');
|
|
405
|
-
}
|
|
406
|
-
const seed = await this.seed();
|
|
407
|
-
let wallet;
|
|
408
|
-
try {
|
|
409
|
-
const execution = await signingWallet(seed, index, this.settings(), async (block) => {
|
|
410
|
-
await this.store.withWalletLock(async () => {
|
|
411
|
-
this.requireMcpWrite();
|
|
412
|
-
this.payments.requireAvailable(index);
|
|
413
|
-
if (automatic && !this.settings().autoReceive)
|
|
414
|
-
throw new AttoError('AUTO_RECEIVE_DISABLED', 'Automatic receiving is disabled.');
|
|
415
|
-
this.store.set(key, { hash, index, blockHash: block.hash.toString() });
|
|
416
|
-
});
|
|
417
|
-
}, this.work.worker());
|
|
418
|
-
wallet = execution.wallet;
|
|
419
|
-
const transaction = await wallet.receive(receivable, parseAddress(request.representative ?? this.settings().representative), null);
|
|
420
|
-
const result = { ...this.result(transaction, 'received'), index, amount: amountOutput(receivable.amount.toString()) };
|
|
421
|
-
this.store.set(key, { hash, index, blockHash: transaction.hash.toString(), result });
|
|
422
|
-
this.work.prepareConfirmed(transaction.block);
|
|
423
|
-
return result;
|
|
424
|
-
}
|
|
425
|
-
finally {
|
|
426
|
-
wallet?.close();
|
|
427
|
-
seed.value.fill(0);
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
if (!automatic)
|
|
431
|
-
return this.store.withAccountLocks([index], operation);
|
|
432
|
-
// A busy account must not stall receiving for the rest of the wallet or
|
|
433
|
-
// prevent this session from stopping. The receiver will retry this item.
|
|
434
|
-
const release = this.store.tryAccountLocks([index]);
|
|
435
|
-
if (!release)
|
|
436
|
-
throw new AttoError('WALLET_BUSY', 'This account is busy. Automatic receiving will retry it.');
|
|
437
|
-
try {
|
|
438
|
-
return await operation();
|
|
439
|
-
}
|
|
440
|
-
finally {
|
|
441
|
-
release();
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
async receiveAll(input) {
|
|
445
|
-
const index = input.index ?? 0;
|
|
446
|
-
const address = this.address(index).address;
|
|
447
|
-
const list = await this.reader().list({ event: 'receivable', addresses: [address], limit: input.limit ?? 100, timeoutMs: input.timeoutMs ?? 2000 });
|
|
448
|
-
const results = [];
|
|
449
|
-
for (const item of list.items) {
|
|
450
|
-
results.push(await this.receive({ index, hash: item.hash, representative: input.representative }));
|
|
451
|
-
}
|
|
452
|
-
return { results, timedOut: list.timedOut, ...(list.limitReached ? { limitReached: true } : {}) };
|
|
453
|
-
}
|
|
454
377
|
async changeRepresentative(index, representative) {
|
|
455
378
|
return this.store.withAccountLocks([index], async () => {
|
|
456
379
|
await this.store.withWalletLock(async () => {
|
|
457
380
|
this.requireMcpWrite();
|
|
458
|
-
this.
|
|
381
|
+
this.ledger.assertAccountAvailable(index);
|
|
459
382
|
});
|
|
460
383
|
this.address(index);
|
|
461
384
|
const seed = await this.seed();
|
|
@@ -464,7 +387,7 @@ export class AttoApplication {
|
|
|
464
387
|
const execution = await signingWallet(seed, index, this.settings(), async () => {
|
|
465
388
|
await this.store.withWalletLock(async () => {
|
|
466
389
|
this.requireMcpWrite();
|
|
467
|
-
this.
|
|
390
|
+
this.ledger.assertAccountAvailable(index);
|
|
468
391
|
});
|
|
469
392
|
}, this.work.worker());
|
|
470
393
|
wallet = execution.wallet;
|
|
@@ -498,7 +421,34 @@ export class AttoApplication {
|
|
|
498
421
|
const reader = this.reader();
|
|
499
422
|
switch (name) {
|
|
500
423
|
case 'doctor': return runDoctor({ directory: this.store.directory, access: this.mcp ? 'mcp' : undefined, signal: this.doctorAbort.signal, globalDirectory: args.globalDirectory });
|
|
501
|
-
case 'wallet_status': return { directory: this.store.directory, initialized: Boolean(this.identity()), identity: this.identity() ?? null, settings: this.settings(), addresses: this.addresses(), autoReceive: this.auto.status(), backgroundReceive: this.background.status(), mcpAccess: this.ledger.mcpAccess(), pool: this.ledger.pool(), pendingSends: this.ledger.pending().map(({ id, hash, status }) => ({ requestId: id, hash, status })), resetPending: Boolean(this.store.get(RESET_KEY)) };
|
|
424
|
+
case 'wallet_status': return { directory: this.store.directory, initialized: Boolean(this.identity()), identity: this.identity() ?? null, settings: this.settings(), effectiveNodeBatchSize: resolveNodeBatchSize(this.settings()), addresses: this.addresses(), autoReceive: this.auto.status(), backgroundReceive: this.background.status(), mcpAccess: this.ledger.mcpAccess(), pool: this.ledger.pool(), messageSigningIndexes: this.ledger.messageSigningIndexes(), pendingSends: this.ledger.pending().map(({ id, hash, status }) => ({ requestId: id, hash, status })), resetPending: Boolean(this.store.get(RESET_KEY)) };
|
|
425
|
+
case 'message_sign': return this.store.withWalletLock(async () => {
|
|
426
|
+
this.requireMcpWrite();
|
|
427
|
+
const index = args.index;
|
|
428
|
+
if (!this.ledger.messageSigningIndexes().includes(index)) {
|
|
429
|
+
throw new AttoError('SIGNING_NOT_APPROVED', 'This profile has not locally approved message signing for that account index.');
|
|
430
|
+
}
|
|
431
|
+
const saved = this.address(index);
|
|
432
|
+
const seed = await this.seed();
|
|
433
|
+
try {
|
|
434
|
+
const signer = await derivedSigner(seed, index);
|
|
435
|
+
if (signer.address.value !== saved.address || signer.publicKey.toString() !== saved.publicKey) {
|
|
436
|
+
throw new AttoError('WALLET_MISMATCH', 'The signing key does not match the saved account metadata.');
|
|
437
|
+
}
|
|
438
|
+
return { index, address: signer.address.value, publicKey: signer.publicKey.toString(),
|
|
439
|
+
signature: (await signer.signMessage(signedMessageBytes(args))).toString() };
|
|
440
|
+
}
|
|
441
|
+
finally {
|
|
442
|
+
seed.value.fill(0);
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
case 'message_verify': {
|
|
446
|
+
const publicKey = args.address !== undefined
|
|
447
|
+
? parseAddress(args.address).publicKey
|
|
448
|
+
: AttoPublicKey.Companion.parse(args.publicKey);
|
|
449
|
+
const signature = AttoSignature.Companion.parse(args.signature);
|
|
450
|
+
return { valid: await signature.isValidMessage(publicKey, signedMessageBytes(args)) };
|
|
451
|
+
}
|
|
502
452
|
case 'wallet_configure': return this.configure(args);
|
|
503
453
|
case 'address_list': return { addresses: this.addresses() };
|
|
504
454
|
case 'address_add': return this.store.withWalletLock(async () => {
|
|
@@ -537,10 +487,17 @@ export class AttoApplication {
|
|
|
537
487
|
await this.labels.global.refresh(args.refresh);
|
|
538
488
|
return this.labels.list(this.settings().network, args.all, args.search);
|
|
539
489
|
}
|
|
540
|
-
case 'account_get':
|
|
490
|
+
case 'account_get': {
|
|
491
|
+
if (args.addresses !== undefined) {
|
|
492
|
+
const addresses = this.selectedAddresses(args);
|
|
493
|
+
const accounts = await reader.accounts(addresses);
|
|
494
|
+
return { accounts: addresses.map((address, i) => ({ address, account: publicModel(accounts[i]) })) };
|
|
495
|
+
}
|
|
496
|
+
return { account: publicModel(await reader.account(args.address ?? this.address(args.index).address)) };
|
|
497
|
+
}
|
|
541
498
|
case 'balances_get': {
|
|
542
499
|
const addresses = this.selectedAddresses(args);
|
|
543
|
-
const accounts = await
|
|
500
|
+
const accounts = await reader.accounts(addresses);
|
|
544
501
|
const raw = accounts.reduce((sum, account) => sum + BigInt(account?.balance.toString() ?? '0'), 0n).toString();
|
|
545
502
|
return { balances: addresses.map((address, i) => {
|
|
546
503
|
const saved = this.addresses().find(value => value.address === address);
|
|
@@ -565,8 +522,20 @@ export class AttoApplication {
|
|
|
565
522
|
case 'send': return this.payments.send({ ...args,
|
|
566
523
|
destination: args.destinationIndex !== undefined ? this.address(args.destinationIndex).address : args.destination,
|
|
567
524
|
});
|
|
568
|
-
case '
|
|
569
|
-
case '
|
|
525
|
+
case 'marketplace_topup': return this.payments.marketplaceTopUp(args);
|
|
526
|
+
case 'marketplace_topup_status': return this.payments.marketplaceTopUpStatus(args.requestId);
|
|
527
|
+
case 'marketplace_pay_intent': {
|
|
528
|
+
if (!this.internalMarketplacePayment)
|
|
529
|
+
throw new AttoError('INTERNAL_ONLY', 'This operation is available only to the configured private Marketplace wallet child.');
|
|
530
|
+
return this.payments.marketplacePayIntent(args);
|
|
531
|
+
}
|
|
532
|
+
case 'marketplace_pay_intent_status': {
|
|
533
|
+
if (!this.internalMarketplacePayment)
|
|
534
|
+
throw new AttoError('INTERNAL_ONLY', 'This operation is available only to the configured private Marketplace wallet child.');
|
|
535
|
+
return this.payments.marketplacePayIntentStatus(args.requestId);
|
|
536
|
+
}
|
|
537
|
+
case 'receive': return this.receiver.receive(args);
|
|
538
|
+
case 'receive_all': return this.receiver.receiveAll(args);
|
|
570
539
|
case 'representative_change': return this.changeRepresentative(args.index, args.representative);
|
|
571
540
|
case 'limits_get':
|
|
572
541
|
await this.payments.reconcile();
|
|
@@ -579,7 +548,12 @@ export class AttoApplication {
|
|
|
579
548
|
throw new AttoError('JOURNAL_NOT_FOUND', 'This payment request is not in the local journal.');
|
|
580
549
|
return { record };
|
|
581
550
|
}
|
|
582
|
-
case 'limits_propose': return this.store.withWalletLock(async () =>
|
|
551
|
+
case 'limits_propose': return this.store.withWalletLock(async () => {
|
|
552
|
+
const current = { access: this.ledger.mcpAccess(), policy: this.ledger.policy(), pool: this.ledger.pool(),
|
|
553
|
+
messageSigningIndexes: this.ledger.messageSigningIndexes() };
|
|
554
|
+
const proposal = this.ledger.proposePolicy(args.policy, args.access, this.proposalWallet(), args.pool, args.messageSigningIndexes);
|
|
555
|
+
return { proposal, approval: approvalInstructions(proposal, current) };
|
|
556
|
+
});
|
|
583
557
|
case 'metrics_get': return this.market.metrics();
|
|
584
558
|
case 'price_quote': return this.market.quoteUsd(args.amount);
|
|
585
559
|
case 'terms_get': return { ...marketTerms, accepted: this.store.get('market.terms')?.version === marketTerms.version };
|
|
@@ -614,11 +588,13 @@ export class AttoApplication {
|
|
|
614
588
|
else
|
|
615
589
|
this.requireReady();
|
|
616
590
|
const args = parseOperation(name, input);
|
|
617
|
-
if (!
|
|
591
|
+
if (!operationFor(name).readOnly && name !== 'limits_propose' && !['labels_set', 'labels_remove'].includes(name) && !name.startsWith('watch_'))
|
|
618
592
|
this.requireMcpWrite();
|
|
619
593
|
const call = (async () => {
|
|
620
594
|
const result = await this.invoke(name, args);
|
|
621
|
-
if (name === '
|
|
595
|
+
if (this.internalMarketplaceReceiveSafety && name === 'receive' && result?.status === 'unknown')
|
|
596
|
+
return result;
|
|
597
|
+
if (name === 'doctor' || ['labels_get', 'labels_list', 'message_sign', 'message_verify', 'marketplace_pay_intent', 'marketplace_pay_intent_status'].includes(name))
|
|
622
598
|
return result;
|
|
623
599
|
if (this.settings().network === 'LIVE' && ['address_list', 'account_get', 'balances_get', 'transaction_get', 'entry_get', 'representative_weight', 'history_list', 'receivables_list'].includes(name))
|
|
624
600
|
await this.labels.global.refresh();
|
|
@@ -632,6 +608,47 @@ export class AttoApplication {
|
|
|
632
608
|
this.calls.delete(call);
|
|
633
609
|
}
|
|
634
610
|
}
|
|
611
|
+
/** Terminal-only Marketplace controller connection; session tokens remain in memory. */
|
|
612
|
+
async connectMarketplace(input) {
|
|
613
|
+
this.requireReady();
|
|
614
|
+
const connection = await this.store.withWalletLock(() => this.topUps.connect(input));
|
|
615
|
+
return { connected: true, apiUrl: connection.apiUrl, audience: connection.audience,
|
|
616
|
+
controllerIndex: connection.controllerIndex, accountId: connection.accountId, identityId: connection.identityId,
|
|
617
|
+
...(connection.browserOrigins ? { browserOrigins: connection.browserOrigins } : {}) };
|
|
618
|
+
}
|
|
619
|
+
inspectMarketplaceProofApproval(input) {
|
|
620
|
+
this.requireReady();
|
|
621
|
+
return this.topUps.inspectProofApproval(input);
|
|
622
|
+
}
|
|
623
|
+
async approveMarketplaceProof(input) {
|
|
624
|
+
this.requireReady();
|
|
625
|
+
return this.store.withWalletLock(() => this.topUps.signProofApproval(input));
|
|
626
|
+
}
|
|
627
|
+
/** Private Marketplace terminal signing: no standalone connection is read or changed. */
|
|
628
|
+
async approveMarketplaceOwnedProof(input) {
|
|
629
|
+
this.requireReady();
|
|
630
|
+
if (this.mcp || !process.stdin.isTTY || !process.stderr.isTTY) {
|
|
631
|
+
throw new AttoError('LOCAL_APPROVAL_REQUIRED', 'Approve Marketplace controller actions in the local terminal.');
|
|
632
|
+
}
|
|
633
|
+
return this.store.withWalletLock(async () => {
|
|
634
|
+
const request = validateMarketplaceUserProofApproval(input, { network: 'ATTO', nativeNetwork: 'live' });
|
|
635
|
+
if (this.addresses().find(address => address.index === request.controller.index)?.address !== request.controller.address) {
|
|
636
|
+
throw new AttoError('WALLET_MISMATCH', 'The Marketplace controller does not match this selected wallet and index.');
|
|
637
|
+
}
|
|
638
|
+
const seed = await this.seed();
|
|
639
|
+
try {
|
|
640
|
+
const signer = await derivedSigner(seed, request.controller.index);
|
|
641
|
+
if (signer.address.value !== request.controller.address)
|
|
642
|
+
throw new AttoError('WALLET_MISMATCH', 'The selected controller key changed.');
|
|
643
|
+
validateMarketplaceUserProofApproval(input, { network: 'ATTO', nativeNetwork: 'live' });
|
|
644
|
+
const signature = (await signer.signMessage(new Int8Array(Buffer.from(request.challenge.message, 'utf8')))).toString();
|
|
645
|
+
return createMarketplaceProofApprovalResponse(request, signature);
|
|
646
|
+
}
|
|
647
|
+
finally {
|
|
648
|
+
seed.value.fill(0);
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
}
|
|
635
652
|
// The receiver observes current MCP access on every snapshot, and receive()
|
|
636
653
|
// rechecks it under the wallet lock before signing any queued payment.
|
|
637
654
|
async start() {
|
|
@@ -4,6 +4,9 @@ export interface Operation {
|
|
|
4
4
|
description: string;
|
|
5
5
|
schema: z.ZodObject;
|
|
6
6
|
readOnly: boolean;
|
|
7
|
+
internalOnly?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export declare const operations: readonly Operation[];
|
|
10
|
+
export declare const internalOperations: readonly Operation[];
|
|
11
|
+
export declare function operationFor(name: string): Operation | undefined;
|
|
9
12
|
export declare function parseOperation(name: string, input?: unknown): Record<string, unknown>;
|
|
@@ -3,6 +3,7 @@ import { z } from 'zod';
|
|
|
3
3
|
import { AttoError } from '../domain/errors.js';
|
|
4
4
|
import { paymentMetadataSchema } from '../spending/journal.js';
|
|
5
5
|
const index = z.number().int().min(0).max(2_147_483_647);
|
|
6
|
+
const signingIndexes = z.array(index).max(100).refine(indexes => new Set(indexes).size === indexes.length, 'Message-signing indexes must be unique.');
|
|
6
7
|
const address = z.string().min(1).max(128).describe('Atto address.');
|
|
7
8
|
const addresses = z.array(address).min(1).max(100);
|
|
8
9
|
const hash = z.string().regex(/^[a-fA-F0-9]{64}$/).describe('64-character hexadecimal transaction hash.');
|
|
@@ -17,6 +18,16 @@ const endpoint = z.url().max(2048).refine(value => {
|
|
|
17
18
|
return ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password && !url.search && !url.hash;
|
|
18
19
|
}, 'Use an HTTP(S) endpoint without credentials, query parameters, or fragments.');
|
|
19
20
|
const amount = z.strictObject({ amount: decimal, unit });
|
|
21
|
+
const signedMessageInput = z.object({
|
|
22
|
+
message: z.string().refine(value => Buffer.byteLength(value, 'utf8') <= 65_536, 'Message UTF-8 bytes must not exceed 65536.').optional(),
|
|
23
|
+
messageHex: z.string().max(131_072).regex(/^(?:[a-fA-F0-9]{2})*$/, 'Message hex must contain complete bytes.').optional(),
|
|
24
|
+
}).strict().refine(value => (value.message !== undefined) !== (value.messageHex !== undefined), 'Supply exactly one of message or messageHex.');
|
|
25
|
+
const signingMessage = signedMessageInput.extend({ index });
|
|
26
|
+
const verificationMessage = signedMessageInput.extend({
|
|
27
|
+
address: address.optional(),
|
|
28
|
+
publicKey: z.string().regex(/^[a-fA-F0-9]{64}$/).optional(),
|
|
29
|
+
signature: z.string().regex(/^[a-fA-F0-9]{128}$/),
|
|
30
|
+
}).refine(value => (value.address !== undefined) !== (value.publicKey !== undefined), 'Supply exactly one of address or publicKey.');
|
|
20
31
|
const policy = z.strictObject({
|
|
21
32
|
perRequest: amount.nullable(),
|
|
22
33
|
rolling: z.array(amount.extend({ days: z.number().int().positive().max(36_500) })).max(100),
|
|
@@ -42,7 +53,9 @@ function singleSelection(value) {
|
|
|
42
53
|
export const operations = [
|
|
43
54
|
{ name: 'doctor', description: 'Diagnose this process environment, profile, keyring credential access, node APIs and streaming, worker proof of work, and wallet readiness. Full checks can take up to 60 seconds and may trigger an OS keyring prompt. Returns structured checks and actionable remediation, never recovery material. Does not repair settings, grant access, sign, publish, receive, or modify wallet state. Available in read-only sessions. Rerun after an authorized repair; client environment changes require restarting the MCP connection.', schema: z.strictObject({ globalDirectory: z.boolean().optional() }), readOnly: true },
|
|
44
55
|
{ name: 'wallet_status', description: 'Read public wallet configuration, readiness, network, and auto-receive status. Never returns recovery material.', schema: z.strictObject({}), readOnly: true },
|
|
45
|
-
{ name: '
|
|
56
|
+
{ name: 'message_sign', description: 'Sign exact message bytes using the ATTO Signed Message v1 framing. Requires an existing address index granted by a locally approved messageSigningIndexes setting and normal MCP spend access. Handles any challenge like a credential: do not sign untrusted requests. Input is exact UTF-8 text or even-length hex (including empty bytes), capped at 64 KiB.', schema: signingMessage, readOnly: false },
|
|
57
|
+
{ name: 'message_verify', description: 'Verify an ATTO Signed Message v1 signature over exact UTF-8 text or hex bytes using an Atto address or public key. Public data only; never reads wallet credentials. Input is capped at 64 KiB.', schema: verificationMessage, readOnly: true },
|
|
58
|
+
{ name: 'wallet_configure', description: 'Update the supplied wallet settings, preserving omitted settings. nodeBatchSize overrides the accounts/ranges per node request (1-1000); null selects automatic defaults: 5 for official Atto gatekeeper URLs, 1000 for custom nodes. Custom gateways can explicitly select 5. Representative is the default for opening accounts; use representative_change for an existing account. Changes apply to this shared wallet.', schema: z.strictObject({ network: z.enum(['LIVE', 'BETA', 'DEV', 'LOCAL']).optional(), nodeUrl: endpoint.optional(), nodeBatchSize: z.number().int().min(1).max(1000).nullable().optional(), workerUrl: endpoint.optional(), representative: address.optional(), autoReceive: z.boolean().optional(), minReceiveRaw: integer.optional() }).refine(value => Object.values(value).some(value => value !== undefined), 'Supply at least one setting.'), readOnly: false },
|
|
46
59
|
{ name: 'address_add', description: 'Add and activate the next wallet address after the highest saved index. Includes it in default balances and automatic receiving. Does not open an account on the network. Each call adds a different address.', schema: z.strictObject({}), readOnly: false },
|
|
47
60
|
{ name: 'address_derive', description: 'Derive an address at a mnemonic key index and save its public metadata. Does not open an account on the network.', schema: z.strictObject({ index: index.default(0) }), readOnly: false },
|
|
48
61
|
{ name: 'address_list', description: 'List previously derived addresses and which are active for balances and automatic receiving.', schema: z.strictObject({}), readOnly: true },
|
|
@@ -52,14 +65,16 @@ export const operations = [
|
|
|
52
65
|
{ name: 'labels_remove', description: 'Remove a personal label for an address or existing wallet index. Idempotent; available without spending approval. Existing payment request destinations remain pinned.', schema: z.strictObject(labelTarget).refine(oneLabelTarget, 'Choose exactly one address or index.'), readOnly: false },
|
|
53
66
|
{ name: 'labels_get', description: 'Show personal and informational global address/voter labels for one address or saved index. refresh bypasses the global cache backoff. Sources and payout relationships remain distinct.', schema: z.strictObject({ ...labelTarget, refresh: z.boolean().optional() }).refine(oneLabelTarget, 'Choose exactly one address or index.'), readOnly: true },
|
|
54
67
|
{ name: 'labels_list', description: 'List personal labels; all includes LIVE global address and voter names. Search addresses, names, and entities case-insensitively. refresh forces a global refresh. Global names cannot resolve payments.', schema: z.strictObject({ all: z.boolean().optional(), search: z.string().max(4096).optional(), refresh: z.boolean().optional() }), readOnly: true },
|
|
55
|
-
{ name: 'account_get', description: 'Read
|
|
68
|
+
{ name: 'account_get', description: 'Read full account snapshots, including height, balance and representative. Use addresses for up to 100 external or wallet accounts in one call. Node requests use nodeBatchSize: automatically 5 for official Atto gateways or 1000 for custom nodes. Bulk results preserve address order and include account: null for unopened accounts. Use address or index for one account; defaults to index zero.', schema: z.strictObject({ address: address.optional(), index: index.optional(), addresses: addresses.optional() }).refine(value => [value.address !== undefined, value.index !== undefined, value.addresses !== undefined].filter(Boolean).length <= 1, 'Choose an address, an index, or addresses.'), readOnly: true },
|
|
56
69
|
{ name: 'balances_get', description: 'Read individual and aggregate balances. Defaults to active wallet addresses. Select one saved index, explicit addresses (including foreign addresses), or all saved addresses with all=true.', schema: z.strictObject({ ...accountFields, all: z.boolean().optional() }).refine(singleSelection, 'Choose one account selection.'), readOnly: true },
|
|
57
|
-
{ name: 'transaction_get', description: 'Read
|
|
58
|
-
{ name: 'entry_get', description: 'Read an account entry by transaction hash.', schema: z.strictObject({ hash }), readOnly: true },
|
|
70
|
+
{ name: 'transaction_get', description: 'Read the raw signed protocol transaction by hash, including block, signature and work. Use entry_get for action history; transactions are needed for protocol fields such as a receive block\'s sendHash.', schema: z.strictObject({ hash }), readOnly: true },
|
|
71
|
+
{ name: 'entry_get', description: 'Read an action-oriented account entry by transaction hash. address is the account owner; subjectAddress and subjectRole identify the receiver for SEND, sender for OPEN/RECEIVE, or new representative for CHANGE. Transfers include exact amount.raw and amount.atto; representative changes do not transfer funds.', schema: z.strictObject({ hash }), readOnly: true },
|
|
59
72
|
{ name: 'representative_weight', description: 'Read a representative address voting weight.', schema: z.strictObject({ address }), readOnly: true },
|
|
60
|
-
{ name: 'history_list', description: 'Read
|
|
73
|
+
{ name: 'history_list', description: 'Read action-oriented entries by default; use event=transaction for raw signed protocol records and receive sendHash linkage. Entries expose owner address, subjectAddress, subjectRole and exact transfer amount. Supply up to 100 addresses together for batched reads, or index for one saved account; defaults to active accounts. Results follow address order and ascending height. Limit is at most 1000 records. Reuse nextCursor with the same filters to continue frozen account heights without rescanning earlier pages; timedOut may return a partial page.', schema: z.strictObject({ event: z.enum(['transaction', 'entry']).default('entry'), ...accountFields, fromHeight: integer.optional(), toHeight: integer.optional(), ...listFields }).refine(singleSelection, 'Choose an index or addresses.'), readOnly: true },
|
|
61
74
|
{ name: 'receivables_list', description: 'Scan pending incoming payments, defaulting to active wallet addresses. Select a saved index or explicit addresses, including foreign accounts. This is a bounded scan, without continuation cursors; timedOut means the scan window ended and more payments may exist.', schema: z.strictObject({ ...accountFields, minAmountRaw: integer.optional(), limit: limit.optional(), timeoutMs: timeoutMs.optional() }).refine(singleSelection, 'Choose an index or addresses.'), readOnly: true },
|
|
62
75
|
{ name: 'send', description: 'Send funds to exactly one destination address, saved destinationIndex, or personal destinationLabel, subject to shared spending limits. Omit index to select an account from the approved pool. Explicit MCP indexes must belong to that pool and hold the full amount. Approved consolidation may combine pool funds only when index is omitted. Metadata is optional local journal data (up to 4096 UTF-8 bytes) and is never published on the network. USD uses an indicative price and requires accepted terms. Reuse requestId for retries; the original account, metadata, and USD conversion are preserved. Omit metadata to retain it; changed metadata is rejected.', schema: z.strictObject({ index: index.optional(), destination: address.optional(), destinationLabel: personalNameSchema.optional().describe('Exact personal name; global-only names fail locally. The original label and resolved address are pinned per request ID before network access.'), destinationIndex: index.optional().describe('Existing saved destination account index, instead of destination.'), amount: decimal, unit: z.enum(['ATTO', 'RAW', 'USD']).default('ATTO'), requestId: z.string().min(1).max(128), metadata: paymentMetadataSchema.optional() }).refine(value => [value.destination, value.destinationIndex, value.destinationLabel].filter(value => value !== undefined).length === 1, 'Choose exactly one destination address, destination index, or personal label.'), readOnly: false },
|
|
76
|
+
{ name: 'marketplace_topup', description: 'Fund only the configured Marketplace ATTO account using a bounded native x402 exact payment. Uses this wallet’s approved spend policy and pool; no tasks or hiring actions are available. Reuse requestId to recover the same intent and exact signed payment after uncertainty. Amount is an exact ATTO or RAW decimal string.', schema: z.strictObject({ amount: decimal, unit: unit.default('ATTO'), requestId: z.string().min(1).max(128), index: index.optional() }), readOnly: false },
|
|
77
|
+
{ name: 'marketplace_topup_status', description: 'Read the current Marketplace account top-up status by its original requestId and reconcile the same native payment. Does not create or replace a payment.', schema: z.strictObject({ requestId: z.string().min(1).max(128) }), readOnly: true },
|
|
63
78
|
{ name: 'pool_get', description: 'Read the approved send pool, its account balances, and readiness for payments. Does not reserve an account or move funds.', schema: z.strictObject({}), readOnly: true },
|
|
64
79
|
{ name: 'journal_list', description: 'List local payment journal records, newest first, with an optional status filter. Includes caller metadata and recorded payment progress; metadata is not an authenticated statement from the network.', schema: z.strictObject({ limit: z.number().int().min(1).max(100).default(50), cursor: cursor.optional(), status: z.enum(['reserved', 'signed', 'published', 'unknown', 'failed']).optional() }), readOnly: true },
|
|
65
80
|
{ name: 'journal_get', description: 'Read a local payment journal record by its request ID, including caller metadata and recorded payment progress.', schema: z.strictObject({ requestId: z.string().min(1).max(128) }), readOnly: true },
|
|
@@ -70,15 +85,22 @@ export const operations = [
|
|
|
70
85
|
{ name: 'receive', description: 'Receive one pending payment by hash, opening the account if needed.', schema: z.strictObject({ index: index.default(0), hash, representative: address.optional() }), readOnly: false },
|
|
71
86
|
{ name: 'receive_all', description: 'Receive a bounded set of pending payments for a key index, opening the account if needed.', schema: z.strictObject({ index: index.default(0), limit: limit.default(100), timeoutMs: timeoutMs.default(2000), representative: address.optional() }), readOnly: false },
|
|
72
87
|
{ name: 'representative_change', description: 'Publish a representative change for an existing account. Selecting its current representative returns REPRESENTATIVE_UNCHANGED without publishing.', schema: z.strictObject({ index: index.default(0), representative: address }), readOnly: false },
|
|
73
|
-
{ name: 'limits_get', description: 'Read spending policy, approved send pool, MCP access, proposal status, historical usage, reservations, and remaining allowances.', schema: z.strictObject({}), readOnly: true },
|
|
74
|
-
{ name: 'limits_propose', description: 'Propose spending limits, MCP access,
|
|
88
|
+
{ name: 'limits_get', description: 'Read spending policy, approved send pool, MCP access, message-signing indexes, proposal status, historical usage, reservations, and remaining allowances.', schema: z.strictObject({}), readOnly: true },
|
|
89
|
+
{ name: 'limits_propose', description: 'Propose spending limits, MCP access, send-pool settings, and message-signing indexes for local terminal approval. Omitted pool and messageSigningIndexes preserve their current settings. Does not change active settings or grant access. A new proposal replaces the previous proposal and expires after 24 hours. Read limits_get for active settings and proposal status. Returns proposal plus approval.changes (changed access, policy, pool, and messageSigningIndexes with from/to values), approval.shell, and profile-specific approval.commands.atto/npx for the user to run in a local terminal. Preserve the returned directory and proposal ID; never run approval commands on the user\'s behalf. Spending access, amount limits, source-pool approval, and message-signing grants are separate. Amounts are ATTO or RAW; null perRequest with empty rolling means unlimited spending, not missing authorization.', schema: z.strictObject({ policy, access: z.enum(['read-only', 'spend']).default('spend'), pool: pool.optional(), messageSigningIndexes: signingIndexes.optional() }), readOnly: false },
|
|
75
90
|
{ name: 'watch_start', description: 'Start an observational, reconnecting watch for this session, defaulting to active wallet addresses. Choose one saved index, explicit addresses (including foreign accounts), a transaction/entry hash, or networkWide=true. Network-wide receivables are unsupported. Read buffered events and connection status with watch_read. Does not enable automatic receiving.', schema: z.strictObject({ event: z.enum(['account', 'transaction', 'entry', 'receivable']), ...streamFields, index: index.optional(), networkWide: z.boolean().optional() }).refine(singleSelection, 'Choose one watch selection.').refine(value => !(value.networkWide && value.event === 'receivable'), 'Receivable watches require addresses.'), readOnly: false },
|
|
76
91
|
{ name: 'watch_list', description: 'List watches owned by this process.', schema: z.strictObject({}), readOnly: true },
|
|
77
92
|
{ name: 'watch_read', description: 'Read buffered events after an optional numeric cursor. Gaps are reported if bounded event retention was exceeded.', schema: z.strictObject({ id: z.string().min(1).max(128), cursor: z.number().int().nonnegative().optional(), limit: limit.optional() }), readOnly: true },
|
|
78
93
|
{ name: 'watch_stop', description: 'Stop a watch owned by this process and cancel its network subscription.', schema: z.strictObject({ id: z.string().min(1).max(128) }), readOnly: false },
|
|
79
94
|
];
|
|
95
|
+
export const internalOperations = [
|
|
96
|
+
{ name: 'marketplace_pay_intent', description: 'Private Marketplace-child operation. Sign one existing exact ATTO x402 intent supplied by the configured Marketplace process. Requires the matching locally configured API origin/audience/network and approved wallet spend access and pool. Persists the exact challenge and signature for same-request recovery. Never creates an intent or submits the payment.', schema: z.strictObject({ requestId: z.string().regex(/^[A-Za-z0-9_-]{16,128}$/), intentId: z.string().uuid(), amountAtomic: integer, paymentIdentifier: z.string().regex(/^[A-Za-z0-9_-]{16,128}$/), paymentRequired: z.string().min(1).max(90_000), apiUrl: z.string().min(1).max(2048), audience: z.string().min(1).max(255), resourceUrl: z.string().min(1).max(2048), expiresAt: z.string().min(1).max(128), index: index.optional() }), readOnly: false, internalOnly: true },
|
|
97
|
+
{ name: 'marketplace_pay_intent_status', description: 'Private Marketplace-child operation. Reconcile the saved block against the configured native chain and return its binding. Recover the exact saved signature while unresolved or published; native rejection returns terminal FAILED without a signature. Never re-sign or replace the saved challenge.', schema: z.strictObject({ requestId: z.string().regex(/^[A-Za-z0-9_-]{16,128}$/) }), readOnly: true, internalOnly: true },
|
|
98
|
+
];
|
|
99
|
+
export function operationFor(name) {
|
|
100
|
+
return [...operations, ...internalOperations].find(operation => operation.name === name);
|
|
101
|
+
}
|
|
80
102
|
export function parseOperation(name, input = {}) {
|
|
81
|
-
const operation =
|
|
103
|
+
const operation = operationFor(name);
|
|
82
104
|
if (!operation)
|
|
83
105
|
throw new AttoError('UNKNOWN_OPERATION', 'Unknown Atto operation.');
|
|
84
106
|
const parsed = operation.schema.safeParse(input);
|
package/dist/cli/cli.d.ts
CHANGED