@attocash/cli 0.5.0 → 0.7.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/dist/application/app.d.ts +3 -1
- package/dist/application/app.js +23 -19
- package/dist/application/operations.d.ts +0 -1
- package/dist/application/operations.js +1 -7
- package/dist/cli/cli.js +4 -21
- package/dist/internal-marketplace.d.ts +2 -11
- package/dist/internal-marketplace.js +6 -13
- package/dist/marketplace/approval-preview.js +5 -20
- package/dist/marketplace/connection.d.ts +43 -0
- package/dist/marketplace/{topups.js → connection.js} +18 -213
- package/dist/marketplace/proof-approval.d.ts +1 -1
- package/dist/marketplace/proof-approval.js +10 -119
- package/dist/marketplace/relay.d.ts +58 -0
- package/dist/marketplace/relay.js +122 -0
- package/dist/marketplace/strict-json.d.ts +2 -0
- package/dist/marketplace/strict-json.js +96 -0
- package/dist/spending/atto-x402.d.ts +2 -0
- package/dist/spending/atto-x402.js +1 -1
- package/dist/spending/journal.d.ts +9 -0
- package/dist/spending/journal.js +11 -0
- package/dist/spending/ledger.d.ts +11 -3
- package/dist/spending/ledger.js +42 -7
- package/dist/spending/payments.d.ts +9 -36
- package/dist/spending/payments.js +253 -817
- package/dist/wallet/signing.d.ts +3 -1
- package/dist/wallet/signing.js +25 -17
- package/package.json +1 -1
- package/dist/marketplace/topups.d.ts +0 -82
package/dist/wallet/signing.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ import type { WalletSettings } from './types.js';
|
|
|
4
4
|
import type { BlockWorker } from './work.js';
|
|
5
5
|
export declare function mnemonicSeed(phrase: string): Promise<AttoSeed>;
|
|
6
6
|
export declare function derivedSigner(seed: AttoSeed, index: number): Promise<AttoSigner>;
|
|
7
|
-
|
|
7
|
+
/** Publish an already validated candidate without rebuilding, signing or requesting work. */
|
|
8
|
+
export declare function publishTransaction(transaction: AttoTransaction, settings: WalletSettings, beforePublish: () => void | Promise<void>, retry?: SendRetry): Promise<void>;
|
|
9
|
+
export declare function signingWallet(seed: AttoSeed, index: number, settings: WalletSettings, beforeSign: (block: AttoBlock) => void | Promise<void>, suppliedWorker?: BlockWorker, retry?: SendRetry, beforePublish?: (transaction: AttoTransaction) => void | Promise<void>): Promise<{
|
|
8
10
|
wallet: {
|
|
9
11
|
sendByIndex(value: AttoKeyIndex, destination: AttoAddress, amount: AttoAmount, timestamp?: AttoInstant | null): Promise<AttoTransaction>;
|
|
10
12
|
prepareSendByIndex(value: AttoKeyIndex, destination: AttoAddress, amount: AttoAmount, timestamp?: AttoInstant | null): Promise<AttoTransaction>;
|
package/dist/wallet/signing.js
CHANGED
|
@@ -24,7 +24,28 @@ export async function derivedSigner(seed, index) {
|
|
|
24
24
|
}
|
|
25
25
|
return privateKeyToSigner(await seed.toPrivateKey(toAttoIndex(index)));
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
/** Publish an already validated candidate without rebuilding, signing or requesting work. */
|
|
28
|
+
export async function publishTransaction(transaction, settings, beforePublish, retry) {
|
|
29
|
+
const client = new AttoNodeClientAsyncBuilder(settings.nodeUrl).build();
|
|
30
|
+
let attempted = false;
|
|
31
|
+
await retryNetwork(async () => {
|
|
32
|
+
if (attempted) {
|
|
33
|
+
const confirmed = await new NodeReader(settings).transaction(transaction.hash.toString(), retry?.signal);
|
|
34
|
+
if (confirmed) {
|
|
35
|
+
if (confirmed.hash.toString() !== transaction.hash.toString() || !await confirmed.isValid()) {
|
|
36
|
+
throw new AttoError('INVALID_NODE_RESPONSE', 'The node returned a different or invalid transaction.');
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
await beforePublish();
|
|
42
|
+
if (retry?.signal.aborted)
|
|
43
|
+
throw new AttoError('CANCELLED', 'Send cancelled.');
|
|
44
|
+
attempted = true;
|
|
45
|
+
await client.publish(transaction);
|
|
46
|
+
}, retry);
|
|
47
|
+
}
|
|
48
|
+
export async function signingWallet(seed, index, settings, beforeSign, suppliedWorker, retry, beforePublish) {
|
|
28
49
|
const client = new AttoNodeClientAsyncBuilder(settings.nodeUrl).build();
|
|
29
50
|
const worker = suppliedWorker ?? new AttoWorkerAsyncBuilder(settings.workerUrl).cached(false).timeoutSeconds(60n).build();
|
|
30
51
|
let signer = await derivedSigner(seed, index);
|
|
@@ -83,25 +104,12 @@ export async function signingWallet(seed, index, settings, beforeSign, suppliedW
|
|
|
83
104
|
async function perform(build, timestamp) {
|
|
84
105
|
return serialized(async () => {
|
|
85
106
|
const { update, block, transaction } = await prepareTransaction(build, timestamp);
|
|
86
|
-
|
|
87
|
-
await
|
|
88
|
-
|
|
89
|
-
const confirmed = await new NodeReader(settings).transaction(transaction.hash.toString(), retry?.signal);
|
|
90
|
-
if (confirmed) {
|
|
91
|
-
if (confirmed.hash.toString() !== transaction.hash.toString() || !await confirmed.isValid()) {
|
|
92
|
-
throw new AttoError('INVALID_NODE_RESPONSE', 'The node returned a different or invalid transaction.');
|
|
93
|
-
}
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
107
|
+
// The payment owner must durably retain the complete candidate before HTTP.
|
|
108
|
+
await beforePublish?.(transaction);
|
|
109
|
+
await publishTransaction(transaction, settings, async () => {
|
|
97
110
|
// Approval may have changed while waiting for work or during backoff.
|
|
98
|
-
// Recheck that the journal still permits this exact block.
|
|
99
111
|
if (retry)
|
|
100
112
|
await beforeSign(block);
|
|
101
|
-
if (retry?.signal.aborted)
|
|
102
|
-
throw new AttoError('CANCELLED', 'Send cancelled.');
|
|
103
|
-
attempted = true;
|
|
104
|
-
await client.publish(transaction);
|
|
105
113
|
}, retry);
|
|
106
114
|
account = update.account;
|
|
107
115
|
return transaction;
|
package/package.json
CHANGED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { WalletAddress, WalletSettings } from '../wallet/types.js';
|
|
2
|
-
import type { StateStore } from '../storage/state.js';
|
|
3
|
-
import type { AttoSeed } from '@attocash/commons-core';
|
|
4
|
-
import { type AttoExactRequirement } from '../spending/atto-x402.js';
|
|
5
|
-
import { type MarketplaceProofApprovalResponse } from './proof-approval.js';
|
|
6
|
-
export interface MarketplaceConnection {
|
|
7
|
-
version: 1;
|
|
8
|
-
apiUrl: string;
|
|
9
|
-
audience: string;
|
|
10
|
-
controllerIndex: number;
|
|
11
|
-
controllerAddress: string;
|
|
12
|
-
accountId: string;
|
|
13
|
-
agentId: string;
|
|
14
|
-
identityId: string;
|
|
15
|
-
walletFingerprint: string;
|
|
16
|
-
browserOrigins?: string[];
|
|
17
|
-
}
|
|
18
|
-
export interface MarketplaceTopUpStatus {
|
|
19
|
-
intentId: string;
|
|
20
|
-
asset: string;
|
|
21
|
-
network: string;
|
|
22
|
-
amountAtomic: string;
|
|
23
|
-
state: 'PENDING' | 'ACCEPTED' | 'SETTLED' | 'REJECTED';
|
|
24
|
-
expiresAt: string;
|
|
25
|
-
sendHash: string | null;
|
|
26
|
-
payer: string | null;
|
|
27
|
-
paymentState: 'PENDING' | 'ACCEPTED' | 'SETTLED' | 'REJECTED' | null;
|
|
28
|
-
receivePending: boolean | null;
|
|
29
|
-
discrepancy: string | null;
|
|
30
|
-
receiveStatus: 'PENDING' | 'ACCEPTED' | 'SETTLED' | 'REJECTED' | null;
|
|
31
|
-
}
|
|
32
|
-
export interface TopUpChallenge {
|
|
33
|
-
status: MarketplaceTopUpStatus;
|
|
34
|
-
requirementHeader: string;
|
|
35
|
-
requirement: AttoExactRequirement;
|
|
36
|
-
}
|
|
37
|
-
export interface MarketplaceWalletAccess {
|
|
38
|
-
settings(): WalletSettings;
|
|
39
|
-
addresses(): WalletAddress[];
|
|
40
|
-
seed(): Promise<AttoSeed>;
|
|
41
|
-
mcp: boolean;
|
|
42
|
-
}
|
|
43
|
-
export declare function validateMarketplaceApiUrl(value: string, network: WalletSettings['network']): string;
|
|
44
|
-
export declare class MarketplaceTopUpClient {
|
|
45
|
-
private readonly store;
|
|
46
|
-
private readonly wallet;
|
|
47
|
-
private session?;
|
|
48
|
-
constructor(store: StateStore, wallet: MarketplaceWalletAccess);
|
|
49
|
-
connect(input: {
|
|
50
|
-
apiUrl: string;
|
|
51
|
-
audience: string;
|
|
52
|
-
controllerIndex: number;
|
|
53
|
-
browserOrigins?: string[];
|
|
54
|
-
}): Promise<MarketplaceConnection>;
|
|
55
|
-
connection(): MarketplaceConnection;
|
|
56
|
-
inspectProofApproval(input: unknown): {
|
|
57
|
-
request: import("./proof-approval.js").MarketplaceProofApprovalRequest;
|
|
58
|
-
preview: import("./proof-approval.js").MarketplaceProofApprovalPreview;
|
|
59
|
-
};
|
|
60
|
-
signProofApproval(input: unknown): Promise<MarketplaceProofApprovalResponse>;
|
|
61
|
-
challenge(connection: MarketplaceConnection, paymentIdentifier: string, amountRaw: string): Promise<{
|
|
62
|
-
status: MarketplaceTopUpStatus;
|
|
63
|
-
challenge?: TopUpChallenge;
|
|
64
|
-
}>;
|
|
65
|
-
pay(connection: MarketplaceConnection, status: MarketplaceTopUpStatus, paymentIdentifier: string, paymentHeader: string, expected: {
|
|
66
|
-
hash: string;
|
|
67
|
-
network: string;
|
|
68
|
-
payer: string;
|
|
69
|
-
}, beforeSubmit: () => Promise<void>): Promise<MarketplaceTopUpStatus>;
|
|
70
|
-
status(connection: MarketplaceConnection, intentId: string, paymentIdentifier: string, amountRaw: string, network: string, expected?: {
|
|
71
|
-
hash: string;
|
|
72
|
-
payer: string;
|
|
73
|
-
}): Promise<MarketplaceTopUpStatus>;
|
|
74
|
-
private authorize;
|
|
75
|
-
private login;
|
|
76
|
-
private authUrl;
|
|
77
|
-
private fetchJson;
|
|
78
|
-
private decodeObject;
|
|
79
|
-
private assertStatusBinding;
|
|
80
|
-
private httpFailure;
|
|
81
|
-
private sessionKey;
|
|
82
|
-
}
|