Skip to main content

Overview

The @atproto/identity package provides TypeScript utilities for resolving and managing decentralized identities in the AT Protocol. It supports DID resolution (did:plc and did:web) and handle resolution via DNS and HTTP methods.

Installation

Core Concepts

The identity package handles two main types of identifiers:
  • DIDs (Decentralized Identifiers): Persistent, cryptographically-verifiable identifiers
  • Handles: Human-readable domain names that resolve to DIDs
This package provides resolvers for both identifier types and utilities for extracting AT Protocol-specific data from DID documents.

Main Exports

Classes

IdResolver

The main class that combines both DID and handle resolution.
IdentityResolverOpts
Configuration options for the resolver
Properties:
  • handle: HandleResolver - Handle resolver instance
  • did: DidResolver - DID resolver instance

DidResolver

Resolves DIDs to their DID documents. Supports did:plc and did:web methods.
DidResolverOpts
Configuration options
Methods:
Promise<DidDocument>
Resolves a DID to its document. Uses cache unless forceRefresh is true.
string
required
The DID to resolve
boolean
default:"false"
Skip cache and force fresh resolution
Promise<AtprotoData>
Resolves a DID and extracts AT Protocol-specific data.Returns an object with:
  • did: string - The DID
  • signingKey: string - The signing key in did:key format
  • handle: string - The associated handle
  • pds: string - The PDS endpoint URL

HandleResolver

Resolves handles to DIDs using DNS TXT records and HTTP well-known endpoints.
HandleResolverOpts
Configuration options
Methods:
Promise<string | undefined>
Resolves a handle to a DID. Tries DNS first, then HTTP, then backup DNS.
string
required
The handle to resolve (e.g., ‘alice.bsky.social’)
Promise<string | undefined>
Resolves via DNS TXT record at _atproto.{handle}
Promise<string | undefined>
Resolves via HTTPS at https://{handle}/.well-known/atproto-did

Utility Functions

DID Document Parsing

Extract AT Protocol-specific data from DID documents.
Partial<AtprotoData>
Extracts AT Protocol data from a DID document. Returns partial data - some fields may be undefined.
AtprotoData
Ensures all required AT Protocol fields are present. Throws if any are missing.
string | undefined
Extracts the signing key in did:key format.
string | undefined
Extracts the handle from the DID document.
string | undefined
Extracts the PDS endpoint URL.

Types

AtprotoData

Complete AT Protocol-specific data extracted from a DID document.

DidDocument

W3C DID Document structure. Re-exported from @atproto/common-web.

DidCache

Interface for implementing custom DID document caching.

Errors

The package exports several error classes:
  • DidNotFoundError - DID could not be resolved
  • PoorlyFormattedDidError - DID syntax is invalid
  • UnsupportedDidMethodError - DID method is not supported (only did:plc and did:web are supported)
  • PoorlyFormattedDidDocumentError - DID document structure is invalid
  • UnsupportedDidWebPathError - did:web path is not supported

Complete Example

Additional Resources