@atproto-labs/handle-resolver 0.3.6 → 0.4.0-next.0
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 +21 -0
- package/dist/atproto-doh-handle-resolver.js +6 -10
- package/dist/atproto-doh-handle-resolver.js.map +1 -1
- package/dist/atproto-handle-resolver.js +6 -28
- package/dist/atproto-handle-resolver.js.map +1 -1
- package/dist/cached-handle-resolver.js +5 -15
- package/dist/cached-handle-resolver.js.map +1 -1
- package/dist/create-handle-resolver.js +6 -9
- package/dist/create-handle-resolver.js.map +1 -1
- package/dist/handle-resolver-error.js +2 -11
- package/dist/handle-resolver-error.js.map +1 -1
- package/dist/index.js +7 -23
- package/dist/index.js.map +1 -1
- package/dist/internal-resolvers/dns-handle-resolver.d.ts +1 -1
- package/dist/internal-resolvers/dns-handle-resolver.d.ts.map +1 -1
- package/dist/internal-resolvers/dns-handle-resolver.js +4 -13
- package/dist/internal-resolvers/dns-handle-resolver.js.map +1 -1
- package/dist/internal-resolvers/well-known-handler-resolver.js +3 -13
- package/dist/internal-resolvers/well-known-handler-resolver.js.map +1 -1
- package/dist/types.js +4 -8
- package/dist/types.js.map +1 -1
- package/dist/xrpc-handle-resolver.js +12 -32
- package/dist/xrpc-handle-resolver.js.map +1 -1
- package/package.json +9 -8
- package/src/internal-resolvers/dns-handle-resolver.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atproto-labs/handle-resolver
|
|
2
2
|
|
|
3
|
+
## 0.4.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#4929](https://github.com/bluesky-social/atproto/pull/4929) [`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Drop support for Node.js 18 and 20. Node.js 22 is now the minimum supported version. Docker images now use Node.js 24.
|
|
8
|
+
|
|
9
|
+
- [#4943](https://github.com/bluesky-social/atproto/pull/4943) [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Convert to pure ESM. All packages now ship `"type": "module"` with ES module output and Node16 module resolution.
|
|
10
|
+
|
|
11
|
+
Node.js 22's `require()` compatibility layer can still load these packages in CommonJS code.
|
|
12
|
+
|
|
13
|
+
- [#4930](https://github.com/bluesky-social/atproto/pull/4930) [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9) Thanks [@devinivy](https://github.com/devinivy)! - Build with TypeScript 6.0. Emitted `.d.ts` files now use TypeScript 6's stricter `Uint8Array<ArrayBuffer>` typing in places where Web/Node APIs require buffer-backed (not shared-memory) byte arrays. Consumers compiling against these types on older TypeScript should see no runtime impact, but may need to widen or cast in spots that previously relied on `Uint8Array` defaulting to `<ArrayBufferLike>`.
|
|
14
|
+
|
|
15
|
+
Internal: tsconfig `moduleResolution: "node"` is silenced via `ignoreDeprecations: "6.0"` for now; the proper migration to `node16`/`bundler` resolution is deferred.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b), [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028), [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9)]:
|
|
20
|
+
- @atproto/did@0.4.0-next.0
|
|
21
|
+
- @atproto-labs/simple-store@0.4.0-next.0
|
|
22
|
+
- @atproto-labs/simple-store-memory@0.2.0-next.0
|
|
23
|
+
|
|
3
24
|
## 0.3.6
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const atproto_handle_resolver_js_1 = require("./atproto-handle-resolver.js");
|
|
5
|
-
const handle_resolver_error_js_1 = require("./handle-resolver-error.js");
|
|
6
|
-
class AtprotoDohHandleResolver extends atproto_handle_resolver_js_1.AtprotoHandleResolver {
|
|
1
|
+
import { AtprotoHandleResolver, } from './atproto-handle-resolver.js';
|
|
2
|
+
import { HandleResolverError } from './handle-resolver-error.js';
|
|
3
|
+
export class AtprotoDohHandleResolver extends AtprotoHandleResolver {
|
|
7
4
|
constructor(options) {
|
|
8
5
|
super({
|
|
9
6
|
...options,
|
|
@@ -12,7 +9,6 @@ class AtprotoDohHandleResolver extends atproto_handle_resolver_js_1.AtprotoHandl
|
|
|
12
9
|
});
|
|
13
10
|
}
|
|
14
11
|
}
|
|
15
|
-
exports.AtprotoDohHandleResolver = AtprotoDohHandleResolver;
|
|
16
12
|
/**
|
|
17
13
|
* Resolver for DNS-over-HTTPS (DoH) handles. Only works with servers supporting
|
|
18
14
|
* Google Flavoured "application/dns-json" queries.
|
|
@@ -37,10 +33,10 @@ function dohResolveTxtFactory({ dohEndpoint, fetch = globalThis.fetch, }) {
|
|
|
37
33
|
const message = contentType?.startsWith('text/plain')
|
|
38
34
|
? await response.text()
|
|
39
35
|
: `Failed to resolve ${hostname}`;
|
|
40
|
-
throw new
|
|
36
|
+
throw new HandleResolverError(message);
|
|
41
37
|
}
|
|
42
38
|
else if (contentType?.match(/application\/(dns-)?json/i) == null) {
|
|
43
|
-
throw new
|
|
39
|
+
throw new HandleResolverError('Unexpected response from DoH server');
|
|
44
40
|
}
|
|
45
41
|
const result = asResult(await response.json());
|
|
46
42
|
return result.Answer?.filter(isAnswerTxt).map(extractTxtData) ?? null;
|
|
@@ -73,7 +69,7 @@ function isResult(result) {
|
|
|
73
69
|
function asResult(result) {
|
|
74
70
|
if (isResult(result))
|
|
75
71
|
return result;
|
|
76
|
-
throw new
|
|
72
|
+
throw new HandleResolverError('Invalid DoH response');
|
|
77
73
|
}
|
|
78
74
|
function isArrayOf(value, predicate) {
|
|
79
75
|
return Array.isArray(value) && value.every(predicate);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atproto-doh-handle-resolver.js","sourceRoot":"","sources":["../src/atproto-doh-handle-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"atproto-doh-handle-resolver.js","sourceRoot":"","sources":["../src/atproto-doh-handle-resolver.ts"],"names":[],"mappings":"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","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,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.AtprotoHandleResolver = void 0;
|
|
4
|
-
const dns_handle_resolver_js_1 = require("./internal-resolvers/dns-handle-resolver.js");
|
|
5
|
-
const well_known_handler_resolver_js_1 = require("./internal-resolvers/well-known-handler-resolver.js");
|
|
1
|
+
import { DnsHandleResolver, } from './internal-resolvers/dns-handle-resolver.js';
|
|
2
|
+
import { WellKnownHandleResolver, } from './internal-resolvers/well-known-handler-resolver.js';
|
|
6
3
|
const noop = () => { };
|
|
7
4
|
/**
|
|
8
5
|
* Implementation of the official ATPROTO handle resolution strategy.
|
|
@@ -10,30 +7,12 @@ const noop = () => { };
|
|
|
10
7
|
* - HTTP Well-Known URI resolution (requires a `fetch()` implementation)
|
|
11
8
|
* - DNS TXT record resolution (requires a `resolveTxt()` function)
|
|
12
9
|
*/
|
|
13
|
-
class AtprotoHandleResolver {
|
|
10
|
+
export class AtprotoHandleResolver {
|
|
14
11
|
constructor(options) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: void 0
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(this, "dnsResolver", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: void 0
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(this, "dnsResolverFallback", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: void 0
|
|
32
|
-
});
|
|
33
|
-
this.httpResolver = new well_known_handler_resolver_js_1.WellKnownHandleResolver(options);
|
|
34
|
-
this.dnsResolver = new dns_handle_resolver_js_1.DnsHandleResolver(options.resolveTxt);
|
|
12
|
+
this.httpResolver = new WellKnownHandleResolver(options);
|
|
13
|
+
this.dnsResolver = new DnsHandleResolver(options.resolveTxt);
|
|
35
14
|
this.dnsResolverFallback = options.resolveTxtFallback
|
|
36
|
-
? new
|
|
15
|
+
? new DnsHandleResolver(options.resolveTxtFallback)
|
|
37
16
|
: undefined;
|
|
38
17
|
}
|
|
39
18
|
async resolve(handle, options) {
|
|
@@ -65,5 +44,4 @@ class AtprotoHandleResolver {
|
|
|
65
44
|
}
|
|
66
45
|
}
|
|
67
46
|
}
|
|
68
|
-
exports.AtprotoHandleResolver = AtprotoHandleResolver;
|
|
69
47
|
//# sourceMappingURL=atproto-handle-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atproto-handle-resolver.js","sourceRoot":"","sources":["../src/atproto-handle-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"atproto-handle-resolver.js","sourceRoot":"","sources":["../src/atproto-handle-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAElB,MAAM,6CAA6C,CAAA;AACpD,OAAO,EACL,uBAAuB,GAExB,MAAM,qDAAqD,CAAA;AAa5D,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA;AAErB;;;;;GAKG;AACH,MAAM,OAAO,qBAAqB;IAKhC,YAAY,OAAqC;QAC/C,IAAI,CAAC,YAAY,GAAG,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAA;QACxD,IAAI,CAAC,WAAW,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QAC5D,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,kBAAkB;YACnD,CAAC,CAAC,IAAI,iBAAiB,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,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","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,28 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const simple_store_1 = require("@atproto-labs/simple-store");
|
|
5
|
-
const simple_store_memory_1 = require("@atproto-labs/simple-store-memory");
|
|
6
|
-
class CachedHandleResolver {
|
|
1
|
+
import { CachedGetter } from '@atproto-labs/simple-store';
|
|
2
|
+
import { SimpleStoreMemory } from '@atproto-labs/simple-store-memory';
|
|
3
|
+
export class CachedHandleResolver {
|
|
7
4
|
constructor(
|
|
8
5
|
/**
|
|
9
6
|
* The resolver that will be used to resolve handles.
|
|
10
7
|
*/
|
|
11
|
-
resolver, cache = new
|
|
8
|
+
resolver, cache = new SimpleStoreMemory({
|
|
12
9
|
max: 1000,
|
|
13
10
|
ttl: 10 * 60e3,
|
|
14
11
|
})) {
|
|
15
|
-
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: void 0
|
|
20
|
-
});
|
|
21
|
-
this.getter = new simple_store_1.CachedGetter((handle, options) => resolver.resolve(handle, options), cache);
|
|
12
|
+
this.getter = new CachedGetter((handle, options) => resolver.resolve(handle, options), cache);
|
|
22
13
|
}
|
|
23
14
|
async resolve(handle, options) {
|
|
24
15
|
return this.getter.get(handle, options);
|
|
25
16
|
}
|
|
26
17
|
}
|
|
27
|
-
exports.CachedHandleResolver = CachedHandleResolver;
|
|
28
18
|
//# sourceMappingURL=cached-handle-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cached-handle-resolver.js","sourceRoot":"","sources":["../src/cached-handle-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cached-handle-resolver.js","sourceRoot":"","sources":["../src/cached-handle-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,4BAA4B,CAAA;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AASrE,MAAM,OAAO,oBAAoB;IAG/B;IACE;;OAEG;IACH,QAAwB,EACxB,QAAqB,IAAI,iBAAiB,CAAyB;QACjE,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,EAAE,GAAG,IAAI;KACf,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,IAAI,YAAY,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","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,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const cached_handle_resolver_js_1 = require("./cached-handle-resolver.js");
|
|
5
|
-
const xrpc_handle_resolver_js_1 = require("./xrpc-handle-resolver.js");
|
|
6
|
-
function createHandleResolver(options) {
|
|
1
|
+
import { CachedHandleResolver } from './cached-handle-resolver.js';
|
|
2
|
+
import { XrpcHandleResolver, } from './xrpc-handle-resolver.js';
|
|
3
|
+
export function createHandleResolver(options) {
|
|
7
4
|
const { handleResolver, handleCache } = options;
|
|
8
|
-
if (handleResolver instanceof
|
|
5
|
+
if (handleResolver instanceof CachedHandleResolver && !handleCache) {
|
|
9
6
|
return handleResolver;
|
|
10
7
|
}
|
|
11
|
-
return new
|
|
12
|
-
? new
|
|
8
|
+
return new CachedHandleResolver(typeof handleResolver === 'string' || handleResolver instanceof URL
|
|
9
|
+
? new XrpcHandleResolver(handleResolver, options)
|
|
13
10
|
: handleResolver, handleCache);
|
|
14
11
|
}
|
|
15
12
|
//# sourceMappingURL=create-handle-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-handle-resolver.js","sourceRoot":"","sources":["../src/create-handle-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-handle-resolver.js","sourceRoot":"","sources":["../src/create-handle-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAe,MAAM,6BAA6B,CAAA;AAE/E,OAAO,EACL,kBAAkB,GAEnB,MAAM,2BAA2B,CAAA;AAOlC,MAAM,UAAU,oBAAoB,CAClC,OAAoC;IAEpC,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;IAE/C,IAAI,cAAc,YAAY,oBAAoB,IAAI,CAAC,WAAW,EAAE,CAAC;QACnE,OAAO,cAAc,CAAA;IACvB,CAAC;IAED,OAAO,IAAI,oBAAoB,CAC7B,OAAO,cAAc,KAAK,QAAQ,IAAI,cAAc,YAAY,GAAG;QACjE,CAAC,CAAC,IAAI,kBAAkB,CAAC,cAAc,EAAE,OAAO,CAAC;QACjD,CAAC,CAAC,cAAc,EAClB,WAAW,CACZ,CAAA;AACH,CAAC","sourcesContent":["import { CachedHandleResolver, HandleCache } from './cached-handle-resolver.js'\nimport { HandleResolver } from './types.js'\nimport {\n XrpcHandleResolver,\n XrpcHandleResolverOptions,\n} from './xrpc-handle-resolver.js'\n\nexport type CreateHandleResolverOptions = {\n handleResolver: URL | string | HandleResolver\n handleCache?: HandleCache\n} & Partial<XrpcHandleResolverOptions>\n\nexport function createHandleResolver(\n options: CreateHandleResolverOptions,\n): HandleResolver {\n const { handleResolver, handleCache } = options\n\n if (handleResolver instanceof CachedHandleResolver && !handleCache) {\n return handleResolver\n }\n\n return new CachedHandleResolver(\n typeof handleResolver === 'string' || handleResolver instanceof URL\n ? new XrpcHandleResolver(handleResolver, options)\n : handleResolver,\n handleCache,\n )\n}\n"]}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HandleResolverError = void 0;
|
|
4
|
-
class HandleResolverError extends Error {
|
|
1
|
+
export class HandleResolverError extends Error {
|
|
5
2
|
constructor() {
|
|
6
3
|
super(...arguments);
|
|
7
|
-
|
|
8
|
-
enumerable: true,
|
|
9
|
-
configurable: true,
|
|
10
|
-
writable: true,
|
|
11
|
-
value: 'HandleResolverError'
|
|
12
|
-
});
|
|
4
|
+
this.name = 'HandleResolverError';
|
|
13
5
|
}
|
|
14
6
|
}
|
|
15
|
-
exports.HandleResolverError = HandleResolverError;
|
|
16
7
|
//# sourceMappingURL=handle-resolver-error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-resolver-error.js","sourceRoot":"","sources":["../src/handle-resolver-error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handle-resolver-error.js","sourceRoot":"","sources":["../src/handle-resolver-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAA9C;;QACE,SAAI,GAAG,qBAAqB,CAAA;IAC9B,CAAC;CAAA","sourcesContent":["export class HandleResolverError extends Error {\n name = 'HandleResolverError'\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./handle-resolver-error.js"), exports);
|
|
18
|
-
__exportStar(require("./types.js"), exports);
|
|
1
|
+
export * from './handle-resolver-error.js';
|
|
2
|
+
export * from './types.js';
|
|
19
3
|
// Main Handle Resolvers strategies
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
export * from './xrpc-handle-resolver.js';
|
|
5
|
+
export * from './atproto-doh-handle-resolver.js';
|
|
6
|
+
export * from './atproto-handle-resolver.js';
|
|
23
7
|
// Handle Resolver Caching utility
|
|
24
|
-
|
|
8
|
+
export * from './cached-handle-resolver.js';
|
|
25
9
|
// utils
|
|
26
|
-
|
|
10
|
+
export * from './create-handle-resolver.js';
|
|
27
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,YAAY,CAAA;AAE1B,mCAAmC;AACnC,cAAc,2BAA2B,CAAA;AACzC,cAAc,kCAAkC,CAAA;AAChD,cAAc,8BAA8B,CAAA;AAE5C,kCAAkC;AAClC,cAAc,6BAA6B,CAAA;AAE3C,QAAQ;AACR,cAAc,6BAA6B,CAAA","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\n// utils\nexport * from './create-handle-resolver.js'\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HandleResolver, ResolvedHandle } from '../types';
|
|
1
|
+
import { HandleResolver, ResolvedHandle } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* DNS TXT record resolver. Return `null` if the hostname successfully does not
|
|
4
4
|
* resolve to a valid DID. Throw an error if an unexpected error occurs.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dns-handle-resolver.d.ts","sourceRoot":"","sources":["../../src/internal-resolvers/dns-handle-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAoB,MAAM,
|
|
1
|
+
{"version":3,"file":"dns-handle-resolver.d.ts","sourceRoot":"","sources":["../../src/internal-resolvers/dns-handle-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAoB,MAAM,aAAa,CAAA;AAK9E;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,GAAG,MAAM,EAAE,CAAC,CAAA;AAEvE,qBAAa,iBAAkB,YAAW,cAAc;IAC1C,SAAS,CAAC,UAAU,EAAE,UAAU;gBAAtB,UAAU,EAAE,UAAU;IAEtC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;CAuBvD"}
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DnsHandleResolver = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
1
|
+
import { isResolvedHandle } from '../types.js';
|
|
5
2
|
const SUBDOMAIN = '_atproto';
|
|
6
3
|
const PREFIX = 'did=';
|
|
7
|
-
class DnsHandleResolver {
|
|
4
|
+
export class DnsHandleResolver {
|
|
8
5
|
constructor(resolveTxt) {
|
|
9
|
-
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true,
|
|
13
|
-
value: resolveTxt
|
|
14
|
-
});
|
|
6
|
+
this.resolveTxt = resolveTxt;
|
|
15
7
|
}
|
|
16
8
|
async resolve(handle) {
|
|
17
9
|
const results = await this.resolveTxt.call(null, `${SUBDOMAIN}.${handle}`);
|
|
@@ -29,10 +21,9 @@ class DnsHandleResolver {
|
|
|
29
21
|
// Note: No trimming (to be consistent with spec)
|
|
30
22
|
const did = results[i].slice(PREFIX.length);
|
|
31
23
|
// Invalid DBS record
|
|
32
|
-
return
|
|
24
|
+
return isResolvedHandle(did) ? did : null;
|
|
33
25
|
}
|
|
34
26
|
return null;
|
|
35
27
|
}
|
|
36
28
|
}
|
|
37
|
-
exports.DnsHandleResolver = DnsHandleResolver;
|
|
38
29
|
//# sourceMappingURL=dns-handle-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dns-handle-resolver.js","sourceRoot":"","sources":["../../src/internal-resolvers/dns-handle-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dns-handle-resolver.js","sourceRoot":"","sources":["../../src/internal-resolvers/dns-handle-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9E,MAAM,SAAS,GAAG,UAAU,CAAA;AAC5B,MAAM,MAAM,GAAG,MAAM,CAAA;AAQrB,MAAM,OAAO,iBAAiB;IAC5B,YAAsB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;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,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAE3C,qBAAqB;YACrB,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAA;QAC3C,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { HandleResolver, ResolvedHandle, isResolvedHandle } from '../types.js'\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,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.WellKnownHandleResolver = void 0;
|
|
4
|
-
const types_js_1 = require("../types.js");
|
|
5
|
-
class WellKnownHandleResolver {
|
|
1
|
+
import { isResolvedHandle, } from '../types.js';
|
|
2
|
+
export class WellKnownHandleResolver {
|
|
6
3
|
constructor(options) {
|
|
7
|
-
Object.defineProperty(this, "fetch", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
configurable: true,
|
|
10
|
-
writable: true,
|
|
11
|
-
value: void 0
|
|
12
|
-
});
|
|
13
4
|
this.fetch = options?.fetch ?? globalThis.fetch;
|
|
14
5
|
}
|
|
15
6
|
async resolve(handle, options) {
|
|
@@ -22,7 +13,7 @@ class WellKnownHandleResolver {
|
|
|
22
13
|
});
|
|
23
14
|
const text = await response.text();
|
|
24
15
|
const firstLine = text.split('\n')[0].trim();
|
|
25
|
-
if (
|
|
16
|
+
if (isResolvedHandle(firstLine))
|
|
26
17
|
return firstLine;
|
|
27
18
|
return null;
|
|
28
19
|
}
|
|
@@ -34,5 +25,4 @@ class WellKnownHandleResolver {
|
|
|
34
25
|
}
|
|
35
26
|
}
|
|
36
27
|
}
|
|
37
|
-
exports.WellKnownHandleResolver = WellKnownHandleResolver;
|
|
38
28
|
//# sourceMappingURL=well-known-handler-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"well-known-handler-resolver.js","sourceRoot":"","sources":["../../src/internal-resolvers/well-known-handler-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"well-known-handler-resolver.js","sourceRoot":"","sources":["../../src/internal-resolvers/well-known-handler-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,gBAAgB,GACjB,MAAM,aAAa,CAAA;AAcpB,MAAM,OAAO,uBAAuB;IAGlC,YAAY,OAAwC;QAClD,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,gBAAgB,CAAC,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","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.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isResolvedHandle = isResolvedHandle;
|
|
4
|
-
exports.asResolvedHandle = asResolvedHandle;
|
|
5
|
-
const did_1 = require("@atproto/did");
|
|
1
|
+
import { isAtprotoDid } from '@atproto/did';
|
|
6
2
|
/**
|
|
7
3
|
* @see {@link https://atproto.com/specs/did#blessed-did-methods}
|
|
8
4
|
*/
|
|
9
|
-
function isResolvedHandle(value) {
|
|
10
|
-
return value === null ||
|
|
5
|
+
export function isResolvedHandle(value) {
|
|
6
|
+
return value === null || isAtprotoDid(value);
|
|
11
7
|
}
|
|
12
|
-
function asResolvedHandle(value) {
|
|
8
|
+
export function asResolvedHandle(value) {
|
|
13
9
|
return isResolvedHandle(value) ? value : null;
|
|
14
10
|
}
|
|
15
11
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAE,MAAM,cAAc,CAAA;AAavD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,KAAK,IAAI,IAAI,YAAY,CAAC,KAAK,CAAC,CAAA;AAC9C,CAAC;AAED,MAAM,UAAU,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,31 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.xrpcErrorSchema = zod_1.z.object({
|
|
8
|
-
error: zod_1.z.string(),
|
|
9
|
-
message: zod_1.z.string().optional(),
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { HandleResolverError } from './handle-resolver-error.js';
|
|
3
|
+
import { isResolvedHandle, } from './types.js';
|
|
4
|
+
export const xrpcErrorSchema = z.object({
|
|
5
|
+
error: z.string(),
|
|
6
|
+
message: z.string().optional(),
|
|
10
7
|
});
|
|
11
|
-
class XrpcHandleResolver {
|
|
8
|
+
export class XrpcHandleResolver {
|
|
12
9
|
constructor(service, options) {
|
|
13
|
-
/**
|
|
14
|
-
* URL of the atproto lexicon server. This is the base URL where the
|
|
15
|
-
* `com.atproto.identity.resolveHandle` XRPC method is located.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(this, "serviceUrl", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true,
|
|
21
|
-
value: void 0
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(this, "fetch", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true,
|
|
27
|
-
value: void 0
|
|
28
|
-
});
|
|
29
10
|
this.serviceUrl = new URL(service);
|
|
30
11
|
this.fetch = options?.fetch ?? globalThis.fetch;
|
|
31
12
|
}
|
|
@@ -43,9 +24,9 @@ class XrpcHandleResolver {
|
|
|
43
24
|
// - 200 OK with { did: NonNullable<ResolvedHandle> }
|
|
44
25
|
// Any other response is considered unexpected behavior an should throw an error.
|
|
45
26
|
if (response.status === 400) {
|
|
46
|
-
const { error, data } =
|
|
27
|
+
const { error, data } = xrpcErrorSchema.safeParse(payload);
|
|
47
28
|
if (error) {
|
|
48
|
-
throw new
|
|
29
|
+
throw new HandleResolverError(`Invalid response from resolveHandle method: ${error.message}`, { cause: error });
|
|
49
30
|
}
|
|
50
31
|
if (data.error === 'InvalidRequest' &&
|
|
51
32
|
data.message === 'Unable to resolve handle') {
|
|
@@ -53,14 +34,13 @@ class XrpcHandleResolver {
|
|
|
53
34
|
}
|
|
54
35
|
}
|
|
55
36
|
if (!response.ok) {
|
|
56
|
-
throw new
|
|
37
|
+
throw new HandleResolverError('Invalid status code from resolveHandle method');
|
|
57
38
|
}
|
|
58
39
|
const value = payload?.did;
|
|
59
|
-
if (!
|
|
60
|
-
throw new
|
|
40
|
+
if (!isResolvedHandle(value)) {
|
|
41
|
+
throw new HandleResolverError('Invalid DID returned from resolveHandle method');
|
|
61
42
|
}
|
|
62
43
|
return value;
|
|
63
44
|
}
|
|
64
45
|
}
|
|
65
|
-
exports.XrpcHandleResolver = XrpcHandleResolver;
|
|
66
46
|
//# sourceMappingURL=xrpc-handle-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xrpc-handle-resolver.js","sourceRoot":"","sources":["../src/xrpc-handle-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"xrpc-handle-resolver.js","sourceRoot":"","sources":["../src/xrpc-handle-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAChE,OAAO,EAIL,gBAAgB,GACjB,MAAM,YAAY,CAAA;AAEnB,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAA;AAYF,MAAM,OAAO,kBAAkB;IAQ7B,YAAY,OAAqB,EAAE,OAAmC;QACpE,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAA;QAClC,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,CACjB,0CAA0C,EAC1C,IAAI,CAAC,UAAU,CAChB,CAAA;QACD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QAEtC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE;YAChD,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;YAChD,MAAM,EAAE,OAAO,EAAE,MAAM;YACvB,QAAQ,EAAE,OAAO;SAClB,CAAC,CAAA;QACF,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAErC,gCAAgC;QAChC,0FAA0F;QAC1F,qDAAqD;QACrD,iFAAiF;QAEjF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;YAC1D,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,IAAI,mBAAmB,CAC3B,+CAA+C,KAAK,CAAC,OAAO,EAAE,EAC9D,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAA;YACH,CAAC;YACD,IACE,IAAI,CAAC,KAAK,KAAK,gBAAgB;gBAC/B,IAAI,CAAC,OAAO,KAAK,0BAA0B,EAC3C,CAAC;gBACD,OAAO,IAAI,CAAA;YACb,CAAC;QACH,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,mBAAmB,CAC3B,+CAA+C,CAChD,CAAA;QACH,CAAC;QAED,MAAM,KAAK,GAAY,OAAO,EAAE,GAAG,CAAA;QAEnC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,mBAAmB,CAC3B,gDAAgD,CACjD,CAAA;QACH,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;CACF","sourcesContent":["import { z } from 'zod'\nimport { HandleResolverError } from './handle-resolver-error.js'\nimport {\n HandleResolver,\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,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto-labs/handle-resolver",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-next.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=22"
|
|
6
|
+
},
|
|
4
7
|
"license": "MIT",
|
|
5
8
|
"description": "Isomorphic ATProto handle to DID resolver",
|
|
6
9
|
"keywords": [
|
|
@@ -18,9 +21,7 @@
|
|
|
18
21
|
"url": "https://github.com/bluesky-social/atproto",
|
|
19
22
|
"directory": "packages/internal/handle-resolver"
|
|
20
23
|
},
|
|
21
|
-
"type": "
|
|
22
|
-
"main": "dist/index.js",
|
|
23
|
-
"types": "dist/index.d.ts",
|
|
24
|
+
"type": "module",
|
|
24
25
|
"exports": {
|
|
25
26
|
".": {
|
|
26
27
|
"types": "./dist/index.d.ts",
|
|
@@ -29,12 +30,12 @@
|
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
32
|
"zod": "^3.23.8",
|
|
32
|
-
"@atproto-labs/simple-store": "0.
|
|
33
|
-
"@atproto
|
|
34
|
-
"@atproto/
|
|
33
|
+
"@atproto-labs/simple-store": "^0.4.0-next.0",
|
|
34
|
+
"@atproto/did": "^0.4.0-next.0",
|
|
35
|
+
"@atproto-labs/simple-store-memory": "^0.2.0-next.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"typescript": "^
|
|
38
|
+
"typescript": "^6.0.3"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
41
|
"build": "tsc --build tsconfig.build.json"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/atproto-doh-handle-resolver.ts","./src/atproto-handle-resolver.ts","./src/cached-handle-resolver.ts","./src/create-handle-resolver.ts","./src/handle-resolver-error.ts","./src/index.ts","./src/types.ts","./src/xrpc-handle-resolver.ts","./src/internal-resolvers/dns-handle-resolver.ts","./src/internal-resolvers/well-known-handler-resolver.ts"],"version":"
|
|
1
|
+
{"root":["./src/atproto-doh-handle-resolver.ts","./src/atproto-handle-resolver.ts","./src/cached-handle-resolver.ts","./src/create-handle-resolver.ts","./src/handle-resolver-error.ts","./src/index.ts","./src/types.ts","./src/xrpc-handle-resolver.ts","./src/internal-resolvers/dns-handle-resolver.ts","./src/internal-resolvers/well-known-handler-resolver.ts"],"version":"6.0.3"}
|