@atproto-labs/identity-resolver 0.1.0 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @atproto-labs/identity-resolver
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
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
+
9
+ - Updated dependencies [[`acc9093d2`](https://github.com/bluesky-social/atproto/commit/acc9093d2845eba02b68fb2f9db33e4f1b59bb10)]:
10
+ - @atproto-labs/handle-resolver@0.1.1
11
+ - @atproto-labs/did-resolver@0.1.1
12
+
3
13
  ## 0.1.0
4
14
 
5
15
  ### Minor Changes
@@ -1,14 +1,16 @@
1
- import { ResolveOptions as DidResolveOptions, DidResolver } from '@atproto-labs/did-resolver';
2
- import { ResolveOptions as HandleResolveOptions, HandleResolver, ResolvedHandle } from '@atproto-labs/handle-resolver';
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
- export type ResolveOptions = DidResolveOptions & HandleResolveOptions;
7
+ export type ResolveIdentityOptions = ResolveDidOptions & ResolveHandleOptions;
8
8
  export declare class IdentityResolver {
9
- readonly didResolver: DidResolver<'plc' | 'web'>;
9
+ readonly didResolver: DidResolver<AtprotoIdentityDidMethods>;
10
10
  readonly handleResolver: HandleResolver;
11
- constructor(didResolver: DidResolver<'plc' | 'web'>, handleResolver: HandleResolver);
12
- resolve(input: string, options?: ResolveOptions): Promise<ResolvedIdentity>;
11
+ constructor(didResolver: DidResolver<AtprotoIdentityDidMethods>, handleResolver: HandleResolver);
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,EAGL,cAAc,IAAI,iBAAiB,EACnC,WAAW,EAEZ,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,cAAc,IAAI,oBAAoB,EACtC,cAAc,EACd,cAAc,EAEf,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,cAAc,GAAG,iBAAiB,GAAG,oBAAoB,CAAA;AAErE,qBAAa,gBAAgB;IAEzB,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC;IAChD,QAAQ,CAAC,cAAc,EAAE,cAAc;gBAD9B,WAAW,EAAE,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC,EACvC,cAAc,EAAE,cAAc;IAG5B,OAAO,CAClB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,gBAAgB,CAAC;CA+B7B"}
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 did = (0, handle_resolver_1.isResolvedHandle)(input)
23
- ? input // Already a did
24
- : await this.handleResolver.resolve((0, syntax_1.normalizeAndEnsureValidHandle)(input), options);
25
- options?.signal?.throwIfAborted();
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 "${input}" does not resolve to a DID`);
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
- const service = document.service?.find((isAtprotoPersonalDataServerService), document);
31
- if (!service) {
32
- throw new TypeError(`No valid "AtprotoPersonalDataServer" service found in "${did}" DID document`);
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
- const pds = new URL(service.serviceEndpoint);
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 === '#atproto_pds' || s.id === `${this.id}#atproto_pds`));
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,mEAKsC;AACtC,4CAA+D;AAS/D,MAAa,gBAAgB;IAC3B,YACW,WAAuC,EACvC,cAA8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E,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.0",
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.0",
29
- "@atproto-labs/handle-resolver": "0.1.0",
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": {
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  Did,
3
3
  DidDocument,
4
- ResolveOptions as DidResolveOptions,
5
4
  DidResolver,
6
5
  DidService,
6
+ ResolveDidOptions,
7
7
  } from '@atproto-labs/did-resolver'
8
8
  import {
9
- ResolveOptions as HandleResolveOptions,
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
 
@@ -18,47 +19,73 @@ export type ResolvedIdentity = {
18
19
  pds: URL
19
20
  }
20
21
 
21
- export type ResolveOptions = DidResolveOptions & HandleResolveOptions
22
+ export type ResolveIdentityOptions = ResolveDidOptions & ResolveHandleOptions
22
23
 
23
24
  export class IdentityResolver {
24
25
  constructor(
25
- readonly didResolver: DidResolver<'plc' | 'web'>,
26
+ readonly didResolver: DidResolver<AtprotoIdentityDidMethods>,
26
27
  readonly handleResolver: HandleResolver,
27
28
  ) {}
28
29
 
29
30
  public async resolve(
30
31
  input: string,
31
- options?: ResolveOptions,
32
+ options?: ResolveIdentityOptions,
32
33
  ): Promise<ResolvedIdentity> {
33
- const did = isResolvedHandle(input)
34
- ? input // Already a did
35
- : await this.handleResolver.resolve(
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<'plc' | 'web'>,
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 "${did}" DID document`,
45
+ `No valid "AtprotoPersonalDataServer" service found in "${document.id}" DID document`,
56
46
  )
57
47
  }
58
48
 
59
- const pds = new URL(service.serviceEndpoint)
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 { did, pds }
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 === '#atproto_pds' || s.id === `${this.id}#atproto_pds`)
103
+ (s.id.startsWith('#')
104
+ ? s.id === '#atproto_pds'
105
+ : s.id === `${this.id}#atproto_pds`)
77
106
  )
78
107
  }