@atproto/lexicon-resolver 0.1.1 → 0.2.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 +29 -0
- package/dist/lexicon.d.ts +7 -4
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lexicon.js +33 -13
- package/dist/lexicon.js.map +1 -1
- package/dist/record.d.ts +3 -2
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +5 -1
- package/dist/record.js.map +1 -1
- package/package.json +9 -9
- package/src/lexicon.ts +36 -11
- package/src/record.ts +4 -4
- package/tests/lexicon.test.ts +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @atproto/lexicon-resolver
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`055a413fb`](https://github.com/bluesky-social/atproto/commit/055a413fba4fab510ec899377154f1204ab12099), [`055a413fb`](https://github.com/bluesky-social/atproto/commit/055a413fba4fab510ec899377154f1204ab12099)]:
|
|
8
|
+
- @atproto/repo@0.8.9
|
|
9
|
+
- @atproto/identity@0.4.9
|
|
10
|
+
- @atproto/lexicon@0.5.1
|
|
11
|
+
- @atproto/xrpc@0.7.5
|
|
12
|
+
|
|
13
|
+
## 0.2.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [#4108](https://github.com/bluesky-social/atproto/pull/4108) [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `nsid` property to `LexiconResolutionError`
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- [#4108](https://github.com/bluesky-social/atproto/pull/4108) [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `LexiconResolutionError.from` method to create an error from a string `nsid`
|
|
22
|
+
|
|
23
|
+
- [#4108](https://github.com/bluesky-social/atproto/pull/4108) [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Export all types used in public interfaces
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d), [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d), [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d), [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d), [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d), [`f9dc9aa4c`](https://github.com/bluesky-social/atproto/commit/f9dc9aa4c9eaf2f82d140fbf011a9015e7f1a00d)]:
|
|
26
|
+
- @atproto/lexicon@0.5.0
|
|
27
|
+
- @atproto/syntax@0.4.1
|
|
28
|
+
- @atproto-labs/fetch-node@0.1.10
|
|
29
|
+
- @atproto/xrpc@0.7.4
|
|
30
|
+
- @atproto/repo@0.8.8
|
|
31
|
+
|
|
3
32
|
## 0.1.1
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/dist/lexicon.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export type LexiconResolution = {
|
|
|
23
23
|
nsid: NSID;
|
|
24
24
|
lexicon: LexiconDoc & LexiconSchemaRecord;
|
|
25
25
|
};
|
|
26
|
+
export { AtUri, CID, type Commit, type LexiconDoc, type LexiconSchemaRecord, NSID, };
|
|
26
27
|
/**
|
|
27
28
|
* Build a Lexicon resolver function.
|
|
28
29
|
*/
|
|
@@ -30,14 +31,16 @@ export declare function buildLexiconResolver(options?: BuildLexiconResolverOptio
|
|
|
30
31
|
export declare const resolveLexicon: AtprotoLexiconResolver;
|
|
31
32
|
/**
|
|
32
33
|
* Resolve the DID authority for a Lexicon from the network using DNS, based on its NSID.
|
|
33
|
-
* @param
|
|
34
|
+
* @param input NSID or string representing one for which to lookup its Lexicon DID authority.
|
|
34
35
|
*/
|
|
35
|
-
export declare function resolveLexiconDidAuthority(
|
|
36
|
+
export declare function resolveLexiconDidAuthority(input: NSID | string): Promise<string | undefined>;
|
|
36
37
|
export declare class LexiconResolutionError extends Error {
|
|
37
|
-
|
|
38
|
+
readonly nsid: NSID;
|
|
39
|
+
readonly description: string;
|
|
40
|
+
constructor(nsid: NSID, description?: string, options?: ErrorOptions);
|
|
41
|
+
static from(input: NSID | string, description?: string, options?: ErrorOptions): LexiconResolutionError;
|
|
38
42
|
}
|
|
39
43
|
type LexiconSchemaRecord = {
|
|
40
44
|
$type: typeof LEXICON_SCHEMA_NSID;
|
|
41
45
|
};
|
|
42
|
-
export {};
|
|
43
46
|
//# sourceMappingURL=lexicon.d.ts.map
|
package/dist/lexicon.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon.d.ts","sourceRoot":"","sources":["../src/lexicon.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAmB,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAkB,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EAErB,MAAM,aAAa,CAAA;AAKpB,eAAO,MAAM,mBAAmB,+BAA+B,CAAA;A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|
@@ -3,12 +3,16 @@ 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.LexiconResolutionError = exports.resolveLexicon = exports.LEXICON_SCHEMA_NSID = void 0;
|
|
6
|
+
exports.LexiconResolutionError = exports.resolveLexicon = exports.NSID = exports.CID = exports.AtUri = exports.LEXICON_SCHEMA_NSID = void 0;
|
|
7
7
|
exports.buildLexiconResolver = buildLexiconResolver;
|
|
8
8
|
exports.resolveLexiconDidAuthority = resolveLexiconDidAuthority;
|
|
9
9
|
const promises_1 = __importDefault(require("node:dns/promises"));
|
|
10
|
+
const cid_1 = require("multiformats/cid");
|
|
11
|
+
Object.defineProperty(exports, "CID", { enumerable: true, get: function () { return cid_1.CID; } });
|
|
10
12
|
const lexicon_1 = require("@atproto/lexicon");
|
|
11
13
|
const syntax_1 = require("@atproto/syntax");
|
|
14
|
+
Object.defineProperty(exports, "AtUri", { enumerable: true, get: function () { return syntax_1.AtUri; } });
|
|
15
|
+
Object.defineProperty(exports, "NSID", { enumerable: true, get: function () { return syntax_1.NSID; } });
|
|
12
16
|
const record_js_1 = require("./record.js");
|
|
13
17
|
const util_js_1 = require("./util.js");
|
|
14
18
|
const DNS_SUBDOMAIN = '_lexicon';
|
|
@@ -19,26 +23,26 @@ exports.LEXICON_SCHEMA_NSID = 'com.atproto.lexicon.schema';
|
|
|
19
23
|
*/
|
|
20
24
|
function buildLexiconResolver(options = {}) {
|
|
21
25
|
const resolveRecord = (0, record_js_1.buildRecordResolver)(options);
|
|
22
|
-
return async function (
|
|
23
|
-
const nsid =
|
|
26
|
+
return async function (input, opts = {}) {
|
|
27
|
+
const nsid = syntax_1.NSID.from(input);
|
|
24
28
|
const didAuthority = await getDidAuthority(nsid, opts);
|
|
25
29
|
const verified = await resolveRecord(syntax_1.AtUri.make(didAuthority, exports.LEXICON_SCHEMA_NSID, nsid.toString()), { forceRefresh: opts.forceRefresh }).catch((err) => {
|
|
26
|
-
throw new LexiconResolutionError('Could not resolve Lexicon schema record', { cause: err });
|
|
30
|
+
throw new LexiconResolutionError(nsid, 'Could not resolve Lexicon schema record', { cause: err });
|
|
27
31
|
});
|
|
28
32
|
let lexicon;
|
|
29
33
|
try {
|
|
30
34
|
lexicon = (0, lexicon_1.parseLexiconDoc)(verified.record);
|
|
31
35
|
}
|
|
32
36
|
catch (err) {
|
|
33
|
-
throw new LexiconResolutionError('Invalid Lexicon document', {
|
|
37
|
+
throw new LexiconResolutionError(nsid, 'Invalid Lexicon document', {
|
|
34
38
|
cause: err,
|
|
35
39
|
});
|
|
36
40
|
}
|
|
37
41
|
if (!isLexiconSchemaRecord(lexicon)) {
|
|
38
|
-
throw new LexiconResolutionError('Invalid Lexicon schema record');
|
|
42
|
+
throw new LexiconResolutionError(nsid, 'Invalid Lexicon schema record');
|
|
39
43
|
}
|
|
40
44
|
if (lexicon.id !== nsid.toString()) {
|
|
41
|
-
throw new LexiconResolutionError(`Lexicon schema record id does not match NSID
|
|
45
|
+
throw new LexiconResolutionError(nsid, `Lexicon schema record id (${lexicon.id}) does not match NSID`);
|
|
42
46
|
}
|
|
43
47
|
const { uri, cid, commit } = verified;
|
|
44
48
|
return { commit, uri, cid, nsid, lexicon };
|
|
@@ -47,20 +51,36 @@ function buildLexiconResolver(options = {}) {
|
|
|
47
51
|
exports.resolveLexicon = buildLexiconResolver();
|
|
48
52
|
/**
|
|
49
53
|
* Resolve the DID authority for a Lexicon from the network using DNS, based on its NSID.
|
|
50
|
-
* @param
|
|
54
|
+
* @param input NSID or string representing one for which to lookup its Lexicon DID authority.
|
|
51
55
|
*/
|
|
52
|
-
async function resolveLexiconDidAuthority(
|
|
53
|
-
const nsid =
|
|
56
|
+
async function resolveLexiconDidAuthority(input) {
|
|
57
|
+
const nsid = syntax_1.NSID.from(input);
|
|
54
58
|
const did = await resolveDns(nsid.authority);
|
|
55
59
|
if (did == null || !(0, util_js_1.isValidDid)(did))
|
|
56
60
|
return;
|
|
57
61
|
return did;
|
|
58
62
|
}
|
|
59
63
|
class LexiconResolutionError extends Error {
|
|
60
|
-
constructor(
|
|
61
|
-
super(
|
|
64
|
+
constructor(nsid, description = `Could not resolve Lexicon for NSID`, options) {
|
|
65
|
+
super(`${description} (${nsid})`, options);
|
|
66
|
+
Object.defineProperty(this, "nsid", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: nsid
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(this, "description", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: description
|
|
77
|
+
});
|
|
62
78
|
this.name = 'LexiconResolutionError';
|
|
63
79
|
}
|
|
80
|
+
static from(input, description, options) {
|
|
81
|
+
const nsid = syntax_1.NSID.from(input);
|
|
82
|
+
return new LexiconResolutionError(nsid, description, options);
|
|
83
|
+
}
|
|
64
84
|
}
|
|
65
85
|
exports.LexiconResolutionError = LexiconResolutionError;
|
|
66
86
|
async function getDidAuthority(nsid, options) {
|
|
@@ -70,7 +90,7 @@ async function getDidAuthority(nsid, options) {
|
|
|
70
90
|
}
|
|
71
91
|
const did = await resolveLexiconDidAuthority(nsid);
|
|
72
92
|
if (!did) {
|
|
73
|
-
throw new LexiconResolutionError(`Could not resolve a DID authority for NSID
|
|
93
|
+
throw new LexiconResolutionError(nsid, `Could not resolve a DID authority for NSID`);
|
|
74
94
|
}
|
|
75
95
|
return did;
|
|
76
96
|
}
|
package/dist/lexicon.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon.js","sourceRoot":"","sources":["../src/lexicon.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"lexicon.js","sourceRoot":"","sources":["../src/lexicon.ts"],"names":[],"mappings":";;;;;;AAyDA,oDAwCC;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OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;AAC1C,CAAC;AAGD,SAAS,qBAAqB,CAAC,CAAU;IACvC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,2BAAmB,CAAA;AAC7C,CAAC"}
|
package/dist/record.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ import { BuildFetchHandlerOptions, FetchHandler } from '@atproto/xrpc';
|
|
|
7
7
|
/**
|
|
8
8
|
* Resolve a record from the network.
|
|
9
9
|
*/
|
|
10
|
-
export type RecordResolver = (
|
|
10
|
+
export type RecordResolver = (uri: AtUri | string) => Promise<RecordResolution>;
|
|
11
11
|
/**
|
|
12
12
|
* Resolve a record from the network, verifying its authenticity.
|
|
13
13
|
*/
|
|
14
|
-
export type AtprotoRecordResolver = (
|
|
14
|
+
export type AtprotoRecordResolver = (uri: AtUri | string, options?: ResolveRecordOptions) => Promise<RecordResolution>;
|
|
15
15
|
export type BuildRecordResolverOptions = {
|
|
16
16
|
idResolver?: IdResolver;
|
|
17
17
|
rpc?: Partial<BuildFetchHandlerOptions> | FetchHandler;
|
|
@@ -25,6 +25,7 @@ export type RecordResolution = {
|
|
|
25
25
|
cid: CID;
|
|
26
26
|
record: RepoRecord;
|
|
27
27
|
};
|
|
28
|
+
export { AtUri, CID, type Commit, IdResolver, type RepoRecord };
|
|
28
29
|
/**
|
|
29
30
|
* Build a record resolver function.
|
|
30
31
|
*/
|
package/dist/record.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EACL,MAAM,EAMP,MAAM,eAAe,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KAAK,EAAE,GAAG,EAAE,KAAK,MAAM,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,CAAA;AAE/D;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,0BAA+B,GACvC,qBAAqB,CAyCvB;AAED,eAAO,MAAM,aAAa,uBAAwB,CAAA;AAElD,eAAO,MAAM,SAAS,sFAIpB,CAAA;AAEF,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIrD"}
|
package/dist/record.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RecordResolutionError = exports.safeFetch = exports.resolveRecord = void 0;
|
|
3
|
+
exports.RecordResolutionError = exports.safeFetch = exports.resolveRecord = exports.IdResolver = exports.CID = exports.AtUri = void 0;
|
|
4
4
|
exports.buildRecordResolver = buildRecordResolver;
|
|
5
|
+
const cid_1 = require("multiformats/cid");
|
|
6
|
+
Object.defineProperty(exports, "CID", { enumerable: true, get: function () { return cid_1.CID; } });
|
|
5
7
|
const identity_1 = require("@atproto/identity");
|
|
8
|
+
Object.defineProperty(exports, "IdResolver", { enumerable: true, get: function () { return identity_1.IdResolver; } });
|
|
6
9
|
const repo_1 = require("@atproto/repo");
|
|
7
10
|
const syntax_1 = require("@atproto/syntax");
|
|
11
|
+
Object.defineProperty(exports, "AtUri", { enumerable: true, get: function () { return syntax_1.AtUri; } });
|
|
8
12
|
const fetch_node_1 = require("@atproto-labs/fetch-node");
|
|
9
13
|
const index_js_1 = require("./client/index.js");
|
|
10
14
|
const util_js_1 = require("./util.js");
|
package/dist/record.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":";;;AAmDA,kDA2CC;
|
|
1
|
+
{"version":3,"file":"record.js","sour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,gCAAgC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAClD,CAAA;IACH,CAAC;IACD,MAAM,GAAG,GAAG,UAAG,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;IAC1D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,qBAAqB,CAAC,2BAA2B,CAAC,CAAA;IAC9D,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IAC/C,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,CAAA;AACrC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lexicon-resolver",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "ATProto Lexicon resolution",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"multiformats": "^9.9.0",
|
|
27
|
-
"@atproto-labs/fetch-node": "^0.1.
|
|
28
|
-
"@atproto/identity": "^0.4.
|
|
29
|
-
"@atproto/lexicon": "^0.
|
|
30
|
-
"@atproto/repo": "^0.8.
|
|
31
|
-
"@atproto/syntax": "^0.4.
|
|
32
|
-
"@atproto/xrpc": "^0.7.
|
|
27
|
+
"@atproto-labs/fetch-node": "^0.1.10",
|
|
28
|
+
"@atproto/identity": "^0.4.9",
|
|
29
|
+
"@atproto/lexicon": "^0.5.1",
|
|
30
|
+
"@atproto/repo": "^0.8.9",
|
|
31
|
+
"@atproto/syntax": "^0.4.1",
|
|
32
|
+
"@atproto/xrpc": "^0.7.5"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"jest": "^28.1.2",
|
|
36
36
|
"typescript": "^5.6.3",
|
|
37
|
-
"@atproto/common": "^0.4.
|
|
38
|
-
"@atproto/lex-cli": "^0.9.
|
|
37
|
+
"@atproto/common": "^0.4.12",
|
|
38
|
+
"@atproto/lex-cli": "^0.9.5"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"test": "jest",
|
package/src/lexicon.ts
CHANGED
|
@@ -43,6 +43,15 @@ export type LexiconResolution = {
|
|
|
43
43
|
lexicon: LexiconDoc & LexiconSchemaRecord
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
export {
|
|
47
|
+
AtUri,
|
|
48
|
+
CID,
|
|
49
|
+
type Commit,
|
|
50
|
+
type LexiconDoc,
|
|
51
|
+
type LexiconSchemaRecord,
|
|
52
|
+
NSID,
|
|
53
|
+
}
|
|
54
|
+
|
|
46
55
|
/**
|
|
47
56
|
* Build a Lexicon resolver function.
|
|
48
57
|
*/
|
|
@@ -51,16 +60,17 @@ export function buildLexiconResolver(
|
|
|
51
60
|
): AtprotoLexiconResolver {
|
|
52
61
|
const resolveRecord = buildRecordResolver(options)
|
|
53
62
|
return async function (
|
|
54
|
-
|
|
63
|
+
input: NSID | string,
|
|
55
64
|
opts: ResolveLexiconOptions = {},
|
|
56
65
|
): Promise<LexiconResolution> {
|
|
57
|
-
const nsid =
|
|
66
|
+
const nsid = NSID.from(input)
|
|
58
67
|
const didAuthority = await getDidAuthority(nsid, opts)
|
|
59
68
|
const verified = await resolveRecord(
|
|
60
69
|
AtUri.make(didAuthority, LEXICON_SCHEMA_NSID, nsid.toString()),
|
|
61
70
|
{ forceRefresh: opts.forceRefresh },
|
|
62
71
|
).catch((err) => {
|
|
63
72
|
throw new LexiconResolutionError(
|
|
73
|
+
nsid,
|
|
64
74
|
'Could not resolve Lexicon schema record',
|
|
65
75
|
{ cause: err },
|
|
66
76
|
)
|
|
@@ -69,16 +79,17 @@ export function buildLexiconResolver(
|
|
|
69
79
|
try {
|
|
70
80
|
lexicon = parseLexiconDoc(verified.record)
|
|
71
81
|
} catch (err) {
|
|
72
|
-
throw new LexiconResolutionError('Invalid Lexicon document', {
|
|
82
|
+
throw new LexiconResolutionError(nsid, 'Invalid Lexicon document', {
|
|
73
83
|
cause: err,
|
|
74
84
|
})
|
|
75
85
|
}
|
|
76
86
|
if (!isLexiconSchemaRecord(lexicon)) {
|
|
77
|
-
throw new LexiconResolutionError('Invalid Lexicon schema record')
|
|
87
|
+
throw new LexiconResolutionError(nsid, 'Invalid Lexicon schema record')
|
|
78
88
|
}
|
|
79
89
|
if (lexicon.id !== nsid.toString()) {
|
|
80
90
|
throw new LexiconResolutionError(
|
|
81
|
-
|
|
91
|
+
nsid,
|
|
92
|
+
`Lexicon schema record id (${lexicon.id}) does not match NSID`,
|
|
82
93
|
)
|
|
83
94
|
}
|
|
84
95
|
const { uri, cid, commit } = verified
|
|
@@ -90,22 +101,35 @@ export const resolveLexicon = buildLexiconResolver()
|
|
|
90
101
|
|
|
91
102
|
/**
|
|
92
103
|
* Resolve the DID authority for a Lexicon from the network using DNS, based on its NSID.
|
|
93
|
-
* @param
|
|
104
|
+
* @param input NSID or string representing one for which to lookup its Lexicon DID authority.
|
|
94
105
|
*/
|
|
95
106
|
export async function resolveLexiconDidAuthority(
|
|
96
|
-
|
|
107
|
+
input: NSID | string,
|
|
97
108
|
): Promise<string | undefined> {
|
|
98
|
-
const nsid =
|
|
109
|
+
const nsid = NSID.from(input)
|
|
99
110
|
const did = await resolveDns(nsid.authority)
|
|
100
111
|
if (did == null || !isValidDid(did)) return
|
|
101
112
|
return did
|
|
102
113
|
}
|
|
103
114
|
|
|
104
115
|
export class LexiconResolutionError extends Error {
|
|
105
|
-
constructor(
|
|
106
|
-
|
|
116
|
+
constructor(
|
|
117
|
+
public readonly nsid: NSID,
|
|
118
|
+
public readonly description = `Could not resolve Lexicon for NSID`,
|
|
119
|
+
options?: ErrorOptions,
|
|
120
|
+
) {
|
|
121
|
+
super(`${description} (${nsid})`, options)
|
|
107
122
|
this.name = 'LexiconResolutionError'
|
|
108
123
|
}
|
|
124
|
+
|
|
125
|
+
static from(
|
|
126
|
+
input: NSID | string,
|
|
127
|
+
description?: string,
|
|
128
|
+
options?: ErrorOptions,
|
|
129
|
+
): LexiconResolutionError {
|
|
130
|
+
const nsid = NSID.from(input)
|
|
131
|
+
return new LexiconResolutionError(nsid, description, options)
|
|
132
|
+
}
|
|
109
133
|
}
|
|
110
134
|
|
|
111
135
|
async function getDidAuthority(nsid: NSID, options: ResolveLexiconOptions) {
|
|
@@ -116,7 +140,8 @@ async function getDidAuthority(nsid: NSID, options: ResolveLexiconOptions) {
|
|
|
116
140
|
const did = await resolveLexiconDidAuthority(nsid)
|
|
117
141
|
if (!did) {
|
|
118
142
|
throw new LexiconResolutionError(
|
|
119
|
-
|
|
143
|
+
nsid,
|
|
144
|
+
`Could not resolve a DID authority for NSID`,
|
|
120
145
|
)
|
|
121
146
|
}
|
|
122
147
|
return did
|
package/src/record.ts
CHANGED
|
@@ -18,15 +18,13 @@ import { isValidDid } from './util.js'
|
|
|
18
18
|
/**
|
|
19
19
|
* Resolve a record from the network.
|
|
20
20
|
*/
|
|
21
|
-
export type RecordResolver = (
|
|
22
|
-
uriStr: AtUri | string,
|
|
23
|
-
) => Promise<RecordResolution>
|
|
21
|
+
export type RecordResolver = (uri: AtUri | string) => Promise<RecordResolution>
|
|
24
22
|
|
|
25
23
|
/**
|
|
26
24
|
* Resolve a record from the network, verifying its authenticity.
|
|
27
25
|
*/
|
|
28
26
|
export type AtprotoRecordResolver = (
|
|
29
|
-
|
|
27
|
+
uri: AtUri | string,
|
|
30
28
|
options?: ResolveRecordOptions,
|
|
31
29
|
) => Promise<RecordResolution>
|
|
32
30
|
|
|
@@ -46,6 +44,8 @@ export type RecordResolution = {
|
|
|
46
44
|
record: RepoRecord
|
|
47
45
|
}
|
|
48
46
|
|
|
47
|
+
export { AtUri, CID, type Commit, IdResolver, type RepoRecord }
|
|
48
|
+
|
|
49
49
|
/**
|
|
50
50
|
* Build a record resolver function.
|
|
51
51
|
*/
|
package/tests/lexicon.test.ts
CHANGED
|
@@ -74,7 +74,9 @@ describe('Lexicon resolution', () => {
|
|
|
74
74
|
resolveLexicon('example.alice.mismatch', {
|
|
75
75
|
forceRefresh: true,
|
|
76
76
|
}),
|
|
77
|
-
).rejects.toThrow(
|
|
77
|
+
).rejects.toThrow(
|
|
78
|
+
'Lexicon schema record id (example.test1.mismatch.bad) does not match NSID (example.alice.mismatch)',
|
|
79
|
+
)
|
|
78
80
|
})
|
|
79
81
|
|
|
80
82
|
it('fails on missing DNS entry.', async () => {
|
|
@@ -89,7 +91,7 @@ describe('Lexicon resolution', () => {
|
|
|
89
91
|
forceRefresh: true,
|
|
90
92
|
}),
|
|
91
93
|
).rejects.toThrow(
|
|
92
|
-
'Could not resolve a DID authority for NSID
|
|
94
|
+
'Could not resolve a DID authority for NSID (example.bob.name)',
|
|
93
95
|
)
|
|
94
96
|
})
|
|
95
97
|
|
|
@@ -123,7 +125,8 @@ describe('Lexicon resolution', () => {
|
|
|
123
125
|
).rejects.toThrow(
|
|
124
126
|
expect.objectContaining({
|
|
125
127
|
name: 'LexiconResolutionError',
|
|
126
|
-
message:
|
|
128
|
+
message:
|
|
129
|
+
'Could not resolve Lexicon schema record (example.alice.badsig)',
|
|
127
130
|
cause: expect.objectContaining({
|
|
128
131
|
name: 'RecordResolutionError',
|
|
129
132
|
message: expect.stringContaining('Invalid signature on commit'),
|
|
@@ -152,7 +155,7 @@ describe('Lexicon resolution', () => {
|
|
|
152
155
|
).rejects.toThrow(
|
|
153
156
|
expect.objectContaining({
|
|
154
157
|
name: 'LexiconResolutionError',
|
|
155
|
-
message: 'Invalid Lexicon document',
|
|
158
|
+
message: 'Invalid Lexicon document (example.alice.baddoc)',
|
|
156
159
|
cause: expect.objectContaining({
|
|
157
160
|
name: 'ZodError',
|
|
158
161
|
}),
|