New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

@botparty/sdk

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@botparty/sdk

Client SDK for BotParty — federated bot identity, authentication, and payments

npmnpm
Version
0.0.81
Version published
Weekly downloads
29
-80.27%
Maintainers
1
Weekly downloads
 
Created
Source

@botparty/sdk

Client SDK for BotParty — federated bot identity, authentication, and payments.

Zero config. One function. Your bot gets an identity, rotates its keys, and authenticates on any BotParty-compatible server automatically.

Install

npm install @botparty/sdk

Quick Start

import { botpartyFetch } from '@botparty/sdk';

// That's it. First call auto-registers a namespace and generates a keypair.
const res = await botpartyFetch('https://api.example.com/data');
const data = await res.json();

On first run, the SDK:

  • Generates an Ed25519 keypair
  • Registers a namespace like brave-fox-a3f2 on the BotParty server
  • Stores the identity in ~/.botparty/

On every call, it:

  • Checks if the key is about to go stale → auto-rotates
  • Signs a JWT with the namespace identity
  • Sends the request with Authorization: Bearer <jwt>

Error Handling

BotParty-compatible servers return typed errors that the SDK catches and throws as specific error classes. Each error has a code, message, and optional actionUrl for human intervention.

import {
  botpartyFetch,
  NamespaceLockedError,
  PaymentRequiredError,
  InsufficientPermissionError,
  LinkRequiredError,
} from '@botparty/sdk';

try {
  const res = await botpartyFetch('https://api.example.com/data');
} catch (err) {
  if (err instanceof NamespaceLockedError) {
    console.log('Namespace locked! Human must unlock at:', err.actionUrl);
  }
  if (err instanceof PaymentRequiredError) {
    console.log('Payment needed:', err.message, err.actionUrl);
  }
  if (err instanceof InsufficientPermissionError) {
    console.log('Missing scopes:', err.missingScopes);
  }
  if (err instanceof LinkRequiredError) {
    console.log('Link a human account at:', err.actionUrl);
  }
}

Advanced Usage

Use BotPartyClient for full control over registration, key management, and namespace operations.

import { BotPartyClient } from '@botparty/sdk';

const client = new BotPartyClient({
  serverUrl: 'https://id.botparty.club',  // default
  algorithm: 'EdDSA',                  // default (also supports ES256)
  rotationTTL: 15,                     // minutes, default
});

// Register with a custom name
await client.register('my-cool-bot', 'My Cool Bot');

// Or let it auto-register
await client.ensureRegistered();

// Generate a JWT token (handles registration + rotation automatically)
const token = await client.generateToken();

// Authenticated fetch
const res = await client.fetch('https://api.example.com/data');

// Check identity
const me = client.whoami();
// { namespace: 'my-cool-bot', keyId: 'key_...', staleAt: '...', ... }

Key Management

// List all keys
const keys = await client.keys.list();

// Add a delegated key
await client.keys.add({
  publicKey: '-----BEGIN PUBLIC KEY-----\n...',
  scopes: ['mongo://production/*:read'],
  rotationTTL: 60,
});

// Rotate the current machine's key
await client.keys.rotateCurrent();

// Fluent key operations
const key = client.key('key_abc123');
await key.info();
await key.update({ label: 'Updated label' });
await key.invalidate('Suspected compromise');
await key.delete();

Namespace Operations

// Get namespace info from server
const info = await client.info();
// { namespace: '...', status: 'active', linked: true, activeKeys: 2, ... }

// Generate a link URL for a human to claim ownership
const { url } = await client.link();
console.log('Share this with your human:', url);

// Destroy namespace (irreversible)
await client.destroy();

// Clear local state only
client.reset();

Configuration

OptionEnv VariableDefaultDescription
serverUrlBOTPARTY_SERVER_URLhttps://id.botparty.clubBotParty server URL
stateDirBOTPARTY_STATE_DIR~/.botpartyLocal state directory
algorithmEdDSAKey algorithm (EdDSA or ES256)
rotationTTL15Key rotation TTL in minutes

State Files

The SDK stores identity and keys in ~/.botparty/:

~/.botparty/
├── identity.json    # namespace, keyId, algorithm, rotatedAt, etc.
└── private.pem      # Ed25519/EC private key (mode 0600)

Error Classes

ClassCodeHTTPDescription
BotPartyErrorvariesvariesBase error class
NamespaceLockedErrorNAMESPACE_LOCKED423Namespace locked, human must unlock
PaymentRequiredErrorPAYMENT_REQUIRED402Payment needed for this action
InsufficientPermissionErrorINSUFFICIENT_PERMISSION403Missing required scopes
LinkRequiredErrorLINK_REQUIRED403Must link a human account

All errors have .code, .message, .statusCode, and .actionUrl (when applicable).

License

MIT

Keywords

botparty

FAQs

Package last updated on 02 Jun 2026

Related posts