@agirails/sdk 2.0.2 → 2.0.4
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 +22 -22
- package/dist/ACTPClient.d.ts +24 -24
- package/dist/ACTPClient.d.ts.map +1 -1
- package/dist/ACTPClient.js +18 -18
- package/dist/ACTPClient.js.map +1 -1
- package/dist/adapters/BaseAdapter.js +2 -2
- package/dist/adapters/BaseAdapter.js.map +1 -1
- package/dist/adapters/BasicAdapter.d.ts +152 -0
- package/dist/adapters/BasicAdapter.d.ts.map +1 -0
- package/dist/adapters/BasicAdapter.js +168 -0
- package/dist/adapters/BasicAdapter.js.map +1 -0
- package/dist/adapters/StandardAdapter.d.ts +211 -0
- package/dist/adapters/StandardAdapter.d.ts.map +1 -0
- package/dist/adapters/StandardAdapter.js +260 -0
- package/dist/adapters/StandardAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +4 -4
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +7 -7
- package/dist/adapters/index.js.map +1 -1
- package/dist/builders/QuoteBuilder.js +1 -1
- package/dist/builders/QuoteBuilder.js.map +1 -1
- package/dist/cli/commands/config.js +1 -1
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/pay.d.ts +1 -1
- package/dist/cli/commands/pay.js +2 -2
- package/dist/cli/commands/pay.js.map +1 -1
- package/dist/cli/commands/simulate.js.map +1 -1
- package/dist/cli/commands/time.d.ts.map +1 -1
- package/dist/cli/commands/time.js.map +1 -1
- package/dist/cli/commands/tx.d.ts +1 -1
- package/dist/cli/commands/tx.js +13 -13
- package/dist/cli/commands/tx.js.map +1 -1
- package/dist/cli/commands/watch.js +2 -2
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/level0/request.d.ts.map +1 -1
- package/dist/level0/request.js +1 -2
- package/dist/level0/request.js.map +1 -1
- package/dist/level1/Agent.d.ts.map +1 -1
- package/dist/level1/Agent.js.map +1 -1
- package/dist/level1/pricing/PriceCalculator.js +1 -1
- package/dist/level1/pricing/PriceCalculator.js.map +1 -1
- package/dist/level1/types/Options.d.ts.map +1 -1
- package/dist/protocol/ACTPKernel.d.ts +5 -5
- package/dist/protocol/ACTPKernel.js +5 -5
- package/dist/protocol/MessageSigner.js +1 -1
- package/dist/protocol/MessageSigner.js.map +1 -1
- package/dist/protocol/ProofGenerator.d.ts.map +1 -1
- package/dist/protocol/ProofGenerator.js +1 -0
- package/dist/protocol/ProofGenerator.js.map +1 -1
- package/dist/runtime/BlockchainRuntime.d.ts +4 -4
- package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
- package/dist/runtime/BlockchainRuntime.js +4 -4
- package/dist/runtime/BlockchainRuntime.js.map +1 -1
- package/dist/runtime/IACTPRuntime.d.ts +1 -1
- package/dist/runtime/MockRuntime.d.ts.map +1 -1
- package/dist/runtime/MockRuntime.js.map +1 -1
- package/dist/utils/ErrorRecoveryGuide.d.ts +2 -2
- package/dist/utils/ErrorRecoveryGuide.d.ts.map +1 -1
- package/dist/utils/ErrorRecoveryGuide.js +3 -4
- package/dist/utils/ErrorRecoveryGuide.js.map +1 -1
- package/dist/utils/UsedAttestationTracker.d.ts +1 -1
- package/dist/utils/UsedAttestationTracker.d.ts.map +1 -1
- package/dist/utils/UsedAttestationTracker.js +1 -1
- package/dist/utils/UsedAttestationTracker.js.map +1 -1
- package/package.json +1 -1
- package/src/ACTPClient.ts +26 -26
- package/src/adapters/BaseAdapter.ts +2 -2
- package/src/adapters/{BeginnerAdapter.ts → BasicAdapter.ts} +12 -13
- package/src/adapters/{IntermediateAdapter.ts → StandardAdapter.ts} +16 -16
- package/src/adapters/index.ts +4 -4
- package/src/builders/QuoteBuilder.ts +1 -1
- package/src/cli/commands/config.ts +1 -1
- package/src/cli/commands/pay.ts +2 -2
- package/src/cli/commands/simulate.ts +1 -1
- package/src/cli/commands/time.ts +1 -2
- package/src/cli/commands/tx.ts +13 -13
- package/src/cli/commands/watch.ts +2 -2
- package/src/index.ts +8 -8
- package/src/level0/request.ts +1 -2
- package/src/level1/Agent.ts +2 -2
- package/src/level1/pricing/PriceCalculator.ts +1 -1
- package/src/level1/types/Options.ts +1 -1
- package/src/protocol/ACTPKernel.ts +5 -5
- package/src/protocol/MessageSigner.ts +1 -1
- package/src/protocol/ProofGenerator.ts +1 -0
- package/src/runtime/BlockchainRuntime.ts +4 -4
- package/src/runtime/IACTPRuntime.ts +1 -1
- package/src/runtime/MockRuntime.ts +0 -2
- package/src/utils/ErrorRecoveryGuide.ts +3 -4
- package/src/utils/UsedAttestationTracker.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* BasicAdapter - High-level, opinionated API for simple use cases
|
|
3
3
|
*
|
|
4
4
|
* Provides the simplest possible interface for creating and checking transactions.
|
|
5
5
|
* Designed for developers who want to "just make it work" without deep protocol knowledge.
|
|
@@ -10,20 +10,19 @@
|
|
|
10
10
|
* - User-friendly input (strings, no BigInt)
|
|
11
11
|
* - User-friendly output (formatted amounts, ISO dates)
|
|
12
12
|
*
|
|
13
|
-
* @module adapters/
|
|
13
|
+
* @module adapters/BasicAdapter
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { BaseAdapter, ValidationError
|
|
16
|
+
import { BaseAdapter, ValidationError } from './BaseAdapter';
|
|
17
17
|
import { IACTPRuntime } from '../runtime/IACTPRuntime';
|
|
18
|
-
import { TransactionState } from '../runtime/types/MockState';
|
|
19
18
|
import { EASHelper } from '../protocol/EASHelper';
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* Parameters for creating a simple payment.
|
|
23
22
|
*
|
|
24
|
-
* This is the most
|
|
23
|
+
* This is the most user-friendly interface - minimal required fields.
|
|
25
24
|
*/
|
|
26
|
-
export interface
|
|
25
|
+
export interface BasicPayParams {
|
|
27
26
|
/** Recipient address (provider) */
|
|
28
27
|
to: string;
|
|
29
28
|
|
|
@@ -42,7 +41,7 @@ export interface BeginnerPayParams {
|
|
|
42
41
|
*
|
|
43
42
|
* Provides user-friendly formatted data (not raw protocol types).
|
|
44
43
|
*/
|
|
45
|
-
export interface
|
|
44
|
+
export interface BasicPayResult {
|
|
46
45
|
/** Transaction ID (bytes32 hex string) */
|
|
47
46
|
txId: string;
|
|
48
47
|
|
|
@@ -63,7 +62,7 @@ export interface BeginnerPayResult {
|
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
/**
|
|
66
|
-
*
|
|
65
|
+
* BasicAdapter - High-level API for simple payment flows.
|
|
67
66
|
*
|
|
68
67
|
* This adapter provides the simplest possible interface:
|
|
69
68
|
* - `pay()` - Create and fund a transaction in one call
|
|
@@ -76,7 +75,7 @@ export interface BeginnerPayResult {
|
|
|
76
75
|
* const client = await ACTPClient.create({ mode: 'mock' });
|
|
77
76
|
*
|
|
78
77
|
* // Simple payment (all defaults)
|
|
79
|
-
* const result = await client.
|
|
78
|
+
* const result = await client.basic.pay({
|
|
80
79
|
* to: '0xProvider123',
|
|
81
80
|
* amount: '100',
|
|
82
81
|
* });
|
|
@@ -84,15 +83,15 @@ export interface BeginnerPayResult {
|
|
|
84
83
|
* console.log('Amount:', result.amount); // "100.00 USDC"
|
|
85
84
|
*
|
|
86
85
|
* // Check status
|
|
87
|
-
* const status = await client.
|
|
86
|
+
* const status = await client.basic.checkStatus(result.txId);
|
|
88
87
|
* if (status.canAccept) {
|
|
89
88
|
* console.log('Provider can accept this transaction');
|
|
90
89
|
* }
|
|
91
90
|
* ```
|
|
92
91
|
*/
|
|
93
|
-
export class
|
|
92
|
+
export class BasicAdapter extends BaseAdapter {
|
|
94
93
|
/**
|
|
95
|
-
* Creates a new
|
|
94
|
+
* Creates a new BasicAdapter instance.
|
|
96
95
|
*
|
|
97
96
|
* @param runtime - ACTP runtime implementation (MockRuntime or BlockchainRuntime)
|
|
98
97
|
* @param requesterAddress - The requester's Ethereum address
|
|
@@ -136,7 +135,7 @@ export class BeginnerAdapter extends BaseAdapter {
|
|
|
136
135
|
* });
|
|
137
136
|
* ```
|
|
138
137
|
*/
|
|
139
|
-
async pay(params:
|
|
138
|
+
async pay(params: BasicPayParams): Promise<BasicPayResult> {
|
|
140
139
|
// Validate and parse inputs
|
|
141
140
|
const provider = this.validateAddress(params.to, 'to');
|
|
142
141
|
const amount = this.parseAmount(params.amount);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* StandardAdapter - Balanced API for developers with some protocol knowledge
|
|
3
3
|
*
|
|
4
|
-
* Provides more control than
|
|
4
|
+
* Provides more control than BasicAdapter while still offering convenience:
|
|
5
5
|
* - Explicit transaction lifecycle methods
|
|
6
6
|
* - Direct escrow operations
|
|
7
7
|
* - State transition control
|
|
@@ -9,20 +9,20 @@
|
|
|
9
9
|
* Use this adapter when you need fine-grained control but still want
|
|
10
10
|
* user-friendly input parsing and validation.
|
|
11
11
|
*
|
|
12
|
-
* @module adapters/
|
|
12
|
+
* @module adapters/StandardAdapter
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { BaseAdapter, ValidationError
|
|
15
|
+
import { BaseAdapter, ValidationError } from './BaseAdapter';
|
|
16
16
|
import { IACTPRuntime } from '../runtime/IACTPRuntime';
|
|
17
17
|
import { MockTransaction, TransactionState } from '../runtime/types/MockState';
|
|
18
18
|
import { EASHelper } from '../protocol/EASHelper';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Parameters for creating a transaction (
|
|
21
|
+
* Parameters for creating a transaction (standard level).
|
|
22
22
|
*
|
|
23
|
-
* More explicit than
|
|
23
|
+
* More explicit than BasicPayParams but still with smart defaults.
|
|
24
24
|
*/
|
|
25
|
-
export interface
|
|
25
|
+
export interface StandardTransactionParams {
|
|
26
26
|
/** Provider's Ethereum address */
|
|
27
27
|
provider: string;
|
|
28
28
|
|
|
@@ -40,7 +40,7 @@ export interface IntermediateTransactionParams {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* StandardAdapter - Balanced API for transaction lifecycle control.
|
|
44
44
|
*
|
|
45
45
|
* Provides explicit methods for each stage of the ACTP lifecycle:
|
|
46
46
|
* - `createTransaction()` - Create transaction without escrow
|
|
@@ -55,25 +55,25 @@ export interface IntermediateTransactionParams {
|
|
|
55
55
|
* const client = await ACTPClient.create({ mode: 'mock' });
|
|
56
56
|
*
|
|
57
57
|
* // Create transaction (INITIATED state)
|
|
58
|
-
* const txId = await client.
|
|
58
|
+
* const txId = await client.standard.createTransaction({
|
|
59
59
|
* provider: '0xProvider123',
|
|
60
60
|
* amount: '100',
|
|
61
61
|
* deadline: '+7d',
|
|
62
62
|
* });
|
|
63
63
|
*
|
|
64
64
|
* // Link escrow (auto-transitions to COMMITTED)
|
|
65
|
-
* await client.
|
|
65
|
+
* await client.standard.linkEscrow(txId, '100');
|
|
66
66
|
*
|
|
67
67
|
* // Provider delivers
|
|
68
|
-
* await client.
|
|
68
|
+
* await client.standard.transitionState(txId, 'DELIVERED');
|
|
69
69
|
*
|
|
70
70
|
* // Release funds after dispute window
|
|
71
|
-
* await client.
|
|
71
|
+
* await client.standard.releaseEscrow(escrowId);
|
|
72
72
|
* ```
|
|
73
73
|
*/
|
|
74
|
-
export class
|
|
74
|
+
export class StandardAdapter extends BaseAdapter {
|
|
75
75
|
/**
|
|
76
|
-
* Creates a new
|
|
76
|
+
* Creates a new StandardAdapter instance.
|
|
77
77
|
*
|
|
78
78
|
* @param runtime - ACTP runtime implementation (MockRuntime or BlockchainRuntime)
|
|
79
79
|
* @param requesterAddress - The requester's Ethereum address
|
|
@@ -90,7 +90,7 @@ export class IntermediateAdapter extends BaseAdapter {
|
|
|
90
90
|
/**
|
|
91
91
|
* Create a transaction (INITIATED state, no escrow yet).
|
|
92
92
|
*
|
|
93
|
-
* Unlike `
|
|
93
|
+
* Unlike `basic.pay()`, this only creates the transaction
|
|
94
94
|
* without linking escrow. You must call `linkEscrow()` separately.
|
|
95
95
|
*
|
|
96
96
|
* @param params - Transaction parameters
|
|
@@ -106,7 +106,7 @@ export class IntermediateAdapter extends BaseAdapter {
|
|
|
106
106
|
* });
|
|
107
107
|
* ```
|
|
108
108
|
*/
|
|
109
|
-
async createTransaction(params:
|
|
109
|
+
async createTransaction(params: StandardTransactionParams): Promise<string> {
|
|
110
110
|
const provider = this.validateAddress(params.provider, 'provider');
|
|
111
111
|
const amount = this.parseAmount(params.amount);
|
|
112
112
|
const currentTime = this.runtime.time.now();
|
package/src/adapters/index.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module exports all adapter classes and types for the Three-Level API:
|
|
5
5
|
* - BaseAdapter: Abstract base with shared utilities
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
6
|
+
* - BasicAdapter: High-level, opinionated API
|
|
7
|
+
* - StandardAdapter: Balanced control API
|
|
8
8
|
*
|
|
9
9
|
* @module adapters
|
|
10
10
|
*/
|
|
@@ -18,8 +18,8 @@ export {
|
|
|
18
18
|
MAX_DEADLINE_HOURS,
|
|
19
19
|
MAX_DEADLINE_DAYS,
|
|
20
20
|
} from './BaseAdapter';
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
21
|
+
export { BasicAdapter, BasicPayParams, BasicPayResult } from './BasicAdapter';
|
|
22
|
+
export { StandardAdapter, StandardTransactionParams } from './StandardAdapter';
|
|
23
23
|
|
|
24
24
|
// Re-export runtime interface for convenience
|
|
25
25
|
export { IACTPRuntime, CreateTransactionParams } from '../runtime/IACTPRuntime';
|
|
@@ -233,7 +233,7 @@ export class QuoteBuilder {
|
|
|
233
233
|
*/
|
|
234
234
|
computeHash(quote: QuoteMessage): string {
|
|
235
235
|
// Remove signature field for hashing
|
|
236
|
-
const { signature, ...quoteWithoutSig } = quote;
|
|
236
|
+
const { signature: _signature, ...quoteWithoutSig } = quote;
|
|
237
237
|
return keccak256(toUtf8Bytes(canonicalJsonStringify(quoteWithoutSig)));
|
|
238
238
|
}
|
|
239
239
|
|
|
@@ -156,7 +156,7 @@ function createConfigSetCommand(): Command {
|
|
|
156
156
|
updates.address = value.toLowerCase();
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
updateConfig(updates);
|
|
160
160
|
|
|
161
161
|
output.result({
|
|
162
162
|
[key]: key === 'privateKey' ? '****' + value.slice(-4) : value,
|
package/src/cli/commands/pay.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pay Command - One-liner payment command (
|
|
2
|
+
* Pay Command - One-liner payment command (basic API)
|
|
3
3
|
*
|
|
4
4
|
* The simplest way to create a payment transaction.
|
|
5
5
|
* Creates transaction, links escrow, and returns immediately.
|
|
@@ -76,7 +76,7 @@ async function runPay(
|
|
|
76
76
|
const disputeWindow = parseInt(options.disputeWindow, 10);
|
|
77
77
|
|
|
78
78
|
// Create payment
|
|
79
|
-
const result = await client.
|
|
79
|
+
const result = await client.basic.pay({
|
|
80
80
|
to,
|
|
81
81
|
amount,
|
|
82
82
|
deadline,
|
|
@@ -14,7 +14,7 @@ import { Command } from 'commander';
|
|
|
14
14
|
import { Output, ExitCode, fmt } from '../utils/output';
|
|
15
15
|
import { loadConfig } from '../utils/config';
|
|
16
16
|
import { mapError } from '../utils/client';
|
|
17
|
-
import { BaseAdapter
|
|
17
|
+
import { BaseAdapter } from '../../adapters/BaseAdapter';
|
|
18
18
|
|
|
19
19
|
// ============================================================================
|
|
20
20
|
// Command Definition
|
package/src/cli/commands/time.ts
CHANGED
|
@@ -10,10 +10,9 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { Command } from 'commander';
|
|
13
|
-
import { Output, ExitCode
|
|
13
|
+
import { Output, ExitCode } from '../utils/output';
|
|
14
14
|
import { loadConfig } from '../utils/config';
|
|
15
15
|
import { createClient, mapError } from '../utils/client';
|
|
16
|
-
import { MockRuntime } from '../../runtime/MockRuntime';
|
|
17
16
|
import { IMockRuntime } from '../../runtime/IACTPRuntime';
|
|
18
17
|
|
|
19
18
|
// ============================================================================
|
package/src/cli/commands/tx.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Transaction Commands - tx subcommand group
|
|
3
3
|
*
|
|
4
4
|
* Commands for managing ACTP transactions:
|
|
5
|
-
* - tx create: Create a new transaction (
|
|
5
|
+
* - tx create: Create a new transaction (standard API)
|
|
6
6
|
* - tx status: Check transaction status
|
|
7
7
|
* - tx list: List all transactions
|
|
8
8
|
* - tx deliver: Mark transaction as delivered
|
|
@@ -66,7 +66,7 @@ function createTxCreateCommand(): Command {
|
|
|
66
66
|
const disputeWindow = parseInt(options.disputeWindow, 10);
|
|
67
67
|
|
|
68
68
|
// Create transaction
|
|
69
|
-
const txId = await client.
|
|
69
|
+
const txId = await client.standard.createTransaction({
|
|
70
70
|
provider,
|
|
71
71
|
amount,
|
|
72
72
|
deadline,
|
|
@@ -77,10 +77,10 @@ function createTxCreateCommand(): Command {
|
|
|
77
77
|
// Optionally fund
|
|
78
78
|
let escrowId: string | undefined;
|
|
79
79
|
if (options.fund) {
|
|
80
|
-
escrowId = await client.
|
|
80
|
+
escrowId = await client.standard.linkEscrow(txId);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
const tx = await client.
|
|
83
|
+
const tx = await client.standard.getTransaction(txId);
|
|
84
84
|
if (!tx) throw new Error('Transaction not found after creation');
|
|
85
85
|
|
|
86
86
|
output.result(
|
|
@@ -134,13 +134,13 @@ function createTxStatusCommand(): Command {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
const client = await createClient();
|
|
137
|
-
const tx = await client.
|
|
137
|
+
const tx = await client.standard.getTransaction(txId);
|
|
138
138
|
|
|
139
139
|
if (!tx) {
|
|
140
140
|
throw new Error(`Transaction not found: ${txId}`);
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
const status = await client.
|
|
143
|
+
const status = await client.basic.checkStatus(txId);
|
|
144
144
|
|
|
145
145
|
if (options.quiet) {
|
|
146
146
|
output.raw(tx.state);
|
|
@@ -289,9 +289,9 @@ function createTxDeliverCommand(): Command {
|
|
|
289
289
|
const client = await createClient();
|
|
290
290
|
|
|
291
291
|
// Transition to DELIVERED
|
|
292
|
-
await client.
|
|
292
|
+
await client.standard.transitionState(txId, 'DELIVERED' as TransactionState);
|
|
293
293
|
|
|
294
|
-
const tx = await client.
|
|
294
|
+
const tx = await client.standard.getTransaction(txId);
|
|
295
295
|
if (!tx) throw new Error('Transaction not found');
|
|
296
296
|
|
|
297
297
|
output.result(
|
|
@@ -345,15 +345,15 @@ function createTxSettleCommand(): Command {
|
|
|
345
345
|
const client = await createClient();
|
|
346
346
|
|
|
347
347
|
// Get transaction to find escrow
|
|
348
|
-
const tx = await client.
|
|
348
|
+
const tx = await client.standard.getTransaction(txId);
|
|
349
349
|
if (!tx) throw new Error(`Transaction not found: ${txId}`);
|
|
350
350
|
if (!tx.escrowId) throw new Error('Transaction has no linked escrow');
|
|
351
351
|
|
|
352
352
|
// Release escrow
|
|
353
|
-
await client.
|
|
353
|
+
await client.standard.releaseEscrow(tx.escrowId);
|
|
354
354
|
|
|
355
355
|
// Get updated transaction
|
|
356
|
-
const updatedTx = await client.
|
|
356
|
+
const updatedTx = await client.standard.getTransaction(txId);
|
|
357
357
|
if (!updatedTx) throw new Error('Transaction not found');
|
|
358
358
|
|
|
359
359
|
output.result(
|
|
@@ -402,9 +402,9 @@ function createTxCancelCommand(): Command {
|
|
|
402
402
|
const client = await createClient();
|
|
403
403
|
|
|
404
404
|
// Transition to CANCELLED
|
|
405
|
-
await client.
|
|
405
|
+
await client.standard.transitionState(txId, 'CANCELLED' as TransactionState);
|
|
406
406
|
|
|
407
|
-
const tx = await client.
|
|
407
|
+
const tx = await client.standard.getTransaction(txId);
|
|
408
408
|
if (!tx) throw new Error('Transaction not found');
|
|
409
409
|
|
|
410
410
|
output.result(
|
|
@@ -85,7 +85,7 @@ async function runWatch(
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// Get initial state
|
|
88
|
-
const tx = await client.
|
|
88
|
+
const tx = await client.standard.getTransaction(txId);
|
|
89
89
|
if (!tx) {
|
|
90
90
|
throw new Error(`Transaction not found: ${txId}`);
|
|
91
91
|
}
|
|
@@ -123,7 +123,7 @@ async function runWatch(
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
try {
|
|
126
|
-
const updatedTx = await client.
|
|
126
|
+
const updatedTx = await client.standard.getTransaction(txId);
|
|
127
127
|
if (!updatedTx) {
|
|
128
128
|
output.warning('Transaction no longer exists');
|
|
129
129
|
process.exit(ExitCode.ERROR);
|
package/src/index.ts
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* await client.mintTokens(client.getAddress(), '10000000000');
|
|
21
21
|
*
|
|
22
22
|
* // Create a payment
|
|
23
|
-
* const result = await client.
|
|
23
|
+
* const result = await client.basic.pay({
|
|
24
24
|
* to: '0xProvider...',
|
|
25
25
|
* amount: '100',
|
|
26
26
|
* });
|
|
@@ -54,15 +54,15 @@ export {
|
|
|
54
54
|
} from './adapters/BaseAdapter';
|
|
55
55
|
|
|
56
56
|
export {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
} from './adapters/
|
|
57
|
+
BasicAdapter,
|
|
58
|
+
BasicPayParams,
|
|
59
|
+
BasicPayResult,
|
|
60
|
+
} from './adapters/BasicAdapter';
|
|
61
61
|
|
|
62
62
|
export {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} from './adapters/
|
|
63
|
+
StandardAdapter,
|
|
64
|
+
StandardTransactionParams,
|
|
65
|
+
} from './adapters/StandardAdapter';
|
|
66
66
|
|
|
67
67
|
// =============================================================================
|
|
68
68
|
// Runtime Layer - Protocol Implementation
|
package/src/level0/request.ts
CHANGED
|
@@ -164,7 +164,6 @@ export async function request(
|
|
|
164
164
|
|
|
165
165
|
let tx = await client.runtime.getTransaction(txId);
|
|
166
166
|
let attempts = 0;
|
|
167
|
-
let timedOut = false;
|
|
168
167
|
|
|
169
168
|
while (tx && tx.state !== 'DELIVERED' && tx.state !== 'SETTLED' && attempts < maxAttempts) {
|
|
170
169
|
// Check for terminal states that indicate failure
|
|
@@ -190,7 +189,7 @@ export async function request(
|
|
|
190
189
|
|
|
191
190
|
// Check if we got a result
|
|
192
191
|
if (!tx || (tx.state !== 'DELIVERED' && tx.state !== 'SETTLED')) {
|
|
193
|
-
|
|
192
|
+
const _timedOut = true; // Flag for potential future use
|
|
194
193
|
|
|
195
194
|
// SECURITY FIX (H-3): Auto-cancel transaction on timeout if still in early state
|
|
196
195
|
// This prevents funds from being locked indefinitely if provider never responds
|
package/src/level1/Agent.ts
CHANGED
|
@@ -14,10 +14,10 @@ import * as fs from 'fs';
|
|
|
14
14
|
import { ethers } from 'ethers';
|
|
15
15
|
import { ACTPClient } from '../ACTPClient';
|
|
16
16
|
import { Job, JobHandler, JobContext } from './types/Job';
|
|
17
|
-
import {
|
|
17
|
+
import { RequestOptions, RequestResult, NetworkOption } from './types/Options';
|
|
18
18
|
import { PricingStrategy } from './pricing/PricingStrategy';
|
|
19
19
|
import { AgentLifecycleError, ServiceConfigError, ValidationError } from '../errors';
|
|
20
|
-
import { validateServiceName, validatePath,
|
|
20
|
+
import { validateServiceName, validatePath, LRUCache } from '../utils/security';
|
|
21
21
|
import { Logger } from '../utils/Logger';
|
|
22
22
|
import { ServiceHash } from '../utils/Helpers';
|
|
23
23
|
import { Semaphore } from '../utils/Semaphore';
|
|
@@ -214,7 +214,7 @@ function estimateUnits(job: Job, unit: string): number {
|
|
|
214
214
|
*
|
|
215
215
|
* @internal
|
|
216
216
|
*/
|
|
217
|
-
function estimateApiCost(
|
|
217
|
+
function estimateApiCost(_api: string, _job: Job): number {
|
|
218
218
|
// MVP: Returns 0 (API costs tracked externally by agent)
|
|
219
219
|
// V2: Integrate with OpenAI/Anthropic pricing APIs
|
|
220
220
|
|
|
@@ -455,13 +455,13 @@ export class ACTPKernel {
|
|
|
455
455
|
*
|
|
456
456
|
* **REQUIRED: Use secure wrapper methods instead:**
|
|
457
457
|
*
|
|
458
|
-
* 1. **
|
|
458
|
+
* 1. **BasicAdapter.completePayment()** (recommended for most users)
|
|
459
459
|
* - Automatically verifies attestation before release
|
|
460
460
|
* - Validates attestation belongs to this transaction
|
|
461
461
|
* - Checks attestation hasn't been used before
|
|
462
462
|
* - Handles all state transitions
|
|
463
463
|
*
|
|
464
|
-
* 2. **
|
|
464
|
+
* 2. **StandardAdapter.releaseEscrow()** (for more control)
|
|
465
465
|
* - Explicitly requires attestation verification
|
|
466
466
|
* - Throws error if attestation invalid or missing
|
|
467
467
|
* - Allows custom verification logic
|
|
@@ -493,15 +493,15 @@ export class ACTPKernel {
|
|
|
493
493
|
*
|
|
494
494
|
* **For testnet/mainnet deployments:**
|
|
495
495
|
* - MUST configure easConfig in ACTPClient
|
|
496
|
-
* - MUST use wrapper methods (
|
|
496
|
+
* - MUST use wrapper methods (Basic/Standard adapters)
|
|
497
497
|
* - NEVER call this method directly unless attestation verified
|
|
498
498
|
*
|
|
499
499
|
* @param txId - Transaction ID to settle
|
|
500
500
|
* @throws {ValidationError} If txId is invalid
|
|
501
501
|
* @throws {TransactionRevertedError} If contract reverts
|
|
502
502
|
*
|
|
503
|
-
* @see {@link
|
|
504
|
-
* @see {@link
|
|
503
|
+
* @see {@link BasicAdapter.completePayment} Recommended method with built-in verification
|
|
504
|
+
* @see {@link StandardAdapter.releaseEscrow} Explicit verification method
|
|
505
505
|
* @see {@link EASHelper.verifyDeliveryAttestation} Manual verification helper
|
|
506
506
|
*/
|
|
507
507
|
async releaseEscrow(txId: string): Promise<void> {
|
|
@@ -157,7 +157,7 @@ export class MessageSigner {
|
|
|
157
157
|
);
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
const { type, version, from, to, timestamp, nonce, signature, ...payload } = message;
|
|
160
|
+
const { type, version, from, to, timestamp, nonce, signature: _sig, ...payload } = message;
|
|
161
161
|
|
|
162
162
|
// SECURITY FIX (H-3): Validate nonce format (must be bytes32)
|
|
163
163
|
if (!nonce || !/^0x[a-fA-F0-9]{64}$/.test(nonce)) {
|
|
@@ -84,7 +84,7 @@ export interface BlockchainRuntimeConfig {
|
|
|
84
84
|
* });
|
|
85
85
|
*
|
|
86
86
|
* // Now use with adapters
|
|
87
|
-
* const adapter = new
|
|
87
|
+
* const adapter = new BasicAdapter(runtime, requesterAddress);
|
|
88
88
|
* await adapter.createJob({...});
|
|
89
89
|
* ```
|
|
90
90
|
*/
|
|
@@ -892,7 +892,7 @@ export class BlockchainRuntime implements IACTPRuntime {
|
|
|
892
892
|
* @param params - Transaction parameters
|
|
893
893
|
* @returns Estimated gas limit and cost in wei
|
|
894
894
|
*/
|
|
895
|
-
async estimateCreateTransactionGas(
|
|
895
|
+
async estimateCreateTransactionGas(_params: CreateTransactionParams): Promise<{
|
|
896
896
|
gasLimit: bigint;
|
|
897
897
|
gasCostWei: bigint;
|
|
898
898
|
gasCostGwei: string;
|
|
@@ -921,7 +921,7 @@ export class BlockchainRuntime implements IACTPRuntime {
|
|
|
921
921
|
* @param txId - Transaction ID
|
|
922
922
|
* @returns Estimated gas limit and cost
|
|
923
923
|
*/
|
|
924
|
-
async estimateLinkEscrowGas(
|
|
924
|
+
async estimateLinkEscrowGas(_txId: string): Promise<{
|
|
925
925
|
gasLimit: bigint;
|
|
926
926
|
gasCostWei: bigint;
|
|
927
927
|
gasCostGwei: string;
|
|
@@ -949,7 +949,7 @@ export class BlockchainRuntime implements IACTPRuntime {
|
|
|
949
949
|
* @param newState - Target state
|
|
950
950
|
* @returns Estimated gas limit and cost
|
|
951
951
|
*/
|
|
952
|
-
async estimateTransitionGas(
|
|
952
|
+
async estimateTransitionGas(_txId: string, _newState: string): Promise<{
|
|
953
953
|
gasLimit: bigint;
|
|
954
954
|
gasCostWei: bigint;
|
|
955
955
|
gasCostGwei: string;
|
|
@@ -49,7 +49,7 @@ export interface CreateTransactionParams {
|
|
|
49
49
|
* });
|
|
50
50
|
*
|
|
51
51
|
* // Adapters work with either implementation
|
|
52
|
-
* const adapter = new
|
|
52
|
+
* const adapter = new BasicAdapter(runtime, requesterAddress);
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
55
|
export interface IACTPRuntime {
|
|
@@ -465,7 +465,7 @@ const DEFAULT_RECOVERY: ErrorRecoveryInfo = {
|
|
|
465
465
|
* @example
|
|
466
466
|
* ```typescript
|
|
467
467
|
* try {
|
|
468
|
-
* await client.
|
|
468
|
+
* await client.basic.pay({ to: provider, amount: '100' });
|
|
469
469
|
* } catch (error) {
|
|
470
470
|
* const recovery = ErrorRecoveryGuide.analyze(error);
|
|
471
471
|
* console.log('Category:', recovery.category);
|
|
@@ -622,7 +622,7 @@ ${recovery.securityNotes.map((n) => ` ! ${n}`).join('\n')}`;
|
|
|
622
622
|
* @example
|
|
623
623
|
* ```typescript
|
|
624
624
|
* const result = await withRecoveryGuidance(
|
|
625
|
-
* () => client.
|
|
625
|
+
* () => client.basic.pay({ to: provider, amount: '100' }),
|
|
626
626
|
* { logGuidance: true, autoRetry: true }
|
|
627
627
|
* );
|
|
628
628
|
* ```
|
|
@@ -637,14 +637,12 @@ export async function withRecoveryGuidance<T>(
|
|
|
637
637
|
): Promise<T> {
|
|
638
638
|
const { logGuidance = false, autoRetry = false, onError } = options;
|
|
639
639
|
|
|
640
|
-
let lastError: unknown;
|
|
641
640
|
let attempts = 0;
|
|
642
641
|
|
|
643
642
|
do {
|
|
644
643
|
try {
|
|
645
644
|
return await operation();
|
|
646
645
|
} catch (error) {
|
|
647
|
-
lastError = error;
|
|
648
646
|
const recovery = ErrorRecoveryGuide.analyze(error);
|
|
649
647
|
|
|
650
648
|
if (onError) {
|
|
@@ -671,5 +669,6 @@ export async function withRecoveryGuidance<T>(
|
|
|
671
669
|
|
|
672
670
|
throw error;
|
|
673
671
|
}
|
|
672
|
+
// eslint-disable-next-line no-constant-condition
|
|
674
673
|
} while (true);
|
|
675
674
|
}
|
|
@@ -202,7 +202,7 @@ export class InMemoryUsedAttestationTracker implements IUsedAttestationTracker {
|
|
|
202
202
|
*
|
|
203
203
|
* @param maxAgeHours - Remove entries older than this many hours
|
|
204
204
|
*/
|
|
205
|
-
cleanupOldEntries(
|
|
205
|
+
cleanupOldEntries(_maxAgeHours: number): number {
|
|
206
206
|
// In-memory tracker doesn't track timestamps
|
|
207
207
|
// This is a placeholder for future enhancement
|
|
208
208
|
console.warn(
|