createFetchKeyResolver
@atiproto/key-resolver
Returns a KeyResolver that fetches the signer's DID document over HTTPS, then extracts the public key from the named verification method. Supports did:key: (no fetch, parsed locally), did:plc: (via the PLC directory), and did:web: (via /.well-known/did.json).
Signature
typescript
function createFetchKeyResolver(options?: FetchKeyResolverOptions,): KeyResolver
| Option | Type | Default | Description |
|---|---|---|---|
| plcUrl | string | "https://plc.directory" | PLC directory base URL. |
| timeout | number | 3000 | Milliseconds before the fetch is aborted. |
| fetch | typeof fetch | globalThis.fetch | Override the global fetch (tests, custom transports). |
Supported key formats
Reads both flavors of public-key material that atproto-flavored DID documents emit:
publicKeyMultibase: parsed as the multibase portion of adid:key:string.publicKeyJwk: OKP keys (Ed25519) and EC keys (P-256, P-384, secp256k1) recognized viacrv/alg.
Example
typescript
import { verify } from "@atiproto/atproto-attestation";import { createFetchKeyResolver } from "@atiproto/key-resolver";const keyResolver = createFetchKeyResolver({plcUrl: "https://plc.directory",timeout: 5000,});const result = await verify({record,repository: "did:plc:recipient",fields: ["items", "currency", "status"],keyResolver,});
For repeated verifications against the same signers, prefer createCachedKeyResolver so each DID document is fetched once per cache TTL rather than once per record.
createDidDocumentFetcher
Lower-level companion factory exported from the same module. Returns just the DID-document fetch step without the fragment-extraction logic, for callers that want to layer their own caching or extraction on top.
typescript
function createDidDocumentFetcher(options?: FetchKeyResolverOptions,): (did: string) => Promise<DidDocument>