@atproto-labs/identity-resolver 0.1.1 → 0.1.2-rc.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.
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { DidDocument, DidResolver, ResolveDidOptions } from '@atproto-labs/did-resolver';
|
|
2
|
+
import { AtprotoIdentityDidMethods, HandleResolver, ResolvedHandle, ResolveHandleOptions } from '@atproto-labs/handle-resolver';
|
|
3
3
|
export type ResolvedIdentity = {
|
|
4
4
|
did: NonNullable<ResolvedHandle>;
|
|
5
5
|
pds: URL;
|
|
6
6
|
};
|
|
7
7
|
export type ResolveIdentityOptions = ResolveDidOptions & ResolveHandleOptions;
|
|
8
8
|
export declare class IdentityResolver {
|
|
9
|
-
readonly didResolver: DidResolver<
|
|
9
|
+
readonly didResolver: DidResolver<AtprotoIdentityDidMethods>;
|
|
10
10
|
readonly handleResolver: HandleResolver;
|
|
11
|
-
constructor(didResolver: DidResolver<
|
|
11
|
+
constructor(didResolver: DidResolver<AtprotoIdentityDidMethods>, handleResolver: HandleResolver);
|
|
12
12
|
resolve(input: string, options?: ResolveIdentityOptions): Promise<ResolvedIdentity>;
|
|
13
|
+
getDocumentFromDid(did: NonNullable<ResolvedHandle>, options?: ResolveDidOptions): Promise<DidDocument<AtprotoIdentityDidMethods>>;
|
|
14
|
+
getDocumentFromHandle(input: string, options?: ResolveHandleOptions): Promise<DidDocument<AtprotoIdentityDidMethods>>;
|
|
13
15
|
}
|
|
14
16
|
//# sourceMappingURL=identity-resolver.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-resolver.d.ts","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"identity-resolver.d.ts","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,WAAW,EAEX,iBAAiB,EAClB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,yBAAyB,EACzB,cAAc,EAEd,cAAc,EACd,oBAAoB,EACrB,MAAM,+BAA+B,CAAA;AAGtC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,WAAW,CAAC,cAAc,CAAC,CAAA;IAChC,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG,iBAAiB,GAAG,oBAAoB,CAAA;AAE7E,qBAAa,gBAAgB;IAEzB,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,yBAAyB,CAAC;IAC5D,QAAQ,CAAC,cAAc,EAAE,cAAc;gBAD9B,WAAW,EAAE,WAAW,CAAC,yBAAyB,CAAC,EACnD,cAAc,EAAE,cAAc;IAG5B,OAAO,CAClB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,gBAAgB,CAAC;IAsBf,kBAAkB,CAC7B,GAAG,EAAE,WAAW,CAAC,cAAc,CAAC,EAChC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAC;IAIrC,qBAAqB,CAChC,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAC;CAyBnD"}
|
|
@@ -19,26 +19,44 @@ class IdentityResolver {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
async resolve(input, options) {
|
|
22
|
-
const
|
|
23
|
-
? input
|
|
24
|
-
: await this.
|
|
25
|
-
|
|
22
|
+
const document = (0, handle_resolver_1.isResolvedHandle)(input)
|
|
23
|
+
? await this.getDocumentFromDid(input, options)
|
|
24
|
+
: await this.getDocumentFromHandle(input, options);
|
|
25
|
+
const service = document.service?.find((isAtprotoPersonalDataServerService), document);
|
|
26
|
+
if (!service) {
|
|
27
|
+
throw new TypeError(`No valid "AtprotoPersonalDataServer" service found in "${document.id}" DID document`);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
did: document.id,
|
|
31
|
+
pds: new URL(service.serviceEndpoint),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async getDocumentFromDid(did, options) {
|
|
35
|
+
return this.didResolver.resolve(did, options);
|
|
36
|
+
}
|
|
37
|
+
async getDocumentFromHandle(input, options) {
|
|
38
|
+
const handle = (0, syntax_1.normalizeAndEnsureValidHandle)(input);
|
|
39
|
+
const did = await this.handleResolver.resolve(handle, options);
|
|
26
40
|
if (!did) {
|
|
27
|
-
throw new TypeError(`Handle "${
|
|
41
|
+
throw new TypeError(`Handle "${handle}" does not resolve to a DID`);
|
|
28
42
|
}
|
|
43
|
+
options?.signal?.throwIfAborted();
|
|
44
|
+
// Note: Not using "return this.resolveDid(did, options)" to make the extra
|
|
45
|
+
// check for the handle in the DID document:
|
|
29
46
|
const document = await this.didResolver.resolve(did, options);
|
|
30
|
-
|
|
31
|
-
if (!
|
|
32
|
-
throw new TypeError(`
|
|
47
|
+
// Ensure that the handle is included in the document
|
|
48
|
+
if (!document.alsoKnownAs?.includes(`at://${handle}`)) {
|
|
49
|
+
throw new TypeError(`Did document for "${did}" does not include the handle "${handle}"`);
|
|
33
50
|
}
|
|
34
|
-
|
|
35
|
-
return { did, pds };
|
|
51
|
+
return document;
|
|
36
52
|
}
|
|
37
53
|
}
|
|
38
54
|
exports.IdentityResolver = IdentityResolver;
|
|
39
55
|
function isAtprotoPersonalDataServerService(s) {
|
|
40
56
|
return (typeof s.serviceEndpoint === 'string' &&
|
|
41
57
|
s.type === 'AtprotoPersonalDataServer' &&
|
|
42
|
-
(s.id
|
|
58
|
+
(s.id.startsWith('#')
|
|
59
|
+
? s.id === '#atproto_pds'
|
|
60
|
+
: s.id === `${this.id}#atproto_pds`));
|
|
43
61
|
}
|
|
44
62
|
//# sourceMappingURL=identity-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-resolver.js","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":";;;AAOA,
|
|
1
|
+
{"version":3,"file":"identity-resolver.js","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":";;;AAOA,mEAMsC;AACtC,4CAA+D;AAS/D,MAAa,gBAAgB;IAC3B,YACW,WAAmD,EACnD,cAA8B;QADvC;;;;mBAAS,WAAW;WAAwC;QAC5D;;;;mBAAS,cAAc;WAAgB;IACtC,CAAC;IAEG,KAAK,CAAC,OAAO,CAClB,KAAa,EACb,OAAgC;QAEhC,MAAM,QAAQ,GAAG,IAAA,kCAAgB,EAAC,KAAK,CAAC;YACtC,CAAC,CAAC,MAAM,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC;YAC/C,CAAC,CAAC,MAAM,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAEpD,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,EAAE,IAAI,CACpC,CAAA,kCAA6D,CAAA,EAC7D,QAAQ,CACT,CAAA;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,SAAS,CACjB,0DAA0D,QAAQ,CAAC,EAAE,gBAAgB,CACtF,CAAA;QACH,CAAC;QAED,OAAO;YACL,GAAG,EAAE,QAAQ,CAAC,EAAE;YAChB,GAAG,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC;SACtC,CAAA;IACH,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAC7B,GAAgC,EAChC,OAA2B;QAE3B,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAC/C,CAAC;IAEM,KAAK,CAAC,qBAAqB,CAChC,KAAa,EACb,OAA8B;QAE9B,MAAM,MAAM,GAAG,IAAA,sCAA6B,EAAC,KAAK,CAAC,CAAA;QAEnD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAE9D,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,SAAS,CAAC,WAAW,MAAM,6BAA6B,CAAC,CAAA;QACrE,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;QAEjC,2EAA2E;QAC3E,4CAA4C;QAE5C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAE7D,qDAAqD;QACrD,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,QAAQ,MAAM,EAAE,CAAC,EAAE,CAAC;YACtD,MAAM,IAAI,SAAS,CACjB,qBAAqB,GAAG,kCAAkC,MAAM,GAAG,CACpE,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF;AAlED,4CAkEC;AAED,SAAS,kCAAkC,CAEzC,CAAa;IAMb,OAAO,CACL,OAAO,CAAC,CAAC,eAAe,KAAK,QAAQ;QACrC,CAAC,CAAC,IAAI,KAAK,2BAA2B;QACtC,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC;YACnB,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,cAAc;YACzB,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,EAAE,cAAc,CAAC,CACvC,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto-labs/identity-resolver",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "A library resolving ATPROTO identities",
|
|
6
6
|
"keywords": [
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@atproto-labs/did-resolver": "0.1.
|
|
29
|
-
"@atproto-labs/handle-resolver": "0.1.
|
|
28
|
+
"@atproto-labs/did-resolver": "0.1.2-rc.0",
|
|
29
|
+
"@atproto-labs/handle-resolver": "0.1.2-rc.0",
|
|
30
30
|
"@atproto/syntax": "0.3.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
package/src/identity-resolver.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Did,
|
|
3
3
|
DidDocument,
|
|
4
|
-
ResolveDidOptions,
|
|
5
4
|
DidResolver,
|
|
6
5
|
DidService,
|
|
6
|
+
ResolveDidOptions,
|
|
7
7
|
} from '@atproto-labs/did-resolver'
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
AtprotoIdentityDidMethods,
|
|
10
10
|
HandleResolver,
|
|
11
|
-
ResolvedHandle,
|
|
12
11
|
isResolvedHandle,
|
|
12
|
+
ResolvedHandle,
|
|
13
|
+
ResolveHandleOptions,
|
|
13
14
|
} from '@atproto-labs/handle-resolver'
|
|
14
15
|
import { normalizeAndEnsureValidHandle } from '@atproto/syntax'
|
|
15
16
|
|
|
@@ -22,7 +23,7 @@ export type ResolveIdentityOptions = ResolveDidOptions & ResolveHandleOptions
|
|
|
22
23
|
|
|
23
24
|
export class IdentityResolver {
|
|
24
25
|
constructor(
|
|
25
|
-
readonly didResolver: DidResolver<
|
|
26
|
+
readonly didResolver: DidResolver<AtprotoIdentityDidMethods>,
|
|
26
27
|
readonly handleResolver: HandleResolver,
|
|
27
28
|
) {}
|
|
28
29
|
|
|
@@ -30,35 +31,61 @@ export class IdentityResolver {
|
|
|
30
31
|
input: string,
|
|
31
32
|
options?: ResolveIdentityOptions,
|
|
32
33
|
): Promise<ResolvedIdentity> {
|
|
33
|
-
const
|
|
34
|
-
? input
|
|
35
|
-
: await this.
|
|
36
|
-
normalizeAndEnsureValidHandle(input),
|
|
37
|
-
options,
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
options?.signal?.throwIfAborted()
|
|
41
|
-
|
|
42
|
-
if (!did) {
|
|
43
|
-
throw new TypeError(`Handle "${input}" does not resolve to a DID`)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const document = await this.didResolver.resolve(did, options)
|
|
34
|
+
const document = isResolvedHandle(input)
|
|
35
|
+
? await this.getDocumentFromDid(input, options)
|
|
36
|
+
: await this.getDocumentFromHandle(input, options)
|
|
47
37
|
|
|
48
38
|
const service = document.service?.find(
|
|
49
|
-
isAtprotoPersonalDataServerService<
|
|
39
|
+
isAtprotoPersonalDataServerService<AtprotoIdentityDidMethods>,
|
|
50
40
|
document,
|
|
51
41
|
)
|
|
52
42
|
|
|
53
43
|
if (!service) {
|
|
54
44
|
throw new TypeError(
|
|
55
|
-
`No valid "AtprotoPersonalDataServer" service found in "${
|
|
45
|
+
`No valid "AtprotoPersonalDataServer" service found in "${document.id}" DID document`,
|
|
56
46
|
)
|
|
57
47
|
}
|
|
58
48
|
|
|
59
|
-
|
|
49
|
+
return {
|
|
50
|
+
did: document.id,
|
|
51
|
+
pds: new URL(service.serviceEndpoint),
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public async getDocumentFromDid(
|
|
56
|
+
did: NonNullable<ResolvedHandle>,
|
|
57
|
+
options?: ResolveDidOptions,
|
|
58
|
+
): Promise<DidDocument<AtprotoIdentityDidMethods>> {
|
|
59
|
+
return this.didResolver.resolve(did, options)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public async getDocumentFromHandle(
|
|
63
|
+
input: string,
|
|
64
|
+
options?: ResolveHandleOptions,
|
|
65
|
+
): Promise<DidDocument<AtprotoIdentityDidMethods>> {
|
|
66
|
+
const handle = normalizeAndEnsureValidHandle(input)
|
|
67
|
+
|
|
68
|
+
const did = await this.handleResolver.resolve(handle, options)
|
|
69
|
+
|
|
70
|
+
if (!did) {
|
|
71
|
+
throw new TypeError(`Handle "${handle}" does not resolve to a DID`)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
options?.signal?.throwIfAborted()
|
|
75
|
+
|
|
76
|
+
// Note: Not using "return this.resolveDid(did, options)" to make the extra
|
|
77
|
+
// check for the handle in the DID document:
|
|
78
|
+
|
|
79
|
+
const document = await this.didResolver.resolve(did, options)
|
|
80
|
+
|
|
81
|
+
// Ensure that the handle is included in the document
|
|
82
|
+
if (!document.alsoKnownAs?.includes(`at://${handle}`)) {
|
|
83
|
+
throw new TypeError(
|
|
84
|
+
`Did document for "${did}" does not include the handle "${handle}"`,
|
|
85
|
+
)
|
|
86
|
+
}
|
|
60
87
|
|
|
61
|
-
return
|
|
88
|
+
return document
|
|
62
89
|
}
|
|
63
90
|
}
|
|
64
91
|
|
|
@@ -73,6 +100,8 @@ function isAtprotoPersonalDataServerService<M extends string>(
|
|
|
73
100
|
return (
|
|
74
101
|
typeof s.serviceEndpoint === 'string' &&
|
|
75
102
|
s.type === 'AtprotoPersonalDataServer' &&
|
|
76
|
-
(s.id
|
|
103
|
+
(s.id.startsWith('#')
|
|
104
|
+
? s.id === '#atproto_pds'
|
|
105
|
+
: s.id === `${this.id}#atproto_pds`)
|
|
77
106
|
)
|
|
78
107
|
}
|