@lawreneliang/atel-sdk 0.5.5 → 0.5.7
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/bin/atel.mjs +304 -15
- package/dist/anchor/base.js +1 -1
- package/dist/anchor/bsc.js +1 -1
- package/dist/anchor/evm.js +1 -1
- package/dist/anchor/index.js +1 -1
- package/dist/anchor/mock.js +1 -1
- package/dist/anchor/solana.js +1 -1
- package/dist/auditor/index.js +1 -1
- package/dist/collaboration/index.js +1 -1
- package/dist/crypto/index.js +1 -1
- package/dist/endpoint/index.js +1 -1
- package/dist/envelope/index.js +1 -1
- package/dist/gateway/index.js +1 -1
- package/dist/graph/index.js +1 -1
- package/dist/handshake/index.js +1 -1
- package/dist/identity/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/negotiation/index.js +1 -1
- package/dist/network/index.js +1 -1
- package/dist/orchestrator/index.js +1 -1
- package/dist/policy/index.js +1 -1
- package/dist/proof/index.js +1 -1
- package/dist/registry/index.js +1 -1
- package/dist/rollback/index.js +1 -1
- package/dist/score/index.js +1 -1
- package/dist/service/index.js +1 -1
- package/dist/service/server.js +1 -1
- package/dist/trace/index.js +1 -1
- package/dist/trust/index.js +1 -1
- package/dist/trust-sync/index.js +1 -1
- package/package.json +1 -1
- package/skill/SKILL.md +175 -8
package/bin/atel.mjs
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { readFileSync, writeFileSync, existsSync, mkdirSync, appendFileSync } from 'node:fs';
|
|
21
|
-
import { resolve } from 'node:path';
|
|
21
|
+
import { resolve, join } from 'node:path';
|
|
22
22
|
import {
|
|
23
23
|
AgentIdentity, AgentEndpoint, AgentClient, HandshakeManager,
|
|
24
24
|
createMessage, RegistryClient, ExecutionTrace, ProofGenerator,
|
|
@@ -36,8 +36,9 @@ const INBOX_FILE = resolve(ATEL_DIR, 'inbox.jsonl');
|
|
|
36
36
|
const POLICY_FILE = resolve(ATEL_DIR, 'policy.json');
|
|
37
37
|
const TASKS_FILE = resolve(ATEL_DIR, 'tasks.json');
|
|
38
38
|
const NETWORK_FILE = resolve(ATEL_DIR, 'network.json');
|
|
39
|
+
const TRACES_DIR = resolve(ATEL_DIR, 'traces');
|
|
39
40
|
|
|
40
|
-
const DEFAULT_POLICY = { rateLimit: 60, maxPayloadBytes: 1048576, maxConcurrent: 10, allowedDIDs: [], blockedDIDs: [] };
|
|
41
|
+
const DEFAULT_POLICY = { rateLimit: 60, maxPayloadBytes: 1048576, maxConcurrent: 10, allowedDIDs: [], blockedDIDs: [], trustPolicy: { minScore: 0, newAgentPolicy: 'allow_low_risk', riskThresholds: { low: 0, medium: 50, high: 75, critical: 90 } } };
|
|
41
42
|
|
|
42
43
|
// ─── Helpers ─────────────────────────────────────────────────────
|
|
43
44
|
|
|
@@ -56,6 +57,8 @@ function loadTasks() { if (!existsSync(TASKS_FILE)) return {}; try { return JSON
|
|
|
56
57
|
function saveTasks(t) { ensureDir(); writeFileSync(TASKS_FILE, JSON.stringify(t, null, 2)); }
|
|
57
58
|
function loadNetwork() { if (!existsSync(NETWORK_FILE)) return null; try { return JSON.parse(readFileSync(NETWORK_FILE, 'utf-8')); } catch { return null; } }
|
|
58
59
|
function saveNetwork(n) { ensureDir(); writeFileSync(NETWORK_FILE, JSON.stringify(n, null, 2)); }
|
|
60
|
+
function saveTrace(taskId, trace) { if (!existsSync(TRACES_DIR)) mkdirSync(TRACES_DIR, { recursive: true }); writeFileSync(resolve(TRACES_DIR, `${taskId}.jsonl`), trace.export()); }
|
|
61
|
+
function loadTrace(taskId) { const f = resolve(TRACES_DIR, `${taskId}.jsonl`); if (!existsSync(f)) return null; return readFileSync(f, 'utf-8'); }
|
|
59
62
|
|
|
60
63
|
// ─── Policy Enforcer ─────────────────────────────────────────────
|
|
61
64
|
|
|
@@ -175,6 +178,15 @@ async function cmdStart(port) {
|
|
|
175
178
|
return { proof_id: proof.proof_id, trace_root: proof.trace_root };
|
|
176
179
|
}
|
|
177
180
|
|
|
181
|
+
// ── Trace endpoint (for audit requests from other agents) ──
|
|
182
|
+
endpoint.app?.get?.('/atel/v1/trace/:taskId', (req, res) => {
|
|
183
|
+
const taskId = req.params.taskId;
|
|
184
|
+
const traceData = loadTrace(taskId);
|
|
185
|
+
if (!traceData) { res.status(404).json({ error: 'Trace not found' }); return; }
|
|
186
|
+
const events = traceData.split('\n').filter(l => l.trim()).map(l => JSON.parse(l));
|
|
187
|
+
res.json({ taskId, events, agent: id.did });
|
|
188
|
+
});
|
|
189
|
+
|
|
178
190
|
// Result callback: POST /atel/v1/result (executor calls this when done)
|
|
179
191
|
endpoint.app?.post?.('/atel/v1/result', async (req, res) => {
|
|
180
192
|
const { taskId, result, success } = req.body || {};
|
|
@@ -220,6 +232,9 @@ async function cmdStart(port) {
|
|
|
220
232
|
trace.finalize(typeof result === 'object' ? result : { result });
|
|
221
233
|
}
|
|
222
234
|
|
|
235
|
+
// ── Save Trace (for audit requests) ──
|
|
236
|
+
saveTrace(taskId, trace);
|
|
237
|
+
|
|
223
238
|
// ── Proof Generation ──
|
|
224
239
|
const proofGen = new ProofGenerator(trace, id);
|
|
225
240
|
const proof = proofGen.generate(capTypes.join(',') || 'no-policy', `task-from-${task.from}`, JSON.stringify(result));
|
|
@@ -345,7 +360,7 @@ async function cmdStart(port) {
|
|
|
345
360
|
|
|
346
361
|
// Ignore task-result messages (these are responses, not new tasks)
|
|
347
362
|
if (message.type === 'task-result' || payload.status === 'completed' || payload.status === 'failed') {
|
|
348
|
-
log({ event: 'result_received', from: message.from, taskId: payload.taskId, status: payload.status, timestamp: new Date().toISOString() });
|
|
363
|
+
log({ event: 'result_received', type: 'task-result', from: message.from, taskId: payload.taskId, status: payload.status, proof: payload.proof || null, anchor: payload.anchor || null, execution: payload.execution || null, result: payload.result || null, timestamp: new Date().toISOString() });
|
|
349
364
|
return { status: 'ok', message: 'Result received' };
|
|
350
365
|
}
|
|
351
366
|
|
|
@@ -380,8 +395,8 @@ async function cmdStart(port) {
|
|
|
380
395
|
return { status: 'rejected', error: pc.reason, proof: rp };
|
|
381
396
|
}
|
|
382
397
|
|
|
383
|
-
// ── Capability check ──
|
|
384
|
-
if (capTypes.length > 0 && !capTypes.includes(action)
|
|
398
|
+
// ── Capability check (strict matching, no wildcards) ──
|
|
399
|
+
if (capTypes.length > 0 && !capTypes.includes(action)) {
|
|
385
400
|
const reason = `Outside capability: [${capTypes.join(',')}]`;
|
|
386
401
|
const rp = generateRejectionProof(message.from, action, reason, 'CAPABILITY_REJECTED');
|
|
387
402
|
log({ event: 'task_rejected', from: message.from, action, reason, timestamp: new Date().toISOString() });
|
|
@@ -418,6 +433,7 @@ async function cmdStart(port) {
|
|
|
418
433
|
trace.append('TASK_ACCEPTED', { from: message.from, action, payload });
|
|
419
434
|
const result = { status: 'no_executor', agent: id.agent_id, action, received_payload: payload };
|
|
420
435
|
trace.append('TASK_ECHO', { result }); trace.finalize(result);
|
|
436
|
+
saveTrace(taskId, trace);
|
|
421
437
|
const proofGen = new ProofGenerator(trace, id);
|
|
422
438
|
const proof = proofGen.generate(capTypes.join(',') || 'no-policy', `task-from-${message.from}`, JSON.stringify(result));
|
|
423
439
|
const anchor = await anchorOnChain(proof.trace_root, { proof_id: proof.proof_id, task_from: message.from, action, taskId });
|
|
@@ -581,6 +597,15 @@ async function cmdHandshake(remoteEndpoint, remoteDid) {
|
|
|
581
597
|
|
|
582
598
|
async function cmdTask(target, taskJson) {
|
|
583
599
|
const id = requireIdentity();
|
|
600
|
+
const policy = loadPolicy();
|
|
601
|
+
const tp = policy.trustPolicy || DEFAULT_POLICY.trustPolicy;
|
|
602
|
+
|
|
603
|
+
// Parse task payload and extract risk level
|
|
604
|
+
const payload = typeof taskJson === 'string' ? JSON.parse(taskJson) : taskJson;
|
|
605
|
+
const risk = payload._risk || 'low';
|
|
606
|
+
delete payload._risk;
|
|
607
|
+
const force = payload._force || false;
|
|
608
|
+
delete payload._force;
|
|
584
609
|
|
|
585
610
|
let remoteEndpoint = target;
|
|
586
611
|
let remoteDid;
|
|
@@ -590,12 +615,10 @@ async function cmdTask(target, taskJson) {
|
|
|
590
615
|
if (!target.startsWith('http')) {
|
|
591
616
|
const regClient = new RegistryClient({ registryUrl: REGISTRY_URL });
|
|
592
617
|
let entry;
|
|
593
|
-
// Try as DID first
|
|
594
618
|
try {
|
|
595
619
|
const resp = await fetch(`${REGISTRY_URL}/registry/v1/agent/${encodeURIComponent(target)}`);
|
|
596
620
|
if (resp.ok) entry = await resp.json();
|
|
597
621
|
} catch {}
|
|
598
|
-
// Try as capability search
|
|
599
622
|
if (!entry) {
|
|
600
623
|
const results = await regClient.search({ type: target, limit: 5 });
|
|
601
624
|
if (results.length > 0) entry = results[0];
|
|
@@ -604,6 +627,49 @@ async function cmdTask(target, taskJson) {
|
|
|
604
627
|
|
|
605
628
|
remoteDid = entry.did;
|
|
606
629
|
|
|
630
|
+
// ── Pre-task trust check ──
|
|
631
|
+
if (!force) {
|
|
632
|
+
const localHistoryFile = resolve(ATEL_DIR, 'trust-history.json');
|
|
633
|
+
let history = {};
|
|
634
|
+
try { history = JSON.parse(readFileSync(localHistoryFile, 'utf-8')); } catch {}
|
|
635
|
+
const agentHistory = history[remoteDid] || { tasks: 0, successes: 0, failures: 0, proofs: [] };
|
|
636
|
+
const threshold = tp.riskThresholds?.[risk] ?? 0;
|
|
637
|
+
const isNewAgent = agentHistory.tasks === 0;
|
|
638
|
+
|
|
639
|
+
if (isNewAgent && tp.newAgentPolicy === 'deny') {
|
|
640
|
+
console.log(JSON.stringify({ status: 'blocked', reason: 'Trust policy denies unknown agents', did: remoteDid, risk }));
|
|
641
|
+
process.exit(1);
|
|
642
|
+
}
|
|
643
|
+
if (isNewAgent && tp.newAgentPolicy === 'allow_low_risk' && (risk === 'high' || risk === 'critical')) {
|
|
644
|
+
console.log(JSON.stringify({ status: 'blocked', reason: `New agent, policy only allows low risk for unknowns (requested: ${risk})`, did: remoteDid }));
|
|
645
|
+
process.exit(1);
|
|
646
|
+
}
|
|
647
|
+
if (!isNewAgent && threshold > 0) {
|
|
648
|
+
const successRate = agentHistory.successes / agentHistory.tasks;
|
|
649
|
+
const score = Math.round(successRate * 60 + Math.min(agentHistory.tasks / 20, 1) * 15);
|
|
650
|
+
if (score < threshold) {
|
|
651
|
+
console.log(JSON.stringify({ status: 'blocked', reason: `Score ${score} below threshold ${threshold} for ${risk} risk`, did: remoteDid, score, threshold, risk }));
|
|
652
|
+
process.exit(1);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
console.log(JSON.stringify({ event: 'trust_check_passed', did: remoteDid, risk, threshold }));
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// Try candidates if available
|
|
659
|
+
if (entry.candidates && entry.candidates.length > 0) {
|
|
660
|
+
console.log(JSON.stringify({ event: 'connecting', did: remoteDid, candidates: entry.candidates.length }));
|
|
661
|
+
const conn = await connectToAgent(entry.candidates, remoteDid);
|
|
662
|
+
if (conn) {
|
|
663
|
+
remoteEndpoint = conn.url;
|
|
664
|
+
connectionType = conn.candidateType;
|
|
665
|
+
console.log(JSON.stringify({ event: 'connected', type: conn.candidateType, url: conn.url, latencyMs: conn.latencyMs }));
|
|
666
|
+
} else {
|
|
667
|
+
console.error('All candidates unreachable'); process.exit(1);
|
|
668
|
+
}
|
|
669
|
+
} else {
|
|
670
|
+
remoteEndpoint = entry.endpoint;
|
|
671
|
+
}
|
|
672
|
+
|
|
607
673
|
// Try candidates if available
|
|
608
674
|
if (entry.candidates && entry.candidates.length > 0) {
|
|
609
675
|
console.log(JSON.stringify({ event: 'connecting', did: remoteDid, candidates: entry.candidates.length }));
|
|
@@ -620,6 +686,19 @@ async function cmdTask(target, taskJson) {
|
|
|
620
686
|
}
|
|
621
687
|
}
|
|
622
688
|
|
|
689
|
+
// ── Helper: update local trust history after task ──
|
|
690
|
+
function updateTrustHistory(did, success, proofInfo) {
|
|
691
|
+
const localHistoryFile = resolve(ATEL_DIR, 'trust-history.json');
|
|
692
|
+
let history = {};
|
|
693
|
+
try { history = JSON.parse(readFileSync(localHistoryFile, 'utf-8')); } catch {}
|
|
694
|
+
if (!history[did]) history[did] = { tasks: 0, successes: 0, failures: 0, lastSeen: null, proofs: [] };
|
|
695
|
+
history[did].tasks++;
|
|
696
|
+
if (success) history[did].successes++; else history[did].failures++;
|
|
697
|
+
history[did].lastSeen = new Date().toISOString();
|
|
698
|
+
if (proofInfo) history[did].proofs.push(proofInfo);
|
|
699
|
+
writeFileSync(localHistoryFile, JSON.stringify(history, null, 2));
|
|
700
|
+
}
|
|
701
|
+
|
|
623
702
|
if (connectionType === 'relay') {
|
|
624
703
|
// Relay mode: all requests go through relay's /relay/v1/send/:did API
|
|
625
704
|
const relayUrl = remoteEndpoint; // e.g. http://47.251.8.19:9000/relay/v1/send/did:atel:xxx
|
|
@@ -647,11 +726,44 @@ async function cmdTask(target, taskJson) {
|
|
|
647
726
|
await relaySend('/atel/v1/handshake', confirm);
|
|
648
727
|
|
|
649
728
|
// Step 3: send task
|
|
650
|
-
const payload = typeof taskJson === 'string' ? JSON.parse(taskJson) : taskJson;
|
|
651
729
|
const msg = createMessage({ type: 'task', from: id.did, to: remoteDid, payload, secretKey: id.secretKey });
|
|
652
|
-
const
|
|
730
|
+
const relayAck = await relaySend('/atel/v1/task', msg);
|
|
731
|
+
|
|
732
|
+
console.log(JSON.stringify({ status: 'task_sent', remoteDid, via: 'relay', relay_ack: relayAck, note: 'Relay mode is async. Waiting for result (up to 120s)...' }));
|
|
733
|
+
|
|
734
|
+
// Wait for result to arrive in inbox (poll for task-result)
|
|
735
|
+
const taskId = msg.id || msg.payload?.taskId;
|
|
736
|
+
let result = null;
|
|
737
|
+
const waitStart = Date.now();
|
|
738
|
+
const WAIT_TIMEOUT = 120000; // 2 minutes
|
|
739
|
+
while (Date.now() - waitStart < WAIT_TIMEOUT) {
|
|
740
|
+
await new Promise(r => setTimeout(r, 3000)); // poll every 3s
|
|
741
|
+
if (existsSync(INBOX_FILE)) {
|
|
742
|
+
const lines = readFileSync(INBOX_FILE, 'utf-8').split('\n').filter(l => l.trim());
|
|
743
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
744
|
+
try {
|
|
745
|
+
const entry = JSON.parse(lines[i]);
|
|
746
|
+
// Look for result_received from the target
|
|
747
|
+
if (entry.event === 'result_received' && entry.from === remoteDid) {
|
|
748
|
+
result = { taskId: entry.taskId, status: entry.status, result: entry.result, proof: entry.proof, anchor: entry.anchor, execution: entry.execution };
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
} catch {}
|
|
752
|
+
}
|
|
753
|
+
if (result) break;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
653
756
|
|
|
654
|
-
|
|
757
|
+
if (result) {
|
|
758
|
+
console.log(JSON.stringify({ status: 'task_completed', remoteDid, via: 'relay', result }, null, 2));
|
|
759
|
+
} else {
|
|
760
|
+
console.log(JSON.stringify({ status: 'task_sent_no_result', remoteDid, via: 'relay', note: 'Result not received within timeout. Check: atel inbox' }, null, 2));
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// Update local trust history
|
|
764
|
+
const success = result?.status === 'completed' || (result && result?.status !== 'rejected' && result?.status !== 'failed');
|
|
765
|
+
const proofInfo = result?.proof ? { proof_id: result.proof.proof_id, trace_root: result.proof.trace_root, verified: !!result?.anchor?.txHash, anchor_tx: result?.anchor?.txHash || null, timestamp: new Date().toISOString() } : null;
|
|
766
|
+
if (remoteDid) updateTrustHistory(remoteDid, success, proofInfo);
|
|
655
767
|
} else {
|
|
656
768
|
// Direct mode: standard handshake + task
|
|
657
769
|
const client = new AgentClient(id);
|
|
@@ -665,10 +777,14 @@ async function cmdTask(target, taskJson) {
|
|
|
665
777
|
sessions[remoteEndpoint] = { did: remoteDid };
|
|
666
778
|
writeFileSync(sf, JSON.stringify(sessions, null, 2));
|
|
667
779
|
|
|
668
|
-
const payload = typeof taskJson === 'string' ? JSON.parse(taskJson) : taskJson;
|
|
669
780
|
const msg = createMessage({ type: 'task', from: id.did, to: remoteDid, payload, secretKey: id.secretKey });
|
|
670
781
|
const result = await client.sendTask(remoteEndpoint, msg, hsManager);
|
|
671
782
|
console.log(JSON.stringify({ status: 'task_sent', remoteDid, via: remoteEndpoint, result }, null, 2));
|
|
783
|
+
|
|
784
|
+
// Update local trust history
|
|
785
|
+
const success = result?.status !== 'rejected' && result?.status !== 'failed';
|
|
786
|
+
const proofInfo = result?.proof ? { proof_id: result.proof.proof_id, trace_root: result.proof.trace_root, verified: !!result?.anchor?.txHash, anchor_tx: result?.anchor?.txHash || null, timestamp: new Date().toISOString() } : null;
|
|
787
|
+
if (remoteDid) updateTrustHistory(remoteDid, success, proofInfo);
|
|
672
788
|
}
|
|
673
789
|
}
|
|
674
790
|
|
|
@@ -678,6 +794,174 @@ async function cmdResult(taskId, resultJson) {
|
|
|
678
794
|
console.log(JSON.stringify(await resp.json(), null, 2));
|
|
679
795
|
}
|
|
680
796
|
|
|
797
|
+
// ─── Trust Verification Commands ─────────────────────────────────
|
|
798
|
+
|
|
799
|
+
async function cmdCheck(targetDid, riskLevel) {
|
|
800
|
+
const risk = riskLevel || 'low';
|
|
801
|
+
const policy = loadPolicy();
|
|
802
|
+
const tp = policy.trustPolicy || DEFAULT_POLICY.trustPolicy;
|
|
803
|
+
|
|
804
|
+
console.log(JSON.stringify({ event: 'checking_trust', did: targetDid, risk }));
|
|
805
|
+
|
|
806
|
+
// 1. Get Registry info (reference only)
|
|
807
|
+
let registryScore = null;
|
|
808
|
+
let agentName = null;
|
|
809
|
+
try {
|
|
810
|
+
const r = await fetch(`${REGISTRY_URL}/registry/v1/agent/${encodeURIComponent(targetDid)}`, { signal: AbortSignal.timeout(5000) });
|
|
811
|
+
if (r.ok) { const d = await r.json(); registryScore = d.trustScore; agentName = d.name; }
|
|
812
|
+
} catch {}
|
|
813
|
+
|
|
814
|
+
// 2. Query on-chain proofs for this DID (via Solana)
|
|
815
|
+
// For now, use Registry score as baseline + local interaction history
|
|
816
|
+
const localHistoryFile = resolve(ATEL_DIR, 'trust-history.json');
|
|
817
|
+
let history = {};
|
|
818
|
+
try { history = JSON.parse(readFileSync(localHistoryFile, 'utf-8')); } catch {}
|
|
819
|
+
const agentHistory = history[targetDid] || { tasks: 0, successes: 0, failures: 0, lastSeen: null, proofs: [] };
|
|
820
|
+
|
|
821
|
+
// 3. Compute local trust score
|
|
822
|
+
let computedScore = 0;
|
|
823
|
+
if (agentHistory.tasks > 0) {
|
|
824
|
+
const successRate = agentHistory.successes / agentHistory.tasks;
|
|
825
|
+
const volumeScore = Math.min(agentHistory.tasks / 20, 1) * 15;
|
|
826
|
+
const successScore = successRate * 60;
|
|
827
|
+
const verifiedProofs = agentHistory.proofs.filter(p => p.verified).length;
|
|
828
|
+
const verifiedRatio = agentHistory.proofs.length > 0 ? verifiedProofs / agentHistory.proofs.length : 0;
|
|
829
|
+
const proofScore = verifiedRatio * 25;
|
|
830
|
+
computedScore = Math.round((volumeScore + successScore + proofScore) * 100) / 100;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// 4. Apply trust policy
|
|
834
|
+
const threshold = tp.riskThresholds?.[risk] ?? 0;
|
|
835
|
+
const effectiveScore = computedScore > 0 ? computedScore : (registryScore || 0);
|
|
836
|
+
const isNewAgent = agentHistory.tasks === 0;
|
|
837
|
+
let decision = 'allow';
|
|
838
|
+
let reason = '';
|
|
839
|
+
|
|
840
|
+
if (isNewAgent) {
|
|
841
|
+
if (tp.newAgentPolicy === 'deny') { decision = 'deny'; reason = 'New agent, policy denies unknown agents'; }
|
|
842
|
+
else if (tp.newAgentPolicy === 'allow_low_risk' && (risk === 'high' || risk === 'critical')) { decision = 'deny'; reason = `New agent, policy only allows low risk (requested: ${risk})`; }
|
|
843
|
+
else { decision = 'allow'; reason = `New agent, policy: ${tp.newAgentPolicy}`; }
|
|
844
|
+
} else if (effectiveScore < threshold) {
|
|
845
|
+
decision = 'deny';
|
|
846
|
+
reason = `Score ${effectiveScore} below threshold ${threshold} for ${risk} risk`;
|
|
847
|
+
} else {
|
|
848
|
+
decision = 'allow';
|
|
849
|
+
reason = `Score ${effectiveScore} meets threshold ${threshold} for ${risk} risk`;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
console.log(JSON.stringify({
|
|
853
|
+
did: targetDid,
|
|
854
|
+
name: agentName,
|
|
855
|
+
trust: {
|
|
856
|
+
computed_score: computedScore,
|
|
857
|
+
registry_score: registryScore,
|
|
858
|
+
effective_score: effectiveScore,
|
|
859
|
+
total_tasks: agentHistory.tasks,
|
|
860
|
+
successes: agentHistory.successes,
|
|
861
|
+
failures: agentHistory.failures,
|
|
862
|
+
verified_proofs: agentHistory.proofs.filter(p => p.verified).length,
|
|
863
|
+
total_proofs: agentHistory.proofs.length,
|
|
864
|
+
},
|
|
865
|
+
policy: { risk, threshold, decision, reason },
|
|
866
|
+
}, null, 2));
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
async function cmdVerifyProof(anchorTx, traceRoot) {
|
|
870
|
+
if (!anchorTx || !traceRoot) { console.error('Usage: atel verify-proof <anchor_tx> <trace_root>'); process.exit(1); }
|
|
871
|
+
|
|
872
|
+
console.log(JSON.stringify({ event: 'verifying_proof', anchor_tx: anchorTx, trace_root: traceRoot }));
|
|
873
|
+
|
|
874
|
+
const rpcUrl = process.env.ATEL_SOLANA_RPC_URL || 'https://api.mainnet-beta.solana.com';
|
|
875
|
+
try {
|
|
876
|
+
const provider = new SolanaAnchorProvider({ rpcUrl });
|
|
877
|
+
const result = await provider.verify(traceRoot, anchorTx);
|
|
878
|
+
console.log(JSON.stringify({
|
|
879
|
+
verified: result.valid,
|
|
880
|
+
chain: 'solana',
|
|
881
|
+
anchor_tx: anchorTx,
|
|
882
|
+
trace_root: traceRoot,
|
|
883
|
+
detail: result.detail || (result.valid ? 'Memo matches trace_root' : 'Memo does not match'),
|
|
884
|
+
block: result.blockNumber,
|
|
885
|
+
timestamp: result.timestamp,
|
|
886
|
+
}, null, 2));
|
|
887
|
+
} catch (e) {
|
|
888
|
+
console.log(JSON.stringify({ verified: false, error: e.message }));
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
async function cmdAudit(targetDidOrUrl, taskId) {
|
|
893
|
+
if (!targetDidOrUrl || !taskId) { console.error('Usage: atel audit <did_or_endpoint> <taskId>'); process.exit(1); }
|
|
894
|
+
|
|
895
|
+
// Resolve endpoint
|
|
896
|
+
let endpoint = targetDidOrUrl;
|
|
897
|
+
if (targetDidOrUrl.startsWith('did:')) {
|
|
898
|
+
try {
|
|
899
|
+
const r = await fetch(`${REGISTRY_URL}/registry/v1/agent/${encodeURIComponent(targetDidOrUrl)}`, { signal: AbortSignal.timeout(5000) });
|
|
900
|
+
if (r.ok) {
|
|
901
|
+
const d = await r.json();
|
|
902
|
+
if (d.candidates && d.candidates.length > 0) {
|
|
903
|
+
const conn = await connectToAgent(d.candidates, targetDidOrUrl);
|
|
904
|
+
if (conn) endpoint = conn.url;
|
|
905
|
+
}
|
|
906
|
+
if (endpoint === targetDidOrUrl && d.endpoint) endpoint = d.endpoint;
|
|
907
|
+
}
|
|
908
|
+
} catch {}
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
if (endpoint.startsWith('did:')) { console.error('Could not resolve endpoint for DID'); process.exit(1); }
|
|
912
|
+
|
|
913
|
+
console.log(JSON.stringify({ event: 'auditing', target: endpoint, taskId }));
|
|
914
|
+
|
|
915
|
+
try {
|
|
916
|
+
// Fetch trace from target
|
|
917
|
+
const traceUrl = endpoint.replace(/\/$/, '') + `/atel/v1/trace/${taskId}`;
|
|
918
|
+
const resp = await fetch(traceUrl, { signal: AbortSignal.timeout(10000) });
|
|
919
|
+
if (!resp.ok) { console.log(JSON.stringify({ audit: 'failed', error: `Trace fetch failed: ${resp.status}` })); return; }
|
|
920
|
+
const traceData = await resp.json();
|
|
921
|
+
|
|
922
|
+
// Verify hash chain
|
|
923
|
+
const events = traceData.events || [];
|
|
924
|
+
let chainValid = true;
|
|
925
|
+
const chainErrors = [];
|
|
926
|
+
for (let i = 0; i < events.length; i++) {
|
|
927
|
+
const e = events[i];
|
|
928
|
+
const expectedPrev = i === 0 ? '0x00' : events[i - 1].hash;
|
|
929
|
+
if (e.prev !== expectedPrev) {
|
|
930
|
+
chainValid = false;
|
|
931
|
+
chainErrors.push(`Event #${e.seq}: prev mismatch (expected ${expectedPrev}, got ${e.prev})`);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// Recompute merkle root
|
|
936
|
+
const { createHash } = await import('node:crypto');
|
|
937
|
+
const hashes = events.map(e => e.hash);
|
|
938
|
+
let level = [...hashes];
|
|
939
|
+
while (level.length > 1) {
|
|
940
|
+
const next = [];
|
|
941
|
+
for (let i = 0; i < level.length; i += 2) {
|
|
942
|
+
const left = level[i];
|
|
943
|
+
const right = i + 1 < level.length ? level[i + 1] : left;
|
|
944
|
+
next.push(createHash('sha256').update(left + right).digest('hex'));
|
|
945
|
+
}
|
|
946
|
+
level = next;
|
|
947
|
+
}
|
|
948
|
+
const computedRoot = level[0] || '';
|
|
949
|
+
|
|
950
|
+
console.log(JSON.stringify({
|
|
951
|
+
audit: 'complete',
|
|
952
|
+
taskId,
|
|
953
|
+
agent: traceData.agent,
|
|
954
|
+
events_count: events.length,
|
|
955
|
+
hash_chain_valid: chainValid,
|
|
956
|
+
chain_errors: chainErrors,
|
|
957
|
+
computed_merkle_root: computedRoot,
|
|
958
|
+
event_types: events.map(e => e.type),
|
|
959
|
+
}, null, 2));
|
|
960
|
+
} catch (e) {
|
|
961
|
+
console.log(JSON.stringify({ audit: 'failed', error: e.message }));
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
|
|
681
965
|
// ─── Main ────────────────────────────────────────────────────────
|
|
682
966
|
|
|
683
967
|
const [,, cmd, ...args] = process.argv;
|
|
@@ -693,6 +977,9 @@ const commands = {
|
|
|
693
977
|
handshake: () => cmdHandshake(args[0], args[1]),
|
|
694
978
|
task: () => cmdTask(args[0], args[1]),
|
|
695
979
|
result: () => cmdResult(args[0], args[1]),
|
|
980
|
+
check: () => cmdCheck(args[0], args[1]),
|
|
981
|
+
'verify-proof': () => cmdVerifyProof(args[0], args[1]),
|
|
982
|
+
audit: () => cmdAudit(args[0], args[1]),
|
|
696
983
|
};
|
|
697
984
|
|
|
698
985
|
if (!cmd || !commands[cmd]) {
|
|
@@ -710,8 +997,11 @@ Commands:
|
|
|
710
997
|
register [name] [caps] [endpoint] Register on public registry
|
|
711
998
|
search <capability> Search registry for agents
|
|
712
999
|
handshake <endpoint> [did] Handshake with remote agent
|
|
713
|
-
task <
|
|
1000
|
+
task <target> <json> Delegate task (auto trust check)
|
|
714
1001
|
result <taskId> <json> Submit execution result (from executor)
|
|
1002
|
+
check <did> [risk] Check agent trust (risk: low|medium|high|critical)
|
|
1003
|
+
verify-proof <anchor_tx> <root> Verify on-chain proof
|
|
1004
|
+
audit <did_or_url> <taskId> Deep audit: fetch trace + verify hash chain
|
|
715
1005
|
|
|
716
1006
|
Environment:
|
|
717
1007
|
ATEL_DIR Identity directory (default: .atel)
|
|
@@ -720,9 +1010,8 @@ Environment:
|
|
|
720
1010
|
ATEL_SOLANA_PRIVATE_KEY Solana key for on-chain anchoring
|
|
721
1011
|
ATEL_SOLANA_RPC_URL Solana RPC (default: mainnet-beta)
|
|
722
1012
|
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
on your router and run: atel verify`);
|
|
1013
|
+
Trust Policy: Configure .atel/policy.json trustPolicy for automatic
|
|
1014
|
+
pre-task trust evaluation. Use _risk in payload or --risk flag.`);
|
|
726
1015
|
process.exit(cmd ? 1 : 0);
|
|
727
1016
|
}
|
|
728
1017
|
|
package/dist/anchor/base.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
(function(_0xa95328,_0x3590b3){var _0xedb81c=_0x4e3d,_0x4ada8d=_0xa95328();while(!![]){try{var _0x568cc2=-parseInt(_0xedb81c(0xc9))/0x1*(-parseInt(_0xedb81c(0xcd))/0x2)+-parseInt(_0xedb81c(0xcb))/0x3+parseInt(_0xedb81c(0xc7))/0x4*(-parseInt(_0xedb81c(0xc3))/0x5)+-parseInt(_0xedb81c(0xbf))/0x6*(-parseInt(_0xedb81c(0xc1))/0x7)+-parseInt(_0xedb81c(0xbe))/0x8*(parseInt(_0xedb81c(0xc2))/0x9)+parseInt(_0xedb81c(0xc8))/0xa+-parseInt(_0xedb81c(0xc6))/0xb*(-parseInt(_0xedb81c(0xcc))/0xc);if(_0x568cc2===_0x3590b3)break;else _0x4ada8d['push'](_0x4ada8d['shift']());}catch(_0xab7799){_0x4ada8d['push'](_0x4ada8d['shift']());}}}(_0x56e7,0x34c59));function _0x56e7(){var _0x120e74=['yMfZzq','ndy5ELfSyvHn','mtG5AhHdrfLL','mJiYndbPwMD6Afa','ChjPDMf0zuTLEq','revgqvvmvf9suenFvvjm','mtK5mxLHvKXYva','odbcDgLTvvK','mZG4ndmXmfHNAhDxwq','mteXotLsqLbstgq','qMfZzq','mtiXmtm4ofD0ugDQrq','nZy5mMHMt0Xpva','ndbrt09qEMG','CNbJvxjS','ntyZotjiug96rge','mte1mdHyweHftNO'];_0x56e7=function(){return _0x120e74;};return _0x56e7();}import{EvmAnchorProvider}from'./evm.js';function _0x4e3d(_0xec67cc,_0x1a2a1b){_0xec67cc=_0xec67cc-0xbe;var _0x56e7e3=_0x56e7();var _0x4e3de2=_0x56e7e3[_0xec67cc];if(_0x4e3d['TYKytS']===undefined){var _0x7c1529=function(_0x11f7ee){var _0x74353a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var _0x5b61d0='',_0x31ac7a='';for(var _0x539921=0x0,_0x24c738,_0x107458,_0x21c8f4=0x0;_0x107458=_0x11f7ee['charAt'](_0x21c8f4++);~_0x107458&&(_0x24c738=_0x539921%0x4?_0x24c738*0x40+_0x107458:_0x107458,_0x539921++%0x4)?_0x5b61d0+=String['fromCharCode'](0xff&_0x24c738>>(-0x2*_0x539921&0x6)):0x0){_0x107458=_0x74353a['indexOf'](_0x107458);}for(var _0x330c9d=0x0,_0x3d2908=_0x5b61d0['length'];_0x330c9d<_0x3d2908;_0x330c9d++){_0x31ac7a+='%'+('00'+_0x5b61d0['charCodeAt'](_0x330c9d)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x31ac7a);};_0x4e3d['pKwuLg']=_0x7c1529,_0x4e3d['YVtnDP']={},_0x4e3d['TYKytS']=!![];}var _0x444d42=_0x56e7e3[0x0],_0x5b4d26=_0xec67cc+_0x444d42,_0x1853c2=_0x4e3d['YVtnDP'][_0x5b4d26];return!_0x1853c2?(_0x4e3de2=_0x4e3d['pKwuLg'](_0x4e3de2),_0x4e3d['YVtnDP'][_0x5b4d26]=_0x4e3de2):_0x4e3de2=_0x1853c2,_0x4e3de2;}export class BaseAnchorProvider extends EvmAnchorProvider{static ['DEFAULT_RPC_URL']='https://mainnet.base.org';constructor(_0x21e15a){var _0x190224=_0x4e3d,_0x5dd250={};_0x5dd250['rpcUrl']=_0x21e15a?.[_0x190224(0xce)]??BaseAnchorProvider[_0x190224(0xc5)],_0x5dd250[_0x190224(0xc4)]=_0x21e15a?.['privateKey'],super(_0x190224(0xca),_0x190224(0xc0),_0x5dd250);}}
|
package/dist/anchor/bsc.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function _0x1f0d(){var _0x3cd523=['mJrWz1rRyvy','qLnd','ndzsAwHdzNm','nJi4mMLtu3bkqW','CNbJvxjS','ntm4mZq0ngDdAeXUzW','mZGYowX3DMHTBa','mti1nte1nZjLA3PxEeO','ndq4mdqZn2H6tu5sDa','nwTZuxrsyq','otyWEhrVD1zR','revgqvvmvf9suenFvvjm','odm2nfDQr3nkDq','y2jeC1q','ChjPDMf0zuTLEq','mtGYndnJDNHIrKy','odeZnZK3mgPPAKfvAq'];_0x1f0d=function(){return _0x3cd523;};return _0x1f0d();}var _0x35a255=_0x279d;(function(_0x95fb8e,_0x5c9f03){var _0x484959=_0x279d,_0x39f815=_0x95fb8e();while(!![]){try{var _0x2d2791=-parseInt(_0x484959(0xe8))/0x1*(parseInt(_0x484959(0xe7))/0x2)+parseInt(_0x484959(0xed))/0x3+-parseInt(_0x484959(0xea))/0x4*(parseInt(_0x484959(0xee))/0x5)+-parseInt(_0x484959(0xe0))/0x6*(parseInt(_0x484959(0xeb))/0x7)+parseInt(_0x484959(0xef))/0x8*(parseInt(_0x484959(0xe3))/0x9)+-parseInt(_0x484959(0xe4))/0xa+-parseInt(_0x484959(0xec))/0xb*(-parseInt(_0x484959(0xe5))/0xc);if(_0x2d2791===_0x5c9f03)break;else _0x39f815['push'](_0x39f815['shift']());}catch(_0x58f57a){_0x39f815['push'](_0x39f815['shift']());}}}(_0x1f0d,0xe8761));import{EvmAnchorProvider}from'./evm.js';function _0x279d(_0x22a307,_0x5ec28f){_0x22a307=_0x22a307-0xe0;var _0x1f0de0=_0x1f0d();var _0x279d2b=_0x1f0de0[_0x22a307];if(_0x279d['yKmteb']===undefined){var _0x46ef41=function(_0x241a52){var _0x768c5f='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var _0x515d3c='',_0x818f2='';for(var _0x40cac8=0x0,_0x3b4268,_0x512c2b,_0x5c4e71=0x0;_0x512c2b=_0x241a52['charAt'](_0x5c4e71++);~_0x512c2b&&(_0x3b4268=_0x40cac8%0x4?_0x3b4268*0x40+_0x512c2b:_0x512c2b,_0x40cac8++%0x4)?_0x515d3c+=String['fromCharCode'](0xff&_0x3b4268>>(-0x2*_0x40cac8&0x6)):0x0){_0x512c2b=_0x768c5f['indexOf'](_0x512c2b);}for(var _0x2a2b19=0x0,_0x37010c=_0x515d3c['length'];_0x2a2b19<_0x37010c;_0x2a2b19++){_0x818f2+='%'+('00'+_0x515d3c['charCodeAt'](_0x2a2b19)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x818f2);};_0x279d['COboOD']=_0x46ef41,_0x279d['iDKeOo']={},_0x279d['yKmteb']=!![];}var _0x39dc34=_0x1f0de0[0x0],_0x304537=_0x22a307+_0x39dc34,_0x59e1b5=_0x279d['iDKeOo'][_0x304537];return!_0x59e1b5?(_0x279d2b=_0x279d['COboOD'](_0x279d2b),_0x279d['iDKeOo'][_0x304537]=_0x279d2b):_0x279d2b=_0x59e1b5,_0x279d2b;}export class BSCAnchorProvider extends EvmAnchorProvider{static [_0x35a255(0xf0)]='https://bsc-dataseed.binance.org';constructor(_0x2d8360){var _0x312e54=_0x35a255,_0x8ab598={};_0x8ab598[_0x312e54(0xe1)]='bsc';var _0x1545fd=_0x8ab598,_0x362bc0={};_0x362bc0[_0x312e54(0xe9)]=_0x2d8360?.[_0x312e54(0xe9)]??BSCAnchorProvider[_0x312e54(0xf0)],_0x362bc0[_0x312e54(0xe2)]=_0x2d8360?.['privateKey'],super(_0x312e54(0xe6),_0x1545fd[_0x312e54(0xe1)],_0x362bc0);}}
|
package/dist/anchor/evm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function _0x3b26(){const _0x59fefe=['sgfZAcbTyxrJAgvZig9UlwnOywLUigrHDge','vhjHBNnHy3rPB24Gzgf0ysbKB2vZig5VDcbJB250ywLUigeGDMfSAwqGyw5JAg9Y','z2v0qMXVy2ToDw1Izxi','nZu2mZiXmhzssLD6yW','v2fSBgv0','EwvMyLO','zgv0ywLS','AgfZAa','ndm5ofPpq0XvAW','CNbJvxjS','DMfSAwq','ChjVDMLKzxi','zgvJB2rLrgf0yq','z2v0qMXVy2S','ntC2mvHAD3PQDG','mtm0mtLNthnJtfq','BMDvzLa','qvrftf9btKnit1i6','oIbdyw5UB3qGyw5JAg9YihDPDgHVDxqGysbWCML2yxrLigTLEq','vhjHBNnHy3rPB24GCMvJzwLWDcbPCYbUDwXSiokaLcb0EcbTyxKGAgf2zsbIzwvUigrYB3bWzwq','ywrKCMvZCW','C2XPy2u','nte0tu91CeHe','yMXVy2TuAw1LC3rHBxa','BwvZC2fNzq','ChjPDMf0zuTLEq','iIWGzM91BMqGiG','Bg9VA3vW','yMXVy2ToDw1Izxi','zw5JB2rLrgf0yq','whvhEwC','vMvYAwzPy2f0Aw9UigvYCM9YoIa','BM93','mJe5nZK0mxncqLDLEa','odf0sKrkAwS','BgvUz3rO','sNnVBLjWy1bYB3zPzgvY','D2fPDa','mJC1mtm0mhrUvufksW','z2v0vhjHBNnHy3rPB24','y2HHAw4','DgLTzxn0yw1W','Dg9vDgy4u3rYAw5N','nJqWmZuYuhfkAer3','C2vUzfrYyw5Zywn0Aw9U','zgf0yq','mJyYnJKXnw9ICwziCa','BMfTzq','Dg9vDgy4qNL0zxm','DhHiyxnO','D2fSBgv0'];_0x3b26=function(){return _0x59fefe;};return _0x3b26();}const _0x588a4b=_0x28d3;(function(_0x3aaf02,_0x45aa99){const _0x15c9f3=_0x28d3,_0x4839f5=_0x3aaf02();while(!![]){try{const _0x576870=parseInt(_0x15c9f3(0xf7))/0x1*(parseInt(_0x15c9f3(0xcc))/0x2)+-parseInt(_0x15c9f3(0xd7))/0x3+parseInt(_0x15c9f3(0xdc))/0x4+-parseInt(_0x15c9f3(0xe4))/0x5+parseInt(_0x15c9f3(0xf1))/0x6*(-parseInt(_0x15c9f3(0xf8))/0x7)+-parseInt(_0x15c9f3(0xe1))/0x8*(-parseInt(_0x15c9f3(0xd8))/0x9)+parseInt(_0x15c9f3(0xec))/0xa;if(_0x576870===_0x45aa99)break;else _0x4839f5['push'](_0x4839f5['shift']());}catch(_0x23a4c2){_0x4839f5['push'](_0x4839f5['shift']());}}}(_0x3b26,0xefbb2));import{ethers}from'ethers';const ANCHOR_PREFIX=_0x588a4b(0xfa);function _0x28d3(_0x1b0709,_0x3afc33){_0x1b0709=_0x1b0709-0xcb;const _0x3b2626=_0x3b26();let _0x28d367=_0x3b2626[_0x1b0709];if(_0x28d3['XoTkgJ']===undefined){var _0x386ece=function(_0x31a99f){const _0xea5e16='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0xb26d25='',_0x18b86d='';for(let _0x962e19=0x0,_0x5d7709,_0x173493,_0x2859d2=0x0;_0x173493=_0x31a99f['charAt'](_0x2859d2++);~_0x173493&&(_0x5d7709=_0x962e19%0x4?_0x5d7709*0x40+_0x173493:_0x173493,_0x962e19++%0x4)?_0xb26d25+=String['fromCharCode'](0xff&_0x5d7709>>(-0x2*_0x962e19&0x6)):0x0){_0x173493=_0xea5e16['indexOf'](_0x173493);}for(let _0x5b5668=0x0,_0x2d724f=_0xb26d25['length'];_0x5b5668<_0x2d724f;_0x5b5668++){_0x18b86d+='%'+('00'+_0xb26d25['charCodeAt'](_0x5b5668)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x18b86d);};_0x28d3['nksVSJ']=_0x386ece,_0x28d3['TfaqHz']={},_0x28d3['XoTkgJ']=!![];}const _0x2ad2a8=_0x3b2626[0x0],_0x179e28=_0x1b0709+_0x2ad2a8,_0x1f9d82=_0x28d3['TfaqHz'][_0x179e28];return!_0x1f9d82?(_0x28d367=_0x28d3['nksVSJ'](_0x28d367),_0x28d3['TfaqHz'][_0x179e28]=_0x28d367):_0x28d367=_0x1f9d82,_0x28d367;}export class EvmAnchorProvider{['name'];[_0x588a4b(0xde)];['provider'];[_0x588a4b(0xe8)];constructor(_0x1713c9,_0x58e044,_0x54579d){const _0x596a8a=_0x588a4b;this['name']=_0x1713c9,this['chain']=_0x58e044,this['provider']=new ethers[(_0x596a8a(0xda))](_0x54579d[_0x596a8a(0xf2)]),_0x54579d[_0x596a8a(0xcf)]&&(this[_0x596a8a(0xe8)]=new ethers[(_0x596a8a(0xed))](_0x54579d[_0x596a8a(0xcf)],this['provider']));}static[_0x588a4b(0xd3)](_0x4578e9){const _0xa875f8=_0x588a4b;return ethers['hexlify'](ethers[_0xa875f8(0xe6)](''+ANCHOR_PREFIX+_0x4578e9));}static[_0x588a4b(0xf5)](_0x23616f){const _0x5a1b87=_0x588a4b;try{const _0x5dd3d7=ethers[_0x5a1b87(0xe0)](_0x23616f);if(_0x5dd3d7['startsWith'](ANCHOR_PREFIX))return _0x5dd3d7[_0x5a1b87(0xcb)](ANCHOR_PREFIX[_0x5a1b87(0xd9)]);return null;}catch{return null;}}async['anchor'](_0x1e0db4,_0x4542ff){const _0xbb04ba=_0x588a4b,_0x4bd071={};_0x4bd071[_0xbb04ba(0xd4)]=function(_0x26b963,_0x2da6f7){return _0x26b963 instanceof _0x2da6f7;};const _0x38ff96=_0x4bd071;if(!this[_0xbb04ba(0xe8)])throw new Error(this[_0xbb04ba(0xe5)]+_0xbb04ba(0xfb));const _0x5e780b=EvmAnchorProvider[_0xbb04ba(0xd3)](_0x1e0db4);try{const _0x10a054=await this[_0xbb04ba(0xe8)][_0xbb04ba(0xe2)]({'to':this[_0xbb04ba(0xe8)][_0xbb04ba(0xfd)],'value':0x0n,'data':_0x5e780b}),_0x811383=await _0x10a054[_0xbb04ba(0xdb)]();if(!_0x811383)throw new Error(_0xbb04ba(0xfc));return{'hash':_0x1e0db4,'txHash':_0x811383['hash'],'chain':this['chain'],'timestamp':Date[_0xbb04ba(0xd6)](),'blockNumber':_0x811383[_0xbb04ba(0xd2)],'metadata':_0x4542ff};}catch(_0x46b9a6){const _0x1310cb=_0x38ff96[_0xbb04ba(0xd4)](_0x46b9a6,Error)?_0x46b9a6[_0xbb04ba(0xce)]:String(_0x46b9a6);throw new Error(this['name']+'\x20anchor\x20failed:\x20'+_0x1310cb);}}async['verify'](_0x3dae89,_0x37e25e){const _0x4345a8=_0x588a4b,_0x2db253={'WqcuE':function(_0x33ba1f,_0x8722bf){return _0x33ba1f===_0x8722bf;},'SVESc':_0x4345a8(0xee),'uqLwe':function(_0x22ff6e,_0x43d7c5){return _0x22ff6e*_0x43d7c5;},'ngUfP':function(_0x4b504d,_0x1c8c76){return _0x4b504d instanceof _0x1c8c76;},'MXEWY':function(_0x13eea9,_0x141348){return _0x13eea9(_0x141348);}};try{const _0x521907=await this['provider'][_0x4345a8(0xdd)](_0x37e25e);if(!_0x521907){const _0x2e43dd={};return _0x2e43dd[_0x4345a8(0xf3)]=![],_0x2e43dd[_0x4345a8(0xf0)]=_0x3dae89,_0x2e43dd[_0x4345a8(0xe7)]=_0x37e25e,_0x2e43dd[_0x4345a8(0xde)]=this[_0x4345a8(0xde)],_0x2e43dd[_0x4345a8(0xef)]='Transaction\x20not\x20found',_0x2e43dd;}const _0x35c84c=EvmAnchorProvider['decodeData'](_0x521907[_0x4345a8(0xe3)]);if(_0x35c84c===null){const _0x4b6d49={};return _0x4b6d49['valid']=![],_0x4b6d49[_0x4345a8(0xf0)]=_0x3dae89,_0x4b6d49['txHash']=_0x37e25e,_0x4b6d49['chain']=this[_0x4345a8(0xde)],_0x4b6d49['detail']=_0x4345a8(0xea),_0x4b6d49;}const _0xe91149=_0x2db253['WqcuE'](_0x35c84c,_0x3dae89);let _0x15c205;if(_0x521907[_0x4345a8(0xd2)]){if(_0x2db253['SVESc']===_0x2db253['SVESc'])try{const _0x32d9b3=await this[_0x4345a8(0xf4)][_0x4345a8(0xf6)](_0x521907['blockNumber']);_0x15c205=_0x32d9b3?_0x2db253['uqLwe'](_0x32d9b3[_0x4345a8(0xdf)],0x3e8):undefined;}catch{}else{const _0x4c20ad=_0x4d20c7 instanceof _0x3fd0ee?_0xe46acd[_0x4345a8(0xce)]:_0x437d56(_0x4c3724),_0x1a762c={};return _0x1a762c[_0x4345a8(0xf3)]=![],_0x1a762c[_0x4345a8(0xf0)]=_0x157285,_0x1a762c[_0x4345a8(0xe7)]=_0x3a81de,_0x1a762c['chain']=this[_0x4345a8(0xde)],_0x1a762c[_0x4345a8(0xef)]='Verification\x20error:\x20'+_0x4c20ad,_0x1a762c;}}const _0x140d99={};return _0x140d99[_0x4345a8(0xf3)]=_0xe91149,_0x140d99[_0x4345a8(0xf0)]=_0x3dae89,_0x140d99['txHash']=_0x37e25e,_0x140d99['chain']=this[_0x4345a8(0xde)],_0x140d99[_0x4345a8(0xcd)]=_0x15c205,_0x140d99[_0x4345a8(0xef)]=_0xe91149?_0x4345a8(0xe9):'Hash\x20mismatch:\x20expected\x20\x22'+_0x3dae89+_0x4345a8(0xd0)+_0x35c84c+'\x22',_0x140d99;}catch(_0x1a49ea){const _0x33cd29=_0x2db253[_0x4345a8(0xf9)](_0x1a49ea,Error)?_0x1a49ea[_0x4345a8(0xce)]:_0x2db253['MXEWY'](String,_0x1a49ea),_0x53c180={};return _0x53c180[_0x4345a8(0xf3)]=![],_0x53c180[_0x4345a8(0xf0)]=_0x3dae89,_0x53c180[_0x4345a8(0xe7)]=_0x37e25e,_0x53c180[_0x4345a8(0xde)]=this[_0x4345a8(0xde)],_0x53c180[_0x4345a8(0xef)]=_0x4345a8(0xd5)+_0x33cd29,_0x53c180;}}async[_0x588a4b(0xd1)](_0x2aa2ec){return[];}async['isAvailable'](){const _0xa846f5=_0x588a4b;try{return await this['provider'][_0xa846f5(0xeb)](),!![];}catch{return![];}}}
|
package/dist/anchor/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function _0x5c46(_0x225d6f,_0x5f3124){_0x225d6f=_0x225d6f-0x196;const _0x30c28e=_0x30c2();let _0x5c4686=_0x30c28e[_0x225d6f];if(_0x5c46['xxlEyF']===undefined){var _0x42f886=function(_0x478c8d){const _0x3e4a10='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x368b84='',_0x5d78ac='';for(let _0x4beb3b=0x0,_0x592887,_0x5e43ab,_0x344950=0x0;_0x5e43ab=_0x478c8d['charAt'](_0x344950++);~_0x5e43ab&&(_0x592887=_0x4beb3b%0x4?_0x592887*0x40+_0x5e43ab:_0x5e43ab,_0x4beb3b++%0x4)?_0x368b84+=String['fromCharCode'](0xff&_0x592887>>(-0x2*_0x4beb3b&0x6)):0x0){_0x5e43ab=_0x3e4a10['indexOf'](_0x5e43ab);}for(let _0x5375bf=0x0,_0xb4239=_0x368b84['length'];_0x5375bf<_0xb4239;_0x5375bf++){_0x5d78ac+='%'+('00'+_0x368b84['charCodeAt'](_0x5375bf)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x5d78ac);};_0x5c46['sGbcEo']=_0x42f886,_0x5c46['utWzPX']={},_0x5c46['xxlEyF']=!![];}const _0x28effc=_0x30c28e[0x0],_0x2ea2e4=_0x225d6f+_0x28effc,_0x4766ef=_0x5c46['utWzPX'][_0x2ea2e4];return!_0x4766ef?(_0x5c4686=_0x5c46['sGbcEo'](_0x5c4686),_0x5c46['utWzPX'][_0x2ea2e4]=_0x5c4686):_0x5c4686=_0x4766ef,_0x5c4686;}const _0x2b2fb4=_0x5c46;(function(_0x1895ca,_0x1b939d){const _0x43b1e9=_0x5c46,_0x577e62=_0x1895ca();while(!![]){try{const _0x1a9ccd=parseInt(_0x43b1e9(0x1be))/0x1+parseInt(_0x43b1e9(0x1a7))/0x2+-parseInt(_0x43b1e9(0x1a0))/0x3*(-parseInt(_0x43b1e9(0x1a5))/0x4)+-parseInt(_0x43b1e9(0x1ac))/0x5+-parseInt(_0x43b1e9(0x1aa))/0x6+parseInt(_0x43b1e9(0x19d))/0x7+parseInt(_0x43b1e9(0x1b5))/0x8;if(_0x1a9ccd===_0x1b939d)break;else _0x577e62['push'](_0x577e62['shift']());}catch(_0x40a040){_0x577e62['push'](_0x577e62['shift']());}}}(_0x30c2,0x61bc5));export class AnchorManager{['providers']=new Map();[_0x2b2fb4(0x1b7)]=[];['registerProvider'](_0x2203d9){const _0x64df16=_0x2b2fb4,_0x45f97d={};_0x45f97d['yoVqF']=function(_0x554c19,_0x494144){return _0x554c19!==_0x494144;};const _0x4123f2=_0x45f97d;if(this['providers']['has'](_0x2203d9[_0x64df16(0x1b9)])){if(_0x4123f2[_0x64df16(0x1c0)]('VfCoU','LjrpP'))throw new Error(_0x64df16(0x1b2)+_0x2203d9['chain']+'\x22\x20is\x20already\x20registered');else throw new _0x5e27fd(_0x64df16(0x19e));}this['providers'][_0x64df16(0x1a9)](_0x2203d9['chain'],_0x2203d9);}[_0x2b2fb4(0x1a2)](){const _0xcdf604=_0x2b2fb4;return Array[_0xcdf604(0x1bd)](this['providers'][_0xcdf604(0x1b0)]());}async[_0x2b2fb4(0x1ae)](_0x3b5a88,_0x2df901,_0x1a1868){const _0x44b6d2=_0x2b2fb4,_0x8f783b=this['getProvider'](_0x2df901),_0x1abc44=await _0x8f783b[_0x44b6d2(0x1ae)](_0x3b5a88,_0x1a1868);return this[_0x44b6d2(0x1b7)][_0x44b6d2(0x1b3)](_0x1abc44),_0x1abc44;}async[_0x2b2fb4(0x1a8)](_0x19b207,_0x39ffce){const _0x5f4f76=_0x2b2fb4,_0x86acf7={};_0x86acf7[_0x5f4f76(0x1b6)]=_0x5f4f76(0x1b1),_0x86acf7['LgiYZ']=function(_0x3e3d63,_0xccefb7){return _0x3e3d63===_0xccefb7;};const _0x1df227=_0x86acf7,_0x9ef368=[],_0x55c6ec=[];for(const [_0x29cd5c,_0x845dd]of this[_0x5f4f76(0x1ab)]){if(_0x1df227[_0x5f4f76(0x1b6)]!==_0x1df227['nYvPM']){const _0x270c72={};_0x270c72['chain']=_0x571f4e,_0x270c72[_0x5f4f76(0x1a6)]=_0x47a331,_0xf86223['push'](_0x270c72);}else try{const _0x5768fa=await _0x845dd['anchor'](_0x19b207,_0x39ffce);this[_0x5f4f76(0x1b7)]['push'](_0x5768fa),_0x9ef368['push'](_0x5768fa);}catch(_0x508c5d){const _0x40ae27={};_0x40ae27[_0x5f4f76(0x1b9)]=_0x29cd5c,_0x40ae27[_0x5f4f76(0x1a6)]=_0x508c5d,_0x55c6ec['push'](_0x40ae27);}}if(_0x1df227[_0x5f4f76(0x198)](_0x9ef368['length'],0x0)&&_0x55c6ec[_0x5f4f76(0x1ba)]>0x0){const _0x128b46=_0x55c6ec[_0x5f4f76(0x1b4)](_0x247cd4=>_0x247cd4[_0x5f4f76(0x1b9)]+':\x20'+_0x247cd4['error']['message'])['join'](';\x20');throw new Error(_0x5f4f76(0x1bb)+_0x128b46);}return _0x9ef368;}async['verify'](_0x1cc06e,_0x34e1e4,_0x120f9e){const _0x3cc776=this['getProvider'](_0x120f9e);return _0x3cc776['verify'](_0x1cc06e,_0x34e1e4);}async[_0x2b2fb4(0x1a4)](_0x281102){const _0x2d9d38=_0x2b2fb4,_0x18d3b6=[];for(const _0x401b2f of this[_0x2d9d38(0x1ab)][_0x2d9d38(0x1bc)]()){try{const _0x53ed47=await _0x401b2f[_0x2d9d38(0x1a4)](_0x281102);_0x18d3b6['push'](..._0x53ed47);}catch{}}for(const _0x28e974 of this['records']){_0x28e974[_0x2d9d38(0x1a1)]===_0x281102&&!_0x18d3b6[_0x2d9d38(0x196)](_0x54d49e=>_0x54d49e[_0x2d9d38(0x1ad)]===_0x28e974['txHash'])&&_0x18d3b6['push'](_0x28e974);}return _0x18d3b6;}[_0x2b2fb4(0x19a)](){const _0x5f41ff=_0x2b2fb4;return[...this[_0x5f41ff(0x1b7)]];}[_0x2b2fb4(0x19b)](){const _0x392cc0=_0x2b2fb4;return JSON[_0x392cc0(0x1c1)](this['records'],null,0x2);}[_0x2b2fb4(0x19f)](_0x42857c){const _0x53a9fc=_0x2b2fb4,_0x26a862={};_0x26a862['ZelwU']='iDwNv';const _0x24897e=_0x26a862,_0x3aca25=JSON[_0x53a9fc(0x1b8)](_0x42857c);if(!Array[_0x53a9fc(0x1bf)](_0x3aca25)){if(_0x24897e['ZelwU']!==_0x24897e[_0x53a9fc(0x1a3)]){if(this['providers'][_0x53a9fc(0x197)](_0x344950['chain']))throw new _0x49b93b(_0x53a9fc(0x1b2)+_0x494c29[_0x53a9fc(0x1b9)]+'\x22\x20is\x20already\x20registered');this['providers'][_0x53a9fc(0x1a9)](_0x4d9180[_0x53a9fc(0x1b9)],_0x2144da);}else throw new Error(_0x53a9fc(0x19e));}this[_0x53a9fc(0x1b7)][_0x53a9fc(0x1b3)](..._0x3aca25);}[_0x2b2fb4(0x1af)](_0x1e696e){const _0x4766e1=_0x2b2fb4,_0x5c0d16=this[_0x4766e1(0x1ab)][_0x4766e1(0x19c)](_0x1e696e);if(!_0x5c0d16)throw new Error(_0x4766e1(0x199)+_0x1e696e+'\x22');return _0x5c0d16;}}export{EvmAnchorProvider}from'./evm.js';export{BaseAnchorProvider}from'./base.js';export{BSCAnchorProvider}from'./bsc.js';export{SolanaAnchorProvider}from'./solana.js';export{MockAnchorProvider}from'./mock.js';function _0x30c2(){const _0x692d11=['yw5JAg9YqwXS','C2v0','mZmZndq1ofvyz3rJuq','ChjVDMLKzxjZ','mZaYnJCYmgjZBgDnsW','DhHiyxnO','yw5JAg9Y','z2v0uhjVDMLKzxi','A2v5CW','vhrfEwe','uhjVDMLKzxiGzM9YignOywLUici','ChvZAa','BwfW','mtGWndCYmgj6vMDYvW','BLL2ue0','CMvJB3jKCW','CgfYC2u','y2HHAw4','BgvUz3rO','qwXSigfUy2HVCIbWCM92AwrLCNmGzMfPBgvKoIa','DMfSDwvZ','zNjVBq','mJmWnZLkCwntvfG','AxnbCNjHEq','Ew9wCuy','C3rYAw5NAwz5','C29Tzq','AgfZ','tgDPwvO','tM8Gyw5JAg9YihbYB3zPzgvYihjLz2LZDgvYzwqGzM9YignOywLUici','z2v0uMvJB3jKCW','zxHWB3j0uMvJB3jKCW','z2v0','mZqXmJi5Ewvyq01K','Aw1WB3j0uMvJB3jKCYbLEhbLy3rZigeGsLnptIbHCNjHEq','Aw1WB3j0uMvJB3jKCW','m0Txz29Wrq','AgfZAa','z2v0uhjVDMLKzxjZ','wMvSD1u','Bg9VA3vW','mJCXnJm2nerUrhLQyq','zxjYB3i','mte2otGXmhLQy1zWtW'];_0x30c2=function(){return _0x692d11;};return _0x30c2();}
|