@attocash/cli 0.6.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.
@@ -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
- export declare function signingWallet(seed: AttoSeed, index: number, settings: WalletSettings, beforeSign: (block: AttoBlock) => void | Promise<void>, suppliedWorker?: BlockWorker, retry?: SendRetry): Promise<{
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>;
@@ -24,7 +24,28 @@ export async function derivedSigner(seed, index) {
24
24
  }
25
25
  return privateKeyToSigner(await seed.toPrivateKey(toAttoIndex(index)));
26
26
  }
27
- export async function signingWallet(seed, index, settings, beforeSign, suppliedWorker, retry) {
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
- let attempted = false;
87
- await retryNetwork(async () => {
88
- if (attempted) {
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@attocash/cli",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Atto wallet CLI and reusable wallet engine with local key custody and shared spending limits",
5
5
  "license": "BSD-3-Clause",
6
6
  "type": "module",
@@ -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
- }