@atproto-labs/handle-resolver 0.0.1 → 0.1.1
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 +18 -6
- package/README.md +148 -0
- package/dist/{atproto-lexicon-handle-resolver.d.ts → app-view-handle-resolver.d.ts} +11 -14
- package/dist/app-view-handle-resolver.d.ts.map +1 -0
- package/dist/{atproto-lexicon-handle-resolver.js → app-view-handle-resolver.js} +28 -15
- package/dist/app-view-handle-resolver.js.map +1 -0
- package/dist/atproto-doh-handle-resolver.d.ts +9 -0
- package/dist/atproto-doh-handle-resolver.d.ts.map +1 -0
- package/dist/atproto-doh-handle-resolver.js +98 -0
- package/dist/atproto-doh-handle-resolver.js.map +1 -0
- package/dist/atproto-handle-resolver.d.ts +22 -0
- package/dist/atproto-handle-resolver.d.ts.map +1 -0
- package/dist/atproto-handle-resolver.js +69 -0
- package/dist/atproto-handle-resolver.js.map +1 -0
- package/dist/cached-handle-resolver.d.ts +8 -12
- package/dist/cached-handle-resolver.d.ts.map +1 -1
- package/dist/cached-handle-resolver.js +17 -6
- package/dist/cached-handle-resolver.js.map +1 -1
- package/dist/index.d.ts +4 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -10
- package/dist/index.js.map +1 -1
- package/dist/internal-resolvers/dns-handle-resolver.d.ts +12 -0
- package/dist/internal-resolvers/dns-handle-resolver.d.ts.map +1 -0
- package/dist/internal-resolvers/dns-handle-resolver.js +38 -0
- package/dist/internal-resolvers/dns-handle-resolver.js.map +1 -0
- package/dist/internal-resolvers/well-known-handler-resolver.d.ts +18 -0
- package/dist/internal-resolvers/well-known-handler-resolver.d.ts.map +1 -0
- package/dist/{well-known-handler-resolver.js → internal-resolvers/well-known-handler-resolver.js} +9 -7
- package/dist/internal-resolvers/well-known-handler-resolver.js.map +1 -0
- package/dist/{handle-resolver.d.ts → types.d.ts} +13 -6
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/package.json +6 -7
- package/src/{atproto-lexicon-handle-resolver.ts → app-view-handle-resolver.ts} +34 -27
- package/src/atproto-doh-handle-resolver.ts +123 -0
- package/src/atproto-handle-resolver.ts +79 -0
- package/src/cached-handle-resolver.ts +20 -24
- package/src/index.ts +6 -8
- package/src/internal-resolvers/dns-handle-resolver.ts +38 -0
- package/src/{well-known-handler-resolver.ts → internal-resolvers/well-known-handler-resolver.ts} +20 -15
- package/src/{handle-resolver.ts → types.ts} +15 -6
- package/tsconfig.build.json +1 -1
- package/dist/atproto-lexicon-handle-resolver.d.ts.map +0 -1
- package/dist/atproto-lexicon-handle-resolver.js.map +0 -1
- package/dist/handle-resolver.d.ts.map +0 -1
- package/dist/handle-resolver.js +0 -9
- package/dist/handle-resolver.js.map +0 -1
- package/dist/serial-handle-resolver.d.ts +0 -7
- package/dist/serial-handle-resolver.d.ts.map +0 -1
- package/dist/serial-handle-resolver.js +0 -29
- package/dist/serial-handle-resolver.js.map +0 -1
- package/dist/universal-handle-resolver.d.ts +0 -32
- package/dist/universal-handle-resolver.d.ts.map +0 -1
- package/dist/universal-handle-resolver.js +0 -25
- package/dist/universal-handle-resolver.js.map +0 -1
- package/dist/well-known-handler-resolver.d.ts +0 -11
- package/dist/well-known-handler-resolver.d.ts.map +0 -1
- package/dist/well-known-handler-resolver.js.map +0 -1
- package/src/serial-handle-resolver.ts +0 -29
- package/src/universal-handle-resolver.ts +0 -58
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
# @atproto-labs/handle-resolver
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.1.1
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- [`
|
|
7
|
+
- [#2633](https://github.com/bluesky-social/atproto/pull/2633) [`acc9093d2`](https://github.com/bluesky-social/atproto/commit/acc9093d2845eba02b68fb2f9db33e4f1b59bb10) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Use distinct type names to prevent conflicts
|
|
8
8
|
|
|
9
|
-
- Updated dependencies [[`
|
|
10
|
-
- @atproto-labs/
|
|
11
|
-
- @atproto-labs/
|
|
12
|
-
|
|
9
|
+
- Updated dependencies [[`acc9093d2`](https://github.com/bluesky-social/atproto/commit/acc9093d2845eba02b68fb2f9db33e4f1b59bb10), [`acc9093d2`](https://github.com/bluesky-social/atproto/commit/acc9093d2845eba02b68fb2f9db33e4f1b59bb10)]:
|
|
10
|
+
- @atproto-labs/simple-store@0.1.1
|
|
11
|
+
- @atproto-labs/simple-store-memory@0.1.1
|
|
12
|
+
|
|
13
|
+
## 0.1.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [#2482](https://github.com/bluesky-social/atproto/pull/2482) [`a8d6c1123`](https://github.com/bluesky-social/atproto/commit/a8d6c112359f5c4c0cfbe2df63443ed275f2a646) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add OAuth provider capability & support for DPoP signed tokens
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`a8d6c1123`](https://github.com/bluesky-social/atproto/commit/a8d6c112359f5c4c0cfbe2df63443ed275f2a646)]:
|
|
22
|
+
- @atproto-labs/simple-store-memory@0.1.0
|
|
23
|
+
- @atproto-labs/simple-store@0.1.0
|
|
24
|
+
- @atproto/did@0.1.0
|
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Universal Handle Resolver implementation for ATPROTO
|
|
2
|
+
|
|
3
|
+
This package provides a handle resolver implementation for ATPROTO. It is used
|
|
4
|
+
to resolve handles to their corresponding DID.
|
|
5
|
+
|
|
6
|
+
This package is meant to be used in any JavaScript environment that support the
|
|
7
|
+
`fetch()` function. Because APTORO handle resolution requires DNS resolution,
|
|
8
|
+
you will need to provide your own DNS resolution function when using this
|
|
9
|
+
package.
|
|
10
|
+
|
|
11
|
+
There are two main classes in this package:
|
|
12
|
+
|
|
13
|
+
- `AtprotoHandleResolver` This implements the official ATPROTO handle resolution
|
|
14
|
+
algorithm (and requires a DNS resolver).
|
|
15
|
+
- `AppViewHandleResolver` This uses HTTP requests to the Bluesky AppView
|
|
16
|
+
(bsky.app) to provide handle resolution.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### From a front-end app
|
|
21
|
+
|
|
22
|
+
Since the ATPROTO handle resolution algorithm requires DNS resolution, and the
|
|
23
|
+
browser does not provide a built-in DNS resolver, this package offers two
|
|
24
|
+
options:
|
|
25
|
+
|
|
26
|
+
- Delegate handle resolution to an AppView (`AppViewHandleResolver`). This is
|
|
27
|
+
the recommended approach for front-end apps.
|
|
28
|
+
- Use a DNS-over-HTTPS (DoH) server (`DohHandleResolver`). Prefer this method
|
|
29
|
+
if you don't own an AppView and already have a DoH server that you trust.
|
|
30
|
+
|
|
31
|
+
Using an AppView:
|
|
32
|
+
|
|
33
|
+
> [!CAUTION]
|
|
34
|
+
> Use the Bluesky owned AppView (`https://api.bsky.app/`), or PDS
|
|
35
|
+
> (`https://bsky.social/`), at your own risk. Using these servers in a
|
|
36
|
+
> third-party application might expose your users' data (IP address) to Bluesky.
|
|
37
|
+
> Bluesky might log the data sent to it when your app is resolving handles.
|
|
38
|
+
> Bluesky might also change the API, or terms or use, at any time without
|
|
39
|
+
> notice. Make sure you are compliant with the Bluesky terms of use as well as
|
|
40
|
+
> any laws and regulations that apply to your use case.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { AppViewHandleResolver } from '@atproto-labs/handle-resolver'
|
|
44
|
+
|
|
45
|
+
const resolver = new AppViewHandleResolver({
|
|
46
|
+
service: 'https://my-app-view.com/',
|
|
47
|
+
})
|
|
48
|
+
const did = await resolver.resolve('my-handle.bsky.social')
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Using DNS-over-HTTPS (DoH) for DNS resolution:
|
|
52
|
+
|
|
53
|
+
> [!CAUTION]
|
|
54
|
+
> Using a DoH server that you don't own might expose your users' data to
|
|
55
|
+
> the DoH server provider. The DoH server provider might log the data sent to it
|
|
56
|
+
> by your app, allowing them to track which handles are being resolved by your
|
|
57
|
+
> users. In the browser, it is recommended to use a DoH server that you own and
|
|
58
|
+
> control. Or to implement your own AppView and use the `AppViewHandleResolver`
|
|
59
|
+
> class.
|
|
60
|
+
|
|
61
|
+
> [!NOTE]
|
|
62
|
+
> Using the `DohHandleResolver` requires a DNS-over-HTTPS server that
|
|
63
|
+
> supports the DNS-over-HTTPS protocol with "application/dns-json" responses.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { DohHandleResolver } from '@atproto-labs/handle-resolver'
|
|
67
|
+
|
|
68
|
+
// Also works with 'https://cloudflare-dns.com/dns-query'
|
|
69
|
+
const resolver = new DohHandleResolver('https://dns.google/resolve', {
|
|
70
|
+
// Optional: Custom fetch function that will be used both for DNS resolution
|
|
71
|
+
// and well-known resolution.
|
|
72
|
+
fetch: globalThis.fetch.bind(globalThis),
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
const did = await resolver.resolve('my-handle.bsky.social')
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### From a Node.js app
|
|
79
|
+
|
|
80
|
+
> [!NOTE]
|
|
81
|
+
> On a Node.js backend, you will probably want to use the
|
|
82
|
+
> "@atproto-labs/handle-resolver-node" package. The example below applies to
|
|
83
|
+
> Node.js code running on a user's machine (e.g. through Electron).
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { AtprotoHandleResolver } from '@atproto-labs/handle-resolver'
|
|
87
|
+
import { resolveTxt } from 'node:dns/promises'
|
|
88
|
+
|
|
89
|
+
const resolver = new AtprotoHandleResolver({
|
|
90
|
+
// Optional: Custom fetch function (used for well-known resolution)
|
|
91
|
+
fetch: globalThis.fetch.bind(globalThis),
|
|
92
|
+
|
|
93
|
+
resolveTxt: async (domain: string) =>
|
|
94
|
+
resolveTxt(domain).then((chunks) => chunks.join('')),
|
|
95
|
+
})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Caching
|
|
99
|
+
|
|
100
|
+
Using a default, in-memory cache, in which items expire after 10 minutes:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import {
|
|
104
|
+
AppViewHandleResolver,
|
|
105
|
+
CachedHandleResolver,
|
|
106
|
+
HandleResolver,
|
|
107
|
+
HandleCache,
|
|
108
|
+
} from '@atproto-labs/handle-resolver'
|
|
109
|
+
|
|
110
|
+
// See previous examples for creating a resolver
|
|
111
|
+
declare const sourceResolver: HandleResolver
|
|
112
|
+
|
|
113
|
+
const resolver = new CachedHandleResolver(sourceResolver)
|
|
114
|
+
const did = await resolver.resolve('my-handle.bsky.social')
|
|
115
|
+
const did = await resolver.resolve('my-handle.bsky.social') // Result from cache
|
|
116
|
+
const did = await resolver.resolve('my-handle.bsky.social') // Result from cache
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Using a custom cache:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import {
|
|
123
|
+
AppViewHandleResolver,
|
|
124
|
+
CachedHandleResolver,
|
|
125
|
+
HandleResolver,
|
|
126
|
+
HandleCache,
|
|
127
|
+
} from '@atproto-labs/handle-resolver'
|
|
128
|
+
|
|
129
|
+
// See previous examples for creating a resolver
|
|
130
|
+
declare const sourceResolver: HandleResolver
|
|
131
|
+
|
|
132
|
+
const cache: HandleCache = {
|
|
133
|
+
set(handle, did): Promise<void> {
|
|
134
|
+
/* TODO */
|
|
135
|
+
},
|
|
136
|
+
get(handle): Promise<undefined | string> {
|
|
137
|
+
/* TODO */
|
|
138
|
+
},
|
|
139
|
+
del(handle): Promise<void> {
|
|
140
|
+
/* TODO */
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const resolver = new CachedHandleResolver(sourceResolver, cache)
|
|
145
|
+
const did = await resolver.resolve('my-handle.bsky.social')
|
|
146
|
+
const did = await resolver.resolve('my-handle.bsky.social') // Result from cache
|
|
147
|
+
const did = await resolver.resolve('my-handle.bsky.social') // Result from cache
|
|
148
|
+
```
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Fetch } from '@atproto-labs/fetch';
|
|
2
1
|
import z from 'zod';
|
|
3
|
-
import {
|
|
2
|
+
import { HandleResolver, ResolveHandleOptions, ResolvedHandle } from './types.js';
|
|
4
3
|
export declare const xrpcErrorSchema: z.ZodObject<{
|
|
5
4
|
error: z.ZodString;
|
|
6
5
|
message: z.ZodOptional<z.ZodString>;
|
|
@@ -11,26 +10,24 @@ export declare const xrpcErrorSchema: z.ZodObject<{
|
|
|
11
10
|
error: string;
|
|
12
11
|
message?: string | undefined;
|
|
13
12
|
}>;
|
|
14
|
-
export type
|
|
13
|
+
export type AppViewHandleResolverOptions = {
|
|
15
14
|
/**
|
|
16
15
|
* Fetch function to use for HTTP requests. Allows customizing the request
|
|
17
16
|
* behavior, e.g. adding headers, setting a timeout, mocking, etc.
|
|
18
17
|
*
|
|
19
18
|
* @default globalThis.fetch
|
|
20
19
|
*/
|
|
21
|
-
fetch?:
|
|
20
|
+
fetch?: typeof globalThis.fetch;
|
|
21
|
+
};
|
|
22
|
+
export declare class AppViewHandleResolver implements HandleResolver {
|
|
23
|
+
static from(service: URL | string | HandleResolver, options?: AppViewHandleResolverOptions): HandleResolver;
|
|
22
24
|
/**
|
|
23
25
|
* URL of the atproto lexicon server. This is the base URL where the
|
|
24
26
|
* `com.atproto.identity.resolveHandle` XRPC method is located.
|
|
25
|
-
*
|
|
26
|
-
* @default 'https://bsky.social'
|
|
27
27
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
protected readonly fetch: Fetch;
|
|
33
|
-
constructor({ url, fetch, }?: AtprotoLexiconHandleResolverOptions);
|
|
34
|
-
resolve(handle: string, options?: HandleResolveOptions): Promise<ResolvedHandle>;
|
|
28
|
+
protected readonly serviceUrl: URL;
|
|
29
|
+
protected readonly fetch: typeof globalThis.fetch;
|
|
30
|
+
constructor(service: URL | string, options?: AppViewHandleResolverOptions);
|
|
31
|
+
resolve(handle: string, options?: ResolveHandleOptions): Promise<ResolvedHandle>;
|
|
35
32
|
}
|
|
36
|
-
//# sourceMappingURL=
|
|
33
|
+
//# sourceMappingURL=app-view-handle-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-view-handle-resolver.d.ts","sourceRoot":"","sources":["../src/app-view-handle-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,cAAc,EAEf,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,eAAe;;;;;;;;;EAG1B,CAAA;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;CAChC,CAAA;AAED,qBAAa,qBAAsB,YAAW,cAAc;IAC1D,MAAM,CAAC,IAAI,CACT,OAAO,EAAE,GAAG,GAAG,MAAM,GAAG,cAAc,EACtC,OAAO,CAAC,EAAE,4BAA4B,GACrC,cAAc;IAOjB;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAA;IAClC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;gBAErC,OAAO,EAAE,GAAG,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,4BAA4B;IAK5D,OAAO,CAClB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,cAAc,CAAC;CA4C3B"}
|
|
@@ -3,16 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.AppViewHandleResolver = exports.xrpcErrorSchema = void 0;
|
|
7
7
|
const zod_1 = __importDefault(require("zod"));
|
|
8
|
-
const
|
|
8
|
+
const types_js_1 = require("./types.js");
|
|
9
9
|
exports.xrpcErrorSchema = zod_1.default.object({
|
|
10
10
|
error: zod_1.default.string(),
|
|
11
11
|
message: zod_1.default.string().optional(),
|
|
12
12
|
});
|
|
13
|
-
class
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
class AppViewHandleResolver {
|
|
14
|
+
static from(service, options) {
|
|
15
|
+
if (typeof service === 'string' || service instanceof URL) {
|
|
16
|
+
return new AppViewHandleResolver(service, options);
|
|
17
|
+
}
|
|
18
|
+
return service;
|
|
19
|
+
}
|
|
20
|
+
constructor(service, options) {
|
|
21
|
+
/**
|
|
22
|
+
* URL of the atproto lexicon server. This is the base URL where the
|
|
23
|
+
* `com.atproto.identity.resolveHandle` XRPC method is located.
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(this, "serviceUrl", {
|
|
16
26
|
enumerable: true,
|
|
17
27
|
configurable: true,
|
|
18
28
|
writable: true,
|
|
@@ -24,17 +34,20 @@ class AtprotoLexiconHandleResolver {
|
|
|
24
34
|
writable: true,
|
|
25
35
|
value: void 0
|
|
26
36
|
});
|
|
27
|
-
this.
|
|
28
|
-
this.fetch = fetch;
|
|
37
|
+
this.serviceUrl = new URL(service);
|
|
38
|
+
this.fetch = options?.fetch ?? globalThis.fetch;
|
|
29
39
|
}
|
|
30
40
|
async resolve(handle, options) {
|
|
31
|
-
const url = new URL('/xrpc/com.atproto.identity.resolveHandle', this.
|
|
41
|
+
const url = new URL('/xrpc/com.atproto.identity.resolveHandle', this.serviceUrl);
|
|
32
42
|
url.searchParams.set('handle', handle);
|
|
33
43
|
const headers = new Headers();
|
|
34
44
|
if (options?.noCache)
|
|
35
45
|
headers.set('cache-control', 'no-cache');
|
|
36
|
-
const
|
|
37
|
-
|
|
46
|
+
const response = await this.fetch.call(null, url, {
|
|
47
|
+
headers,
|
|
48
|
+
signal: options?.signal,
|
|
49
|
+
redirect: 'error',
|
|
50
|
+
});
|
|
38
51
|
const payload = await response.json();
|
|
39
52
|
// The response should either be
|
|
40
53
|
// - 400 Bad Request with { error: 'InvalidRequest', message: 'Unable to resolve handle' }
|
|
@@ -48,14 +61,14 @@ class AtprotoLexiconHandleResolver {
|
|
|
48
61
|
}
|
|
49
62
|
}
|
|
50
63
|
if (!response.ok) {
|
|
51
|
-
throw new
|
|
64
|
+
throw new TypeError('Invalid response from resolveHandle method');
|
|
52
65
|
}
|
|
53
66
|
const value = payload?.did;
|
|
54
|
-
if (!
|
|
55
|
-
throw new
|
|
67
|
+
if (!(0, types_js_1.isResolvedHandle)(value)) {
|
|
68
|
+
throw new TypeError('Invalid DID returned from resolveHandle method');
|
|
56
69
|
}
|
|
57
70
|
return value;
|
|
58
71
|
}
|
|
59
72
|
}
|
|
60
|
-
exports.
|
|
61
|
-
//# sourceMappingURL=
|
|
73
|
+
exports.AppViewHandleResolver = AppViewHandleResolver;
|
|
74
|
+
//# sourceMappingURL=app-view-handle-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-view-handle-resolver.js","sourceRoot":"","sources":["../src/app-view-handle-resolver.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAmB;AAEnB,yCAKmB;AAEN,QAAA,eAAe,GAAG,aAAC,CAAC,MAAM,CAAC;IACtC,KAAK,EAAE,aAAC,CAAC,MAAM,EAAE;IACjB,OAAO,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAA;AAYF,MAAa,qBAAqB;IAChC,MAAM,CAAC,IAAI,CACT,OAAsC,EACtC,OAAsC;QAEtC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,YAAY,GAAG,EAAE,CAAC;YAC1D,OAAO,IAAI,qBAAqB,CAAC,OAAO,EAAE,OA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,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAA;QACnE,CAAC;QAED,MAAM,KAAK,GAAY,OAAO,EAAE,GAAG,CAAA;QAEnC,IAAI,CAAC,IAAA,2BAAgB,EAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAA;QACvE,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AAtED,sDAsEC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AtprotoHandleResolver, AtprotoHandleResolverOptions } from './atproto-handle-resolver.js';
|
|
2
|
+
import { HandleResolver } from './types.js';
|
|
3
|
+
export type AtprotoDohHandleResolverOptions = Omit<AtprotoHandleResolverOptions, 'resolveTxt' | 'resolveTxtFallback'> & {
|
|
4
|
+
dohEndpoint: string | URL;
|
|
5
|
+
};
|
|
6
|
+
export declare class AtprotoDohHandleResolver extends AtprotoHandleResolver implements HandleResolver {
|
|
7
|
+
constructor(options: AtprotoDohHandleResolverOptions);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=atproto-doh-handle-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atproto-doh-handle-resolver.d.ts","sourceRoot":"","sources":["../src/atproto-doh-handle-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAG3C,MAAM,MAAM,+BAA+B,GAAG,IAAI,CAChD,4BAA4B,EAC5B,YAAY,GAAG,oBAAoB,CACpC,GAAG;IACF,WAAW,EAAE,MAAM,GAAG,GAAG,CAAA;CAC1B,CAAA;AAED,qBAAa,wBACX,SAAQ,qBACR,YAAW,cAAc;gBAEb,OAAO,EAAE,+BAA+B;CAOrD"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AtprotoDohHandleResolver = void 0;
|
|
4
|
+
const atproto_handle_resolver_js_1 = require("./atproto-handle-resolver.js");
|
|
5
|
+
class AtprotoDohHandleResolver extends atproto_handle_resolver_js_1.AtprotoHandleResolver {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super({
|
|
8
|
+
...options,
|
|
9
|
+
resolveTxt: dohResolveTxtFactory(options),
|
|
10
|
+
resolveTxtFallback: undefined,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.AtprotoDohHandleResolver = AtprotoDohHandleResolver;
|
|
15
|
+
/**
|
|
16
|
+
* Resolver for DNS-over-HTTPS (DoH) handles. Only works with servers supporting
|
|
17
|
+
* Google Flavoured "application/dns-json" queries.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link https://developers.google.com/speed/public-dns/docs/doh/json}
|
|
20
|
+
* @see {@link https://developers.cloudflare.com/1.1.1.1/encryption/dns-over-https/make-api-requests/dns-json/}
|
|
21
|
+
* @todo Add support for DoH using application/dns-message (?)
|
|
22
|
+
*/
|
|
23
|
+
function dohResolveTxtFactory({ dohEndpoint, fetch = globalThis.fetch, }) {
|
|
24
|
+
return async (hostname) => {
|
|
25
|
+
const url = new URL(dohEndpoint);
|
|
26
|
+
url.searchParams.set('type', 'TXT');
|
|
27
|
+
url.searchParams.set('name', hostname);
|
|
28
|
+
const response = await fetch(url, {
|
|
29
|
+
method: 'GET',
|
|
30
|
+
headers: { accept: 'application/dns-json' },
|
|
31
|
+
redirect: 'follow',
|
|
32
|
+
});
|
|
33
|
+
try {
|
|
34
|
+
const contentType = response.headers.get('content-type')?.trim();
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
const message = contentType?.startsWith('text/plain')
|
|
37
|
+
? await response.text()
|
|
38
|
+
: `Failed to resolve ${hostname}`;
|
|
39
|
+
throw new TypeError(message);
|
|
40
|
+
}
|
|
41
|
+
else if (contentType !== 'application/dns-json') {
|
|
42
|
+
throw new TypeError('Unexpected response from DoH server');
|
|
43
|
+
}
|
|
44
|
+
const result = asResult(await response.json());
|
|
45
|
+
return result.Answer?.filter(isAnswerTxt).map(extractTxtData) ?? null;
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
// Make sure to always cancel the response body as some engines (Node 👀)
|
|
49
|
+
// do not do this automatically.
|
|
50
|
+
// https://undici.nodejs.org/#/?id=garbage-collection
|
|
51
|
+
if (response.bodyUsed === false) {
|
|
52
|
+
// Handle rejection asynchronously
|
|
53
|
+
void response.body?.cancel().catch(onCancelError);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function onCancelError(err) {
|
|
59
|
+
if (!(err instanceof DOMException) || err.name !== 'AbortError') {
|
|
60
|
+
console.error('An error occurred while cancelling the response body:', err);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function isResult(result) {
|
|
64
|
+
if (typeof result !== 'object' || result === null)
|
|
65
|
+
return false;
|
|
66
|
+
if (!('Status' in result) || typeof result.Status !== 'number')
|
|
67
|
+
return false;
|
|
68
|
+
if ('Answer' in result && !isArrayOf(result.Answer, isAnswer))
|
|
69
|
+
return false;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
function asResult(result) {
|
|
73
|
+
if (isResult(result))
|
|
74
|
+
return result;
|
|
75
|
+
throw new TypeError('Invalid DoH response');
|
|
76
|
+
}
|
|
77
|
+
function isArrayOf(value, predicate) {
|
|
78
|
+
return Array.isArray(value) && value.every(predicate);
|
|
79
|
+
}
|
|
80
|
+
function isAnswer(answer) {
|
|
81
|
+
return (typeof answer === 'object' &&
|
|
82
|
+
answer !== null &&
|
|
83
|
+
'name' in answer &&
|
|
84
|
+
typeof answer.name === 'string' &&
|
|
85
|
+
'type' in answer &&
|
|
86
|
+
typeof answer.type === 'number' &&
|
|
87
|
+
'data' in answer &&
|
|
88
|
+
typeof answer.data === 'string' &&
|
|
89
|
+
'TTL' in answer &&
|
|
90
|
+
typeof answer.TTL === 'number');
|
|
91
|
+
}
|
|
92
|
+
function isAnswerTxt(answer) {
|
|
93
|
+
return answer.type === 16;
|
|
94
|
+
}
|
|
95
|
+
function extractTxtData(answer) {
|
|
96
|
+
return answer.data.replace(/^"|"$/g, '').replace(/\\"/g, '"');
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=atproto-doh-handle-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atproto-doh-handle-resolver.js","sourceRoot":"","sources":["../src/atproto-doh-handle-resolver.ts"],"names":[],"mappings":";;;AAAA,6EAGqC;AAWrC,MAAa,wBACX,SAAQ,kDAAqB;IAG7B,YAAY,OAAwC;QAClD,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,UAAU,EAAE,oBAAoB,CAAC,OAAO,CAAC;YACzC,kBAAkB,EAAE,SAAS;SAC9B,CAAC,CAAA;IACJ,CAAC;CACF;AAXD,4DAWC;AAED;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAAC,EAC5B,WAAW,EACX,KAAK,GAAG,UAAU,CAAC,KAAK,GACQ;IAChC,OAAO,KAAK,EAAE,QAAQ,EAAE,EAAE;QACxB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAA;QAChC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QACnC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QAEtC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,EAAE,MAAM,EAAE,sBAAsB,EAAE;YAC3C,QAAQ,EAAE,QAAQ;SACnB,CAAC,CAAA;QACF,IAAI,CAAC;YACH,MAAM,WA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CAAC,CAAA;AAC/D,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ResolveTxt } from './internal-resolvers/dns-handle-resolver.js';
|
|
2
|
+
import { WellKnownHandleResolverOptions } from './internal-resolvers/well-known-handler-resolver.js';
|
|
3
|
+
import { HandleResolver, ResolveHandleOptions, ResolvedHandle } from './types.js';
|
|
4
|
+
export type { ResolveTxt };
|
|
5
|
+
export type AtprotoHandleResolverOptions = WellKnownHandleResolverOptions & {
|
|
6
|
+
resolveTxt: ResolveTxt;
|
|
7
|
+
resolveTxtFallback?: ResolveTxt;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Implementation of the official ATPROTO handle resolution strategy.
|
|
11
|
+
* This implementation relies on two primitives:
|
|
12
|
+
* - HTTP Well-Known URI resolution (requires a `fetch()` implementation)
|
|
13
|
+
* - DNS TXT record resolution (requires a `resolveTxt()` function)
|
|
14
|
+
*/
|
|
15
|
+
export declare class AtprotoHandleResolver implements HandleResolver {
|
|
16
|
+
private readonly httpResolver;
|
|
17
|
+
private readonly dnsResolver;
|
|
18
|
+
private readonly dnsResolverFallback?;
|
|
19
|
+
constructor(options: AtprotoHandleResolverOptions);
|
|
20
|
+
resolve(handle: string, options?: ResolveHandleOptions): Promise<ResolvedHandle>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=atproto-handle-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atproto-handle-resolver.d.ts","sourceRoot":"","sources":["../src/atproto-handle-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACX,MAAM,6CAA6C,CAAA;AACpD,OAAO,EAEL,8BAA8B,EAC/B,MAAM,qDAAqD,CAAA;AAC5D,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,cAAc,EACf,MAAM,YAAY,CAAA;AAEnB,YAAY,EAAE,UAAU,EAAE,CAAA;AAC1B,MAAM,MAAM,4BAA4B,GAAG,8BAA8B,GAAG;IAC1E,UAAU,EAAE,UAAU,CAAA;IACtB,kBAAkB,CAAC,EAAE,UAAU,CAAA;CAChC,CAAA;AAID;;;;;GAKG;AACH,qBAAa,qBAAsB,YAAW,cAAc;IAC1D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAC7C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgB;IAC5C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAgB;gBAEzC,OAAO,EAAE,4BAA4B;IAQ3C,OAAO,CACX,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,cAAc,CAAC;CAkC3B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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");
|
|
6
|
+
const noop = () => { };
|
|
7
|
+
/**
|
|
8
|
+
* Implementation of the official ATPROTO handle resolution strategy.
|
|
9
|
+
* This implementation relies on two primitives:
|
|
10
|
+
* - HTTP Well-Known URI resolution (requires a `fetch()` implementation)
|
|
11
|
+
* - DNS TXT record resolution (requires a `resolveTxt()` function)
|
|
12
|
+
*/
|
|
13
|
+
class AtprotoHandleResolver {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
Object.defineProperty(this, "httpResolver", {
|
|
16
|
+
enumerable: true,
|
|
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);
|
|
35
|
+
this.dnsResolverFallback = options.resolveTxtFallback
|
|
36
|
+
? new dns_handle_resolver_js_1.DnsHandleResolver(options.resolveTxtFallback)
|
|
37
|
+
: undefined;
|
|
38
|
+
}
|
|
39
|
+
async resolve(handle, options) {
|
|
40
|
+
options?.signal?.throwIfAborted();
|
|
41
|
+
const abortController = new AbortController();
|
|
42
|
+
const { signal } = abortController;
|
|
43
|
+
options?.signal?.addEventListener('abort', () => abortController.abort(), {
|
|
44
|
+
signal,
|
|
45
|
+
});
|
|
46
|
+
const wrappedOptions = { ...options, signal };
|
|
47
|
+
try {
|
|
48
|
+
const dnsPromise = this.dnsResolver.resolve(handle, wrappedOptions);
|
|
49
|
+
const httpPromise = this.httpResolver.resolve(handle, wrappedOptions);
|
|
50
|
+
// Prevent uncaught promise rejection
|
|
51
|
+
httpPromise.catch(noop);
|
|
52
|
+
const dnsRes = await dnsPromise;
|
|
53
|
+
if (dnsRes)
|
|
54
|
+
return dnsRes;
|
|
55
|
+
signal.throwIfAborted();
|
|
56
|
+
const res = await httpPromise;
|
|
57
|
+
if (res)
|
|
58
|
+
return res;
|
|
59
|
+
signal.throwIfAborted();
|
|
60
|
+
return this.dnsResolverFallback?.resolve(handle, wrappedOptions) ?? null;
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
// Cancel pending requests, and remove "abort" listener on incoming signal
|
|
64
|
+
abortController.abort();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.AtprotoHandleResolver = AtprotoHandleResolver;
|
|
69
|
+
//# sourceMappingURL=atproto-handle-resolver.js.map
|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ACrC,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"}
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export type
|
|
1
|
+
import { SimpleStore } from '@atproto-labs/simple-store';
|
|
2
|
+
import { HandleResolver, ResolvedHandle, ResolveHandleOptions } from './types.js';
|
|
3
|
+
export type HandleCache = SimpleStore<string, ResolvedHandle>;
|
|
4
|
+
export declare class CachedHandleResolver implements HandleResolver {
|
|
5
|
+
private getter;
|
|
6
|
+
constructor(
|
|
4
7
|
/**
|
|
5
8
|
* The resolver that will be used to resolve handles.
|
|
6
9
|
*/
|
|
7
|
-
resolver: HandleResolver;
|
|
8
|
-
|
|
9
|
-
* A store that will be used to cache resolved values.
|
|
10
|
-
*/
|
|
11
|
-
cache?: GenericStore<string, ResolvedHandle>;
|
|
12
|
-
};
|
|
13
|
-
export declare class CachedHandleResolver extends CachedGetter<string, ResolvedHandle> implements HandleResolver {
|
|
14
|
-
constructor({ resolver, cache, }: CachedHandleResolverOptions);
|
|
15
|
-
resolve(handle: string, options?: HandleResolveOptions): Promise<ResolvedHandle>;
|
|
10
|
+
resolver: HandleResolver, cache?: HandleCache);
|
|
11
|
+
resolve(handle: string, options?: ResolveHandleOptions): Promise<ResolvedHandle>;
|
|
16
12
|
}
|
|
17
13
|
//# sourceMappingURL=cached-handle-resolver.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cached-handle-resolver.d.ts","sourceRoot":"","sources":["../src/cached-handle-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"cached-handle-resolver.d.ts","sourceRoot":"","sources":["../src/cached-handle-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAEtE,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACrB,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;AAE7D,qBAAa,oBAAqB,YAAW,cAAc;IACzD,OAAO,CAAC,MAAM,CAAsC;;IAGlD;;OAEG;IACH,QAAQ,EAAE,cAAc,EACxB,KAAK,GAAE,WAGL;IAQE,OAAO,CACX,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,cAAc,CAAC;CAG3B"}
|
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CachedHandleResolver = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
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 {
|
|
7
|
+
constructor(
|
|
8
|
+
/**
|
|
9
|
+
* The resolver that will be used to resolve handles.
|
|
10
|
+
*/
|
|
11
|
+
resolver, cache = new simple_store_memory_1.SimpleStoreMemory({
|
|
7
12
|
max: 1000,
|
|
8
13
|
ttl: 10 * 60e3,
|
|
9
|
-
})
|
|
10
|
-
|
|
14
|
+
})) {
|
|
15
|
+
Object.defineProperty(this, "getter", {
|
|
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);
|
|
11
22
|
}
|
|
12
23
|
async resolve(handle, options) {
|
|
13
|
-
return this.get(handle, options);
|
|
24
|
+
return this.getter.get(handle, options);
|
|
14
25
|
}
|
|
15
26
|
}
|
|
16
27
|
exports.CachedHandleResolver = CachedHandleResolver;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cached-handle-resolver.js","sourceRoot":"","sources":["../src/cached-handle-resolver.ts"],"names":[],"mappings":";;;AAAA,
|
|
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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './app-view-handle-resolver.js';
|
|
3
|
+
export * from './atproto-doh-handle-resolver.js';
|
|
4
|
+
export * from './atproto-handle-resolver.js';
|
|
4
5
|
export * from './cached-handle-resolver.js';
|
|
5
|
-
export * from './atproto-lexicon-handle-resolver.js';
|
|
6
|
-
export * from './serial-handle-resolver.js';
|
|
7
|
-
export * from './well-known-handler-resolver.js';
|
|
8
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAG1B,cAAc,+BAA+B,CAAA;AAC7C,cAAc,kCAAkC,CAAA;AAChD,cAAc,8BAA8B,CAAA;AAG5C,cAAc,6BAA6B,CAAA"}
|