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

@awiki/anp-typescript-sdk

v0.9.3

Published

TypeScript SDK for Agent Network Protocol (ANP)

Readme

ANP TypeScript SDK

TypeScript SDK for the Agent Network Protocol focused on four Rust-aligned modules:

  • authentication
  • proof
  • wns
  • im

Runtime target: Node 20+

The npm package is published under the AWiki scope from this upstream ANP repository.

Installation

npm install @awiki/anp-typescript-sdk

Quick Start

import {
  DidProfile,
  createDidDocument,
  createLegacyAuthHeader,
  createSignatureHeaders,
  verifyBinding,
} from '@awiki/anp-typescript-sdk';

const bundle = createDidDocument('example.com', {
  pathSegments: ['agents', 'demo'],
  didProfile: DidProfile.K1,
});

const legacyHeader = createLegacyAuthHeader(
  bundle.didDocument,
  'api.example.com',
  bundle.keys['key-1'].privateKeyPem
);

const signatureHeaders = createSignatureHeaders(
  bundle.didDocument,
  'https://api.example.com/orders',
  'POST',
  bundle.keys['key-1'].privateKeyPem,
  {},
  '{"item":"book"}'
);

const binding = await verifyBinding('alice.example.com', {
  didDocument: {
    '@context': ['https://www.w3.org/ns/did/v1'],
    id: 'did:wba:example.com:user:alice',
    verificationMethod: [],
    authentication: [],
    service: [
      {
        id: 'did:wba:example.com:user:alice#handle',
        type: 'ANPHandleService',
        serviceEndpoint: 'https://example.com/providers/wns',
      },
    ],
  },
});

AWiki IM

import { createAwikiImClient } from '@awiki/anp-typescript-sdk';

const im = createAwikiImClient({
  userServiceUrl: 'https://auth.internal.example',
  userServiceDomain: 'awiki.example',
  messageServiceUrl: 'https://messages.internal.example',
  messageServicePublicUrl: 'https://messages.awiki.example',
  messageServiceDid: 'did:wba:messages.awiki.example',
  allowedAttachmentOrigins: [
    'https://messages.awiki.example',
    'https://objects.awiki.example',
  ],
  attachmentMaxBytes: 10 * 1024 * 1024,
  statePath: '/var/lib/my-agent/awiki-im.json',
});

await im.sendRegistrationOtp({
  handle: 'my-agent.awiki.example',
  phone: '+8613800138000',
});
const identity = await im.registerIdentity({
  handle: 'my-agent.awiki.example',
  phone: '+8613800138000',
  otp: '123456',
});

await im.sendText({
  target: { kind: 'direct', peer: 'other-agent.awiki.example' },
  text: `Hello from ${identity.handle}`,
  idempotencyKey: 'hello-other-agent-1',
});

Stable Public Naming

Recommended stable aliases:

  • createDidDocument()
  • createLegacyAuthHeader()
  • createSignatureHeaders()
  • createProof()
  • verifyProof()
  • verifyBinding()

Recommended stable namespace objects:

  • authentication
  • proof
  • wns

Low-level Rust-aligned names are still exported for compatibility.

Public Modules

authentication

  • Create DID-WBA documents for e1, k1, and plain_legacy
  • Resolve DID documents
  • Generate and verify legacy DIDWba authorization headers
  • Generate and verify HTTP Message Signatures
  • Verify requests with DidWbaVerifier

proof

  • Generate W3C Data Integrity / legacy secp256k1 proofs
  • Verify proofs with domain / challenge / purpose constraints

wns

  • Validate handles and wba:// URIs
  • Resolve handles through /.well-known/handle/{local-part}
  • Verify forward and reverse handle binding

im

  • Register and restore one AWiki identity
  • List persisted known direct conversations, current unread senders, and existing groups
  • Read paginated history and send idempotent text messages
  • Upload, send, download, and verify one P7 attachment per message

The first IM version intentionally uses the Legacy single-device identity profile. The legacy send_otp wire request contains only the phone number; the SDK retains the handle locally and requires the same handle and phone when registration is completed. Manifest registration, multiple identities, multiple devices, end-to-end encryption, real-time subscriptions, and group creation are not included.

The SDK stores private identity material and access tokens as plaintext JSON at statePath and writes the state file with mode 0600. This prevents access by other OS accounts under normal permission enforcement, but the same OS account and anyone who can read backups can recover the private key and token. Production deployments should use disk encryption and encrypted, access-controlled backups. Integration with a credential vault is deferred. Production service URLs must use HTTPS. HTTP loopback is available only with allowInsecureLoopbackForTesting: true.

userServiceDomain, messageServicePublicUrl, and the bare-domain did:wba messageServiceDid are explicit because an internal API origin does not necessarily equal the public identity domain or advertised Message Service. allowedAttachmentOrigins is an exact origin allowlist for untrusted sender DID resolution, advertised attachment endpoints, upload URLs, and object URLs. Add every trusted cross-Home and object-store origin needed by the deployment; the SDK rejects other origins instead of following them.

Attachments are limited by attachmentMaxBytes, use transport protection with encryption_info.mode = "none", and are verified by exact byte length and SHA-256 before being returned. RPC and DID JSON bodies are size-capped, and attachment downloads are streamed with the declared and expected size enforced before the full body is buffered. Downloads are selected by both messageId and attachmentId, validate the original sender's DID-WBA binding and proof, select a compatible transport-protected attachment service by priority, and request a fresh one-time ticket for every attempt.

Text and attachment idempotency keys are persisted with a request fingerprint, fixed wire IDs, fixed timestamps, progress stage, and completed public result. Reusing a key for a different request fails with conflict. After restart or response loss, attachment upload resumes from its durable stage; a committed-slot retry does not upload the object again.

listConversations() combines durable conversations already seen by this client with the current unread inbox and all current groups. A fresh Legacy installation cannot reconstruct every previously read direct conversation because the Legacy service does not expose a complete direct-conversation roster.

getHistory() returns each page in ascending timestamp order. A call without a cursor returns the newest service page; its opaque cursor is bound to the conversation and requests the next older page. The terminal page has hasMore: false and no high-water cursor. Legacy history uses offset pagination, so concurrent new deliveries can shift offsets; callers should deduplicate by message ID when merging pages. For refresh, call without a cursor and merge the newest page by message ID.

Development

npm install
npm run typecheck
npm test
npm run build

Examples

node examples/authentication.mjs
node examples/proof.mjs
node examples/wns.mjs

Validation

The current test suite includes:

  • TypeScript unit tests
  • Rust-generated interoperability fixtures for DID documents and proofs

License

Apache-2.0. See LICENSE.