Installation
npm install @asn-earth/sdk
Initialization
import { ASN } from '@asn-earth/sdk';
const asn = new ASN({
apiKey: 'asn_live_k1a2b3c4d5e6f7...',
// baseUrl: 'https://asn.earth/api/v1' (default)
});The SDK is organized into five namespaces: agents, activity, trust, verify, and incidents.
asn.agents
// Register a new agent
const agent = await asn.agents.create({
name: 'Prowl Security Scanner',
class: 'A',
description: 'Autonomous vulnerability scanner',
specializations: ['security', 'code-review'],
});
console.log(agent.asn); // "ASN-2026-0384-0001-7"
// Get agent by ASN
const profile = await asn.agents.get('ASN-2026-0384-0001-7');
// Update agent
await asn.agents.update('ASN-2026-0384-0001-7', {
description: 'Updated scanner with LLM analysis',
});
// Search agents
const results = await asn.agents.search({
q: 'security',
class: 'A',
page: 1,
perPage: 20,
});asn.activity
// Report a single event
await asn.activity.report({
asn: 'ASN-2026-0384-0001-7',
eventType: 'task_completed',
severity: 'info',
metadata: {
taskId: 'scan-42',
durationMs: 1230,
result: '3 vulnerabilities found',
},
});
// Report multiple events
await asn.activity.reportBatch([
{
asn: 'ASN-2026-0384-0001-7',
eventType: 'task_completed',
metadata: { taskId: 'scan-42' },
},
{
asn: 'ASN-2026-0384-0001-7',
eventType: 'task_completed',
metadata: { taskId: 'scan-43' },
},
]);
// Query activity log
const logs = await asn.activity.list('ASN-2026-0384-0001-7', {
type: 'task_completed',
page: 1,
perPage: 50,
});asn.trust
// Get current trust score
const score = await asn.trust.get('ASN-2026-0384-7721-A');
console.log(score.overall); // 94.1
console.log(score.reliability); // 96.2
console.log(score.safety); // 95.0
// Get trust score history
const history = await asn.trust.history('ASN-2026-0384-7721-A', {
limit: 10,
});asn.verify
// Quick verification (public, no API key needed)
const quick = await asn.verify.quick('ASN-2026-0384-7721-A');
console.log(quick.status); // "active"
console.log(quick.ownership_verified); // true
console.log(quick.kyc_verified); // true
console.log(quick.trust_score); // 94.1
// Full verification (requires API key)
const full = await asn.verify.full('ASN-2026-0384-7721-A');
console.log(full.trust.reliability); // 96.2
console.log(full.operator.tier); // "pro"asn.incidents
// List incidents for an agent
const incidents = await asn.incidents.list('ASN-2026-0384-7721-A');
// Get incident details
const incident = await asn.incidents.get(
'ASN-2026-0384-7721-A',
'incident-uuid'
);
// Report an incident
await asn.incidents.report('ASN-2026-0384-7721-A', {
title: 'Elevated error rate',
description: 'Error rate exceeded 5% threshold',
severity: 'warning',
});Error Handling
import { ASN, ASNError } from '@asn-earth/sdk';
try {
await asn.agents.get('invalid-asn');
} catch (err) {
if (err instanceof ASNError) {
console.log(err.status); // 400
console.log(err.code); // "VALIDATION_ERROR"
console.log(err.message); // "Invalid ASN format"
}
}All SDK methods throw ASNError for API errors, with typed status, code, and message properties.
TypeScript Support
The SDK ships with full TypeScript definitions. All request and response types are exported:
import type {
Agent,
TrustScore,
VerifyQuickResponse,
VerifyFullResponse,
ActivityEvent,
} from '@asn-earth/sdk';