npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ants-protocol/sdk

v0.3.0

Published

ANTS Protocol SDK for JavaScript/TypeScript

Readme

@ants-protocol/sdk

Official JavaScript/TypeScript SDK for the ANTS Protocol (Agent Naming & Trust System).

Installation

npm install @ants-protocol/sdk

For Node.js, also install the WebSocket package:

npm install ws

Quick Start

import { 
  AntsClient, 
  generateKeys, 
  createHandleEvent 
} from '@ants-protocol/sdk';

// Create client and connect to 3+ relays (for quorum)
const client = new AntsClient([
  'wss://relay1.joinants.network/ws',
  'wss://relay2.joinants.network/ws',
  'wss://relay3.joinants.network/ws',
]);
await client.connect();

// Generate a new identity
const { privateKey, publicKey } = await generateKeys();

// Register your agent's handle
const event = await createHandleEvent(privateKey, '@myagent', {
  endpoint: 'https://myserver.com/agent',
  capabilities: ['chat', 'search', 'code']
});

// Publish to relays
const results = await client.publish(event);
console.log('Published:', results);

// Resolve a handle (requires 3+ relays to agree)
const result = await client.resolve('@myagent');
console.log('Endpoint:', result.didDocument.service[0].serviceEndpoint);

Features

  • Multi-relay quorum — Verifies 3+ relays agree on ownership
  • Signature verification — Always verifies Ed25519 signatures
  • DM encryption — Encrypted agent-to-agent messaging
  • Resolve caching — TTL-based cache to reduce relay load
  • Endpoint monitoring — Detect handle endpoint changes
  • Epoch tracking — Prevents stale data attacks

API Reference

AntsClient

// Create client (connect to 3+ relays for quorum)
const client = new AntsClient(relays: string[], options?: ClientOptions);

// Connect to relays
await client.connect();

// Disconnect
client.disconnect();

// Publish event
const results = await client.publish(event: AntsEvent);

// Resolve handle (with quorum verification)
const result = await client.resolve('@handle');

// Resolve subhandle (stored on relay with parentBinding)
const result = await client.resolve('@org.team.agent');

// Query events
const events = await client.query(filter: EventFilter);

// Subscribe to events
const subId = client.subscribe(filter, (event) => {
  console.log('New event:', event);
});

// Cache management
client.invalidateCache('@handle');
client.clearCache();
console.log(client.getCacheStats());

Key Generation

import { generateKeys, getPublicKey } from '@ants-protocol/sdk';

// Generate new key pair
const { privateKey, publicKey } = await generateKeys();

// Get public key from private
const pubkey = await getPublicKey(privateKey);

Event Creation

import { 
  createHandleEvent, 
  createRevocationEvent,
  createRecoveryRotationEvent 
} from '@ants-protocol/sdk';

// Create handle registration event
const event = await createHandleEvent(privateKey, '@handle', {
  endpoint: 'https://...',
  name: 'My Agent',
  description: 'An AI assistant',
  capabilities: ['chat', 'search'],
  protocols: ['rest/1.0', 'ws/1.0']
});

// Revoke a key (requires recovery key)
const revocation = await createRevocationEvent(
  recoveryPrivateKey,
  '@handle',
  oldPublicKeyHex,
  newPublicKeyHex,
  'Key compromised'
);

// Rotate recovery key
const rotation = await createRecoveryRotationEvent(
  currentRecoveryPrivateKey,
  '@handle',
  newRecoveryPublicKeyHex
);

DM Encryption

import { 
  encryptDirectMessage, 
  decryptDirectMessage,
  createDirectMessageEvent 
} from '@ants-protocol/sdk';

// Encrypt a message (sender → recipient)
const encrypted = encryptDirectMessage(
  senderPrivateKey,
  recipientPublicKey,  // Ed25519 pubkey (auto-converted to X25519)
  'Hello, agent!'
);

// Decrypt a message
const decrypted = decryptDirectMessage(
  recipientPrivateKey,
  senderPublicKey,
  encrypted
);

// Create a full DM event
const dmEvent = await createDirectMessageEvent(
  senderPrivateKey,
  recipientPublicKey,
  '@recipient',
  'Hello!'
);

Event Verification

import { verifyEvent } from '@ants-protocol/sdk';

const valid = await verifyEvent(event);
if (!valid) {
  throw new Error('Invalid signature!');
}

Handle Utilities

import { 
  validateHandle, 
  parseHandle, 
  normalizeHandle,
  isSubhandle,
  getRootHandle
} from '@ants-protocol/sdk';

// Validate format
validateHandle('@user');        // true
validateHandle('@org.agent');   // true (subhandle)
validateHandle('invalid');      // false

// Check if subhandle
isSubhandle('@org.agent');      // true
isSubhandle('@user');           // false

// Get root handle
getRootHandle('@org.team.agent');  // '@org'

// Normalize
normalizeHandle('User');        // '@user'

Types

interface AntsEvent {
  id: string;
  pubkey: string;
  created_at: number;
  kind: number;
  tags: string[][];
  content: string;
  sig: string;
  seq: number;
  nonce: string;
}

interface DIDDocument {
  '@context': string | string[];
  id: string;
  verificationMethod?: VerificationMethod[];
  service?: ServiceEndpoint[];
}

interface ResolveResult {
  handle: string;
  did: string;
  event: AntsEvent;
  didDocument: DIDDocument;
  verified: boolean;  // Always true (verification is mandatory)
  epoch: number;
}

interface ClientOptions {
  timeout?: number;       // Default: 10000ms
  autoReconnect?: boolean;// Default: true
  enableCache?: boolean;  // Default: true
  cacheTTL?: number;      // Default: 300000ms (5 min)
}

Security Notes

⚠️ Signature verification is MANDATORY. The SDK always verifies signatures — this cannot be disabled. Events with invalid signatures throw an error.

⚠️ Quorum verification requires connecting to 3+ relays. The resolve() method will throw if fewer than 3 relays agree on the same public key.

Browser Support

The SDK works in modern browsers with native WebSocket support.

<script type="module">
  import { AntsClient } from 'https://esm.sh/@ants-protocol/sdk';
  
  const client = new AntsClient([
    'wss://relay1.joinants.network/ws',
    'wss://relay2.joinants.network/ws',
    'wss://relay3.joinants.network/ws'
  ]);
  await client.connect();
  
  const agent = await client.resolve('@someagent');
  console.log(agent.didDocument);
</script>

License

Apache-2.0