@atproto-labs/handle-resolver 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atproto-labs/handle-resolver
2
2
 
3
+ ## 0.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`09439d7d6`](https://github.com/bluesky-social/atproto/commit/09439d7d688294ad1a0c78a74b901ba2f7c5f4c3)]:
8
+ - @atproto/did@0.2.1
9
+
10
+ ## 0.3.1
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [[`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d), [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d), [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d), [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d), [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d), [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d)]:
15
+ - @atproto/did@0.2.0
16
+ - @atproto-labs/simple-store@0.3.0
17
+ - @atproto-labs/simple-store-memory@0.1.4
18
+
3
19
  ## 0.3.0
4
20
 
5
21
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"atproto-doh-handle-resolver.js","sourceRoot":"","sources":["../src/atproto-doh-handle-resolver.ts"],"names":[],"mappings":";;;AAAA,6EAGqC;AACrC,yEAAgE;AAWhE,MAAa,wBACX,SAAQ,kDAAqB;IAG7B,YAAY,OAAwC;QAClD,KAAK,CAAC;YACJ,GAA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AAO,MAAM,CAAC,IAAI,KAAK,QAAQ;QAC/B,MAAM,IAAI,MAAM;QAChB,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;QAC/B,KAAK,IAAI,MAAM;QACf,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,CAC/B,CAAA;AACH,CAAC;AAGD,SAAS,WAAW,CAAC,MAAc;IACjC,OAAO,MAAM,CAAC,IAAI,KAAK,EAAE,CAAA;AAC3B,CAAC;AAED,SAAS,cAAc,CAAC,MAAiB;IACvC,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAC/D,CAAC","sourcesContent":["import {\n AtprotoHandleResolver,\n AtprotoHandleResolverOptions,\n} from './atproto-handle-resolver.js'\nimport { HandleResolverError } from './handle-resolver-error.js'\nimport { ResolveTxt } from './internal-resolvers/dns-handle-resolver.js'\nimport { HandleResolver } from './types.js'\n\nexport type AtprotoDohHandleResolverOptions = Omit<\n AtprotoHandleResolverOptions,\n 'resolveTxt' | 'resolveTxtFallback'\n> & {\n dohEndpoint: string | URL\n}\n\nexport class AtprotoDohHandleResolver\n extends AtprotoHandleResolver\n implements HandleResolver\n{\n constructor(options: AtprotoDohHandleResolverOptions) {\n super({\n ...options,\n resolveTxt: dohResolveTxtFactory(options),\n resolveTxtFallback: undefined,\n })\n }\n}\n\n/**\n * Resolver for DNS-over-HTTPS (DoH) handles. Only works with servers supporting\n * Google Flavoured \"application/dns-json\" queries.\n *\n * @see {@link https://developers.google.com/speed/public-dns/docs/doh/json}\n * @see {@link https://developers.cloudflare.com/1.1.1.1/encryption/dns-over-https/make-api-requests/dns-json/}\n * @todo Add support for DoH using application/dns-message (?)\n */\nfunction dohResolveTxtFactory({\n dohEndpoint,\n fetch = globalThis.fetch,\n}: AtprotoDohHandleResolverOptions): ResolveTxt {\n return async (hostname) => {\n const url = new URL(dohEndpoint)\n url.searchParams.set('type', 'TXT')\n url.searchParams.set('name', hostname)\n\n const response = await fetch(url, {\n method: 'GET',\n headers: { accept: 'application/dns-json' },\n redirect: 'follow',\n })\n try {\n const contentType = response.headers.get('content-type')?.trim()\n if (!response.ok) {\n const message = contentType?.startsWith('text/plain')\n ? await response.text()\n : `Failed to resolve ${hostname}`\n throw new HandleResolverError(message)\n } else if (contentType?.match(/application\\/(dns-)?json/i) == null) {\n throw new HandleResolverError('Unexpected response from DoH server')\n }\n\n const result = asResult(await response.json())\n return result.Answer?.filter(isAnswerTxt).map(extractTxtData) ?? null\n } finally {\n // Make sure to always cancel the response body as some engines (Node 👀)\n // do not do this automatically.\n // https://undici.nodejs.org/#/?id=garbage-collection\n if (response.bodyUsed === false) {\n // Handle rejection asynchronously\n void response.body?.cancel().catch(onCancelError)\n }\n }\n }\n}\n\nfunction onCancelError(err: unknown) {\n if (!(err instanceof DOMException) || err.name !== 'AbortError') {\n console.error('An error occurred while cancelling the response body:', err)\n }\n}\n\ntype Result = { Status: number; Answer?: Answer[] }\nfunction isResult(result: unknown): result is Result {\n if (typeof result !== 'object' || result === null) return false\n if (!('Status' in result) || typeof result.Status !== 'number') return false\n if ('Answer' in result && !isArrayOf(result.Answer, isAnswer)) return false\n return true\n}\nfunction asResult(result: unknown): Result {\n if (isResult(result)) return result\n throw new HandleResolverError('Invalid DoH response')\n}\n\nfunction isArrayOf<T>(\n value: unknown,\n predicate: (v: unknown) => v is T,\n): value is T[] {\n return Array.isArray(value) && value.every(predicate)\n}\n\ntype Answer = { name: string; type: number; data: string; TTL: number }\nfunction isAnswer(answer: unknown): answer is Answer {\n return (\n typeof answer === 'object' &&\n answer !== null &&\n 'name' in answer &&\n typeof answer.name === 'string' &&\n 'type' in answer &&\n typeof answer.type === 'number' &&\n 'data' in answer &&\n typeof answer.data === 'string' &&\n 'TTL' in answer &&\n typeof answer.TTL === 'number'\n )\n}\n\ntype AnswerTxt = Answer & { type: 16 }\nfunction isAnswerTxt(answer: Answer): answer is AnswerTxt {\n return answer.type === 16\n}\n\nfunction extractTxtData(answer: AnswerTxt): string {\n return answer.data.replace(/^\"|\"$/g, '').replace(/\\\\\"/g, '\"')\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"atproto-handle-resolver.js","sourceRoot":"","sources":["../src/atproto-handle-resolver.ts"],"names":[],"mappings":";;;AAAA,wFAGoD;AACpD,wGAG4D;AAa5D,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA;AAErB;;;;;GAKG;AACH,MAAa,qBAAqB;IAKhC,YAAY,OAAqC;QAJhC;;;;;WAA4B;QAC5B;;;;;WAA2B;QAC3B;;;;;WAAoC;QAGnD,IAAI,CAAC,YAAY,GAAG,IAAI,wDAAuB,CAAC,OAAO,CAAC,CAAA;QACxD,IAAI,CAAC,WAAW,GAAG,IAAI,0CAAiB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QAC5D,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,kBAAkB;YACnD,CAAC,CAAC,IAAI,0CAAiB,CAAC,OAAO,CAAC,kBAAkB,CAAC;YACnD,CAAC,CAAC,SAAS,CAAA;IACf,CAAC;IAED,KAAK,CAAC,OAAO,CACX,MAAc,EACd,OAA8B;QAE9B,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;QAEjC,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;QAC7C,MAAM,EAAE,MAAM,EAAE,GAAG,eAAe,CAAA;QAClC,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE;YACxE,MAAM;SACP,CAAC,CAAA;QAEF,MAAM,cAAc,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAA;QAE7C,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;YACnE,M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X,MAAc,EACd,OAA8B;QAE9B,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;QAEjC,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;QAC7C,MAAM,EAAE,MAAM,EAAE,GAAG,eAAe,CAAA;QAClC,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE;YACxE,MAAM;SACP,CAAC,CAAA;QAEF,MAAM,cAAc,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAA;QAE7C,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;YACnE,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;YAErE,qCAAqC;YACrC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YAEvB,MAAM,MAAM,GAAG,MAAM,UAAU,CAAA;YAC/B,IAAI,MAAM;gBAAE,OAAO,MAAM,CAAA;YAEzB,MAAM,CAAC,cAAc,EAAE,CAAA;YAEvB,MAAM,GAAG,GAAG,MAAM,WAAW,CAAA;YAC7B,IAAI,GAAG;gBAAE,OAAO,GAAG,CAAA;YAEnB,MAAM,CAAC,cAAc,EAAE,CAAA;YAEvB,OAAO,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,MAAM,EAAE,cAAc,CAAC,IAAI,IAAI,CAAA;QAC1E,CAAC;gBAAS,CAAC;YACT,0EAA0E;YAC1E,eAAe,CAAC,KAAK,EAAE,CAAA;QACzB,CAAC;IACH,CAAC;CACF;AAlDD,sDAkDC","sourcesContent":["import {\n DnsHandleResolver,\n ResolveTxt,\n} from './internal-resolvers/dns-handle-resolver.js'\nimport {\n WellKnownHandleResolver,\n WellKnownHandleResolverOptions,\n} from './internal-resolvers/well-known-handler-resolver.js'\nimport {\n HandleResolver,\n ResolveHandleOptions,\n ResolvedHandle,\n} from './types.js'\n\nexport type { ResolveTxt }\nexport type AtprotoHandleResolverOptions = WellKnownHandleResolverOptions & {\n resolveTxt: ResolveTxt\n resolveTxtFallback?: ResolveTxt\n}\n\nconst noop = () => {}\n\n/**\n * Implementation of the official ATPROTO handle resolution strategy.\n * This implementation relies on two primitives:\n * - HTTP Well-Known URI resolution (requires a `fetch()` implementation)\n * - DNS TXT record resolution (requires a `resolveTxt()` function)\n */\nexport class AtprotoHandleResolver implements HandleResolver {\n private readonly httpResolver: HandleResolver\n private readonly dnsResolver: HandleResolver\n private readonly dnsResolverFallback?: HandleResolver\n\n constructor(options: AtprotoHandleResolverOptions) {\n this.httpResolver = new WellKnownHandleResolver(options)\n this.dnsResolver = new DnsHandleResolver(options.resolveTxt)\n this.dnsResolverFallback = options.resolveTxtFallback\n ? new DnsHandleResolver(options.resolveTxtFallback)\n : undefined\n }\n\n async resolve(\n handle: string,\n options?: ResolveHandleOptions,\n ): Promise<ResolvedHandle> {\n options?.signal?.throwIfAborted()\n\n const abortController = new AbortController()\n const { signal } = abortController\n options?.signal?.addEventListener('abort', () => abortController.abort(), {\n signal,\n })\n\n const wrappedOptions = { ...options, signal }\n\n try {\n const dnsPromise = this.dnsResolver.resolve(handle, wrappedOptions)\n const httpPromise = this.httpResolver.resolve(handle, wrappedOptions)\n\n // Prevent uncaught promise rejection\n httpPromise.catch(noop)\n\n const dnsRes = await dnsPromise\n if (dnsRes) return dnsRes\n\n signal.throwIfAborted()\n\n const res = await httpPromise\n if (res) return res\n\n signal.throwIfAborted()\n\n return this.dnsResolverFallback?.resolve(handle, wrappedOptions) ?? null\n } finally {\n // Cancel pending requests, and remove \"abort\" listener on incoming signal\n abortController.abort()\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"cached-handle-resolver.js","sourceRoot":"","sources":["../src/cached-handle-resolver.ts"],"names":[],"mappings":";;;AAAA,6DAAsE;AACtE,2EAAqE;AASrE,MAAa,oBAAoB;IAG/B;IACE;;OAEG;IACH,QAAwB,EACxB,QAAqB,IAAI,uCAAiB,CAAyB;QACjE,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,EAAE,GAAG,IAAI;KACf,CAAC;QAVI;;;;;WAA4C;QAYlD,IAAI,CAAC,MAAM,GAAG,IAAI,2BAAY,CAC5B,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,EACtD,KAAK,CACN,CAAA;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CACX,MAAc,EACd,OAA8B;QAE9B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,CAAC;CACF;AAzBD,oDAyBC"}
1
+ {"version":3,"file":"cached-handle-resolver.js","sourceRoot":"","sources":["../src/cached-handle-resolver.ts"],"names":[],"mappings":";;;AAAA,6DAAsE;AACtE,2EAAqE;AASrE,MAAa,oBAAoB;IAG/B;IACE;;OAEG;IACH,QAAwB,EACxB,QAAqB,IAAI,uCAAiB,CAAyB;QACjE,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,EAAE,GAAG,IAAI;KACf,CAAC;QAVI;;;;;WAA4C;QAYlD,IAAI,CAAC,MAAM,GAAG,IAAI,2BAAY,CAC5B,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,EACtD,KAAK,CACN,CAAA;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CACX,MAAc,EACd,OAA8B;QAE9B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,CAAC;CACF;AAzBD,oDAyBC","sourcesContent":["import { CachedGetter, SimpleStore } from '@atproto-labs/simple-store'\nimport { SimpleStoreMemory } from '@atproto-labs/simple-store-memory'\nimport {\n HandleResolver,\n ResolveHandleOptions,\n ResolvedHandle,\n} from './types.js'\n\nexport type HandleCache = SimpleStore<string, ResolvedHandle>\n\nexport class CachedHandleResolver implements HandleResolver {\n private getter: CachedGetter<string, ResolvedHandle>\n\n constructor(\n /**\n * The resolver that will be used to resolve handles.\n */\n resolver: HandleResolver,\n cache: HandleCache = new SimpleStoreMemory<string, ResolvedHandle>({\n max: 1000,\n ttl: 10 * 60e3,\n }),\n ) {\n this.getter = new CachedGetter<string, ResolvedHandle>(\n (handle, options) => resolver.resolve(handle, options),\n cache,\n )\n }\n\n async resolve(\n handle: string,\n options?: ResolveHandleOptions,\n ): Promise<ResolvedHandle> {\n return this.getter.get(handle, options)\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"handle-resolver-error.js","sourceRoot":"","sources":["../src/handle-resolver-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;IAA9C;;QACE;;;;mBAAO,qBAAqB;WAAA;IAC9B,CAAC;CAAA;AAFD,kDAEC"}
1
+ {"version":3,"file":"handle-resolver-error.js","sourceRoot":"","sources":["../src/handle-resolver-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;IAA9C;;QACE;;;;mBAAO,qBAAqB;WAAA;IAC9B,CAAC;CAAA;AAFD,kDAEC","sourcesContent":["export class HandleResolverError extends Error {\n name = 'HandleResolverError'\n}\n"]}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA0C;AAC1C,6CAA0B;AAE1B,mCAAmC;AACnC,4DAAyC;AACzC,mEAAgD;AAChD,+DAA4C;AAE5C,kCAAkC;AAClC,8DAA2C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA0C;AAC1C,6CAA0B;AAE1B,mCAAmC;AACnC,4DAAyC;AACzC,mEAAgD;AAChD,+DAA4C;AAE5C,kCAAkC;AAClC,8DAA2C","sourcesContent":["export * from './handle-resolver-error.js'\nexport * from './types.js'\n\n// Main Handle Resolvers strategies\nexport * from './xrpc-handle-resolver.js'\nexport * from './atproto-doh-handle-resolver.js'\nexport * from './atproto-handle-resolver.js'\n\n// Handle Resolver Caching utility\nexport * from './cached-handle-resolver.js'\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"dns-handle-resolver.js","sourceRoot":"","sources":["../../src/internal-resolvers/dns-handle-resolver.ts"],"names":[],"mappings":";;;AAAA,oCAA2E;AAE3E,MAAM,SAAS,GAAG,UAAU,CAAA;AAC5B,MAAM,MAAM,GAAG,MAAM,CAAA;AAQrB,MAAa,iBAAiB;IAC5B,YAAsB,UAAsB;QAAhC;;;;mBAAU,UAAU;WAAY;IAAG,CAAC;IAEhD,KAAK,CAAC,OAAO,CAAC,MAAc;QAC1B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,SAAS,IAAI,MAAM,EAAE,CAAC,CAAA;QAE1E,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAA;QAEzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,kDAAkD;YAClD,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;gBAAE,SAAQ;YAE5C,qDAAqD;YACrD,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC5C,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;oBAAE,OAAO,IAAI,CAAA;YAChD,CAAC;YAED,iDAAiD;YACjD,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O,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAE3C,qBAAqB;YACrB,OAAO,IAAA,wBAAgB,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAA;QAC3C,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA1BD,8CA0BC","sourcesContent":["import { HandleResolver, ResolvedHandle, isResolvedHandle } from '../types'\n\nconst SUBDOMAIN = '_atproto'\nconst PREFIX = 'did='\n\n/**\n * DNS TXT record resolver. Return `null` if the hostname successfully does not\n * resolve to a valid DID. Throw an error if an unexpected error occurs.\n */\nexport type ResolveTxt = (hostname: string) => Promise<null | string[]>\n\nexport class DnsHandleResolver implements HandleResolver {\n constructor(protected resolveTxt: ResolveTxt) {}\n\n async resolve(handle: string): Promise<ResolvedHandle> {\n const results = await this.resolveTxt.call(null, `${SUBDOMAIN}.${handle}`)\n\n if (!results) return null\n\n for (let i = 0; i < results.length; i++) {\n // If the line does not start with \"did=\", skip it\n if (!results[i].startsWith(PREFIX)) continue\n\n // Ensure no other entry starting with \"did=\" follows\n for (let j = i + 1; j < results.length; j++) {\n if (results[j].startsWith(PREFIX)) return null\n }\n\n // Note: No trimming (to be consistent with spec)\n const did = results[i].slice(PREFIX.length)\n\n // Invalid DBS record\n return isResolvedHandle(did) ? did : null\n }\n\n return null\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"well-known-handler-resolver.js","sourceRoot":"","sources":["../../src/internal-resolvers/well-known-handler-resolver.ts"],"names":[],"mappings":";;;AAAA,0CAKoB;AAcpB,MAAa,uBAAuB;IAGlC,YAAY,OAAwC;QAFjC;;;;;WAA8B;QAG/C,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,UAAU,CAAC,KAAK,CAAA;IACjD,CAAC;IAEM,KAAK,CAAC,OAAO,CAClB,MAAc,EACd,OAA8B;QAE9B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,0BAA0B,EAAE,WAAW,MAAM,EAAE,CAAC,CAAA;QAEpE,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE;gBAChD,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;gBAChD,MAAM,EAAE,OAAO,EAAE,MAAM;gBACvB,QAAQ,EAAE,OAAO;aAClB,CAAC,CAAA;YACF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;YAClC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,CAAA;YAE7C,IAAI,IAAA,2BAAgB,EAAC,SAAS,CAAC;gBAAE,OAAO,SAAS,CAAA;YAEjD,OAAO,IAAI,CAAA;QACb,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,uEAAuE;YACvE,0DAA0D;YAC1D,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;YAEjC,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;CACF;AAjCD,0DAiCC"}
1
+ {"version":3,"file":"well-known-handler-resolver.js","sourceRoot":"","sources":["../../src/internal-resolvers/well-known-handler-resolver.ts"],"names":[],"mappings":";;;AAAA,0CAKoB;AAcpB,MAAa,uBAAuB;IAGlC,YAAY,OAAwC;QAFjC;;;;;WAA8B;QAG/C,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,UAAU,CAAC,KAAK,CAAA;IACjD,CAAC;IAEM,KAAK,CAAC,OAAO,CAClB,MAAc,EACd,OAA8B;QAE9B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,0BAA0B,EAAE,WAAW,MAAM,EAAE,CAAC,CAAA;QAEpE,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE;gBAChD,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;gBAChD,MAAM,EAAE,OAAO,EAAE,MAAM;gBACvB,QAAQ,EAAE,OAAO;aAClB,CAAC,CAAA;YACF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;YAClC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,CAAA;YAE7C,IAAI,IAAA,2BAAgB,EAAC,SAAS,CAAC;gBAAE,OAAO,SAAS,CAAA;YAEjD,OAAO,IAAI,CAAA;QACb,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,uEAAuE;YACvE,0DAA0D;YAC1D,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;YAEjC,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;CACF;AAjCD,0DAiCC","sourcesContent":["import {\n HandleResolver,\n ResolveHandleOptions,\n ResolvedHandle,\n isResolvedHandle,\n} from '../types.js'\n\nexport type WellKnownHandleResolverOptions = {\n /**\n * Fetch function to use for HTTP requests. Allows customizing the request\n * behavior, e.g. adding headers, setting a timeout, mocking, etc. The\n * provided fetch function will be wrapped with a safeFetchWrap function that\n * adds SSRF protection.\n *\n * @default `globalThis.fetch`\n */\n fetch?: typeof globalThis.fetch\n}\n\nexport class WellKnownHandleResolver implements HandleResolver {\n protected readonly fetch: typeof globalThis.fetch\n\n constructor(options?: WellKnownHandleResolverOptions) {\n this.fetch = options?.fetch ?? globalThis.fetch\n }\n\n public async resolve(\n handle: string,\n options?: ResolveHandleOptions,\n ): Promise<ResolvedHandle> {\n const url = new URL('/.well-known/atproto-did', `https://${handle}`)\n\n try {\n const response = await this.fetch.call(null, url, {\n cache: options?.noCache ? 'no-cache' : undefined,\n signal: options?.signal,\n redirect: 'error',\n })\n const text = await response.text()\n const firstLine = text.split('\\n')[0]!.trim()\n\n if (isResolvedHandle(firstLine)) return firstLine\n\n return null\n } catch (err) {\n // The the request failed, assume the handle does not resolve to a DID,\n // unless the failure was due to the signal being aborted.\n options?.signal?.throwIfAborted()\n\n return null\n }\n }\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -11,8 +11,8 @@ export type ResolvedHandle = null | AtprotoDid;
11
11
  /**
12
12
  * @see {@link https://atproto.com/specs/did#blessed-did-methods}
13
13
  */
14
- export declare function isResolvedHandle<T>(value: T): value is T & ResolvedHandle;
15
- export declare function asResolvedHandle(value: string): ResolvedHandle;
14
+ export declare function isResolvedHandle(value: unknown): value is ResolvedHandle;
15
+ export declare function asResolvedHandle<T>(value: T): null | (T & AtprotoDid);
16
16
  export interface HandleResolver {
17
17
  /**
18
18
  * @returns the DID that corresponds to the given handle, or `null` if no DID
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgB,MAAM,cAAc,CAAA;AACvD,YAAY,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAEzE,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,GAAG,UAAU,CAAA;AAE9C;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,cAAc,CAEzE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAE9D;AAED,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,OAAO,CACL,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,cAAc,CAAC,CAAA;CAC3B"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgB,MAAM,cAAc,CAAA;AACvD,YAAY,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAEzE,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,GAAG,UAAU,CAAA;AAE9C;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAExE;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAErE;AAED,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,OAAO,CACL,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,cAAc,CAAC,CAAA;CAC3B"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AAgBA,4CAEC;AAED,4CAEC;AAtBD,sCAAuD;AAavD;;GAEG;AACH,SAAgB,gBAAgB,CAAI,KAAQ;IAC1C,OAAO,KAAK,KAAK,IAAI,IAAI,IAAA,kBAAY,EAAC,KAAK,CAAC,CAAA;AAC9C,CAAC;AAED,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AAC/C,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AAgBA,4CAEC;AAED,4CAEC;AAtBD,sCAAuD;AAavD;;GAEG;AACH,SAAgB,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,KAAK,IAAI,IAAI,IAAA,kBAAY,EAAC,KAAK,CAAC,CAAA;AAC9C,CAAC;AAED,SAAgB,gBAAgB,CAAI,KAAQ;IAC1C,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AAC/C,CAAC","sourcesContent":["import { AtprotoDid, isAtprotoDid } from '@atproto/did'\nexport type { AtprotoDid, AtprotoIdentityDidMethods } from '@atproto/did'\n\nexport type ResolveHandleOptions = {\n signal?: AbortSignal\n noCache?: boolean\n}\n\n/**\n * @see {@link https://atproto.com/specs/did#blessed-did-methods}\n */\nexport type ResolvedHandle = null | AtprotoDid\n\n/**\n * @see {@link https://atproto.com/specs/did#blessed-did-methods}\n */\nexport function isResolvedHandle(value: unknown): value is ResolvedHandle {\n return value === null || isAtprotoDid(value)\n}\n\nexport function asResolvedHandle<T>(value: T): null | (T & AtprotoDid) {\n return isResolvedHandle(value) ? value : null\n}\n\nexport interface HandleResolver {\n /**\n * @returns the DID that corresponds to the given handle, or `null` if no DID\n * is found. `null` should only be returned if no unexpected behavior occurred\n * during the resolution process.\n * @throws Error if the resolution method fails due to an unexpected error, or\n * if the resolution is aborted ({@link ResolveHandleOptions}).\n */\n resolve(\n handle: string,\n options?: ResolveHandleOptions,\n ): Promise<ResolvedHandle>\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"xrpc-handle-resolver.js","sourceRoot":"","sources":["../src/xrpc-handle-resolver.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AACvB,yEAAgE;AAChE,yCAKmB;AAEN,QAAA,eAAe,GAAG,OAAC,CAAC,MAAM,CAAC;IACtC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;IACjB,OAAO,EAAE,OAAC,CAAC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andleResolver,\n ResolveHandleOptions,\n ResolvedHandle,\n isResolvedHandle,\n} from './types.js'\n\nexport const xrpcErrorSchema = z.object({\n error: z.string(),\n message: z.string().optional(),\n})\n\nexport type XrpcHandleResolverOptions = {\n /**\n * Fetch function to use for HTTP requests. Allows customizing the request\n * behavior, e.g. adding headers, setting a timeout, mocking, etc.\n *\n * @default globalThis.fetch\n */\n fetch?: typeof globalThis.fetch\n}\n\nexport class XrpcHandleResolver implements HandleResolver {\n /**\n * URL of the atproto lexicon server. This is the base URL where the\n * `com.atproto.identity.resolveHandle` XRPC method is located.\n */\n protected readonly serviceUrl: URL\n protected readonly fetch: typeof globalThis.fetch\n\n constructor(service: URL | string, options?: XrpcHandleResolverOptions) {\n this.serviceUrl = new URL(service)\n this.fetch = options?.fetch ?? globalThis.fetch\n }\n\n public async resolve(\n handle: string,\n options?: ResolveHandleOptions,\n ): Promise<ResolvedHandle> {\n const url = new URL(\n '/xrpc/com.atproto.identity.resolveHandle',\n this.serviceUrl,\n )\n url.searchParams.set('handle', handle)\n\n const response = await this.fetch.call(null, url, {\n cache: options?.noCache ? 'no-cache' : undefined,\n signal: options?.signal,\n redirect: 'error',\n })\n const payload = await response.json()\n\n // The response should either be\n // - 400 Bad Request with { error: 'InvalidRequest', message: 'Unable to resolve handle' }\n // - 200 OK with { did: NonNullable<ResolvedHandle> }\n // Any other response is considered unexpected behavior an should throw an error.\n\n if (response.status === 400) {\n const { error, data } = xrpcErrorSchema.safeParse(payload)\n if (error) {\n throw new HandleResolverError(\n `Invalid response from resolveHandle method: ${error.message}`,\n { cause: error },\n )\n }\n if (\n data.error === 'InvalidRequest' &&\n data.message === 'Unable to resolve handle'\n ) {\n return null\n }\n }\n\n if (!response.ok) {\n throw new HandleResolverError(\n 'Invalid status code from resolveHandle method',\n )\n }\n\n const value: unknown = payload?.did\n\n if (!isResolvedHandle(value)) {\n throw new HandleResolverError(\n 'Invalid DID returned from resolveHandle method',\n )\n }\n\n return value\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto-labs/handle-resolver",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "license": "MIT",
5
5
  "description": "Isomorphic ATProto handle to DID resolver",
6
6
  "keywords": [
@@ -29,9 +29,9 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "zod": "^3.23.8",
32
- "@atproto-labs/simple-store": "0.2.0",
33
- "@atproto-labs/simple-store-memory": "0.1.3",
34
- "@atproto/did": "0.1.5"
32
+ "@atproto-labs/simple-store": "0.3.0",
33
+ "@atproto-labs/simple-store-memory": "0.1.4",
34
+ "@atproto/did": "0.2.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "typescript": "^5.6.3"
package/src/types.ts CHANGED
@@ -14,11 +14,11 @@ export type ResolvedHandle = null | AtprotoDid
14
14
  /**
15
15
  * @see {@link https://atproto.com/specs/did#blessed-did-methods}
16
16
  */
17
- export function isResolvedHandle<T>(value: T): value is T & ResolvedHandle {
17
+ export function isResolvedHandle(value: unknown): value is ResolvedHandle {
18
18
  return value === null || isAtprotoDid(value)
19
19
  }
20
20
 
21
- export function asResolvedHandle(value: string): ResolvedHandle {
21
+ export function asResolvedHandle<T>(value: T): null | (T & AtprotoDid) {
22
22
  return isResolvedHandle(value) ? value : null
23
23
  }
24
24