@agirails/sdk 2.0.0-beta
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 +183 -0
- package/dist/ACTPClient.d.ts +52 -0
- package/dist/ACTPClient.d.ts.map +1 -0
- package/dist/ACTPClient.js +120 -0
- package/dist/ACTPClient.js.map +1 -0
- package/dist/abi/ACTPKernel.json +1340 -0
- package/dist/abi/ERC20.json +38 -0
- package/dist/abi/EscrowVault.json +64 -0
- package/dist/builders/DeliveryProofBuilder.d.ts +37 -0
- package/dist/builders/DeliveryProofBuilder.d.ts.map +1 -0
- package/dist/builders/DeliveryProofBuilder.js +165 -0
- package/dist/builders/DeliveryProofBuilder.js.map +1 -0
- package/dist/builders/QuoteBuilder.d.ts +68 -0
- package/dist/builders/QuoteBuilder.d.ts.map +1 -0
- package/dist/builders/QuoteBuilder.js +255 -0
- package/dist/builders/QuoteBuilder.js.map +1 -0
- package/dist/builders/index.d.ts +3 -0
- package/dist/builders/index.d.ts.map +1 -0
- package/dist/builders/index.js +10 -0
- package/dist/builders/index.js.map +1 -0
- package/dist/config/networks.d.ts +27 -0
- package/dist/config/networks.d.ts.map +1 -0
- package/dist/config/networks.js +103 -0
- package/dist/config/networks.js.map +1 -0
- package/dist/errors/index.d.ts +38 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +87 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/ACTPKernel.d.ts +30 -0
- package/dist/protocol/ACTPKernel.d.ts.map +1 -0
- package/dist/protocol/ACTPKernel.js +261 -0
- package/dist/protocol/ACTPKernel.js.map +1 -0
- package/dist/protocol/EASHelper.d.ts +23 -0
- package/dist/protocol/EASHelper.d.ts.map +1 -0
- package/dist/protocol/EASHelper.js +106 -0
- package/dist/protocol/EASHelper.js.map +1 -0
- package/dist/protocol/EscrowVault.d.ts +24 -0
- package/dist/protocol/EscrowVault.d.ts.map +1 -0
- package/dist/protocol/EscrowVault.js +114 -0
- package/dist/protocol/EscrowVault.js.map +1 -0
- package/dist/protocol/EventMonitor.d.ts +18 -0
- package/dist/protocol/EventMonitor.d.ts.map +1 -0
- package/dist/protocol/EventMonitor.js +92 -0
- package/dist/protocol/EventMonitor.js.map +1 -0
- package/dist/protocol/MessageSigner.d.ts +23 -0
- package/dist/protocol/MessageSigner.d.ts.map +1 -0
- package/dist/protocol/MessageSigner.js +178 -0
- package/dist/protocol/MessageSigner.js.map +1 -0
- package/dist/protocol/ProofGenerator.d.ts +22 -0
- package/dist/protocol/ProofGenerator.d.ts.map +1 -0
- package/dist/protocol/ProofGenerator.js +64 -0
- package/dist/protocol/ProofGenerator.js.map +1 -0
- package/dist/protocol/QuoteBuilder.d.ts +2 -0
- package/dist/protocol/QuoteBuilder.d.ts.map +1 -0
- package/dist/protocol/QuoteBuilder.js +7 -0
- package/dist/protocol/QuoteBuilder.js.map +1 -0
- package/dist/types/eip712.d.ts +106 -0
- package/dist/types/eip712.d.ts.map +1 -0
- package/dist/types/eip712.js +84 -0
- package/dist/types/eip712.js.map +1 -0
- package/dist/types/escrow.d.ts +18 -0
- package/dist/types/escrow.d.ts.map +1 -0
- package/dist/types/escrow.js +3 -0
- package/dist/types/escrow.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +22 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/message.d.ts +109 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +3 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/state.d.ts +19 -0
- package/dist/types/state.d.ts.map +1 -0
- package/dist/types/state.js +49 -0
- package/dist/types/state.js.map +1 -0
- package/dist/types/transaction.d.ts +36 -0
- package/dist/types/transaction.d.ts.map +1 -0
- package/dist/types/transaction.js +3 -0
- package/dist/types/transaction.js.map +1 -0
- package/dist/utils/IPFSClient.d.ts +37 -0
- package/dist/utils/IPFSClient.d.ts.map +1 -0
- package/dist/utils/IPFSClient.js +128 -0
- package/dist/utils/IPFSClient.js.map +1 -0
- package/dist/utils/NonceManager.d.ts +34 -0
- package/dist/utils/NonceManager.d.ts.map +1 -0
- package/dist/utils/NonceManager.js +114 -0
- package/dist/utils/NonceManager.js.map +1 -0
- package/dist/utils/ReceivedNonceTracker.d.ts +35 -0
- package/dist/utils/ReceivedNonceTracker.d.ts.map +1 -0
- package/dist/utils/ReceivedNonceTracker.js +196 -0
- package/dist/utils/ReceivedNonceTracker.js.map +1 -0
- package/dist/utils/canonicalJson.d.ts +4 -0
- package/dist/utils/canonicalJson.d.ts.map +1 -0
- package/dist/utils/canonicalJson.js +21 -0
- package/dist/utils/canonicalJson.js.map +1 -0
- package/dist/utils/computeTypeHash.d.ts +3 -0
- package/dist/utils/computeTypeHash.d.ts.map +1 -0
- package/dist/utils/computeTypeHash.js +30 -0
- package/dist/utils/computeTypeHash.js.map +1 -0
- package/dist/utils/validation.d.ts +6 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +46 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +73 -0
- package/src/ACTPClient.ts +276 -0
- package/src/__tests__/ProofGenerator.test.ts +124 -0
- package/src/__tests__/QuoteBuilder.test.ts +516 -0
- package/src/__tests__/StateMachine.test.ts +82 -0
- package/src/__tests__/builders/DeliveryProofBuilder.test.ts +581 -0
- package/src/__tests__/integration/ACTPClient.test.ts +263 -0
- package/src/__tests__/integration.test.ts +289 -0
- package/src/__tests__/protocol/EASHelper.test.ts +472 -0
- package/src/__tests__/protocol/EventMonitor.test.ts +382 -0
- package/src/__tests__/security/ACTPKernel.security.test.ts +1167 -0
- package/src/__tests__/security/EscrowVault.security.test.ts +570 -0
- package/src/__tests__/security/MessageSigner.security.test.ts +286 -0
- package/src/__tests__/security/NonceReplay.security.test.ts +501 -0
- package/src/__tests__/security/validation.security.test.ts +376 -0
- package/src/__tests__/utils/IPFSClient.test.ts +262 -0
- package/src/__tests__/utils/NonceManager.test.ts +205 -0
- package/src/__tests__/utils/canonicalJson.test.ts +153 -0
- package/src/abi/ACTPKernel.json +1340 -0
- package/src/abi/ERC20.json +40 -0
- package/src/abi/EscrowVault.json +66 -0
- package/src/builders/DeliveryProofBuilder.ts +326 -0
- package/src/builders/QuoteBuilder.ts +483 -0
- package/src/builders/index.ts +17 -0
- package/src/config/networks.ts +165 -0
- package/src/errors/index.ts +130 -0
- package/src/index.ts +108 -0
- package/src/protocol/ACTPKernel.ts +625 -0
- package/src/protocol/EASHelper.ts +197 -0
- package/src/protocol/EscrowVault.ts +237 -0
- package/src/protocol/EventMonitor.ts +161 -0
- package/src/protocol/MessageSigner.ts +336 -0
- package/src/protocol/ProofGenerator.ts +119 -0
- package/src/protocol/QuoteBuilder.ts +15 -0
- package/src/types/eip712.ts +175 -0
- package/src/types/escrow.ts +26 -0
- package/src/types/index.ts +10 -0
- package/src/types/message.ts +145 -0
- package/src/types/state.ts +77 -0
- package/src/types/transaction.ts +54 -0
- package/src/utils/IPFSClient.ts +248 -0
- package/src/utils/NonceManager.ts +293 -0
- package/src/utils/ReceivedNonceTracker.ts +397 -0
- package/src/utils/canonicalJson.ts +38 -0
- package/src/utils/computeTypeHash.ts +50 -0
- package/src/utils/validation.ts +82 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { State } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base ACTP Error
|
|
5
|
+
*/
|
|
6
|
+
export class ACTPError extends Error {
|
|
7
|
+
constructor(
|
|
8
|
+
message: string,
|
|
9
|
+
public readonly code: string,
|
|
10
|
+
public readonly txHash?: string,
|
|
11
|
+
public readonly details?: any
|
|
12
|
+
) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'ACTPError';
|
|
15
|
+
Object.setPrototypeOf(this, ACTPError.prototype);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Transaction Errors
|
|
21
|
+
*/
|
|
22
|
+
export class InsufficientFundsError extends ACTPError {
|
|
23
|
+
constructor(required: bigint, available: bigint) {
|
|
24
|
+
super(
|
|
25
|
+
`Insufficient funds: need ${required.toString()} wei, have ${available.toString()} wei`,
|
|
26
|
+
'INSUFFICIENT_FUNDS',
|
|
27
|
+
undefined,
|
|
28
|
+
{ required: required.toString(), available: available.toString() }
|
|
29
|
+
);
|
|
30
|
+
this.name = 'InsufficientFundsError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class TransactionNotFoundError extends ACTPError {
|
|
35
|
+
constructor(txId: string) {
|
|
36
|
+
super(`Transaction ${txId} not found`, 'TRANSACTION_NOT_FOUND', undefined, { txId });
|
|
37
|
+
this.name = 'TransactionNotFoundError';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class DeadlineExpiredError extends ACTPError {
|
|
42
|
+
constructor(txId: string, deadline: number) {
|
|
43
|
+
super(
|
|
44
|
+
`Transaction ${txId} deadline expired at ${new Date(deadline * 1000).toISOString()}`,
|
|
45
|
+
'DEADLINE_EXPIRED',
|
|
46
|
+
undefined,
|
|
47
|
+
{ txId, deadline }
|
|
48
|
+
);
|
|
49
|
+
this.name = 'DeadlineExpiredError';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* State Machine Errors
|
|
55
|
+
*/
|
|
56
|
+
export class InvalidStateTransitionError extends ACTPError {
|
|
57
|
+
constructor(from: State, to: State, validTransitions: string[]) {
|
|
58
|
+
super(
|
|
59
|
+
`Invalid state transition: ${State[from]} → ${State[to]}. ` +
|
|
60
|
+
`Valid transitions: ${validTransitions.join(', ') || 'none (terminal state)'}`,
|
|
61
|
+
'INVALID_STATE_TRANSITION',
|
|
62
|
+
undefined,
|
|
63
|
+
{ from: State[from], to: State[to], validTransitions }
|
|
64
|
+
);
|
|
65
|
+
this.name = 'InvalidStateTransitionError';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Signature Errors
|
|
71
|
+
*/
|
|
72
|
+
export class SignatureVerificationError extends ACTPError {
|
|
73
|
+
constructor(expectedSigner: string, recoveredSigner: string) {
|
|
74
|
+
super(
|
|
75
|
+
`Signature verification failed. Expected ${expectedSigner}, got ${recoveredSigner}`,
|
|
76
|
+
'SIGNATURE_VERIFICATION_FAILED',
|
|
77
|
+
undefined,
|
|
78
|
+
{ expectedSigner, recoveredSigner }
|
|
79
|
+
);
|
|
80
|
+
this.name = 'SignatureVerificationError';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Blockchain Errors
|
|
86
|
+
*/
|
|
87
|
+
export class TransactionRevertedError extends ACTPError {
|
|
88
|
+
constructor(txHash: string, reason?: string) {
|
|
89
|
+
super(
|
|
90
|
+
`Transaction reverted: ${reason || 'Unknown reason'}`,
|
|
91
|
+
'TRANSACTION_REVERTED',
|
|
92
|
+
txHash,
|
|
93
|
+
{ reason }
|
|
94
|
+
);
|
|
95
|
+
this.name = 'TransactionRevertedError';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export class NetworkError extends ACTPError {
|
|
100
|
+
constructor(network: string, message: string) {
|
|
101
|
+
super(`Network error on ${network}: ${message}`, 'NETWORK_ERROR', undefined, { network });
|
|
102
|
+
this.name = 'NetworkError';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Validation Errors
|
|
108
|
+
*/
|
|
109
|
+
export class ValidationError extends ACTPError {
|
|
110
|
+
constructor(field: string, message: string) {
|
|
111
|
+
super(`Validation error for ${field}: ${message}`, 'VALIDATION_ERROR', undefined, { field });
|
|
112
|
+
this.name = 'ValidationError';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export class InvalidAddressError extends ValidationError {
|
|
117
|
+
constructor(address: string) {
|
|
118
|
+
super('address', `Invalid Ethereum address: ${address}`);
|
|
119
|
+
this.name = 'InvalidAddressError';
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export class InvalidAmountError extends ValidationError {
|
|
124
|
+
constructor(amount: string) {
|
|
125
|
+
super('amount', `Invalid amount: ${amount} (must be > 0)`);
|
|
126
|
+
this.name = 'InvalidAmountError';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACTP SDK - Protocol SDK for Agent Commerce
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Main client
|
|
7
|
+
export { ACTPClient, ACTPClientConfig } from './ACTPClient';
|
|
8
|
+
|
|
9
|
+
// Protocol modules
|
|
10
|
+
export { ACTPKernel } from './protocol/ACTPKernel';
|
|
11
|
+
export { EscrowVault } from './protocol/EscrowVault';
|
|
12
|
+
export { EventMonitor } from './protocol/EventMonitor';
|
|
13
|
+
export { ProofGenerator } from './protocol/ProofGenerator';
|
|
14
|
+
export { MessageSigner } from './protocol/MessageSigner';
|
|
15
|
+
export { EASHelper, EASConfig } from './protocol/EASHelper';
|
|
16
|
+
export { QuoteBuilder, QuoteParams, QuoteMessage } from './protocol/QuoteBuilder';
|
|
17
|
+
|
|
18
|
+
// Types
|
|
19
|
+
export {
|
|
20
|
+
State,
|
|
21
|
+
StateMachine,
|
|
22
|
+
Transaction,
|
|
23
|
+
CreateTransactionParams,
|
|
24
|
+
DisputeResolution,
|
|
25
|
+
EconomicParams,
|
|
26
|
+
Escrow,
|
|
27
|
+
ACTPMessage,
|
|
28
|
+
QuoteRequest,
|
|
29
|
+
QuoteResponse,
|
|
30
|
+
DeliveryProof,
|
|
31
|
+
DeliveryProofMessage,
|
|
32
|
+
EASAttestationData
|
|
33
|
+
} from './types';
|
|
34
|
+
|
|
35
|
+
// EIP-712 types
|
|
36
|
+
export {
|
|
37
|
+
EIP712Domain,
|
|
38
|
+
AIP4DeliveryProofTypes,
|
|
39
|
+
AIP4DeliveryProofData,
|
|
40
|
+
DeliveryProofTypes,
|
|
41
|
+
DeliveryProofData,
|
|
42
|
+
deliveryProofDataFromProof
|
|
43
|
+
} from './types/eip712';
|
|
44
|
+
|
|
45
|
+
// Builders
|
|
46
|
+
export {
|
|
47
|
+
DeliveryProofBuilder,
|
|
48
|
+
DeliveryProofParams,
|
|
49
|
+
AGIRAILS_DELIVERY_SCHEMA_UID
|
|
50
|
+
} from './builders';
|
|
51
|
+
|
|
52
|
+
// Utilities
|
|
53
|
+
export {
|
|
54
|
+
canonicalJsonStringify,
|
|
55
|
+
computeCanonicalHash,
|
|
56
|
+
computeResultHash
|
|
57
|
+
} from './utils/canonicalJson';
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
IPFSClient,
|
|
61
|
+
IPFSHTTPClientImpl,
|
|
62
|
+
IPFSClientConfig,
|
|
63
|
+
createIPFSClient,
|
|
64
|
+
IPFS_CONFIGS
|
|
65
|
+
} from './utils/IPFSClient';
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
NonceManager,
|
|
69
|
+
InMemoryNonceManager,
|
|
70
|
+
DIDScopedNonceManager,
|
|
71
|
+
createNonceManager
|
|
72
|
+
} from './utils/NonceManager';
|
|
73
|
+
|
|
74
|
+
// V4 Security: Nonce Replay Protection
|
|
75
|
+
export {
|
|
76
|
+
IReceivedNonceTracker,
|
|
77
|
+
InMemoryReceivedNonceTracker,
|
|
78
|
+
SetBasedReceivedNonceTracker,
|
|
79
|
+
createReceivedNonceTracker,
|
|
80
|
+
NonceValidationResult
|
|
81
|
+
} from './utils/ReceivedNonceTracker';
|
|
82
|
+
|
|
83
|
+
// Validation utilities
|
|
84
|
+
export {
|
|
85
|
+
validateAddress,
|
|
86
|
+
validateAmount,
|
|
87
|
+
validateDeadline,
|
|
88
|
+
validateDisputeWindow,
|
|
89
|
+
validateTxId
|
|
90
|
+
} from './utils/validation';
|
|
91
|
+
|
|
92
|
+
// Errors
|
|
93
|
+
export {
|
|
94
|
+
ACTPError,
|
|
95
|
+
InsufficientFundsError,
|
|
96
|
+
TransactionNotFoundError,
|
|
97
|
+
DeadlineExpiredError,
|
|
98
|
+
InvalidStateTransitionError,
|
|
99
|
+
SignatureVerificationError,
|
|
100
|
+
TransactionRevertedError,
|
|
101
|
+
NetworkError,
|
|
102
|
+
ValidationError,
|
|
103
|
+
InvalidAddressError,
|
|
104
|
+
InvalidAmountError
|
|
105
|
+
} from './errors';
|
|
106
|
+
|
|
107
|
+
// Configuration
|
|
108
|
+
export { NetworkConfig, NETWORKS, getNetwork, isValidNetwork } from './config/networks';
|