@atproto-labs/identity-resolver 0.3.1 → 0.3.3

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,23 @@
1
1
  # @atproto-labs/identity-resolver
2
2
 
3
+ ## 0.3.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4366](https://github.com/bluesky-social/atproto/pull/4366) [`261968fd6`](https://github.com/bluesky-social/atproto/commit/261968fd65014ded613e2bf085d61a7864b8fba7) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Expose `createIdentityResolver` util
8
+
9
+ - Updated dependencies [[`261968fd6`](https://github.com/bluesky-social/atproto/commit/261968fd65014ded613e2bf085d61a7864b8fba7), [`261968fd6`](https://github.com/bluesky-social/atproto/commit/261968fd65014ded613e2bf085d61a7864b8fba7)]:
10
+ - @atproto-labs/handle-resolver@0.3.3
11
+ - @atproto-labs/did-resolver@0.2.3
12
+
13
+ ## 0.3.2
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies []:
18
+ - @atproto-labs/did-resolver@0.2.2
19
+ - @atproto-labs/handle-resolver@0.3.2
20
+
3
21
  ## 0.3.1
4
22
 
5
23
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"atproto-identity-resolver.js","sourceRoot":"","sources":["../src/atproto-identity-resolver.ts"],"names":[],"mappings":";;;AAAA,6DAOmC;AAKnC,iDAA+C;AAC/C,6EAAoE;AAMpE,uCAAuE;AAEvE,mEAAmE;AACnE,4CAA4C;AAC5C,iDAAiD;AAEjD;;;;;GAKG;AACH,MAAa,uBAAuB;IAClC,YACqB,WAAmD,EACnD,cAA8B;QADjD;;;;mBAAmB,WAAW;WAAwC;QACtE;;;;mBAAmB,cAAc;WAAgB;IAChD,CAAC;IAEG,KAAK,CAAC,OAAO,CAClB,KAAa,EACb,OAAgC;QAEhC,OAAO,IAAA,2BAAY,EAAC,KAAK,CAAC;YACxB,CAAC,CAA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SAC5D,CAAA;IACH,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAC7B,GAAe,EACf,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,4BAAkB,EAAC,KAAK,CAAC,CAAA;QACxC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,kDAAqB,CAAC,mBAAmB,KAAK,aAAa,CAAC,CAAA;QACxE,CAAC;QAED,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAE9D,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,kDAAqB,CAC7B,WAAW,MAAM,6BAA6B,CAC/C,CAAA;QACH,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,oCAAoC;QACpC,IAAI,MAAM,KAAK,IAAA,iCAAuB,EAAC,QAAQ,CAAC,EAAE,CAAC;YACjD,MAAM,IAAI,kDAAqB,CAC7B,qBAAqB,GAAG,kCAAkC,MAAM,GAAG,CACpE,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF;AA9FD,0DA8FC","sourcesContent":["import {\n AtprotoDid,\n AtprotoIdentityDidMethods,\n DidDocument,\n DidResolver,\n ResolveDidOptions,\n isAtprotoDid,\n} from '@atproto-labs/did-resolver'\nimport {\n HandleResolver,\n ResolveHandleOptions,\n} from '@atproto-labs/handle-resolver'\nimport { HANDLE_INVALID } from './constants.js'\nimport { IdentityResolverError } from './identity-resolver-error.js'\nimport {\n IdentityInfo,\n IdentityResolver,\n ResolveIdentityOptions,\n} from './identity-resolver.js'\nimport { asNormalizedHandle, extractNormalizedHandle } from './util.js'\n\n// @TODO Move this to its own package as soon as we have a distinct\n// implementation based on XRPC calls to the\n// \"com.atproto.identity.resolveIdentity\" method.\n\n/**\n * Implementation of the official ATPROTO identity resolution strategy.\n * This implementation relies on two primitives:\n * - DID resolution (using the `DidResolver` interface)\n * - Handle resolution (using the `HandleResolver` interface)\n */\nexport class AtprotoIdentityResolver implements IdentityResolver {\n constructor(\n protected readonly didResolver: DidResolver<AtprotoIdentityDidMethods>,\n protected readonly handleResolver: HandleResolver,\n ) {}\n\n public async resolve(\n input: string,\n options?: ResolveIdentityOptions,\n ): Promise<IdentityInfo> {\n return isAtprotoDid(input)\n ? this.resolveFromDid(input, options)\n : this.resolveFromHandle(input, options)\n }\n\n public async resolveFromDid(\n did: AtprotoDid,\n options?: ResolveDidOptions,\n ): Promise<IdentityInfo> {\n const document = await this.getDocumentFromDid(did, options)\n\n options?.signal?.throwIfAborted()\n\n // We will only return the document's handle alias if it resolves to the\n // same DID as the input.\n const handle = extractNormalizedHandle(document)\n const resolvedDid = handle\n ? await this.handleResolver\n .resolve(handle, options)\n .catch(() => undefined) // Ignore errors (temporarily unavailable)\n : undefined\n\n return {\n did: document.id,\n didDoc: document,\n handle: handle && resolvedDid === did ? handle : HANDLE_INVALID,\n }\n }\n\n public async resolveFromHandle(\n handle: string,\n options?: ResolveHandleOptions,\n ): Promise<IdentityInfo> {\n const document = await this.getDocumentFromHandle(handle, options)\n\n // @NOTE bi-directional resolution enforced in getDocumentFromHandle()\n\n return {\n did: document.id,\n didDoc: document,\n handle: extractNormalizedHandle(document) || HANDLE_INVALID,\n }\n }\n\n public async getDocumentFromDid(\n did: AtprotoDid,\n options?: ResolveDidOptions,\n ): Promise<DidDocument<AtprotoIdentityDidMethods>> {\n return this.didResolver.resolve(did, options)\n }\n\n public async getDocumentFromHandle(\n input: string,\n options?: ResolveHandleOptions,\n ): Promise<DidDocument<AtprotoIdentityDidMethods>> {\n const handle = asNormalizedHandle(input)\n if (!handle) {\n throw new IdentityResolverError(`Invalid handle \"${input}\" provided.`)\n }\n\n const did = await this.handleResolver.resolve(handle, options)\n\n if (!did) {\n throw new IdentityResolverError(\n `Handle \"${handle}\" does not resolve to a DID`,\n )\n }\n\n options?.signal?.throwIfAborted()\n\n // Note: Not using \"return this.resolveDid(did, options)\" to make the extra\n // check for the handle in the DID document:\n\n const document = await this.didResolver.resolve(did, options)\n\n // Enforce bi-directional resolution\n if (handle !== extractNormalizedHandle(document)) {\n throw new IdentityResolverError(\n `Did document for \"${did}\" does not include the handle \"${handle}\"`,\n )\n }\n\n return document\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,gBAAgB,CAAA"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,gBAAgB,CAAA","sourcesContent":["export const HANDLE_INVALID = 'handle.invalid'\n"]}
@@ -0,0 +1,8 @@
1
+ import { CreateDidResolverOptions } from '@atproto-labs/did-resolver';
2
+ import { CreateHandleResolverOptions } from '@atproto-labs/handle-resolver';
3
+ import { IdentityResolver } from './identity-resolver.js';
4
+ export type CreateIdentityResolverOptions = {
5
+ identityResolver?: IdentityResolver;
6
+ } & Partial<CreateDidResolverOptions & CreateHandleResolverOptions>;
7
+ export declare function createIdentityResolver(options: CreateIdentityResolverOptions): IdentityResolver;
8
+ //# sourceMappingURL=create-identity-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-identity-resolver.d.ts","sourceRoot":"","sources":["../src/create-identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EAEzB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,2BAA2B,EAE5B,MAAM,+BAA+B,CAAA;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAEzD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CACpC,GAAG,OAAO,CAAC,wBAAwB,GAAG,2BAA2B,CAAC,CAAA;AAEnE,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,6BAA6B,GACrC,gBAAgB,CAgBlB"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createIdentityResolver = createIdentityResolver;
4
+ const did_resolver_1 = require("@atproto-labs/did-resolver");
5
+ const handle_resolver_1 = require("@atproto-labs/handle-resolver");
6
+ const atproto_identity_resolver_js_1 = require("./atproto-identity-resolver.js");
7
+ function createIdentityResolver(options) {
8
+ if ('identityResolver' in options && options.identityResolver != null) {
9
+ return options.identityResolver;
10
+ }
11
+ if ('handleResolver' in options && options.handleResolver != null) {
12
+ const didResolver = (0, did_resolver_1.createDidResolver)(options);
13
+ const handleResolver = (0, handle_resolver_1.createHandleResolver)(options);
14
+ return new atproto_identity_resolver_js_1.AtprotoIdentityResolver(didResolver, handleResolver);
15
+ }
16
+ throw new TypeError('identityResolver or handleResolver option is required');
17
+ }
18
+ //# sourceMappingURL=create-identity-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-identity-resolver.js","sourceRoot":"","sources":["../src/create-identity-resolver.ts"],"names":[],"mappings":";;AAeA,wDAkBC;AAjCD,6DAGmC;AACnC,mEAGsC;AACtC,iFAAwE;AAOxE,SAAgB,sBAAsB,CACpC,OAAsC;IAEtC,IAAI,kBAAkB,IAAI,OAAO,IAAI,OAAO,CAAC,gBAAgB,IAAI,IAAI,EAAE,CAAC;QACtE,OAAO,OAAO,CAAC,gBAAgB,CAAA;IACjC,CAAC;IAED,IAAI,gBAAgB,IAAI,OAAO,IAAI,OAAO,CAAC,cAAc,IAAI,IAAI,EAAE,CAAC;QAClE,MAAM,WAAW,GAAG,IAAA,gCAAiB,EAAC,OAAO,CAAC,CAAA;QAC9C,MAAM,cAAc,GAAG,IAAA,sCAAoB,EACzC,OAEC,CACF,CAAA;QACD,OAAO,IAAI,sDAAuB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAA;IACjE,CAAC;IAED,MAAM,IAAI,SAAS,CAAC,uDAAuD,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import {\n CreateDidResolverOptions,\n createDidResolver,\n} from '@atproto-labs/did-resolver'\nimport {\n CreateHandleResolverOptions,\n createHandleResolver,\n} from '@atproto-labs/handle-resolver'\nimport { AtprotoIdentityResolver } from './atproto-identity-resolver.js'\nimport { IdentityResolver } from './identity-resolver.js'\n\nexport type CreateIdentityResolverOptions = {\n identityResolver?: IdentityResolver\n} & Partial<CreateDidResolverOptions & CreateHandleResolverOptions>\n\nexport function createIdentityResolver(\n options: CreateIdentityResolverOptions,\n): IdentityResolver {\n if ('identityResolver' in options && options.identityResolver != null) {\n return options.identityResolver\n }\n\n if ('handleResolver' in options && options.handleResolver != null) {\n const didResolver = createDidResolver(options)\n const handleResolver = createHandleResolver(\n options as typeof options & {\n handleResolver: NonNullable<(typeof options)['handleResolver']>\n },\n )\n return new AtprotoIdentityResolver(didResolver, handleResolver)\n }\n\n throw new TypeError('identityResolver or handleResolver option is required')\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"identity-resolver-error.js","sourceRoot":"","sources":["../src/identity-resolver-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,qBAAsB,SAAQ,KAAK;IAAhD;;QACE;;;;mBAAO,uBAAuB;WAAA;IAChC,CAAC;CAAA;AAFD,sDAEC"}
1
+ {"version":3,"file":"identity-resolver-error.js","sourceRoot":"","sources":["../src/identity-resolver-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,qBAAsB,SAAQ,KAAK;IAAhD;;QACE;;;;mBAAO,uBAAuB;WAAA;IAChC,CAAC;CAAA;AAFD,sDAEC","sourcesContent":["export class IdentityResolverError extends Error {\n name = 'IdentityResolverError'\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"identity-resolver.js","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"identity-resolver.js","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":"","sourcesContent":["import {\n AtprotoDid,\n AtprotoIdentityDidMethods,\n DidDocument,\n} from '@atproto-labs/did-resolver'\nimport { HANDLE_INVALID } from './constants'\n\n// Consistent with `com.atproto.identity.defs#identityInfo` returned by\n// `com.atproto.identity.resolveIdentity` endpoint.\nexport type IdentityInfo = {\n did: AtprotoDid\n\n didDoc: DidDocument<AtprotoIdentityDidMethods>\n\n /**\n * Will be 'handle.invalid' if the handle does not resolve to the\n * same DID as the input, or if the handle is not present in the DID\n * document.\n */\n handle: typeof HANDLE_INVALID | string\n}\n\nexport type ResolveIdentityOptions = {\n signal?: AbortSignal\n noCache?: boolean\n}\n\nexport interface IdentityResolver {\n resolve(\n identifier: string,\n options?: ResolveIdentityOptions,\n ): Promise<IdentityInfo>\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './atproto-identity-resolver.js';
2
2
  export * from './constants.js';
3
+ export * from './create-identity-resolver.js';
3
4
  export * from './identity-resolver-error.js';
4
5
  export * from './identity-resolver.js';
5
6
  export * from './util.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAA;AAC9C,cAAc,gBAAgB,CAAA;AAC9B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAA;AAC9C,cAAc,gBAAgB,CAAA;AAC9B,cAAc,+BAA+B,CAAA;AAC7C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,WAAW,CAAA"}
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./atproto-identity-resolver.js"), exports);
18
18
  __exportStar(require("./constants.js"), exports);
19
+ __exportStar(require("./create-identity-resolver.js"), exports);
19
20
  __exportStar(require("./identity-resolver-error.js"), exports);
20
21
  __exportStar(require("./identity-resolver.js"), exports);
21
22
  __exportStar(require("./util.js"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA8C;AAC9C,iDAA8B;AAC9B,+DAA4C;AAC5C,yDAAsC;AACtC,4CAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA8C;AAC9C,iDAA8B;AAC9B,gEAA6C;AAC7C,+DAA4C;AAC5C,yDAAsC;AACtC,4CAAyB","sourcesContent":["export * from './atproto-identity-resolver.js'\nexport * from './constants.js'\nexport * from './create-identity-resolver.js'\nexport * from './identity-resolver-error.js'\nexport * from './identity-resolver.js'\nexport * from './util.js'\n"]}
package/dist/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAQA,oDAYC;AAKD,0DAMC;AAED,gDAGC;AAED,0CAEC;AAED,sCAQC;AA7CD;;GAEG;AACH,SAAgB,oBAAoB,CAClC,QAAgD;IAEhD,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;QACzB,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;YACrC,IAAI,CAAC,CAAC,UA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AK,CAAC,CAAC,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CACrC,QAAgD;IAEhD,MAAM,MAAM,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAA;IAC7C,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAA;IAC7B,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAA;AACnC,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAa;IAC9C,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;IACrC,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;AACnD,CAAC;AAED,SAAgB,eAAe,CAAC,MAAc;IAC5C,OAAO,MAAM,CAAC,WAAW,EAAE,CAAA;AAC7B,CAAC;AAED,SAAgB,aAAa,CAAC,MAAc;IAC1C,OAAO,CACL,MAAM,CAAC,MAAM,GAAG,CAAC;QACjB,MAAM,CAAC,MAAM,GAAG,GAAG;QACnB,4FAA4F,CAAC,IAAI,CAC/F,MAAM,CACP,CACF,CAAA;AACH,CAAC","sourcesContent":["import {\n AtprotoIdentityDidMethods,\n DidDocument,\n} from '@atproto-labs/did-resolver'\n\n/**\n * Extract the raw, un-validated, Atproto handle from a DID document.\n */\nexport function extractAtprotoHandle(\n document: DidDocument<AtprotoIdentityDidMethods>,\n): string | undefined {\n if (document.alsoKnownAs) {\n for (const h of document.alsoKnownAs) {\n if (h.startsWith('at://')) {\n // strip off \"at://\" prefix\n return h.slice(5)\n }\n }\n }\n return undefined\n}\n\n/**\n * Extracts a validated, normalized Atproto handle from a DID document.\n */\nexport function extractNormalizedHandle(\n document: DidDocument<AtprotoIdentityDidMethods>,\n): string | undefined {\n const handle = extractAtprotoHandle(document)\n if (!handle) return undefined\n return asNormalizedHandle(handle)\n}\n\nexport function asNormalizedHandle(input: string): string | undefined {\n const handle = normalizeHandle(input)\n return isValidHandle(handle) ? handle : undefined\n}\n\nexport function normalizeHandle(handle: string): string {\n return handle.toLowerCase()\n}\n\nexport function isValidHandle(handle: string): boolean {\n return (\n handle.length > 0 &&\n handle.length < 254 &&\n /^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/.test(\n handle,\n )\n )\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto-labs/identity-resolver",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
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.2.1",
29
- "@atproto-labs/handle-resolver": "0.3.1"
28
+ "@atproto-labs/did-resolver": "0.2.3",
29
+ "@atproto-labs/handle-resolver": "0.3.3"
30
30
  },
31
31
  "devDependencies": {
32
32
  "typescript": "^5.6.3"
@@ -0,0 +1,34 @@
1
+ import {
2
+ CreateDidResolverOptions,
3
+ createDidResolver,
4
+ } from '@atproto-labs/did-resolver'
5
+ import {
6
+ CreateHandleResolverOptions,
7
+ createHandleResolver,
8
+ } from '@atproto-labs/handle-resolver'
9
+ import { AtprotoIdentityResolver } from './atproto-identity-resolver.js'
10
+ import { IdentityResolver } from './identity-resolver.js'
11
+
12
+ export type CreateIdentityResolverOptions = {
13
+ identityResolver?: IdentityResolver
14
+ } & Partial<CreateDidResolverOptions & CreateHandleResolverOptions>
15
+
16
+ export function createIdentityResolver(
17
+ options: CreateIdentityResolverOptions,
18
+ ): IdentityResolver {
19
+ if ('identityResolver' in options && options.identityResolver != null) {
20
+ return options.identityResolver
21
+ }
22
+
23
+ if ('handleResolver' in options && options.handleResolver != null) {
24
+ const didResolver = createDidResolver(options)
25
+ const handleResolver = createHandleResolver(
26
+ options as typeof options & {
27
+ handleResolver: NonNullable<(typeof options)['handleResolver']>
28
+ },
29
+ )
30
+ return new AtprotoIdentityResolver(didResolver, handleResolver)
31
+ }
32
+
33
+ throw new TypeError('identityResolver or handleResolver option is required')
34
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './atproto-identity-resolver.js'
2
2
  export * from './constants.js'
3
+ export * from './create-identity-resolver.js'
3
4
  export * from './identity-resolver-error.js'
4
5
  export * from './identity-resolver.js'
5
6
  export * from './util.js'
@@ -1 +1 @@
1
- {"root":["./src/atproto-identity-resolver.ts","./src/constants.ts","./src/identity-resolver-error.ts","./src/identity-resolver.ts","./src/index.ts","./src/util.ts"],"version":"5.8.2"}
1
+ {"root":["./src/atproto-identity-resolver.ts","./src/constants.ts","./src/create-identity-resolver.ts","./src/identity-resolver-error.ts","./src/identity-resolver.ts","./src/index.ts","./src/util.ts"],"version":"5.8.2"}