@agirails/sdk 2.2.3 → 2.3.1
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 +65 -31
- package/dist/ACTPClient.d.ts +42 -1
- package/dist/ACTPClient.d.ts.map +1 -1
- package/dist/ACTPClient.js +207 -22
- package/dist/ACTPClient.js.map +1 -1
- package/dist/abi/AgentRegistry.json +133 -0
- package/dist/adapters/AdapterRouter.d.ts.map +1 -1
- package/dist/adapters/AdapterRouter.js.map +1 -1
- package/dist/adapters/BasicAdapter.d.ts +10 -1
- package/dist/adapters/BasicAdapter.d.ts.map +1 -1
- package/dist/adapters/BasicAdapter.js +36 -1
- package/dist/adapters/BasicAdapter.js.map +1 -1
- package/dist/adapters/X402Adapter.d.ts +34 -7
- package/dist/adapters/X402Adapter.d.ts.map +1 -1
- package/dist/adapters/X402Adapter.js +36 -8
- package/dist/adapters/X402Adapter.js.map +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/cli/commands/diff.d.ts +11 -0
- package/dist/cli/commands/diff.d.ts.map +1 -0
- package/dist/cli/commands/diff.js +115 -0
- package/dist/cli/commands/diff.js.map +1 -0
- package/dist/cli/commands/init.d.ts +1 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +260 -19
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/publish.d.ts +11 -0
- package/dist/cli/commands/publish.d.ts.map +1 -0
- package/dist/cli/commands/publish.js +170 -0
- package/dist/cli/commands/publish.js.map +1 -0
- package/dist/cli/commands/pull.d.ts +12 -0
- package/dist/cli/commands/pull.d.ts.map +1 -0
- package/dist/cli/commands/pull.js +99 -0
- package/dist/cli/commands/pull.js.map +1 -0
- package/dist/cli/commands/register.d.ts +16 -0
- package/dist/cli/commands/register.d.ts.map +1 -0
- package/dist/cli/commands/register.js +211 -0
- package/dist/cli/commands/register.js.map +1 -0
- package/dist/cli/index.js +10 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/utils/config.d.ts +6 -0
- package/dist/cli/utils/config.d.ts.map +1 -1
- package/dist/cli/utils/config.js.map +1 -1
- package/dist/config/agirailsmd.d.ts +94 -0
- package/dist/config/agirailsmd.d.ts.map +1 -0
- package/dist/config/agirailsmd.js +209 -0
- package/dist/config/agirailsmd.js.map +1 -0
- package/dist/config/networks.d.ts +22 -4
- package/dist/config/networks.d.ts.map +1 -1
- package/dist/config/networks.js +64 -26
- package/dist/config/networks.js.map +1 -1
- package/dist/config/publishPipeline.d.ts +75 -0
- package/dist/config/publishPipeline.d.ts.map +1 -0
- package/dist/config/publishPipeline.js +193 -0
- package/dist/config/publishPipeline.js.map +1 -0
- package/dist/config/syncOperations.d.ts +67 -0
- package/dist/config/syncOperations.d.ts.map +1 -0
- package/dist/config/syncOperations.js +208 -0
- package/dist/config/syncOperations.js.map +1 -0
- package/dist/erc8004/ERC8004Bridge.d.ts.map +1 -1
- package/dist/erc8004/ERC8004Bridge.js +6 -5
- package/dist/erc8004/ERC8004Bridge.js.map +1 -1
- package/dist/erc8004/ReputationReporter.d.ts.map +1 -1
- package/dist/erc8004/ReputationReporter.js +9 -12
- package/dist/erc8004/ReputationReporter.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/level0/request.d.ts.map +1 -1
- package/dist/level0/request.js +23 -86
- package/dist/level0/request.js.map +1 -1
- package/dist/level1/Agent.d.ts +0 -11
- package/dist/level1/Agent.d.ts.map +1 -1
- package/dist/level1/Agent.js +19 -36
- package/dist/level1/Agent.js.map +1 -1
- package/dist/protocol/ACTPKernel.d.ts +7 -1
- package/dist/protocol/ACTPKernel.d.ts.map +1 -1
- package/dist/protocol/ACTPKernel.js +13 -10
- package/dist/protocol/ACTPKernel.js.map +1 -1
- package/dist/protocol/EventMonitor.d.ts +14 -0
- package/dist/protocol/EventMonitor.d.ts.map +1 -1
- package/dist/protocol/EventMonitor.js +14 -0
- package/dist/protocol/EventMonitor.js.map +1 -1
- package/dist/registry/AgentRegistryClient.d.ts +75 -0
- package/dist/registry/AgentRegistryClient.d.ts.map +1 -0
- package/dist/registry/AgentRegistryClient.js +160 -0
- package/dist/registry/AgentRegistryClient.js.map +1 -0
- package/dist/runtime/BlockchainRuntime.d.ts +5 -0
- package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
- package/dist/runtime/BlockchainRuntime.js +1 -1
- package/dist/runtime/BlockchainRuntime.js.map +1 -1
- package/dist/storage/ArchiveBundleBuilder.d.ts.map +1 -1
- package/dist/storage/ArchiveBundleBuilder.js.map +1 -1
- package/dist/storage/ArweaveClient.d.ts.map +1 -1
- package/dist/storage/ArweaveClient.js +2 -0
- package/dist/storage/ArweaveClient.js.map +1 -1
- package/dist/storage/FilebaseClient.d.ts.map +1 -1
- package/dist/storage/FilebaseClient.js +2 -0
- package/dist/storage/FilebaseClient.js.map +1 -1
- package/dist/types/adapter.d.ts +39 -0
- package/dist/types/adapter.d.ts.map +1 -1
- package/dist/types/adapter.js +7 -0
- package/dist/types/adapter.js.map +1 -1
- package/dist/types/x402.d.ts +23 -0
- package/dist/types/x402.d.ts.map +1 -1
- package/dist/types/x402.js.map +1 -1
- package/dist/utils/ErrorRecoveryGuide.d.ts.map +1 -1
- package/dist/utils/ErrorRecoveryGuide.js +3 -2
- package/dist/utils/ErrorRecoveryGuide.js.map +1 -1
- package/dist/utils/IPFSClient.d.ts +3 -2
- package/dist/utils/IPFSClient.d.ts.map +1 -1
- package/dist/utils/IPFSClient.js +7 -5
- package/dist/utils/IPFSClient.js.map +1 -1
- package/dist/utils/computeTypeHash.js +1 -3
- package/dist/utils/computeTypeHash.js.map +1 -1
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +0 -1
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/validation.d.ts +2 -2
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +2 -2
- package/dist/utils/validation.js.map +1 -1
- package/dist/wallet/AutoWalletProvider.d.ts +77 -0
- package/dist/wallet/AutoWalletProvider.d.ts.map +1 -0
- package/dist/wallet/AutoWalletProvider.js +197 -0
- package/dist/wallet/AutoWalletProvider.js.map +1 -0
- package/dist/wallet/EOAWalletProvider.d.ts +21 -0
- package/dist/wallet/EOAWalletProvider.d.ts.map +1 -0
- package/dist/wallet/EOAWalletProvider.js +57 -0
- package/dist/wallet/EOAWalletProvider.js.map +1 -0
- package/dist/wallet/IWalletProvider.d.ts +115 -0
- package/dist/wallet/IWalletProvider.d.ts.map +1 -0
- package/dist/wallet/IWalletProvider.js +12 -0
- package/dist/wallet/IWalletProvider.js.map +1 -0
- package/dist/wallet/aa/BundlerClient.d.ts +70 -0
- package/dist/wallet/aa/BundlerClient.d.ts.map +1 -0
- package/dist/wallet/aa/BundlerClient.js +183 -0
- package/dist/wallet/aa/BundlerClient.js.map +1 -0
- package/dist/wallet/aa/DualNonceManager.d.ts +55 -0
- package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -0
- package/dist/wallet/aa/DualNonceManager.js +131 -0
- package/dist/wallet/aa/DualNonceManager.js.map +1 -0
- package/dist/wallet/aa/PaymasterClient.d.ts +52 -0
- package/dist/wallet/aa/PaymasterClient.d.ts.map +1 -0
- package/dist/wallet/aa/PaymasterClient.js +115 -0
- package/dist/wallet/aa/PaymasterClient.js.map +1 -0
- package/dist/wallet/aa/TransactionBatcher.d.ts +87 -0
- package/dist/wallet/aa/TransactionBatcher.d.ts.map +1 -0
- package/dist/wallet/aa/TransactionBatcher.js +148 -0
- package/dist/wallet/aa/TransactionBatcher.js.map +1 -0
- package/dist/wallet/aa/UserOpBuilder.d.ts +71 -0
- package/dist/wallet/aa/UserOpBuilder.d.ts.map +1 -0
- package/dist/wallet/aa/UserOpBuilder.js +196 -0
- package/dist/wallet/aa/UserOpBuilder.js.map +1 -0
- package/dist/wallet/aa/constants.d.ts +54 -0
- package/dist/wallet/aa/constants.d.ts.map +1 -0
- package/dist/wallet/aa/constants.js +18 -0
- package/dist/wallet/aa/constants.js.map +1 -0
- package/dist/wallet/keystore.d.ts +16 -0
- package/dist/wallet/keystore.d.ts.map +1 -0
- package/dist/wallet/keystore.js +132 -0
- package/dist/wallet/keystore.js.map +1 -0
- package/package.json +5 -2
- package/src/ACTPClient.ts +275 -27
- package/src/abi/AgentRegistry.json +133 -0
- package/src/adapters/AdapterRouter.ts +0 -1
- package/src/adapters/BasicAdapter.ts +41 -1
- package/src/adapters/X402Adapter.ts +94 -16
- package/src/adapters/index.ts +9 -1
- package/src/cli/commands/diff.ts +141 -0
- package/src/cli/commands/init.ts +311 -22
- package/src/cli/commands/publish.ts +208 -0
- package/src/cli/commands/pull.ts +124 -0
- package/src/cli/commands/register.ts +233 -0
- package/src/cli/index.ts +12 -0
- package/src/cli/utils/config.ts +9 -0
- package/src/config/agirailsmd.ts +262 -0
- package/src/config/networks.ts +89 -26
- package/src/config/publishPipeline.ts +276 -0
- package/src/config/syncOperations.ts +279 -0
- package/src/erc8004/ERC8004Bridge.ts +6 -5
- package/src/erc8004/ReputationReporter.ts +14 -18
- package/src/index.ts +15 -0
- package/src/level0/request.ts +27 -88
- package/src/level1/Agent.ts +21 -37
- package/src/protocol/ACTPKernel.ts +20 -10
- package/src/protocol/EventMonitor.ts +14 -0
- package/src/registry/AgentRegistryClient.ts +202 -0
- package/src/runtime/BlockchainRuntime.ts +7 -1
- package/src/storage/ArchiveBundleBuilder.ts +0 -2
- package/src/storage/ArweaveClient.ts +2 -1
- package/src/storage/FilebaseClient.ts +3 -3
- package/src/types/adapter.ts +14 -0
- package/src/types/x402.ts +32 -0
- package/src/utils/ErrorRecoveryGuide.ts +4 -2
- package/src/utils/IPFSClient.ts +9 -7
- package/src/utils/computeTypeHash.ts +1 -3
- package/src/utils/retry.ts +0 -1
- package/src/utils/validation.ts +2 -2
- package/src/wallet/AutoWalletProvider.ts +294 -0
- package/src/wallet/EOAWalletProvider.ts +69 -0
- package/src/wallet/IWalletProvider.ts +133 -0
- package/src/wallet/aa/BundlerClient.ts +273 -0
- package/src/wallet/aa/DualNonceManager.ts +163 -0
- package/src/wallet/aa/PaymasterClient.ts +173 -0
- package/src/wallet/aa/TransactionBatcher.ts +240 -0
- package/src/wallet/aa/UserOpBuilder.ts +246 -0
- package/src/wallet/aa/constants.ts +60 -0
- package/src/wallet/keystore.ts +119 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sync Operations - Pull + Diff for AGIRAILS.md
|
|
3
|
+
*
|
|
4
|
+
* Terraform-style sync: compare local AGIRAILS.md with on-chain state.
|
|
5
|
+
* Never auto-overwrites — shows diff and requires explicit confirmation.
|
|
6
|
+
*
|
|
7
|
+
* @module config/syncOperations
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { readFileSync, writeFileSync, existsSync } from 'fs';
|
|
11
|
+
import { Provider } from 'ethers';
|
|
12
|
+
import { computeConfigHash, parseAgirailsMd, serializeAgirailsMd } from './agirailsmd';
|
|
13
|
+
import { validateCID } from '../utils/validation';
|
|
14
|
+
import { AgentRegistryClient } from '../registry/AgentRegistryClient';
|
|
15
|
+
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Constants
|
|
18
|
+
// ============================================================================
|
|
19
|
+
|
|
20
|
+
/** Public IPFS gateways for read-only access (no credentials needed) */
|
|
21
|
+
const IPFS_GATEWAYS = [
|
|
22
|
+
'https://ipfs.io/ipfs/',
|
|
23
|
+
'https://dweb.link/ipfs/',
|
|
24
|
+
'https://cloudflare-ipfs.com/ipfs/',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// Types
|
|
29
|
+
// ============================================================================
|
|
30
|
+
|
|
31
|
+
export interface DiffResult {
|
|
32
|
+
/** Whether local and on-chain are in sync */
|
|
33
|
+
inSync: boolean;
|
|
34
|
+
/** Local config hash (or null if no local file) */
|
|
35
|
+
localHash: string | null;
|
|
36
|
+
/** On-chain config hash (or zero hash if not published) */
|
|
37
|
+
onChainHash: string;
|
|
38
|
+
/** On-chain IPFS CID (or empty if not published) */
|
|
39
|
+
onChainCID: string;
|
|
40
|
+
/** Whether on-chain has a published config */
|
|
41
|
+
hasOnChainConfig: boolean;
|
|
42
|
+
/** Whether local file exists */
|
|
43
|
+
hasLocalFile: boolean;
|
|
44
|
+
/** Human-readable status message */
|
|
45
|
+
status: 'in-sync' | 'local-ahead' | 'remote-ahead' | 'diverged' | 'no-local' | 'no-remote';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface PullResult {
|
|
49
|
+
/** Whether a file was written */
|
|
50
|
+
written: boolean;
|
|
51
|
+
/** The pulled content (if any) */
|
|
52
|
+
content?: string;
|
|
53
|
+
/** IPFS CID that was fetched */
|
|
54
|
+
cid?: string;
|
|
55
|
+
/** Status message */
|
|
56
|
+
status: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface DiffOptions {
|
|
60
|
+
/** Path to local AGIRAILS.md */
|
|
61
|
+
path: string;
|
|
62
|
+
/** Agent address to check on-chain */
|
|
63
|
+
agentAddress: string;
|
|
64
|
+
/** AgentRegistry contract address */
|
|
65
|
+
registryAddress: string;
|
|
66
|
+
/** Provider for reading on-chain state */
|
|
67
|
+
provider: Provider;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface PullOptions extends DiffOptions {
|
|
71
|
+
/** Force overwrite without confirmation */
|
|
72
|
+
force?: boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ============================================================================
|
|
76
|
+
// Diff
|
|
77
|
+
// ============================================================================
|
|
78
|
+
|
|
79
|
+
const ZERO_HASH = '0x' + '0'.repeat(64);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Compare local AGIRAILS.md with on-chain config state.
|
|
83
|
+
*
|
|
84
|
+
* @param options - Diff configuration
|
|
85
|
+
* @returns Diff result showing sync status
|
|
86
|
+
*/
|
|
87
|
+
export async function diff(options: DiffOptions): Promise<DiffResult> {
|
|
88
|
+
const { path, agentAddress, registryAddress, provider } = options;
|
|
89
|
+
|
|
90
|
+
// Read on-chain state
|
|
91
|
+
const registryClient = AgentRegistryClient.readOnly(registryAddress, provider);
|
|
92
|
+
const onChainState = await registryClient.getConfig(agentAddress);
|
|
93
|
+
|
|
94
|
+
const hasOnChainConfig = onChainState.configHash !== ZERO_HASH && onChainState.configCID !== '';
|
|
95
|
+
const onChainHash = onChainState.configHash;
|
|
96
|
+
const onChainCID = onChainState.configCID;
|
|
97
|
+
|
|
98
|
+
// Read local state
|
|
99
|
+
const hasLocalFile = existsSync(path);
|
|
100
|
+
let localHash: string | null = null;
|
|
101
|
+
|
|
102
|
+
if (hasLocalFile) {
|
|
103
|
+
const content = readFileSync(path, 'utf-8');
|
|
104
|
+
const { configHash } = computeConfigHash(content);
|
|
105
|
+
localHash = configHash;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Determine status
|
|
109
|
+
let status: DiffResult['status'];
|
|
110
|
+
let inSync: boolean;
|
|
111
|
+
|
|
112
|
+
if (!hasLocalFile && !hasOnChainConfig) {
|
|
113
|
+
status = 'no-local';
|
|
114
|
+
inSync = true; // both empty = in sync
|
|
115
|
+
} else if (!hasLocalFile && hasOnChainConfig) {
|
|
116
|
+
status = 'remote-ahead';
|
|
117
|
+
inSync = false;
|
|
118
|
+
} else if (hasLocalFile && !hasOnChainConfig) {
|
|
119
|
+
status = 'no-remote';
|
|
120
|
+
inSync = false;
|
|
121
|
+
} else if (localHash === onChainHash) {
|
|
122
|
+
status = 'in-sync';
|
|
123
|
+
inSync = true;
|
|
124
|
+
} else {
|
|
125
|
+
// Both exist but hashes differ. Use the stored config_hash in frontmatter
|
|
126
|
+
// to determine directionality:
|
|
127
|
+
// - config_hash matches on-chain → user edited locally after last publish → local-ahead
|
|
128
|
+
// - config_hash doesn't match on-chain → remote was updated too → diverged
|
|
129
|
+
// - no config_hash → never published from this file → local-ahead
|
|
130
|
+
status = 'diverged';
|
|
131
|
+
inSync = false;
|
|
132
|
+
|
|
133
|
+
if (hasLocalFile) {
|
|
134
|
+
try {
|
|
135
|
+
const content = readFileSync(path, 'utf-8');
|
|
136
|
+
const { frontmatter } = parseAgirailsMd(content);
|
|
137
|
+
if (!frontmatter.config_hash) {
|
|
138
|
+
// Never published — local is the only source
|
|
139
|
+
status = 'local-ahead';
|
|
140
|
+
} else if (frontmatter.config_hash === onChainHash) {
|
|
141
|
+
// Last publish matches on-chain, so local edits are newer
|
|
142
|
+
status = 'local-ahead';
|
|
143
|
+
}
|
|
144
|
+
// else: frontmatter.config_hash !== onChainHash → remote updated → diverged
|
|
145
|
+
} catch {
|
|
146
|
+
// Parse error — keep as diverged
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
inSync,
|
|
153
|
+
localHash,
|
|
154
|
+
onChainHash,
|
|
155
|
+
onChainCID,
|
|
156
|
+
hasOnChainConfig,
|
|
157
|
+
hasLocalFile,
|
|
158
|
+
status,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ============================================================================
|
|
163
|
+
// IPFS Fetch (public gateway, no credentials needed)
|
|
164
|
+
// ============================================================================
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Fetch content from IPFS using public gateways (no Filebase credentials needed).
|
|
168
|
+
* Tries multiple gateways with fallback.
|
|
169
|
+
*
|
|
170
|
+
* @param cid - IPFS CID to fetch (validated before use)
|
|
171
|
+
* @returns Raw content as string
|
|
172
|
+
* @throws InvalidCIDError if CID format is invalid
|
|
173
|
+
* @throws Error if all gateways fail
|
|
174
|
+
*/
|
|
175
|
+
async function fetchFromIPFS(cid: string): Promise<string> {
|
|
176
|
+
// Validate CID format before hitting any gateway
|
|
177
|
+
validateCID(cid, 'onChainCID');
|
|
178
|
+
|
|
179
|
+
const errors: string[] = [];
|
|
180
|
+
|
|
181
|
+
for (const gateway of IPFS_GATEWAYS) {
|
|
182
|
+
try {
|
|
183
|
+
const response = await fetch(`${gateway}${cid}`, {
|
|
184
|
+
signal: AbortSignal.timeout(15_000),
|
|
185
|
+
});
|
|
186
|
+
if (!response.ok) {
|
|
187
|
+
errors.push(`${gateway}: HTTP ${response.status}`);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
return await response.text();
|
|
191
|
+
} catch (err) {
|
|
192
|
+
errors.push(`${gateway}: ${err instanceof Error ? err.message : String(err)}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
throw new Error(
|
|
197
|
+
`Failed to fetch CID ${cid} from all IPFS gateways:\n${errors.map(e => ` - ${e}`).join('\n')}`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ============================================================================
|
|
202
|
+
// Pull
|
|
203
|
+
// ============================================================================
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Pull on-chain config to local AGIRAILS.md.
|
|
207
|
+
*
|
|
208
|
+
* Downloads from IPFS via public gateways (no Filebase credentials needed),
|
|
209
|
+
* verifies integrity against on-chain configHash, then writes locally.
|
|
210
|
+
*
|
|
211
|
+
* @param options - Pull configuration
|
|
212
|
+
* @returns Pull result
|
|
213
|
+
*/
|
|
214
|
+
export async function pull(options: PullOptions): Promise<PullResult> {
|
|
215
|
+
const { path, agentAddress, registryAddress, provider, force = false } = options;
|
|
216
|
+
|
|
217
|
+
// First, run diff
|
|
218
|
+
const diffResult = await diff({ path, agentAddress, registryAddress, provider });
|
|
219
|
+
|
|
220
|
+
if (!diffResult.hasOnChainConfig) {
|
|
221
|
+
return {
|
|
222
|
+
written: false,
|
|
223
|
+
status: 'No config published on-chain for this agent.',
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (diffResult.inSync) {
|
|
228
|
+
return {
|
|
229
|
+
written: false,
|
|
230
|
+
status: 'Already in sync. No changes needed.',
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Fetch raw AGIRAILS.md from IPFS (public gateway, no credentials)
|
|
235
|
+
const content = await fetchFromIPFS(diffResult.onChainCID);
|
|
236
|
+
|
|
237
|
+
// Integrity verification: hash downloaded content and compare with on-chain hash
|
|
238
|
+
const { configHash: downloadedHash } = computeConfigHash(content);
|
|
239
|
+
if (downloadedHash !== diffResult.onChainHash) {
|
|
240
|
+
return {
|
|
241
|
+
written: false,
|
|
242
|
+
cid: diffResult.onChainCID,
|
|
243
|
+
status: `Integrity check failed! Downloaded content hash (${downloadedHash}) does not match on-chain hash (${diffResult.onChainHash}). The IPFS content may have been tampered with.`,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Check if local file exists and we're not forcing
|
|
248
|
+
if (diffResult.hasLocalFile && !force) {
|
|
249
|
+
return {
|
|
250
|
+
written: false,
|
|
251
|
+
content,
|
|
252
|
+
cid: diffResult.onChainCID,
|
|
253
|
+
status: `Remote config differs from local. Use --force to overwrite. CID: ${diffResult.onChainCID}`,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Stamp on-chain metadata into frontmatter so diff heuristic can detect
|
|
258
|
+
// future remote changes (without this, pulled files have no config_hash
|
|
259
|
+
// and diff would always report "local-ahead" instead of "diverged")
|
|
260
|
+
const { frontmatter, body } = parseAgirailsMd(content);
|
|
261
|
+
const stamped = serializeAgirailsMd(
|
|
262
|
+
{
|
|
263
|
+
...frontmatter,
|
|
264
|
+
config_hash: diffResult.onChainHash,
|
|
265
|
+
config_cid: diffResult.onChainCID,
|
|
266
|
+
},
|
|
267
|
+
body
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
// Write the stamped file
|
|
271
|
+
writeFileSync(path, stamped, 'utf-8');
|
|
272
|
+
|
|
273
|
+
return {
|
|
274
|
+
written: true,
|
|
275
|
+
content: stamped,
|
|
276
|
+
cid: diffResult.onChainCID,
|
|
277
|
+
status: `Pulled and verified config from IPFS (${diffResult.onChainCID}) → ${path}`,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
ERC8004_IDENTITY_ABI,
|
|
39
39
|
ERC8004_DEFAULT_RPC,
|
|
40
40
|
} from '../types/erc8004';
|
|
41
|
+
import { sdkLogger } from '../utils/Logger';
|
|
41
42
|
|
|
42
43
|
// ============================================================================
|
|
43
44
|
// Types
|
|
@@ -137,7 +138,7 @@ export class ERC8004Bridge {
|
|
|
137
138
|
config.registryAddress ?? ERC8004_IDENTITY_REGISTRY[config.network];
|
|
138
139
|
|
|
139
140
|
if (registryAddress === ethers.ZeroAddress) {
|
|
140
|
-
|
|
141
|
+
sdkLogger.warn(
|
|
141
142
|
`[ERC8004] Registry not deployed on ${config.network}. Using zero address.`
|
|
142
143
|
);
|
|
143
144
|
}
|
|
@@ -327,7 +328,7 @@ export class ERC8004Bridge {
|
|
|
327
328
|
|
|
328
329
|
return agentIds;
|
|
329
330
|
} catch (error) {
|
|
330
|
-
|
|
331
|
+
sdkLogger.warn(`[ERC8004] Failed to get agents for owner ${owner}: ${error instanceof Error ? error.message : error}`);
|
|
331
332
|
return [];
|
|
332
333
|
}
|
|
333
334
|
}
|
|
@@ -417,7 +418,7 @@ export class ERC8004Bridge {
|
|
|
417
418
|
|
|
418
419
|
// Validate URL
|
|
419
420
|
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
|
420
|
-
|
|
421
|
+
sdkLogger.warn(`[ERC8004] Invalid agentURI scheme for ${agentId}: ${url}`);
|
|
421
422
|
return undefined;
|
|
422
423
|
}
|
|
423
424
|
|
|
@@ -434,7 +435,7 @@ export class ERC8004Bridge {
|
|
|
434
435
|
clearTimeout(timeoutId);
|
|
435
436
|
|
|
436
437
|
if (!response.ok) {
|
|
437
|
-
|
|
438
|
+
sdkLogger.warn(
|
|
438
439
|
`[ERC8004] Metadata fetch failed for ${agentId}: HTTP ${response.status}`
|
|
439
440
|
);
|
|
440
441
|
return undefined;
|
|
@@ -454,7 +455,7 @@ export class ERC8004Bridge {
|
|
|
454
455
|
: error.message
|
|
455
456
|
: 'unknown error';
|
|
456
457
|
|
|
457
|
-
|
|
458
|
+
sdkLogger.warn(`[ERC8004] Metadata fetch failed for ${agentId}: ${errorMessage}`);
|
|
458
459
|
return undefined;
|
|
459
460
|
}
|
|
460
461
|
}
|
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
ERC8004_REPUTATION_ABI,
|
|
51
51
|
ACTP_FEEDBACK_TAGS,
|
|
52
52
|
} from '../types/erc8004';
|
|
53
|
+
import { sdkLogger } from '../utils/Logger';
|
|
53
54
|
|
|
54
55
|
// ============================================================================
|
|
55
56
|
// Types
|
|
@@ -214,9 +215,8 @@ export class ReputationReporter {
|
|
|
214
215
|
config.registryAddress ?? ERC8004_REPUTATION_REGISTRY[config.network];
|
|
215
216
|
|
|
216
217
|
if (registryAddress === ethers.ZeroAddress) {
|
|
217
|
-
|
|
218
|
-
`[ERC8004] Reputation Registry not deployed on ${config.network}.
|
|
219
|
-
'Reports will fail.'
|
|
218
|
+
sdkLogger.warn(
|
|
219
|
+
`[ERC8004] Reputation Registry not deployed on ${config.network}. Reports will fail.`
|
|
220
220
|
);
|
|
221
221
|
}
|
|
222
222
|
|
|
@@ -257,7 +257,7 @@ export class ReputationReporter {
|
|
|
257
257
|
|
|
258
258
|
// Local dedup check
|
|
259
259
|
if (this.reportedTxIds.has(txId)) {
|
|
260
|
-
|
|
260
|
+
sdkLogger.warn(`[ERC8004] Already reported txId in this session: ${txId}`);
|
|
261
261
|
return null;
|
|
262
262
|
}
|
|
263
263
|
|
|
@@ -322,7 +322,7 @@ export class ReputationReporter {
|
|
|
322
322
|
|
|
323
323
|
// Local dedup check
|
|
324
324
|
if (this.reportedTxIds.has(txId)) {
|
|
325
|
-
|
|
325
|
+
sdkLogger.warn(`[ERC8004] Already reported txId in this session: ${txId}`);
|
|
326
326
|
return null;
|
|
327
327
|
}
|
|
328
328
|
|
|
@@ -392,9 +392,8 @@ export class ReputationReporter {
|
|
|
392
392
|
score: Number(summaryValue),
|
|
393
393
|
};
|
|
394
394
|
} catch (error) {
|
|
395
|
-
|
|
396
|
-
`[ERC8004] getAgentReputation failed for ${agentId}
|
|
397
|
-
error instanceof Error ? error.message : error
|
|
395
|
+
sdkLogger.error(
|
|
396
|
+
`[ERC8004] getAgentReputation failed for ${agentId}: ${error instanceof Error ? error.message : error}`
|
|
398
397
|
);
|
|
399
398
|
return null;
|
|
400
399
|
}
|
|
@@ -449,23 +448,20 @@ export class ReputationReporter {
|
|
|
449
448
|
|
|
450
449
|
// Check for common error cases
|
|
451
450
|
if (errorMessage.includes('insufficient funds')) {
|
|
452
|
-
|
|
453
|
-
`[ERC8004] ${method} failed for agent ${agentId}:
|
|
454
|
-
'Insufficient funds for gas. Signer needs ETH/native token.'
|
|
451
|
+
sdkLogger.error(
|
|
452
|
+
`[ERC8004] ${method} failed for agent ${agentId}: Insufficient funds for gas. Signer needs ETH/native token.`
|
|
455
453
|
);
|
|
456
454
|
} else if (errorMessage.includes('cannot be the agent owner')) {
|
|
457
|
-
|
|
458
|
-
`[ERC8004] ${method} failed for agent ${agentId}:
|
|
459
|
-
'Caller is agent owner. ERC-8004 requires different address.'
|
|
455
|
+
sdkLogger.error(
|
|
456
|
+
`[ERC8004] ${method} failed for agent ${agentId}: Caller is agent owner. ERC-8004 requires different address.`
|
|
460
457
|
);
|
|
461
458
|
} else if (errorMessage.includes('user rejected')) {
|
|
462
|
-
|
|
459
|
+
sdkLogger.warn(
|
|
463
460
|
`[ERC8004] ${method} cancelled by user for agent ${agentId}`
|
|
464
461
|
);
|
|
465
462
|
} else {
|
|
466
|
-
|
|
467
|
-
`[ERC8004] ${method} failed for agent ${agentId} (tx: ${txId}): `
|
|
468
|
-
errorMessage
|
|
463
|
+
sdkLogger.error(
|
|
464
|
+
`[ERC8004] ${method} failed for agent ${agentId} (tx: ${txId}): ${errorMessage}`
|
|
469
465
|
);
|
|
470
466
|
}
|
|
471
467
|
}
|
package/src/index.ts
CHANGED
|
@@ -176,6 +176,21 @@ export {
|
|
|
176
176
|
createUsedAttestationTracker,
|
|
177
177
|
} from './utils/UsedAttestationTracker';
|
|
178
178
|
|
|
179
|
+
// Wallet
|
|
180
|
+
export { resolvePrivateKey, getCachedAddress } from './wallet/keystore';
|
|
181
|
+
export type {
|
|
182
|
+
IWalletProvider,
|
|
183
|
+
TransactionRequest as WalletTransactionRequest,
|
|
184
|
+
TransactionReceipt as WalletTransactionReceipt,
|
|
185
|
+
WalletInfo,
|
|
186
|
+
WalletTier,
|
|
187
|
+
BatchedPayParams,
|
|
188
|
+
BatchedPayResult,
|
|
189
|
+
} from './wallet/IWalletProvider';
|
|
190
|
+
export { EOAWalletProvider } from './wallet/EOAWalletProvider';
|
|
191
|
+
export { AutoWalletProvider } from './wallet/AutoWalletProvider';
|
|
192
|
+
export type { AutoWalletConfig } from './wallet/AutoWalletProvider';
|
|
193
|
+
|
|
179
194
|
// Helper utilities
|
|
180
195
|
export {
|
|
181
196
|
USDC,
|