@atcute/lexicon-resolver 0.1.5 → 0.1.7
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/README.md +50 -34
- package/dist/authority/doh-json.d.ts +1 -1
- package/dist/authority/doh-json.d.ts.map +1 -1
- package/dist/authority/doh-json.js +2 -45
- package/dist/authority/doh-json.js.map +1 -1
- package/dist/errors.d.ts +7 -7
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -7
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/schemas/xrpc.d.ts +1 -1
- package/dist/schemas/xrpc.d.ts.map +1 -1
- package/dist/schemas/xrpc.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -1
- package/lib/authority/doh-json.ts +7 -61
- package/lib/errors.ts +30 -22
- package/lib/index.ts +5 -5
- package/lib/schemas/xrpc.ts +3 -4
- package/lib/utils.ts +1 -0
- package/package.json +26 -19
package/README.md
CHANGED
|
@@ -1,36 +1,40 @@
|
|
|
1
1
|
# @atcute/lexicon-resolver
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
resolve lexicon schemas from the AT Protocol network.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @atcute/lexicon-resolver
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## usage
|
|
10
|
+
|
|
11
|
+
### resolving lexicon authority
|
|
12
|
+
|
|
13
|
+
find which DID is authoritative for an NSID via DNS TXT records:
|
|
4
14
|
|
|
5
15
|
```ts
|
|
6
|
-
|
|
16
|
+
import { DohJsonLexiconAuthorityResolver } from '@atcute/lexicon-resolver';
|
|
17
|
+
|
|
7
18
|
const authorityResolver = new DohJsonLexiconAuthorityResolver({
|
|
8
19
|
dohUrl: 'https://mozilla.cloudflare-dns.com/dns-query',
|
|
9
20
|
});
|
|
10
21
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} catch (err) {
|
|
15
|
-
if (err instanceof AuthorityNotFoundError) {
|
|
16
|
-
// nsid returned no did
|
|
17
|
-
}
|
|
18
|
-
if (err instanceof InvalidResolvedAuthorityError) {
|
|
19
|
-
// nsid returned a did, but isn't a valid atproto did
|
|
20
|
-
}
|
|
21
|
-
if (err instanceof AmbiguousAuthorityError) {
|
|
22
|
-
// nsid returned multiple did values
|
|
23
|
-
}
|
|
24
|
-
if (err instanceof FailedAuthorityResolutionError) {
|
|
25
|
-
// nsid resolution had thrown something unexpected (fetch error)
|
|
26
|
-
}
|
|
22
|
+
const authority = await authorityResolver.resolve('app.bsky.feed.post');
|
|
23
|
+
// -> 'did:plc:4v4y5r3lwsbtmsxhile2ljac'
|
|
24
|
+
```
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
### fetching lexicon schemas
|
|
27
|
+
|
|
28
|
+
retrieve the lexicon document from an authority's PDS:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import {
|
|
32
|
+
CompositeDidDocumentResolver,
|
|
33
|
+
PlcDidDocumentResolver,
|
|
34
|
+
WebDidDocumentResolver,
|
|
35
|
+
} from '@atcute/identity-resolver';
|
|
36
|
+
import { LexiconSchemaResolver } from '@atcute/lexicon-resolver';
|
|
32
37
|
|
|
33
|
-
// schema resolution
|
|
34
38
|
const schemaResolver = new LexiconSchemaResolver({
|
|
35
39
|
didDocumentResolver: new CompositeDidDocumentResolver({
|
|
36
40
|
methods: {
|
|
@@ -40,22 +44,34 @@ const schemaResolver = new LexiconSchemaResolver({
|
|
|
40
44
|
}),
|
|
41
45
|
});
|
|
42
46
|
|
|
47
|
+
const resolved = await schemaResolver.resolve(authority, 'app.bsky.feed.post');
|
|
48
|
+
// -> { uri: string, cid: string, rawSchema: unknown, schema: LexiconDoc }
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### error handling
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import {
|
|
55
|
+
AuthorityNotFoundError,
|
|
56
|
+
InvalidResolvedAuthorityError,
|
|
57
|
+
LexiconAuthorityResolutionError,
|
|
58
|
+
InvalidLexiconSchemaError,
|
|
59
|
+
LexiconResolutionError,
|
|
60
|
+
} from '@atcute/lexicon-resolver';
|
|
61
|
+
|
|
43
62
|
try {
|
|
44
|
-
|
|
45
|
-
// ^? { uri: string, cid: string, schema: LexiconDoc }
|
|
63
|
+
await authorityResolver.resolve(nsid);
|
|
46
64
|
} catch (err) {
|
|
47
|
-
if (err instanceof
|
|
48
|
-
//
|
|
49
|
-
}
|
|
50
|
-
if (err instanceof InvalidLexiconProofError) {
|
|
51
|
-
// lexicon record proof verification failed
|
|
52
|
-
}
|
|
53
|
-
if (err instanceof FailedLexiconResolutionError) {
|
|
54
|
-
// lexicon resolution had thrown something unexpected (fetch error)
|
|
65
|
+
if (err instanceof LexiconAuthorityResolutionError) {
|
|
66
|
+
// authority resolution failed
|
|
55
67
|
}
|
|
68
|
+
}
|
|
56
69
|
|
|
70
|
+
try {
|
|
71
|
+
await schemaResolver.resolve(authority, nsid);
|
|
72
|
+
} catch (err) {
|
|
57
73
|
if (err instanceof LexiconResolutionError) {
|
|
58
|
-
//
|
|
74
|
+
// schema resolution failed
|
|
59
75
|
}
|
|
60
76
|
}
|
|
61
77
|
```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AtprotoDid, Nsid } from '@atcute/lexicons/syntax';
|
|
2
|
-
import type { LexiconAuthorityResolver, ResolveLexiconAuthorityOptions } from '../types.
|
|
2
|
+
import type { LexiconAuthorityResolver, ResolveLexiconAuthorityOptions } from '../types.ts';
|
|
3
3
|
export interface DohJsonLexiconAuthorityResolverOptions {
|
|
4
4
|
dohUrl: string;
|
|
5
5
|
fetch?: typeof fetch;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doh-json.d.ts","sourceRoot":"","sources":["../../lib/authority/doh-json.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"doh-json.d.ts","sourceRoot":"","sources":["../../lib/authority/doh-json.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAIhE,OAAO,KAAK,EAAE,wBAAwB,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAM5F,MAAM,WAAW,sCAAsC;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACrB;AAED,qBAAa,+BAAgC,YAAW,wBAAwB;;IAC/E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAGxB,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAiB,EAAE,EAAE,sCAAsC,EAGvF;IAEK,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,8BAA8B,GAAG,OAAO,CAAC,UAAU,CAAC,CA6DvF;CACD"}
|
|
@@ -1,52 +1,9 @@
|
|
|
1
|
-
import * as v from '@badrap/valita';
|
|
2
1
|
import { isAtprotoDid } from '@atcute/identity';
|
|
3
|
-
import {
|
|
2
|
+
import { fetchDohJsonTxt } from '@atcute/util-fetch';
|
|
4
3
|
import * as err from '../errors.js';
|
|
5
4
|
import { nsidToLookupDomain } from '../utils.js';
|
|
6
|
-
const uint32 = v.number().assert((input) => Number.isInteger(input) && input >= 0 && input <= 2 ** 32 - 1);
|
|
7
|
-
const question = v.object({
|
|
8
|
-
name: v.string(),
|
|
9
|
-
type: v.literal(16), // TXT
|
|
10
|
-
});
|
|
11
|
-
const answer = v.object({
|
|
12
|
-
name: v.string(),
|
|
13
|
-
type: v.literal(16), // TXT
|
|
14
|
-
TTL: uint32,
|
|
15
|
-
data: v.string().chain((input) => {
|
|
16
|
-
return v.ok(input.replace(/^"|"$/g, '').replace(/\\"/g, '"'));
|
|
17
|
-
}),
|
|
18
|
-
});
|
|
19
|
-
const authority = v.object({
|
|
20
|
-
name: v.string(),
|
|
21
|
-
type: uint32,
|
|
22
|
-
TTL: uint32,
|
|
23
|
-
data: v.string(),
|
|
24
|
-
});
|
|
25
|
-
const result = v.object({
|
|
26
|
-
/** DNS response code */
|
|
27
|
-
Status: uint32,
|
|
28
|
-
/** Whether response is truncated */
|
|
29
|
-
TC: v.boolean(),
|
|
30
|
-
/** Whether recursive desired bit is set, always true for Google and Cloudflare DoH */
|
|
31
|
-
RD: v.boolean(),
|
|
32
|
-
/** Whether recursive available bit is set, always true for Google and Cloudflare DoH */
|
|
33
|
-
RA: v.boolean(),
|
|
34
|
-
/** Whether response data was validated with DNSSEC */
|
|
35
|
-
AD: v.boolean(),
|
|
36
|
-
/** Whether client asked to disable DNSSEC validation */
|
|
37
|
-
CD: v.boolean(),
|
|
38
|
-
/** Requested records */
|
|
39
|
-
Question: v.tuple([question]),
|
|
40
|
-
/** Answers */
|
|
41
|
-
Answer: v.array(answer).optional(() => []),
|
|
42
|
-
/** Authority */
|
|
43
|
-
Authority: v.array(authority).optional(),
|
|
44
|
-
/** Comment from the DNS server */
|
|
45
|
-
Comment: v.string().optional(),
|
|
46
|
-
});
|
|
47
5
|
const SUBDOMAIN = '_lexicon';
|
|
48
6
|
const PREFIX = 'did=';
|
|
49
|
-
const fetchDohJsonHandler = pipe(isResponseOk, parseResponseAsJson(/^application\/(dns-)?json$/, 16 * 1024), validateJsonWith(result, { mode: 'passthrough' }));
|
|
50
7
|
export class DohJsonLexiconAuthorityResolver {
|
|
51
8
|
dohUrl;
|
|
52
9
|
#fetch;
|
|
@@ -66,7 +23,7 @@ export class DohJsonLexiconAuthorityResolver {
|
|
|
66
23
|
cache: options?.noCache ? 'no-cache' : undefined,
|
|
67
24
|
headers: { accept: 'application/dns-json' },
|
|
68
25
|
});
|
|
69
|
-
const handled = await
|
|
26
|
+
const handled = await fetchDohJsonTxt(response);
|
|
70
27
|
json = handled.json;
|
|
71
28
|
}
|
|
72
29
|
catch (cause) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doh-json.js","sourceRoot":"","sources":["../../lib/authority/doh-json.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"doh-json.js","sourceRoot":"","sources":["../../lib/authority/doh-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAyB,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE5E,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,SAAS,GAAG,UAAU,CAAC;AAC7B,MAAM,MAAM,GAAG,MAAM,CAAC;AAOtB,MAAM,OAAO,+BAA+B;IAClC,MAAM,CAAS;IACxB,MAAM,CAAe;IAErB,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,KAAK,EAA0C;QACvF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAU,EAAE,OAAwC;QACjE,MAAM,YAAY,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAE9C,IAAI,IAAsB,CAAC;QAE3B,IAAI,CAAC;YACJ,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACjC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,SAAS,IAAI,YAAY,EAAE,CAAC,CAAC;YAC7D,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAEpC,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE;gBAC5C,MAAM,EAAE,OAAO,EAAE,MAAM;gBACvB,KAAK,EAAE,OAAO,EAAE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jC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;gBAC7B,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC7B,MAAM,IAAI,GAAG,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;gBAC7C,CAAC;YACF,CAAC;YAED,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACtC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;gBACxB,MAAM,IAAI,GAAG,CAAC,6BAA6B,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YACxD,CAAC;YAED,OAAO,GAAG,CAAC;QACZ,CAAC;QAED,sEAAsE;QACtE,MAAM,IAAI,GAAG,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;CACD"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -3,42 +3,42 @@ export declare class LexiconAuthorityResolutionError extends Error {
|
|
|
3
3
|
name: string;
|
|
4
4
|
}
|
|
5
5
|
export declare class AuthorityNotFoundError extends LexiconAuthorityResolutionError {
|
|
6
|
-
nsid: Nsid;
|
|
7
6
|
name: string;
|
|
7
|
+
nsid: Nsid;
|
|
8
8
|
constructor(nsid: Nsid);
|
|
9
9
|
}
|
|
10
10
|
export declare class FailedAuthorityResolutionError extends LexiconAuthorityResolutionError {
|
|
11
|
-
nsid: Nsid;
|
|
12
11
|
name: string;
|
|
12
|
+
nsid: Nsid;
|
|
13
13
|
constructor(nsid: Nsid, options?: ErrorOptions);
|
|
14
14
|
}
|
|
15
15
|
export declare class InvalidResolvedAuthorityError extends LexiconAuthorityResolutionError {
|
|
16
|
+
name: string;
|
|
16
17
|
nsid: Nsid;
|
|
17
18
|
did: string;
|
|
18
|
-
name: string;
|
|
19
19
|
constructor(nsid: Nsid, did: string);
|
|
20
20
|
}
|
|
21
21
|
export declare class AmbiguousAuthorityError extends LexiconAuthorityResolutionError {
|
|
22
|
-
nsid: Nsid;
|
|
23
22
|
name: string;
|
|
23
|
+
nsid: Nsid;
|
|
24
24
|
constructor(nsid: Nsid);
|
|
25
25
|
}
|
|
26
26
|
export declare class LexiconResolutionError extends Error {
|
|
27
27
|
name: string;
|
|
28
28
|
}
|
|
29
29
|
export declare class FailedLexiconResolutionError extends LexiconResolutionError {
|
|
30
|
-
nsid: Nsid;
|
|
31
30
|
name: string;
|
|
31
|
+
nsid: Nsid;
|
|
32
32
|
constructor(nsid: Nsid, options?: ErrorOptions);
|
|
33
33
|
}
|
|
34
34
|
export declare class InvalidLexiconSchemaError extends LexiconResolutionError {
|
|
35
|
-
nsid: Nsid;
|
|
36
35
|
name: string;
|
|
36
|
+
nsid: Nsid;
|
|
37
37
|
constructor(nsid: Nsid, options?: ErrorOptions);
|
|
38
38
|
}
|
|
39
39
|
export declare class InvalidLexiconProofError extends LexiconResolutionError {
|
|
40
|
-
nsid: Nsid;
|
|
41
40
|
name: string;
|
|
41
|
+
nsid: Nsid;
|
|
42
42
|
constructor(nsid: Nsid, options?: ErrorOptions);
|
|
43
43
|
}
|
|
44
44
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../lib/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAGpD,qBAAa,+BAAgC,SAAQ,KAAK;IAChD,IAAI,SAAqC;CAClD;AAED,qBAAa,sBAAuB,SAAQ,+BAA+B;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../lib/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAGpD,qBAAa,+BAAgC,SAAQ,KAAK;IAChD,IAAI,SAAqC;CAClD;AAED,qBAAa,sBAAuB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|
4
4
|
}
|
|
5
5
|
export class AuthorityNotFoundError extends LexiconAuthorityResolutionError {
|
|
6
|
-
nsid;
|
|
7
6
|
name = 'AuthorityNotFoundError';
|
|
7
|
+
nsid;
|
|
8
8
|
constructor(nsid) {
|
|
9
9
|
super(`lexicon authority not found; nsid=${nsid}`);
|
|
10
10
|
this.nsid = nsid;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
export class FailedAuthorityResolutionError extends LexiconAuthorityResolutionError {
|
|
14
|
-
nsid;
|
|
15
14
|
name = 'FailedAuthorityResolutionError';
|
|
15
|
+
nsid;
|
|
16
16
|
constructor(nsid, options) {
|
|
17
17
|
super(`failed to resolve lexicon authority; nsid=${nsid}`, options);
|
|
18
18
|
this.nsid = nsid;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
export class InvalidResolvedAuthorityError extends LexiconAuthorityResolutionError {
|
|
22
|
+
name = 'InvalidResolvedAuthorityError';
|
|
22
23
|
nsid;
|
|
23
24
|
did;
|
|
24
|
-
name = 'InvalidResolvedAuthorityError';
|
|
25
25
|
constructor(nsid, did) {
|
|
26
26
|
super(`lexicon authority returned invalid did; nsid=${nsid}; did=${did}`);
|
|
27
27
|
this.nsid = nsid;
|
|
@@ -29,8 +29,8 @@ export class InvalidResolvedAuthorityError extends LexiconAuthorityResolutionErr
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
export class AmbiguousAuthorityError extends LexiconAuthorityResolutionError {
|
|
32
|
-
nsid;
|
|
33
32
|
name = 'AmbiguousAuthorityError';
|
|
33
|
+
nsid;
|
|
34
34
|
constructor(nsid) {
|
|
35
35
|
super(`lexicon authority returned multiple did values; nsid=${nsid}`);
|
|
36
36
|
this.nsid = nsid;
|
|
@@ -42,24 +42,24 @@ export class LexiconResolutionError extends Error {
|
|
|
42
42
|
name = 'LexiconResolutionError';
|
|
43
43
|
}
|
|
44
44
|
export class FailedLexiconResolutionError extends LexiconResolutionError {
|
|
45
|
-
nsid;
|
|
46
45
|
name = 'FailedLexiconResolutionError';
|
|
46
|
+
nsid;
|
|
47
47
|
constructor(nsid, options) {
|
|
48
48
|
super(`failed to resolve lexicon; nsid=${nsid}`, options);
|
|
49
49
|
this.nsid = nsid;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
export class InvalidLexiconSchemaError extends LexiconResolutionError {
|
|
53
|
-
nsid;
|
|
54
53
|
name = 'InvalidLexiconSchemaError';
|
|
54
|
+
nsid;
|
|
55
55
|
constructor(nsid, options) {
|
|
56
56
|
super(`invalid lexicon schema; nsid=${nsid}`, options);
|
|
57
57
|
this.nsid = nsid;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
export class InvalidLexiconProofError extends LexiconResolutionError {
|
|
61
|
-
nsid;
|
|
62
61
|
name = 'InvalidLexiconProofError';
|
|
62
|
+
nsid;
|
|
63
63
|
constructor(nsid, options) {
|
|
64
64
|
super(`invalid lexicon record proof; nsid=${nsid}`, options);
|
|
65
65
|
this.nsid = nsid;
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../lib/errors.ts"],"names":[],"mappings":"AAEA,8CAA8C;AAC9C,MAAM,OAAO,+BAAgC,SAAQ,KAAK;IAChD,IAAI,GAAG,iCAAiC,CAAC;CAClD;AAED,MAAM,OAAO,sBAAuB,SAAQ,+BAA+B;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../lib/errors.ts"],"names":[],"mappings":"AAEA,8CAA8C;AAC9C,MAAM,OAAO,+BAAgC,SAAQ,KAAK;IAChD,IAAI,GAAG,iCAAiC,CAAC;CAClD;AAED,MAAM,OAAO,sBAAuB,SAAQ,+BAA+B;IACjE,IAAI,GAAG,wBAAwB,CAAC;IAEzC,IAAI,CAAO;IAEX,YAAY,IAAU;QACrB,KAAK,CAAC,qCAAqC,IAAI,EAAE,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI,G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;IAE5C,IAAI,CAAO;IAEX,YAAY,IAAU,EAAE,OAAsB;QAC7C,KAAK,CAAC,gCAAgC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAED,MAAM,OAAO,wBAAyB,SAAQ,sBAAsB;IAC1D,IAAI,GAAG,0BAA0B,CAAC;IAE3C,IAAI,CAAO;IAEX,YAAY,IAAU,EAAE,OAAsB;QAC7C,KAAK,CAAC,sCAAsC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;QAC7D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AACD,aAAa"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './authority/doh-json.
|
|
2
|
-
export * from './errors.
|
|
3
|
-
export * from './schemas/xrpc.
|
|
4
|
-
export * from './types.
|
|
5
|
-
export * from './utils.
|
|
1
|
+
export * from './authority/doh-json.ts';
|
|
2
|
+
export * from './errors.ts';
|
|
3
|
+
export * from './schemas/xrpc.ts';
|
|
4
|
+
export * from './types.ts';
|
|
5
|
+
export * from './utils.ts';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/schemas/xrpc.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DidDocumentResolver } from '@atcute/identity-resolver';
|
|
2
2
|
import type { AtprotoDid, Nsid } from '@atcute/lexicons/syntax';
|
|
3
|
-
import type { ResolvedSchema, ResolveLexiconRecordOptions } from '../types.
|
|
3
|
+
import type { ResolvedSchema, ResolveLexiconRecordOptions } from '../types.ts';
|
|
4
4
|
export interface LexiconSchemaResolverOptions {
|
|
5
5
|
didDocumentResolver: DidDocumentResolver;
|
|
6
6
|
fetch?: typeof fetch;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xrpc.d.ts","sourceRoot":"","sources":["../../lib/schemas/xrpc.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"xrpc.d.ts","sourceRoot":"","sources":["../../lib/schemas/xrpc.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAMhE,OAAO,KAAK,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE/E,MAAM,WAAW,4BAA4B;IAC5C,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACrB;AAED,qBAAa,qBAAqB;;IACjC,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC;IAGlD,YAAY,EAAE,mBAAmB,EAAE,KAAK,EAAE,SAAiB,EAAE,EAAE,4BAA4B,EAG1F;IAEK,OAAO,CACZ,SAAS,EAAE,UAAU,EACrB,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,2BAA2B,GACnC,OAAO,CAAC,cAAc,CAAC,CAgGzB;CACD"}
|
package/dist/schemas/xrpc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xrpc.js","sourceRoot":"","sources":["../../lib/schemas/xrpc.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,6BAA6B,EAC7B,aAAa,EACb,kBAAkB,GAElB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,8BAA8B,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElF,OAAO,EAAE,UAAU,EAAmB,MAAM,qBAAqB,CAAC;AAElE,OAAO,EAAE,YAAY,EAAuB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"x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I,EAAE;YAC7D,GAAG,EAAE,cAAc,CAAC,GAAG;YACvB,SAAS,EAAE,cAAc,CAAC,MAAM;YAChC,MAAM,EAAE,MAAM;SACd,CAAC;IACH,CAAC;CACD"}
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,eAAO,MAAM,kBAAkB,SAAU,IAAI,KAAG,MAK/C,CAAC"}
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const nsidToLookupDomain = (nsid) => {
|
|
2
2
|
const segments = nsid.split('.');
|
|
3
3
|
// Remove the last segment (method name) and reverse to get domain format
|
|
4
|
+
// oxlint-disable-next-line unicorn/no-array-reverse -- slice already clones
|
|
4
5
|
return segments.slice(0, -1).reverse().join('.');
|
|
5
6
|
};
|
|
6
7
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAU,EAAU,EAAE;IACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,yEAAyE;IACzE,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAU,EAAU,EAAE;IACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,yEAAyE;IACzE,4EAA4E;IAC5E,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC,CAAC"}
|
|
@@ -1,68 +1,14 @@
|
|
|
1
|
-
import * as v from '@badrap/valita';
|
|
2
|
-
|
|
3
1
|
import { isAtprotoDid } from '@atcute/identity';
|
|
4
2
|
import type { AtprotoDid, Nsid } from '@atcute/lexicons/syntax';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import * as err from '../errors.
|
|
8
|
-
import type { LexiconAuthorityResolver, ResolveLexiconAuthorityOptions } from '../types.
|
|
9
|
-
import { nsidToLookupDomain } from '../utils.
|
|
10
|
-
|
|
11
|
-
const uint32 = v.number().assert((input) => Number.isInteger(input) && input >= 0 && input <= 2 ** 32 - 1);
|
|
12
|
-
|
|
13
|
-
const question = v.object({
|
|
14
|
-
name: v.string(),
|
|
15
|
-
type: v.literal(16), // TXT
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const answer = v.object({
|
|
19
|
-
name: v.string(),
|
|
20
|
-
type: v.literal(16), // TXT
|
|
21
|
-
TTL: uint32,
|
|
22
|
-
data: v.string().chain((input) => {
|
|
23
|
-
return v.ok(input.replace(/^"|"$/g, '').replace(/\\"/g, '"'));
|
|
24
|
-
}),
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const authority = v.object({
|
|
28
|
-
name: v.string(),
|
|
29
|
-
type: uint32,
|
|
30
|
-
TTL: uint32,
|
|
31
|
-
data: v.string(),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const result = v.object({
|
|
35
|
-
/** DNS response code */
|
|
36
|
-
Status: uint32,
|
|
37
|
-
/** Whether response is truncated */
|
|
38
|
-
TC: v.boolean(),
|
|
39
|
-
/** Whether recursive desired bit is set, always true for Google and Cloudflare DoH */
|
|
40
|
-
RD: v.boolean(),
|
|
41
|
-
/** Whether recursive available bit is set, always true for Google and Cloudflare DoH */
|
|
42
|
-
RA: v.boolean(),
|
|
43
|
-
/** Whether response data was validated with DNSSEC */
|
|
44
|
-
AD: v.boolean(),
|
|
45
|
-
/** Whether client asked to disable DNSSEC validation */
|
|
46
|
-
CD: v.boolean(),
|
|
47
|
-
/** Requested records */
|
|
48
|
-
Question: v.tuple([question]),
|
|
49
|
-
/** Answers */
|
|
50
|
-
Answer: v.array(answer).optional(() => []),
|
|
51
|
-
/** Authority */
|
|
52
|
-
Authority: v.array(authority).optional(),
|
|
53
|
-
/** Comment from the DNS server */
|
|
54
|
-
Comment: v.string().optional(),
|
|
55
|
-
});
|
|
3
|
+
import { type DohJsonTxtResult, fetchDohJsonTxt } from '@atcute/util-fetch';
|
|
4
|
+
|
|
5
|
+
import * as err from '../errors.ts';
|
|
6
|
+
import type { LexiconAuthorityResolver, ResolveLexiconAuthorityOptions } from '../types.ts';
|
|
7
|
+
import { nsidToLookupDomain } from '../utils.ts';
|
|
56
8
|
|
|
57
9
|
const SUBDOMAIN = '_lexicon';
|
|
58
10
|
const PREFIX = 'did=';
|
|
59
11
|
|
|
60
|
-
const fetchDohJsonHandler = pipe(
|
|
61
|
-
isResponseOk,
|
|
62
|
-
parseResponseAsJson(/^application\/(dns-)?json$/, 16 * 1024),
|
|
63
|
-
validateJsonWith(result, { mode: 'passthrough' }),
|
|
64
|
-
);
|
|
65
|
-
|
|
66
12
|
export interface DohJsonLexiconAuthorityResolverOptions {
|
|
67
13
|
dohUrl: string;
|
|
68
14
|
fetch?: typeof fetch;
|
|
@@ -80,7 +26,7 @@ export class DohJsonLexiconAuthorityResolver implements LexiconAuthorityResolver
|
|
|
80
26
|
async resolve(nsid: Nsid, options?: ResolveLexiconAuthorityOptions): Promise<AtprotoDid> {
|
|
81
27
|
const lookupDomain = nsidToLookupDomain(nsid);
|
|
82
28
|
|
|
83
|
-
let json:
|
|
29
|
+
let json: DohJsonTxtResult;
|
|
84
30
|
|
|
85
31
|
try {
|
|
86
32
|
const url = new URL(this.dohUrl);
|
|
@@ -93,7 +39,7 @@ export class DohJsonLexiconAuthorityResolver implements LexiconAuthorityResolver
|
|
|
93
39
|
headers: { accept: 'application/dns-json' },
|
|
94
40
|
});
|
|
95
41
|
|
|
96
|
-
const handled = await
|
|
42
|
+
const handled = await fetchDohJsonTxt(response);
|
|
97
43
|
|
|
98
44
|
json = handled.json;
|
|
99
45
|
} catch (cause) {
|
package/lib/errors.ts
CHANGED
|
@@ -8,38 +8,46 @@ export class LexiconAuthorityResolutionError extends Error {
|
|
|
8
8
|
export class AuthorityNotFoundError extends LexiconAuthorityResolutionError {
|
|
9
9
|
override name = 'AuthorityNotFoundError';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
nsid: Nsid;
|
|
12
|
+
|
|
13
|
+
constructor(nsid: Nsid) {
|
|
12
14
|
super(`lexicon authority not found; nsid=${nsid}`);
|
|
15
|
+
this.nsid = nsid;
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
export class FailedAuthorityResolutionError extends LexiconAuthorityResolutionError {
|
|
17
20
|
override name = 'FailedAuthorityResolutionError';
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
) {
|
|
22
|
+
nsid: Nsid;
|
|
23
|
+
|
|
24
|
+
constructor(nsid: Nsid, options?: ErrorOptions) {
|
|
23
25
|
super(`failed to resolve lexicon authority; nsid=${nsid}`, options);
|
|
26
|
+
this.nsid = nsid;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
export class InvalidResolvedAuthorityError extends LexiconAuthorityResolutionError {
|
|
28
31
|
override name = 'InvalidResolvedAuthorityError';
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
) {
|
|
33
|
+
nsid: Nsid;
|
|
34
|
+
did: string;
|
|
35
|
+
|
|
36
|
+
constructor(nsid: Nsid, did: string) {
|
|
34
37
|
super(`lexicon authority returned invalid did; nsid=${nsid}; did=${did}`);
|
|
38
|
+
this.nsid = nsid;
|
|
39
|
+
this.did = did;
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
export class AmbiguousAuthorityError extends LexiconAuthorityResolutionError {
|
|
39
44
|
override name = 'AmbiguousAuthorityError';
|
|
40
45
|
|
|
41
|
-
|
|
46
|
+
nsid: Nsid;
|
|
47
|
+
|
|
48
|
+
constructor(nsid: Nsid) {
|
|
42
49
|
super(`lexicon authority returned multiple did values; nsid=${nsid}`);
|
|
50
|
+
this.nsid = nsid;
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
53
|
// #endregion
|
|
@@ -52,33 +60,33 @@ export class LexiconResolutionError extends Error {
|
|
|
52
60
|
export class FailedLexiconResolutionError extends LexiconResolutionError {
|
|
53
61
|
override name = 'FailedLexiconResolutionError';
|
|
54
62
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
) {
|
|
63
|
+
nsid: Nsid;
|
|
64
|
+
|
|
65
|
+
constructor(nsid: Nsid, options?: ErrorOptions) {
|
|
59
66
|
super(`failed to resolve lexicon; nsid=${nsid}`, options);
|
|
67
|
+
this.nsid = nsid;
|
|
60
68
|
}
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
export class InvalidLexiconSchemaError extends LexiconResolutionError {
|
|
64
72
|
override name = 'InvalidLexiconSchemaError';
|
|
65
73
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
) {
|
|
74
|
+
nsid: Nsid;
|
|
75
|
+
|
|
76
|
+
constructor(nsid: Nsid, options?: ErrorOptions) {
|
|
70
77
|
super(`invalid lexicon schema; nsid=${nsid}`, options);
|
|
78
|
+
this.nsid = nsid;
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
81
|
|
|
74
82
|
export class InvalidLexiconProofError extends LexiconResolutionError {
|
|
75
83
|
override name = 'InvalidLexiconProofError';
|
|
76
84
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
) {
|
|
85
|
+
nsid: Nsid;
|
|
86
|
+
|
|
87
|
+
constructor(nsid: Nsid, options?: ErrorOptions) {
|
|
81
88
|
super(`invalid lexicon record proof; nsid=${nsid}`, options);
|
|
89
|
+
this.nsid = nsid;
|
|
82
90
|
}
|
|
83
91
|
}
|
|
84
92
|
// #endregion
|
package/lib/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './authority/doh-json.
|
|
2
|
-
export * from './errors.
|
|
3
|
-
export * from './schemas/xrpc.
|
|
4
|
-
export * from './types.
|
|
5
|
-
export * from './utils.
|
|
1
|
+
export * from './authority/doh-json.ts';
|
|
2
|
+
export * from './errors.ts';
|
|
3
|
+
export * from './schemas/xrpc.ts';
|
|
4
|
+
export * from './types.ts';
|
|
5
|
+
export * from './utils.ts';
|
package/lib/schemas/xrpc.ts
CHANGED
|
@@ -9,12 +9,11 @@ import type { DidDocumentResolver } from '@atcute/identity-resolver';
|
|
|
9
9
|
import { lexiconDoc, type LexiconDoc } from '@atcute/lexicon-doc';
|
|
10
10
|
import type { AtprotoDid, Nsid } from '@atcute/lexicons/syntax';
|
|
11
11
|
import { verifyRecord, type VerifiedRecord } from '@atcute/repo';
|
|
12
|
-
|
|
13
12
|
import { FailedResponseError } from '@atcute/util-fetch';
|
|
14
13
|
|
|
15
|
-
import { LEXICON_SCHEMA_COLLECTION } from '../constants.
|
|
16
|
-
import * as err from '../errors.
|
|
17
|
-
import type { ResolvedSchema, ResolveLexiconRecordOptions } from '../types.
|
|
14
|
+
import { LEXICON_SCHEMA_COLLECTION } from '../constants.ts';
|
|
15
|
+
import * as err from '../errors.ts';
|
|
16
|
+
import type { ResolvedSchema, ResolveLexiconRecordOptions } from '../types.ts';
|
|
18
17
|
|
|
19
18
|
export interface LexiconSchemaResolverOptions {
|
|
20
19
|
didDocumentResolver: DidDocumentResolver;
|
package/lib/utils.ts
CHANGED
|
@@ -3,5 +3,6 @@ import type { Nsid } from '@atcute/lexicons/syntax';
|
|
|
3
3
|
export const nsidToLookupDomain = (nsid: Nsid): string => {
|
|
4
4
|
const segments = nsid.split('.');
|
|
5
5
|
// Remove the last segment (method name) and reverse to get domain format
|
|
6
|
+
// oxlint-disable-next-line unicorn/no-array-reverse -- slice already clones
|
|
6
7
|
return segments.slice(0, -1).reverse().join('.');
|
|
7
8
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"type": "module",
|
|
3
2
|
"name": "@atcute/lexicon-resolver",
|
|
4
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
5
4
|
"description": "atproto lexicon authority resolution",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"atproto",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
7
|
+
"did",
|
|
8
|
+
"lexicon"
|
|
10
9
|
],
|
|
11
10
|
"license": "0BSD",
|
|
12
11
|
"repository": {
|
|
@@ -17,32 +16,40 @@
|
|
|
17
16
|
"dist/",
|
|
18
17
|
"lib/",
|
|
19
18
|
"!lib/**/*.bench.ts",
|
|
20
|
-
"!lib/**/*.test.ts"
|
|
19
|
+
"!lib/**/*.test.ts",
|
|
20
|
+
"!dist/**/*.{test,bench}.*"
|
|
21
21
|
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
22
24
|
"exports": {
|
|
23
25
|
".": "./dist/index.js"
|
|
24
26
|
},
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"@atcute/identity": "^1.1.0",
|
|
28
|
-
"@atcute/identity-resolver": "^1.1.3"
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@badrap/valita": "^0.4.6",
|
|
32
|
-
"@atcute/crypto": "^2.
|
|
33
|
-
"@atcute/
|
|
34
|
-
"@atcute/
|
|
35
|
-
"@atcute/
|
|
36
|
-
"@atcute/
|
|
32
|
+
"@atcute/crypto": "^2.4.1",
|
|
33
|
+
"@atcute/lexicons": "^1.3.1",
|
|
34
|
+
"@atcute/lexicon-doc": "^2.2.1",
|
|
35
|
+
"@atcute/util-fetch": "^1.0.5",
|
|
36
|
+
"@atcute/repo": "^0.1.5"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"
|
|
41
|
-
"@atcute/identity
|
|
39
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
40
|
+
"vitest": "^4.1.5",
|
|
41
|
+
"@atcute/identity": "^1.1.5",
|
|
42
|
+
"@atcute/identity-resolver": "^1.2.3"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@atcute/identity": "^1.1.0",
|
|
46
|
+
"@atcute/identity-resolver": "^1.1.3",
|
|
47
|
+
"@atcute/lexicon-doc": "^2.0.0",
|
|
48
|
+
"@atcute/lexicons": "^1.0.0"
|
|
42
49
|
},
|
|
43
50
|
"scripts": {
|
|
44
|
-
"build": "
|
|
45
|
-
"test": "
|
|
51
|
+
"build": "tsgo",
|
|
52
|
+
"test": "vitest",
|
|
46
53
|
"prepublish": "rm -rf dist; pnpm run build"
|
|
47
54
|
}
|
|
48
55
|
}
|