contextvm/cvmi

typescript-sdk

Use the @contextvm/sdk TypeScript SDK effectively. Reference for core interfaces, signers, relay handlers, transports, encryption, logging, and SDK patterns. Use when implementing SDK components, extending interfaces, configuring transports, or debugging SDK usage.

First seen Feb 12, 2026

Installation

$ npx skills add contextvm/cvmi --skill typescript-sdk

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from contextvm/cvmi.

npx skills add contextvm/cvmi

Browse all from contextvm/cvmi

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 1
License MIT
Default branch main
Open issues 0
Status Active

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 7,706 B
  • docs SUMMARY.md 287 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 35 installs

SKILL.md

ContextVM TypeScript SDK

Reference guide for using @contextvm/sdk effectively.

Installation

npm install @contextvm/sdk
# or
bun add @contextvm/sdk

Core Imports

// Transports
import { NostrClientTransport, NostrServerTransport } from '@contextvm/sdk';

// Signers
import { PrivateKeySigner } from '@contextvm/sdk';

// Relay Handlers
import { ApplesauceRelayPool } from '@contextvm/sdk';

// Components
import { NostrMCPProxy, NostrMCPGateway } from '@contextvm/sdk';

// Core types and utilities
import {
  EncryptionMode,
  CTXVM_MESSAGES_KIND,
  SERVER_ANNOUNCEMENT_KIND,
  COMMON_SCHEMA_META_NAMESPACE,
  computeCommonSchemaHash,
  createLogger,
  normalizeSchema,
  withCommonToolSchemas,
} from '@contextvm/sdk';

Core Interfaces

NostrSigner

Abstracts cryptographic signing:

interface NostrSigner {
  getPublicKey(): Promise<string>;
  signEvent(event: EventTemplate): Promise<NostrEvent>;
  nip44?: {
    encrypt(pubkey: string, plaintext: string): Promise<string>;
    decrypt(pubkey: string, ciphertext: string): Promise<string>;
  };
}

Implement for custom key management (hardware wallets, browser extensions, etc.).

RelayHandler

Manages relay connections:

interface RelayHandler {
  connect(): Promise<void>;
  disconnect(relayUrls?: string[]): Promise<void>;
  publish(event: NostrEvent): Promise<void>;
  subscribe(
    filters: Filter[],
    onEvent: (event: NostrEvent) => void,
    onEose?: () => void
  ): Promise<void>;
  unsubscribe(): void;
  getRelayUrls(): string[];
}

Must be non-blocking - subscribe() returns immediately.

Signers

PrivateKeySigner

Default signer using raw private key:

const signer = new PrivateKeySigner('32-byte-hex-private-key');
const pubkey = await signer.getPublicKey();

Security: Never hardcode keys. Use environment variables.

Custom Signers

Implement NostrSigner for:

  • Browser extensions (NIP-07)
  • Hardware wallets
  • Remote signing services
  • Secure enclaves

See [references/custom-signers.md](references/custom-signers.md) for examples.

Relay Handlers

ApplesauceRelayPool (Recommended)

Production-grade relay management:

const pool = new ApplesauceRelayPool(['wss://relay.contextvm.org']);

Features:

  • Automatic reconnection
  • Connection monitoring
  • RxJS-based observables
  • Persistent subscriptions

Use ApplesauceRelayPool for projects.

For [NostrClientTransport](cvmi/skills/typescript-sdk/SKILL.md:22), relayHandler can be omitted when the client should resolve operational relays dynamically. The resolution order is:

  1. explicit operational relays from relayHandler
  2. relay hints embedded in nprofile
  3. CEP-17 relay-list discovery via discoveryRelayUrls
  4. fallbackOperationalRelayUrls
  5. SDK bootstrap discovery relays when discoveryRelayUrls is omitted

This makes client configuration simpler when the server already publishes kind:10002 metadata.

