@atproto-labs/identity-resolver 0.4.1 → 0.4.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 +22 -0
- package/dist/atproto-identity-resolver.d.ts +3 -3
- package/dist/atproto-identity-resolver.d.ts.map +1 -1
- package/dist/atproto-identity-resolver.js.map +1 -1
- package/dist/create-identity-resolver.d.ts +3 -3
- package/dist/create-identity-resolver.d.ts.map +1 -1
- package/dist/create-identity-resolver.js.map +1 -1
- package/dist/identity-resolver.d.ts +1 -1
- package/dist/identity-resolver.d.ts.map +1 -1
- package/dist/identity-resolver.js.map +1 -1
- package/dist/util.d.ts +1 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js.map +1 -1
- package/package.json +10 -7
- package/src/atproto-identity-resolver.ts +0 -126
- package/src/constants.ts +0 -1
- package/src/create-identity-resolver.ts +0 -34
- package/src/identity-resolver-error.ts +0 -3
- package/src/identity-resolver.ts +0 -30
- package/src/index.ts +0 -6
- package/src/util.ts +0 -51
- package/tsconfig.build.json +0 -8
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @atproto-labs/identity-resolver
|
|
2
2
|
|
|
3
|
+
## 0.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update TypeScript build to rely on references to composite internal projects
|
|
8
|
+
|
|
9
|
+
- [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Bundle only necessary files in the NPM tarball, including the `CHANGELOG.md` and `README.md` files (if present).
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07)]:
|
|
12
|
+
- @atproto-labs/handle-resolver@0.4.4
|
|
13
|
+
- @atproto-labs/did-resolver@0.3.4
|
|
14
|
+
|
|
15
|
+
## 0.4.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#5151](https://github.com/bluesky-social/atproto/pull/5151) [`a51c45d`](https://github.com/bluesky-social/atproto/commit/a51c45d38f6bd7b8765f640e564cf921d52162e7) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update dependencies
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`a51c45d`](https://github.com/bluesky-social/atproto/commit/a51c45d38f6bd7b8765f640e564cf921d52162e7)]:
|
|
22
|
+
- @atproto-labs/did-resolver@0.3.3
|
|
23
|
+
- @atproto-labs/handle-resolver@0.4.3
|
|
24
|
+
|
|
3
25
|
## 0.4.1
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AtprotoDid, AtprotoIdentityDidMethods, DidDocument, DidResolver, ResolveDidOptions } from '@atproto-labs/did-resolver';
|
|
2
|
-
import { HandleResolver, ResolveHandleOptions } from '@atproto-labs/handle-resolver';
|
|
3
|
-
import { IdentityInfo, IdentityResolver, ResolveIdentityOptions } from './identity-resolver.js';
|
|
1
|
+
import { type AtprotoDid, type AtprotoIdentityDidMethods, type DidDocument, type DidResolver, type ResolveDidOptions } from '@atproto-labs/did-resolver';
|
|
2
|
+
import type { HandleResolver, ResolveHandleOptions } from '@atproto-labs/handle-resolver';
|
|
3
|
+
import type { IdentityInfo, IdentityResolver, ResolveIdentityOptions } from './identity-resolver.js';
|
|
4
4
|
/**
|
|
5
5
|
* Implementation of the official ATPROTO identity resolution strategy.
|
|
6
6
|
* This implementation relies on two primitives:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atproto-identity-resolver.d.ts","sourceRoot":"","sources":["../src/atproto-identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,
|
|
1
|
+
{"version":3,"file":"atproto-identity-resolver.d.ts","sourceRoot":"","sources":["../src/atproto-identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,yBAAyB,EAC9B,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EAEvB,MAAM,4BAA4B,CAAA;AACnC,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACrB,MAAM,+BAA+B,CAAA;AAGtC,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,wBAAwB,CAAA;AAO/B;;;;;GAKG;AACH,qBAAa,uBAAwB,YAAW,gBAAgB;IAE5D,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,yBAAyB,CAAC;IACtE,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc;IAFnD,YACqB,WAAW,EAAE,WAAW,CAAC,yBAAyB,CAAC,EACnD,cAAc,EAAE,cAAc,EAC/C;IAES,OAAO,CAClB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,YAAY,CAAC,CAIvB;IAEY,cAAc,CACzB,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAmBvB;IAEY,iBAAiB,CAC5B,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,YAAY,CAAC,CAUvB;IAEY,k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,EAAE,CAAC;YACT,MAAM,IAAI,qBAAqB,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,uBAAuB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjD,MAAM,IAAI,qBAAqB,CAC7B,qBAAqB,GAAG,kCAAkC,MAAM,GAAG,CACpE,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF","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
|
+
{"version":3,"file":"atproto-identity-resolver.js","sourceRoot":"","sources":["../src/atproto-identity-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jD,MAAM,IAAI,qBAAqB,CAC7B,qBAAqB,GAAG,kCAAkC,MAAM,GAAG,CACpE,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF","sourcesContent":["import {\n type AtprotoDid,\n type AtprotoIdentityDidMethods,\n type DidDocument,\n type DidResolver,\n type ResolveDidOptions,\n isAtprotoDid,\n} from '@atproto-labs/did-resolver'\nimport type {\n HandleResolver,\n ResolveHandleOptions,\n} from '@atproto-labs/handle-resolver'\nimport { HANDLE_INVALID } from './constants.js'\nimport { IdentityResolverError } from './identity-resolver-error.js'\nimport type {\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,6 +1,6 @@
|
|
|
1
|
-
import { CreateDidResolverOptions } from '@atproto-labs/did-resolver';
|
|
2
|
-
import { CreateHandleResolverOptions } from '@atproto-labs/handle-resolver';
|
|
3
|
-
import { IdentityResolver } from './identity-resolver.js';
|
|
1
|
+
import { type CreateDidResolverOptions } from '@atproto-labs/did-resolver';
|
|
2
|
+
import { type CreateHandleResolverOptions } from '@atproto-labs/handle-resolver';
|
|
3
|
+
import type { IdentityResolver } from './identity-resolver.js';
|
|
4
4
|
export type CreateIdentityResolverOptions = {
|
|
5
5
|
identityResolver?: IdentityResolver;
|
|
6
6
|
} & Partial<CreateDidResolverOptions & CreateHandleResolverOptions>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-identity-resolver.d.ts","sourceRoot":"","sources":["../src/create-identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,
|
|
1
|
+
{"version":3,"file":"create-identity-resolver.d.ts","sourceRoot":"","sources":["../src/create-identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,wBAAwB,EAE9B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,KAAK,2BAA2B,EAEjC,MAAM,+BAA+B,CAAA;AAEtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE9D,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-identity-resolver.js","sourceRoot":"","sources":["../src/create-identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,GAClB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAEL,oBAAoB,GACrB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AAOxE,MAAM,UAAU,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,iBAAiB,CAAC,OAAO,CAAC,CAAA;QAC9C,MAAM,cAAc,GAAG,oBAAoB,CACzC,OAEC,CACF,CAAA;QACD,OAAO,IAAI,uBAAuB,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
|
+
{"version":3,"file":"create-identity-resolver.js","sourceRoot":"","sources":["../src/create-identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,GAClB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAEL,oBAAoB,GACrB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AAOxE,MAAM,UAAU,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,iBAAiB,CAAC,OAAO,CAAC,CAAA;QAC9C,MAAM,cAAc,GAAG,oBAAoB,CACzC,OAEC,CACF,CAAA;QACD,OAAO,IAAI,uBAAuB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAA;IACjE,CAAC;IAED,MAAM,IAAI,SAAS,CAAC,uDAAuD,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import {\n type CreateDidResolverOptions,\n createDidResolver,\n} from '@atproto-labs/did-resolver'\nimport {\n type CreateHandleResolverOptions,\n createHandleResolver,\n} from '@atproto-labs/handle-resolver'\nimport { AtprotoIdentityResolver } from './atproto-identity-resolver.js'\nimport type { 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,4 +1,4 @@
|
|
|
1
|
-
import { AtprotoDid, AtprotoDidDocument } from '@atproto-labs/did-resolver';
|
|
1
|
+
import type { AtprotoDid, AtprotoDidDocument } from '@atproto-labs/did-resolver';
|
|
2
2
|
import { HANDLE_INVALID } from './constants.js';
|
|
3
3
|
export type { AtprotoDid, AtprotoDidDocument };
|
|
4
4
|
export type IdentityInfo = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-resolver.d.ts","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"identity-resolver.d.ts","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,CAAA;AAI9C,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,UAAU,CAAA;IACf,MAAM,EAAE,kBAAkB,CAAA;IAE1B;;;;OAIG;IACH,MAAM,EAAE,OAAO,cAAc,GAAG,MAAM,CAAA;CACvC,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CACL,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,YAAY,CAAC,CAAA;CACzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-resolver.js","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":"","sourcesContent":["import { AtprotoDid, AtprotoDidDocument } from '@atproto-labs/did-resolver'\nimport { HANDLE_INVALID } from './constants.js'\n\nexport type { AtprotoDid, AtprotoDidDocument }\n\n// Consistent with `com.atproto.identity.defs#identityInfo` returned by\n// `com.atproto.identity.resolveIdentity` endpoint.\nexport type IdentityInfo = {\n did: AtprotoDid\n didDoc: AtprotoDidDocument\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"]}
|
|
1
|
+
{"version":3,"file":"identity-resolver.js","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":"","sourcesContent":["import type { AtprotoDid, AtprotoDidDocument } from '@atproto-labs/did-resolver'\nimport { HANDLE_INVALID } from './constants.js'\n\nexport type { AtprotoDid, AtprotoDidDocument }\n\n// Consistent with `com.atproto.identity.defs#identityInfo` returned by\n// `com.atproto.identity.resolveIdentity` endpoint.\nexport type IdentityInfo = {\n did: AtprotoDid\n didDoc: AtprotoDidDocument\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/util.d.ts
CHANGED
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,WAAW,EACZ,MAAM,4BAA4B,CAAA;AAEnC;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,WAAW,CAAC,yBAAyB,CAAC,GAC/C,MAAM,GAAG,SAAS,CAUpB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,WAAW,CAAC,yBAAyB,CAAC,GAC/C,MAAM,GAAG,SAAS,CAIpB;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGpE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4F,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"]}
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,QAAgD;IAEhD,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;QACzB,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;YACrC,IAAI,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC1B,2BAA2B;gBAC3B,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,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,MAAM,UAAU,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,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,OAAO,MAAM,CAAC,WAAW,EAAE,CAAA;AAC7B,CAAC;AAED,MAAM,UAAU,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 type {\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,9 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto-labs/identity-resolver",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"engines": {
|
|
5
|
-
"node": ">=22"
|
|
6
|
-
},
|
|
3
|
+
"version": "0.4.3",
|
|
7
4
|
"license": "MIT",
|
|
8
5
|
"description": "A library resolving ATPROTO identities",
|
|
9
6
|
"keywords": [
|
|
@@ -18,6 +15,10 @@
|
|
|
18
15
|
"url": "https://github.com/bluesky-social/atproto",
|
|
19
16
|
"directory": "packages/internal/identity-resolver"
|
|
20
17
|
},
|
|
18
|
+
"files": [
|
|
19
|
+
"./dist",
|
|
20
|
+
"./CHANGELOG.md"
|
|
21
|
+
],
|
|
21
22
|
"type": "module",
|
|
22
23
|
"exports": {
|
|
23
24
|
".": {
|
|
@@ -25,11 +26,13 @@
|
|
|
25
26
|
"default": "./dist/index.js"
|
|
26
27
|
}
|
|
27
28
|
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22"
|
|
31
|
+
},
|
|
28
32
|
"dependencies": {
|
|
29
|
-
"@atproto-labs/
|
|
30
|
-
"@atproto-labs/
|
|
33
|
+
"@atproto-labs/did-resolver": "^0.3.4",
|
|
34
|
+
"@atproto-labs/handle-resolver": "^0.4.4"
|
|
31
35
|
},
|
|
32
|
-
"devDependencies": {},
|
|
33
36
|
"scripts": {
|
|
34
37
|
"build": "tsgo --build tsconfig.json"
|
|
35
38
|
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AtprotoDid,
|
|
3
|
-
AtprotoIdentityDidMethods,
|
|
4
|
-
DidDocument,
|
|
5
|
-
DidResolver,
|
|
6
|
-
ResolveDidOptions,
|
|
7
|
-
isAtprotoDid,
|
|
8
|
-
} from '@atproto-labs/did-resolver'
|
|
9
|
-
import {
|
|
10
|
-
HandleResolver,
|
|
11
|
-
ResolveHandleOptions,
|
|
12
|
-
} from '@atproto-labs/handle-resolver'
|
|
13
|
-
import { HANDLE_INVALID } from './constants.js'
|
|
14
|
-
import { IdentityResolverError } from './identity-resolver-error.js'
|
|
15
|
-
import {
|
|
16
|
-
IdentityInfo,
|
|
17
|
-
IdentityResolver,
|
|
18
|
-
ResolveIdentityOptions,
|
|
19
|
-
} from './identity-resolver.js'
|
|
20
|
-
import { asNormalizedHandle, extractNormalizedHandle } from './util.js'
|
|
21
|
-
|
|
22
|
-
// @TODO Move this to its own package as soon as we have a distinct
|
|
23
|
-
// implementation based on XRPC calls to the
|
|
24
|
-
// "com.atproto.identity.resolveIdentity" method.
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Implementation of the official ATPROTO identity resolution strategy.
|
|
28
|
-
* This implementation relies on two primitives:
|
|
29
|
-
* - DID resolution (using the `DidResolver` interface)
|
|
30
|
-
* - Handle resolution (using the `HandleResolver` interface)
|
|
31
|
-
*/
|
|
32
|
-
export class AtprotoIdentityResolver implements IdentityResolver {
|
|
33
|
-
constructor(
|
|
34
|
-
protected readonly didResolver: DidResolver<AtprotoIdentityDidMethods>,
|
|
35
|
-
protected readonly handleResolver: HandleResolver,
|
|
36
|
-
) {}
|
|
37
|
-
|
|
38
|
-
public async resolve(
|
|
39
|
-
input: string,
|
|
40
|
-
options?: ResolveIdentityOptions,
|
|
41
|
-
): Promise<IdentityInfo> {
|
|
42
|
-
return isAtprotoDid(input)
|
|
43
|
-
? this.resolveFromDid(input, options)
|
|
44
|
-
: this.resolveFromHandle(input, options)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public async resolveFromDid(
|
|
48
|
-
did: AtprotoDid,
|
|
49
|
-
options?: ResolveDidOptions,
|
|
50
|
-
): Promise<IdentityInfo> {
|
|
51
|
-
const document = await this.getDocumentFromDid(did, options)
|
|
52
|
-
|
|
53
|
-
options?.signal?.throwIfAborted()
|
|
54
|
-
|
|
55
|
-
// We will only return the document's handle alias if it resolves to the
|
|
56
|
-
// same DID as the input.
|
|
57
|
-
const handle = extractNormalizedHandle(document)
|
|
58
|
-
const resolvedDid = handle
|
|
59
|
-
? await this.handleResolver
|
|
60
|
-
.resolve(handle, options)
|
|
61
|
-
.catch(() => undefined) // Ignore errors (temporarily unavailable)
|
|
62
|
-
: undefined
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
did: document.id,
|
|
66
|
-
didDoc: document,
|
|
67
|
-
handle: handle && resolvedDid === did ? handle : HANDLE_INVALID,
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public async resolveFromHandle(
|
|
72
|
-
handle: string,
|
|
73
|
-
options?: ResolveHandleOptions,
|
|
74
|
-
): Promise<IdentityInfo> {
|
|
75
|
-
const document = await this.getDocumentFromHandle(handle, options)
|
|
76
|
-
|
|
77
|
-
// @NOTE bi-directional resolution enforced in getDocumentFromHandle()
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
did: document.id,
|
|
81
|
-
didDoc: document,
|
|
82
|
-
handle: extractNormalizedHandle(document) || HANDLE_INVALID,
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public async getDocumentFromDid(
|
|
87
|
-
did: AtprotoDid,
|
|
88
|
-
options?: ResolveDidOptions,
|
|
89
|
-
): Promise<DidDocument<AtprotoIdentityDidMethods>> {
|
|
90
|
-
return this.didResolver.resolve(did, options)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public async getDocumentFromHandle(
|
|
94
|
-
input: string,
|
|
95
|
-
options?: ResolveHandleOptions,
|
|
96
|
-
): Promise<DidDocument<AtprotoIdentityDidMethods>> {
|
|
97
|
-
const handle = asNormalizedHandle(input)
|
|
98
|
-
if (!handle) {
|
|
99
|
-
throw new IdentityResolverError(`Invalid handle "${input}" provided.`)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const did = await this.handleResolver.resolve(handle, options)
|
|
103
|
-
|
|
104
|
-
if (!did) {
|
|
105
|
-
throw new IdentityResolverError(
|
|
106
|
-
`Handle "${handle}" does not resolve to a DID`,
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
options?.signal?.throwIfAborted()
|
|
111
|
-
|
|
112
|
-
// Note: Not using "return this.resolveDid(did, options)" to make the extra
|
|
113
|
-
// check for the handle in the DID document:
|
|
114
|
-
|
|
115
|
-
const document = await this.didResolver.resolve(did, options)
|
|
116
|
-
|
|
117
|
-
// Enforce bi-directional resolution
|
|
118
|
-
if (handle !== extractNormalizedHandle(document)) {
|
|
119
|
-
throw new IdentityResolverError(
|
|
120
|
-
`Did document for "${did}" does not include the handle "${handle}"`,
|
|
121
|
-
)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return document
|
|
125
|
-
}
|
|
126
|
-
}
|
package/src/constants.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const HANDLE_INVALID = 'handle.invalid'
|
|
@@ -1,34 +0,0 @@
|
|
|
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/identity-resolver.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { AtprotoDid, AtprotoDidDocument } from '@atproto-labs/did-resolver'
|
|
2
|
-
import { HANDLE_INVALID } from './constants.js'
|
|
3
|
-
|
|
4
|
-
export type { AtprotoDid, AtprotoDidDocument }
|
|
5
|
-
|
|
6
|
-
// Consistent with `com.atproto.identity.defs#identityInfo` returned by
|
|
7
|
-
// `com.atproto.identity.resolveIdentity` endpoint.
|
|
8
|
-
export type IdentityInfo = {
|
|
9
|
-
did: AtprotoDid
|
|
10
|
-
didDoc: AtprotoDidDocument
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Will be 'handle.invalid' if the handle does not resolve to the
|
|
14
|
-
* same DID as the input, or if the handle is not present in the DID
|
|
15
|
-
* document.
|
|
16
|
-
*/
|
|
17
|
-
handle: typeof HANDLE_INVALID | string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type ResolveIdentityOptions = {
|
|
21
|
-
signal?: AbortSignal
|
|
22
|
-
noCache?: boolean
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface IdentityResolver {
|
|
26
|
-
resolve(
|
|
27
|
-
identifier: string,
|
|
28
|
-
options?: ResolveIdentityOptions,
|
|
29
|
-
): Promise<IdentityInfo>
|
|
30
|
-
}
|
package/src/index.ts
DELETED
package/src/util.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AtprotoIdentityDidMethods,
|
|
3
|
-
DidDocument,
|
|
4
|
-
} from '@atproto-labs/did-resolver'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Extract the raw, un-validated, Atproto handle from a DID document.
|
|
8
|
-
*/
|
|
9
|
-
export function extractAtprotoHandle(
|
|
10
|
-
document: DidDocument<AtprotoIdentityDidMethods>,
|
|
11
|
-
): string | undefined {
|
|
12
|
-
if (document.alsoKnownAs) {
|
|
13
|
-
for (const h of document.alsoKnownAs) {
|
|
14
|
-
if (h.startsWith('at://')) {
|
|
15
|
-
// strip off "at://" prefix
|
|
16
|
-
return h.slice(5)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return undefined
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Extracts a validated, normalized Atproto handle from a DID document.
|
|
25
|
-
*/
|
|
26
|
-
export function extractNormalizedHandle(
|
|
27
|
-
document: DidDocument<AtprotoIdentityDidMethods>,
|
|
28
|
-
): string | undefined {
|
|
29
|
-
const handle = extractAtprotoHandle(document)
|
|
30
|
-
if (!handle) return undefined
|
|
31
|
-
return asNormalizedHandle(handle)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function asNormalizedHandle(input: string): string | undefined {
|
|
35
|
-
const handle = normalizeHandle(input)
|
|
36
|
-
return isValidHandle(handle) ? handle : undefined
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function normalizeHandle(handle: string): string {
|
|
40
|
-
return handle.toLowerCase()
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function isValidHandle(handle: string): boolean {
|
|
44
|
-
return (
|
|
45
|
-
handle.length > 0 &&
|
|
46
|
-
handle.length < 254 &&
|
|
47
|
-
/^([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(
|
|
48
|
-
handle,
|
|
49
|
-
)
|
|
50
|
-
)
|
|
51
|
-
}
|
package/tsconfig.build.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"7.0.0-dev.20260614.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"]}
|
package/tsconfig.json
DELETED