@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
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# @agirails/sdk
|
|
2
|
+
|
|
3
|
+
Protocol SDK for ACTP (Agent Commerce Transaction Protocol)
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @agirails/sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @agirails/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { ACTPClient, State } from '@agirails/sdk';
|
|
17
|
+
import { ethers } from 'ethers';
|
|
18
|
+
|
|
19
|
+
// Initialize client (async factory pattern ensures EIP-712 domain is ready)
|
|
20
|
+
const client = await ACTPClient.create({
|
|
21
|
+
network: 'base-sepolia',
|
|
22
|
+
privateKey: process.env.PRIVATE_KEY
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Create transaction
|
|
26
|
+
const txId = await client.kernel.createTransaction({
|
|
27
|
+
provider: '0xProviderAddress...',
|
|
28
|
+
requester: await client.getAddress(),
|
|
29
|
+
amount: ethers.utils.parseUnits('100', 6), // 100 USDC
|
|
30
|
+
deadline: Math.floor(Date.now() / 1000) + 86400, // 24 hours
|
|
31
|
+
disputeWindow: 3600 // 1 hour
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log(`Transaction created: ${txId}`);
|
|
35
|
+
|
|
36
|
+
// Watch transaction
|
|
37
|
+
client.events.watchTransaction(txId, (state) => {
|
|
38
|
+
console.log(`State changed to: ${State[state]}`);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Get transaction
|
|
42
|
+
const tx = await client.kernel.getTransaction(txId);
|
|
43
|
+
console.log('Transaction:', tx);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
- ✅ **Protocol SDK** - Direct blockchain interaction with ACTP Kernel
|
|
49
|
+
- ✅ **State Machine** - Full ACTP state validation (8 states)
|
|
50
|
+
- ✅ **Event Monitoring** - Real-time blockchain event listening
|
|
51
|
+
- ✅ **Message Signing** - Cryptographic signing per Yellow Paper §11.4
|
|
52
|
+
- ✅ **Proof Generation** - Content hashing & delivery proofs
|
|
53
|
+
- ✅ **TypeScript** - Full type safety
|
|
54
|
+
- ✅ **Base L2** - Optimized for Base Sepolia & Mainnet
|
|
55
|
+
|
|
56
|
+
## V1 Limitations
|
|
57
|
+
|
|
58
|
+
⚠️ **Important**: ACTP SDK v2.0.0-beta is designed for **Base Sepolia testnet** and controlled partner usage. The following limitations apply:
|
|
59
|
+
|
|
60
|
+
### 1. Attestation Validation is SDK-Enforced, Not Protocol-Enforced
|
|
61
|
+
|
|
62
|
+
The V1 ACTPKernel accepts attestation UIDs without on-chain validation. All verification (existence, schema, txId, revocation, expiry) is performed by SDK helpers like `releaseEscrowWithVerification()`.
|
|
63
|
+
|
|
64
|
+
**Security checks performed by SDK:**
|
|
65
|
+
- Attestation exists and UID matches
|
|
66
|
+
- Schema UID matches canonical delivery schema (`0x1b0e...ffce`)
|
|
67
|
+
- txId in attestation matches expected transaction
|
|
68
|
+
- Attestation is not revoked (`revocationTime === 0`)
|
|
69
|
+
- Attestation has not expired
|
|
70
|
+
|
|
71
|
+
**Integrators who bypass the SDK must implement equivalent verification logic.**
|
|
72
|
+
|
|
73
|
+
### 2. Multiple Attestations Per Transaction Are Possible
|
|
74
|
+
|
|
75
|
+
EAS does not enforce uniqueness - multiple attestations can exist for the same `txId`. The SDK uses the **first valid (non-revoked) attestation** provided. This policy is testnet-appropriate; V2 will enforce uniqueness at the protocol level.
|
|
76
|
+
|
|
77
|
+
### 3. This SDK is Not For Unrestricted Mainnet Usage
|
|
78
|
+
|
|
79
|
+
V2 will move critical verification on-chain. Until then, use only on Base Sepolia testnet with testnet USDC.
|
|
80
|
+
|
|
81
|
+
### Additional Limitations
|
|
82
|
+
|
|
83
|
+
| Area | Limitation | Workaround |
|
|
84
|
+
|------|------------|------------|
|
|
85
|
+
| Network Resilience | No automatic retry | Manual retry required |
|
|
86
|
+
| Timeout Handling | `tx.wait()` may hang | Set custom timeout |
|
|
87
|
+
| State Transitions | TOCTOU race condition | Contract provides final validation |
|
|
88
|
+
| Revocation Window | Attestation can be revoked between verify and settle | Use `releaseEscrowWithVerification()` |
|
|
89
|
+
|
|
90
|
+
See **[KNOWN_LIMITATIONS.md](./KNOWN_LIMITATIONS.md)** for detailed explanations and roadmap.
|
|
91
|
+
|
|
92
|
+
For full details, see the [EAS V1 Scope Governance Document](../../Docs/Governance/).
|
|
93
|
+
|
|
94
|
+
**V2.0 Planned**: On-chain attestation validation, uniqueness enforcement, multi-provider fallback
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Network Support
|
|
99
|
+
|
|
100
|
+
- **Base Sepolia** (testnet) - `chainId: 84532`
|
|
101
|
+
- **Base Mainnet** - `chainId: 8453`
|
|
102
|
+
|
|
103
|
+
## Documentation
|
|
104
|
+
|
|
105
|
+
- [SDK Specification](./sdk-specification.md)
|
|
106
|
+
- [Yellow Paper](../../Docs/99. Final Public Papers/Core/AGIRAILS_Yellow_Paper.md)
|
|
107
|
+
- [Examples](./examples/) *(coming soon)*
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Install dependencies
|
|
113
|
+
npm install
|
|
114
|
+
|
|
115
|
+
# Build
|
|
116
|
+
npm run build
|
|
117
|
+
|
|
118
|
+
# Unit tests (Jest - fast, no network)
|
|
119
|
+
npm test
|
|
120
|
+
|
|
121
|
+
# Integration tests (Hardhat - requires Base Sepolia RPC)
|
|
122
|
+
npm run test:integration
|
|
123
|
+
|
|
124
|
+
# Lint
|
|
125
|
+
npm run lint
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Integration Testing
|
|
129
|
+
|
|
130
|
+
Integration tests run against **deployed contracts** on Base Sepolia testnet:
|
|
131
|
+
|
|
132
|
+
**Prerequisites:**
|
|
133
|
+
1. Create `.env` file:
|
|
134
|
+
```bash
|
|
135
|
+
BASE_SEPOLIA_RPC=https://sepolia.base.org # or your Alchemy URL
|
|
136
|
+
PRIVATE_KEY=0x... # Account with Base Sepolia ETH for gas
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
2. Get testnet ETH:
|
|
140
|
+
- [Base Sepolia Faucet](https://www.coinbase.com/faucets/base-ethereum-goerli-faucet)
|
|
141
|
+
|
|
142
|
+
**Run tests:**
|
|
143
|
+
```bash
|
|
144
|
+
npx hardhat test --network base-sepolia
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Tests will:
|
|
148
|
+
- ✅ Connect to deployed ACTPKernel, EscrowVault, MockUSDC
|
|
149
|
+
- ✅ Mint test USDC (MockUSDC has open minting on testnet)
|
|
150
|
+
- ✅ Run full transaction lifecycle (INITIATED → SETTLED)
|
|
151
|
+
- ✅ Verify escrow release and fund transfers
|
|
152
|
+
|
|
153
|
+
## Contract Addresses
|
|
154
|
+
|
|
155
|
+
### Base Sepolia (Testnet) ✅ Deployed & Verified
|
|
156
|
+
- **ACTPKernel:** `0x6aDB650e185b0ee77981AC5279271f0Fa6CFe7ba` ([view](https://sepolia.basescan.org/address/0x6aDB650e185b0ee77981AC5279271f0Fa6CFe7ba#code))
|
|
157
|
+
- **EscrowVault:** `0x921edE340770db5DB6059B5B866be987d1b7311F` ([view](https://sepolia.basescan.org/address/0x921edE340770db5DB6059B5B866be987d1b7311F#code))
|
|
158
|
+
- **MockUSDC:** `0x444b4e1A65949AB2ac75979D5d0166Eb7A248Ccb` ([view](https://sepolia.basescan.org/address/0x444b4e1A65949AB2ac75979D5d0166Eb7A248Ccb#code))
|
|
159
|
+
- **EAS Contract:** `0x4200000000000000000000000000000000000021` (Base native)
|
|
160
|
+
- **EAS Schema Registry:** `0x4200000000000000000000000000000000000020` (Base native)
|
|
161
|
+
- **Delivery Schema UID:** `0x1b0ebdf0bd20c28ec9d5362571ce8715a55f46e81c3de2f9b0d8e1b95fb5ffce`
|
|
162
|
+
|
|
163
|
+
*Redeployed: 2025-11-25 | Fixed auto-transition in linkEscrow, optimizer-runs 200 | Matches src/config/networks.ts*
|
|
164
|
+
|
|
165
|
+
### Base Mainnet (Production)
|
|
166
|
+
- **ACTPKernel:** TBD *(pending mainnet deployment)*
|
|
167
|
+
- **EscrowVault:** TBD *(pending mainnet deployment)*
|
|
168
|
+
- **USDC:** `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` (official USDC on Base)
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
Apache-2.0
|
|
173
|
+
|
|
174
|
+
## Contributing
|
|
175
|
+
|
|
176
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) *(coming soon)*
|
|
177
|
+
|
|
178
|
+
## Support
|
|
179
|
+
|
|
180
|
+
- **Email:** developers@agirails.io
|
|
181
|
+
- **GitHub:** [github.com/agirails/actp-sdk-typescript](https://github.com/agirails/actp-sdk-typescript)
|
|
182
|
+
- **Discord:** [discord.gg/agirails](https://discord.gg/agirails)
|
|
183
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Signer } from 'ethers';
|
|
2
|
+
import type { JsonRpcProvider } from 'ethers';
|
|
3
|
+
import { ACTPKernel } from './protocol/ACTPKernel';
|
|
4
|
+
import { EscrowVault } from './protocol/EscrowVault';
|
|
5
|
+
import { EventMonitor } from './protocol/EventMonitor';
|
|
6
|
+
import { ProofGenerator } from './protocol/ProofGenerator';
|
|
7
|
+
import { MessageSigner } from './protocol/MessageSigner';
|
|
8
|
+
import { QuoteBuilder } from './builders/QuoteBuilder';
|
|
9
|
+
import { NetworkConfig } from './config/networks';
|
|
10
|
+
import { EASHelper, EASConfig } from './protocol/EASHelper';
|
|
11
|
+
export interface ACTPClientConfig {
|
|
12
|
+
network: 'base-sepolia' | 'base-mainnet';
|
|
13
|
+
privateKey?: string;
|
|
14
|
+
signer?: Signer;
|
|
15
|
+
provider?: JsonRpcProvider;
|
|
16
|
+
rpcUrl?: string;
|
|
17
|
+
contracts?: {
|
|
18
|
+
actpKernel?: string;
|
|
19
|
+
escrowVault?: string;
|
|
20
|
+
usdc?: string;
|
|
21
|
+
};
|
|
22
|
+
gasSettings?: {
|
|
23
|
+
maxFeePerGas?: bigint;
|
|
24
|
+
maxPriorityFeePerGas?: bigint;
|
|
25
|
+
};
|
|
26
|
+
eas?: EASConfig;
|
|
27
|
+
}
|
|
28
|
+
export declare class ACTPClient {
|
|
29
|
+
readonly kernel: ACTPKernel;
|
|
30
|
+
readonly escrow: EscrowVault;
|
|
31
|
+
readonly events: EventMonitor;
|
|
32
|
+
readonly proofGenerator: ProofGenerator;
|
|
33
|
+
readonly messageSigner: MessageSigner;
|
|
34
|
+
readonly quote: QuoteBuilder;
|
|
35
|
+
readonly eas?: EASHelper;
|
|
36
|
+
private readonly provider;
|
|
37
|
+
private readonly signer;
|
|
38
|
+
private readonly networkConfig;
|
|
39
|
+
private readonly nonceManager;
|
|
40
|
+
private readonly ipfs?;
|
|
41
|
+
private constructor();
|
|
42
|
+
static create(config: ACTPClientConfig): Promise<ACTPClient>;
|
|
43
|
+
initialize(): Promise<void>;
|
|
44
|
+
getAddress(): Promise<string>;
|
|
45
|
+
getNetworkConfig(): NetworkConfig;
|
|
46
|
+
getProvider(): JsonRpcProvider;
|
|
47
|
+
getBlockNumber(): Promise<number>;
|
|
48
|
+
getGasPrice(): Promise<bigint>;
|
|
49
|
+
releaseEscrowWithVerification(txId: string, attestationUID: string): Promise<void>;
|
|
50
|
+
private validateConfig;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=ACTPClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ACTPClient.d.ts","sourceRoot":"","sources":["../src/ACTPClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAc,MAAM,mBAAmB,CAAC;AAE9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AI,OAAO,CAAC,MAAM,CAAC;IAOnC,gBAAgB,IAAI,aAAa;IAOjC,WAAW,IAAI,eAAe;IAOxB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAWjC,WAAW;IAkCX,6BAA6B,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBxF,OAAO,CAAC,cAAc;CASvB"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ACTPClient = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const ACTPKernel_1 = require("./protocol/ACTPKernel");
|
|
6
|
+
const EscrowVault_1 = require("./protocol/EscrowVault");
|
|
7
|
+
const EventMonitor_1 = require("./protocol/EventMonitor");
|
|
8
|
+
const ProofGenerator_1 = require("./protocol/ProofGenerator");
|
|
9
|
+
const MessageSigner_1 = require("./protocol/MessageSigner");
|
|
10
|
+
const QuoteBuilder_1 = require("./builders/QuoteBuilder");
|
|
11
|
+
const networks_1 = require("./config/networks");
|
|
12
|
+
const errors_1 = require("./errors");
|
|
13
|
+
const EASHelper_1 = require("./protocol/EASHelper");
|
|
14
|
+
const NonceManager_1 = require("./utils/NonceManager");
|
|
15
|
+
class ACTPClient {
|
|
16
|
+
constructor(config) {
|
|
17
|
+
this.validateConfig(config);
|
|
18
|
+
this.networkConfig = (0, networks_1.getNetwork)(config.network);
|
|
19
|
+
if (config.contracts) {
|
|
20
|
+
this.networkConfig = {
|
|
21
|
+
...this.networkConfig,
|
|
22
|
+
contracts: {
|
|
23
|
+
...this.networkConfig.contracts,
|
|
24
|
+
...config.contracts
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (config.gasSettings) {
|
|
29
|
+
this.networkConfig = {
|
|
30
|
+
...this.networkConfig,
|
|
31
|
+
gasSettings: {
|
|
32
|
+
...this.networkConfig.gasSettings,
|
|
33
|
+
...config.gasSettings
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
Object.freeze(this.networkConfig.contracts);
|
|
38
|
+
Object.freeze(this.networkConfig.gasSettings);
|
|
39
|
+
Object.freeze(this.networkConfig);
|
|
40
|
+
if (config.provider) {
|
|
41
|
+
this.provider = config.provider;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const rpcUrl = config.rpcUrl || this.networkConfig.rpcUrl;
|
|
45
|
+
this.provider = new ethers_1.ethers.JsonRpcProvider(rpcUrl, this.networkConfig.chainId);
|
|
46
|
+
}
|
|
47
|
+
if (config.signer) {
|
|
48
|
+
this.signer = config.signer;
|
|
49
|
+
}
|
|
50
|
+
else if (config.privateKey) {
|
|
51
|
+
this.signer = new ethers_1.Wallet(config.privateKey, this.provider);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throw new errors_1.ValidationError('signer', 'Either privateKey or signer must be provided');
|
|
55
|
+
}
|
|
56
|
+
this.nonceManager = new NonceManager_1.InMemoryNonceManager();
|
|
57
|
+
if (config.rpcUrl) {
|
|
58
|
+
}
|
|
59
|
+
this.kernel = new ACTPKernel_1.ACTPKernel(this.networkConfig.contracts.actpKernel, this.signer, this.networkConfig.gasSettings);
|
|
60
|
+
this.escrow = new EscrowVault_1.EscrowVault(this.networkConfig.contracts.escrowVault, this.signer, this.networkConfig.gasSettings);
|
|
61
|
+
this.events = new EventMonitor_1.EventMonitor(this.kernel['contract'], this.escrow['contract']);
|
|
62
|
+
this.proofGenerator = new ProofGenerator_1.ProofGenerator();
|
|
63
|
+
this.messageSigner = new MessageSigner_1.MessageSigner(this.signer);
|
|
64
|
+
this.quote = new QuoteBuilder_1.QuoteBuilder(this.signer, this.nonceManager, this.ipfs);
|
|
65
|
+
if (config.eas) {
|
|
66
|
+
this.eas = new EASHelper_1.EASHelper(this.signer, config.eas);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
static async create(config) {
|
|
70
|
+
const client = new ACTPClient(config);
|
|
71
|
+
await client.messageSigner.initDomain(client.networkConfig.contracts.actpKernel);
|
|
72
|
+
return client;
|
|
73
|
+
}
|
|
74
|
+
async initialize() {
|
|
75
|
+
await this.messageSigner.initDomain(this.networkConfig.contracts.actpKernel);
|
|
76
|
+
}
|
|
77
|
+
async getAddress() {
|
|
78
|
+
return await this.signer.getAddress();
|
|
79
|
+
}
|
|
80
|
+
getNetworkConfig() {
|
|
81
|
+
return this.networkConfig;
|
|
82
|
+
}
|
|
83
|
+
getProvider() {
|
|
84
|
+
return this.provider;
|
|
85
|
+
}
|
|
86
|
+
async getBlockNumber() {
|
|
87
|
+
try {
|
|
88
|
+
return await this.provider.getBlockNumber();
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw new errors_1.NetworkError(this.networkConfig.name, error.message);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async getGasPrice() {
|
|
95
|
+
try {
|
|
96
|
+
const feeData = await this.provider.getFeeData();
|
|
97
|
+
return feeData.gasPrice || 0n;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
throw new errors_1.NetworkError(this.networkConfig.name, error.message);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async releaseEscrowWithVerification(txId, attestationUID) {
|
|
104
|
+
if (!this.eas) {
|
|
105
|
+
throw new Error('EAS is not configured. Initialize ACTPClient with eas config or use kernel.releaseEscrow() directly (unsafe)');
|
|
106
|
+
}
|
|
107
|
+
await this.eas.verifyDeliveryAttestation(txId, attestationUID);
|
|
108
|
+
await this.kernel.releaseEscrow(txId);
|
|
109
|
+
}
|
|
110
|
+
validateConfig(config) {
|
|
111
|
+
if (!config.network) {
|
|
112
|
+
throw new errors_1.ValidationError('network', 'Network is required');
|
|
113
|
+
}
|
|
114
|
+
if (!config.privateKey && !config.signer && !config.provider) {
|
|
115
|
+
throw new errors_1.ValidationError('auth', 'Provide either privateKey, signer, or provider with signer access');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.ACTPClient = ACTPClient;
|
|
120
|
+
//# sourceMappingURL=ACTPClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ACTPClient.js","sourceRoot":"","sources":["../src/ACTPClient.ts"],"names":[],"mappings":";;;AAAA,mCAAgD;AAEhD,sDAAmD;AACnD,wDAAqD;AACrD,0DAAuD;AACvD,8DAA2D;AAC3D,4DAAyD;AACzD,0DAAuD;AACvD,gDAA8D;AAC9D,qCAAyD;AACzD,oDAA4D;AAC5D,uDAA0E;AAqC1E,MAAa,UAAU;IAkBrB,YAAoB,MAAwB;QAE1C,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAG5B,IAAI,CAAC,aAAa,GAAG,IAAA,qBAAU,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAGhD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,IAAI,CAAC,aAAa,GAAG;gBACnB,GAAG,IAAI,CAAC,aAAa;gBACrB,SAAS,EAAE;oBACT,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS;oBAC/B,GAAG,MAAM,CAAC,SAAS;iBACpB;aACF,CAAC;QACJ,CAAC;QAGD,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YACvB,IAAI,CAAC,aAAa,GAAG;gBACnB,GAAG,IAAI,CAAC,aAAa;gBACrB,WAAW,EAAE;oBACX,GAAG,IAAI,CAAC,aAAa,CAAC,WAAW;oBACjC,GAAG,MAAM,CAAC,WAAW;iBACtB;aACF,CAAC;QACJ,CAAC;QAGD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QAC5C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAC9C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC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