Use [fallbackOperationalRelayUrls](cvmi/skills/typescript-sdk/SKILL.md) when you want non-authoritative operational relays to be probed in parallel with CEP-17 discovery. This is useful for low-latency local relays or known-good operational relays that should only be used when explicit relays and nprofile hints are absent.

Important semantics:

  • [relayHandler](cvmi/skills/typescript-sdk/SKILL.md:124) remains the explicit authoritative operational relay set.
  • [discoveryRelayUrls](cvmi/skills/typescript-sdk/SKILL.md) remains discovery-only.
  • [fallbackOperationalRelayUrls](cvmi/skills/typescript-sdk/SKILL.md) is non-authoritative and should not replace published kind:10002 metadata when that metadata resolves in time.

Encryption Modes

enum EncryptionMode {
  OPTIONAL = 'optional', // Use if supported (default)
  REQUIRED = 'required', // Fail if not supported
  DISABLED = 'disabled', // Never encrypt
}

Oversized Transfer

The SDK supports CEP-22 oversized payload transfer on both client and server transports.

Important consumer-facing behavior:

  • oversized transfer is enabled by default
  • transports automatically fragment and reassemble large payloads
  • most applications do not need to manage chunking directly
  • the main decision is whether to keep it enabled or disable it explicitly

Typical configuration:

const clientTransport = new NostrClientTransport({
  signer,
  serverPubkey,
  oversizedTransfer: {
    enabled: true,
  },
});

Relevant options:

  • enabled: explicit on/off switch for CEP-22 behavior
  • thresholdBytes: proactive fragmentation threshold
  • chunkSizeBytes: per-chunk size
  • acceptTimeoutMs: client-side wait time for accept-gated flows
  • policy: receiver-side limits for bytes, chunks, concurrency, ordering window, and timeout

Use lower thresholds or chunk sizes when relays are more restrictive. Tighten policy values when operating in resource-constrained or adversarial environments.

CEP-15 Common Tool Schemas

Use withCommonToolSchemas() when a server tool is intended to match a shared CEP-15 contract across providers.

const transport = withCommonToolSchemas(
  new NostrServerTransport({
    signer,
    relayHandler: relayPool,
    isAnnouncedServer: true,
  }),
  {
    tools: [{ name: 'translate_text' }],
    categories: ['translation', 'language-tools'],
  }
);

await server.connect(transport);

Important behavior:

  • the SDK computes the schema hash from the tool name, normalized inputSchema, and optional outputSchema
  • _meta['io.contextvm/common-schema'].schemaHash is injected into tools/list results
  • matching i and k tags are added to announced tools lists
  • optional CEP-15 t tags are added when categories are configured; whitespace is trimmed, empty values are dropped, and duplicates are removed
  • remote $ref values must be resolved before hashing

Use computeCommonSchemaHash() and normalizeSchema() for manual verification, tests, or advanced custom flows.

Logging

import { createLogger } from '@contextvm/sdk/core';

const logger = createLogger('my-module');

logger.info('event.name', {
  module: 'my-module',
  txId: 'abc-123',
  durationMs: 245,
});

Configure via environment:

  • LOG_LEVEL=debug|info|warn|error
  • LOG_DESTINATION=stderr|stdout|file
  • LOG_FILE=/path/to/file
  • LOG_ENABLED=true|false

Constants

Constant Value Description
CTXVMMESSAGESKIND 25910 Ephemeral messages
SERVERANNOUNCEMENTKIND 11316 Server metadata
RELAYLISTMETADATA_KIND 10002 Relay-list metadata
TOOLSLISTKIND 11317 Tools announcement
RESOURCESLISTKIND 11318 Resources announcement
GIFTWRAPKIND 1059 Encrypted messages

SDK Patterns

See [references/patterns.md](references/patterns.md) for:

  • Error handling
  • Retry strategies
  • Connection lifecycle
  • Resource cleanup

API Reference

  • [references/interfaces.md](references/interfaces.md) - Complete interface definitions
  • [references/constants.md](references/constants.md) - All exported constants
  • [references/logging.md](references/logging.md) - Logging best practices