@atproto-labs/did-resolver 0.3.3 → 0.3.4
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 +15 -0
- package/dist/did-method.d.ts +1 -1
- package/dist/did-method.d.ts.map +1 -1
- package/dist/did-method.js.map +1 -1
- package/dist/did-resolver-base.d.ts +2 -2
- package/dist/did-resolver-base.d.ts.map +1 -1
- package/dist/did-resolver-base.js.map +1 -1
- package/dist/did-resolver-common.d.ts +1 -1
- package/dist/did-resolver-common.d.ts.map +1 -1
- package/dist/did-resolver-common.js.map +1 -1
- package/dist/did-resolver.d.ts +2 -2
- package/dist/did-resolver.d.ts.map +1 -1
- package/dist/did-resolver.js.map +1 -1
- package/package.json +13 -10
- package/src/create-did-resolver.ts +0 -29
- package/src/did-cache-memory.ts +0 -24
- package/src/did-cache.ts +0 -30
- package/src/did-method.ts +0 -17
- package/src/did-resolver-base.ts +0 -70
- package/src/did-resolver-common.ts +0 -20
- package/src/did-resolver.ts +0 -14
- package/src/index.ts +0 -9
- package/src/methods/plc.ts +0 -56
- package/src/methods/web.ts +0 -77
- package/src/methods.ts +0 -2
- package/src/util.ts +0 -1
- package/tsconfig.build.json +0 -8
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atproto-labs/did-resolver
|
|
2
2
|
|
|
3
|
+
## 0.3.4
|
|
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/simple-store-memory@0.2.3
|
|
13
|
+
- @atproto-labs/simple-store@0.4.3
|
|
14
|
+
- @atproto-labs/fetch@0.3.3
|
|
15
|
+
- @atproto-labs/pipe@0.2.3
|
|
16
|
+
- @atproto/did@0.5.3
|
|
17
|
+
|
|
3
18
|
## 0.3.3
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/did-method.d.ts
CHANGED
package/dist/did-method.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-method.d.ts","sourceRoot":"","sources":["../src/did-method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"did-method.d.ts","sourceRoot":"","sources":["../src/did-method.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAEpD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,MAAM,WAAW,SAAS,CAAC,MAAM,SAAS,MAAM;IAC9C,OAAO,EAAE,CACP,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,EAChB,OAAO,CAAC,EAAE,iBAAiB,KACxB,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,CAAA;CAC5C;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,IAAI;KACxC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;CACvB,CAAA"}
|
package/dist/did-method.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-method.js","sourceRoot":"","sources":["../src/did-method.ts"],"names":[],"mappings":"","sourcesContent":["import { Did, DidDocument } from '@atproto/did'\n\nexport type ResolveDidOptions = {\n signal?: AbortSignal\n noCache?: boolean\n}\n\nexport interface DidMethod<Method extends string> {\n resolve: (\n did: Did<Method>,\n options?: ResolveDidOptions,\n ) => DidDocument | PromiseLike<DidDocument>\n}\n\nexport type DidMethods<M extends string> = {\n [K in M]: DidMethod<K>\n}\n"]}
|
|
1
|
+
{"version":3,"file":"did-method.js","sourceRoot":"","sources":["../src/did-method.ts"],"names":[],"mappings":"","sourcesContent":["import type { Did, DidDocument } from '@atproto/did'\n\nexport type ResolveDidOptions = {\n signal?: AbortSignal\n noCache?: boolean\n}\n\nexport interface DidMethod<Method extends string> {\n resolve: (\n did: Did<Method>,\n options?: ResolveDidOptions,\n ) => DidDocument | PromiseLike<DidDocument>\n}\n\nexport type DidMethods<M extends string> = {\n [K in M]: DidMethod<K>\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Did } from '@atproto/did';
|
|
2
|
-
import { DidMethod, DidMethods, ResolveDidOptions } from './did-method.js';
|
|
3
|
-
import { DidResolver, ResolvedDocument } from './did-resolver.js';
|
|
2
|
+
import type { DidMethod, DidMethods, ResolveDidOptions } from './did-method.js';
|
|
3
|
+
import type { DidResolver, ResolvedDocument } from './did-resolver.js';
|
|
4
4
|
export type { DidMethod, ResolveDidOptions, ResolvedDocument };
|
|
5
5
|
export declare class DidResolverBase<M extends string = string> implements DidResolver<M> {
|
|
6
6
|
protected readonly methods: Map<string, DidMethod<M>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-resolver-base.d.ts","sourceRoot":"","sources":["../src/did-resolver-base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAA8B,MAAM,cAAc,CAAA;AAE9D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"did-resolver-base.d.ts","sourceRoot":"","sources":["../src/did-resolver-base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAA8B,MAAM,cAAc,CAAA;AAE9D,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAC/E,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEtE,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,CAAA;AAE9D,qBAAa,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CACpD,YAAW,WAAW,CAAC,CAAC,CAAC;IAEzB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;IAErD,YAAY,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,EAEjC;IAEK,OAAO,CAAC,CAAC,SAAS,GAAG,EACzB,GAAG,EAAE,CAAC,EACN,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAgDjC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-resolver-base.js","sourceRoot":"","sources":["../src/did-resolver-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AAC9B,OAAO,EAAO,QAAQ,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAMpE,MAAM,OAAO,eAAe;IAK1B,YAAY,OAAsB;QAChC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;IACjD,CAAC;IAED,KAAK,CAAC,OAAO,CACX,GAAM,EACN,OAA2B;QAE3B,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;QAEjC,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAA;QACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,QAAQ,CAChB,GAAG,EACH,wBAAwB,EACxB,oBAAoB,EACpB,GAAG,CACJ,CAAA;QACH,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAa,EAAE,OAAO,CAAC,CAAA;YAC/D,IAAI,QAAQ,CAAC,EAAE,KAAK,GAAG,EAAE,CAAC;gBACxB,MAAM,IAAI,QAAQ,CAChB,GAAG,EACH,oBAAoB,QAAQ,CAAC,EAAE,sBAAsB,EACrD,0BAA0B,EAC1B,GAAG,CACJ,CAAA;YACH,CAAC;YAED,OAAO,QAAkC,CAAA;QAC3C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,kBAAkB,EAAE,CAAC;gBACtC,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAA;gBACrE,MAAM,IAAI,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;YACtE,CAAC;YAED,IAAI,GAAG,YAAY,UAAU,EAAE,CAAC;gBAC9B,MAAM,IAAI,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;YACnE,CAAC;YAED,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;gBAC5B,MAAM,IAAI,QAAQ,CAChB,GAAG,EACH,GAAG,CAAC,OAAO,EACX,2BAA2B,EAC3B,GAAG,EACH,GAAG,CACJ,CAAA;YACH,CAAC;YAED,MAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ZodError } from 'zod'\nimport { Did, DidError, extractDidMethod } from '@atproto/did'\nimport { FetchError, FetchResponseError } from '@atproto-labs/fetch'\nimport { DidMethod, DidMethods, ResolveDidOptions } from './did-method.js'\nimport { DidResolver, ResolvedDocument } from './did-resolver.js'\n\nexport type { DidMethod, ResolveDidOptions, ResolvedDocument }\n\nexport class DidResolverBase<M extends string = string>\n implements DidResolver<M>\n{\n protected readonly methods: Map<string, DidMethod<M>>\n\n constructor(methods: DidMethods<M>) {\n this.methods = new Map(Object.entries(methods))\n }\n\n async resolve<D extends Did>(\n did: D,\n options?: ResolveDidOptions,\n ): Promise<ResolvedDocument<D, M>> {\n options?.signal?.throwIfAborted()\n\n const method = extractDidMethod(did)\n const resolver = this.methods.get(method)\n if (!resolver) {\n throw new DidError(\n did,\n `Unsupported DID method`,\n 'did-method-invalid',\n 400,\n )\n }\n\n try {\n const document = await resolver.resolve(did as Did<M>, options)\n if (document.id !== did) {\n throw new DidError(\n did,\n `DID document id (${document.id}) does not match DID`,\n 'did-document-id-mismatch',\n 400,\n )\n }\n\n return document as ResolvedDocument<D, M>\n } catch (err) {\n if (err instanceof FetchResponseError) {\n const status = err.response.status >= 500 ? 502 : err.response.status\n throw new DidError(did, err.message, 'did-fetch-error', status, err)\n }\n\n if (err instanceof FetchError) {\n throw new DidError(did, err.message, 'did-fetch-error', 400, err)\n }\n\n if (err instanceof ZodError) {\n throw new DidError(\n did,\n err.message,\n 'did-document-format-error',\n 503,\n err,\n )\n }\n\n throw DidError.from(err, did)\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"did-resolver-base.js","sourceRoot":"","sources":["../src/did-resolver-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AAC9B,OAAO,EAAO,QAAQ,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAMpE,MAAM,OAAO,eAAe;IAK1B,YAAY,OAAsB;QAChC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;IACjD,CAAC;IAED,KAAK,CAAC,OAAO,CACX,GAAM,EACN,OAA2B;QAE3B,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;QAEjC,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAA;QACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,QAAQ,CAChB,GAAG,EACH,wBAAwB,EACxB,oBAAoB,EACpB,GAAG,CACJ,CAAA;QACH,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAa,EAAE,OAAO,CAAC,CAAA;YAC/D,IAAI,QAAQ,CAAC,EAAE,KAAK,GAAG,EAAE,CAAC;gBACxB,MAAM,IAAI,QAAQ,CAChB,GAAG,EACH,oBAAoB,QAAQ,CAAC,EAAE,sBAAsB,EACrD,0BAA0B,EAC1B,GAAG,CACJ,CAAA;YACH,CAAC;YAED,OAAO,QAAkC,CAAA;QAC3C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,kBAAkB,EAAE,CAAC;gBACtC,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAA;gBACrE,MAAM,IAAI,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;YACtE,CAAC;YAED,IAAI,GAAG,YAAY,UAAU,EAAE,CAAC;gBAC9B,MAAM,IAAI,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;YACnE,CAAC;YAED,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;gBAC5B,MAAM,IAAI,QAAQ,CAChB,GAAG,EACH,GAAG,CAAC,OAAO,EACX,2BAA2B,EAC3B,GAAG,EACH,GAAG,CACJ,CAAA;YACH,CAAC;YAED,MAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ZodError } from 'zod'\nimport { Did, DidError, extractDidMethod } from '@atproto/did'\nimport { FetchError, FetchResponseError } from '@atproto-labs/fetch'\nimport type { DidMethod, DidMethods, ResolveDidOptions } from './did-method.js'\nimport type { DidResolver, ResolvedDocument } from './did-resolver.js'\n\nexport type { DidMethod, ResolveDidOptions, ResolvedDocument }\n\nexport class DidResolverBase<M extends string = string>\n implements DidResolver<M>\n{\n protected readonly methods: Map<string, DidMethod<M>>\n\n constructor(methods: DidMethods<M>) {\n this.methods = new Map(Object.entries(methods))\n }\n\n async resolve<D extends Did>(\n did: D,\n options?: ResolveDidOptions,\n ): Promise<ResolvedDocument<D, M>> {\n options?.signal?.throwIfAborted()\n\n const method = extractDidMethod(did)\n const resolver = this.methods.get(method)\n if (!resolver) {\n throw new DidError(\n did,\n `Unsupported DID method`,\n 'did-method-invalid',\n 400,\n )\n }\n\n try {\n const document = await resolver.resolve(did as Did<M>, options)\n if (document.id !== did) {\n throw new DidError(\n did,\n `DID document id (${document.id}) does not match DID`,\n 'did-document-id-mismatch',\n 400,\n )\n }\n\n return document as ResolvedDocument<D, M>\n } catch (err) {\n if (err instanceof FetchResponseError) {\n const status = err.response.status >= 500 ? 502 : err.response.status\n throw new DidError(did, err.message, 'did-fetch-error', status, err)\n }\n\n if (err instanceof FetchError) {\n throw new DidError(did, err.message, 'did-fetch-error', 400, err)\n }\n\n if (err instanceof ZodError) {\n throw new DidError(\n did,\n err.message,\n 'did-document-format-error',\n 503,\n err,\n )\n }\n\n throw DidError.from(err, did)\n }\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DidResolverBase } from './did-resolver-base.js';
|
|
2
2
|
import { DidPlcMethodOptions } from './methods/plc.js';
|
|
3
3
|
import { DidWebMethodOptions } from './methods/web.js';
|
|
4
|
-
import { Simplify } from './util.js';
|
|
4
|
+
import type { Simplify } from './util.js';
|
|
5
5
|
export type DidResolverCommonOptions = Simplify<DidPlcMethodOptions & DidWebMethodOptions>;
|
|
6
6
|
export declare class DidResolverCommon extends DidResolverBase<'plc' | 'web'> implements DidResolverBase<'plc' | 'web'> {
|
|
7
7
|
constructor(options?: DidResolverCommonOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-resolver-common.d.ts","sourceRoot":"","sources":["../src/did-resolver-common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAgB,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,EAAgB,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"did-resolver-common.d.ts","sourceRoot":"","sources":["../src/did-resolver-common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAgB,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,EAAgB,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEzC,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAC7C,mBAAmB,GAAG,mBAAmB,CAC1C,CAAA;AAED,qBAAa,iBACX,SAAQ,eAAe,CAAC,KAAK,GAAG,KAAK,CACrC,YAAW,eAAe,CAAC,KAAK,GAAG,KAAK,CAAC;IAEzC,YAAY,OAAO,CAAC,EAAE,wBAAwB,EAK7C;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-resolver-common.js","sourceRoot":"","sources":["../src/did-resolver-common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAuB,MAAM,kBAAkB,CAAA;AACpE,OAAO,EAAE,YAAY,EAAuB,MAAM,kBAAkB,CAAA;AAOpE,MAAM,OAAO,iBACX,SAAQ,eAA8B;IAGtC,YAAY,OAAkC;QAC5C,KAAK,CAAC;YACJ,GAAG,EAAE,IAAI,YAAY,CAAC,OAAO,CAAC;YAC9B,GAAG,EAAE,IAAI,YAAY,CAAC,OAAO,CAAC;SAC/B,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import { DidResolverBase } from './did-resolver-base.js'\nimport { DidPlcMethod, DidPlcMethodOptions } from './methods/plc.js'\nimport { DidWebMethod, DidWebMethodOptions } from './methods/web.js'\nimport { Simplify } from './util.js'\n\nexport type DidResolverCommonOptions = Simplify<\n DidPlcMethodOptions & DidWebMethodOptions\n>\n\nexport class DidResolverCommon\n extends DidResolverBase<'plc' | 'web'>\n implements DidResolverBase<'plc' | 'web'>\n{\n constructor(options?: DidResolverCommonOptions) {\n super({\n plc: new DidPlcMethod(options),\n web: new DidWebMethod(options),\n })\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"did-resolver-common.js","sourceRoot":"","sources":["../src/did-resolver-common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAuB,MAAM,kBAAkB,CAAA;AACpE,OAAO,EAAE,YAAY,EAAuB,MAAM,kBAAkB,CAAA;AAOpE,MAAM,OAAO,iBACX,SAAQ,eAA8B;IAGtC,YAAY,OAAkC;QAC5C,KAAK,CAAC;YACJ,GAAG,EAAE,IAAI,YAAY,CAAC,OAAO,CAAC;YAC9B,GAAG,EAAE,IAAI,YAAY,CAAC,OAAO,CAAC;SAC/B,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import { DidResolverBase } from './did-resolver-base.js'\nimport { DidPlcMethod, DidPlcMethodOptions } from './methods/plc.js'\nimport { DidWebMethod, DidWebMethodOptions } from './methods/web.js'\nimport type { Simplify } from './util.js'\n\nexport type DidResolverCommonOptions = Simplify<\n DidPlcMethodOptions & DidWebMethodOptions\n>\n\nexport class DidResolverCommon\n extends DidResolverBase<'plc' | 'web'>\n implements DidResolverBase<'plc' | 'web'>\n{\n constructor(options?: DidResolverCommonOptions) {\n super({\n plc: new DidPlcMethod(options),\n web: new DidWebMethod(options),\n })\n }\n}\n"]}
|
package/dist/did-resolver.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Did, DidDocument } from '@atproto/did';
|
|
2
|
-
import { ResolveDidOptions } from './did-method.js';
|
|
1
|
+
import type { Did, DidDocument } from '@atproto/did';
|
|
2
|
+
import type { ResolveDidOptions } from './did-method.js';
|
|
3
3
|
export type ResolvedDocument<D extends Did, M extends string = string> = D extends Did<infer N> ? DidDocument<N extends string ? M : N extends M ? N : never> : never;
|
|
4
4
|
export interface DidResolver<M extends string = string> {
|
|
5
5
|
resolve<D extends Did>(did: D, options?: ResolveDidOptions): Promise<ResolvedDocument<D, M>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-resolver.d.ts","sourceRoot":"","sources":["../src/did-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"did-resolver.d.ts","sourceRoot":"","sources":["../src/did-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAExD,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,IACnE,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,CAAC,GAClB,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAC3D,KAAK,CAAA;AAEX,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACpD,OAAO,CAAC,CAAC,SAAS,GAAG,EACnB,GAAG,EAAE,CAAC,EACN,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;CACnC"}
|
package/dist/did-resolver.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-resolver.js","sourceRoot":"","sources":["../src/did-resolver.ts"],"names":[],"mappings":"","sourcesContent":["import { Did, DidDocument } from '@atproto/did'\nimport { ResolveDidOptions } from './did-method.js'\n\nexport type ResolvedDocument<D extends Did, M extends string = string> =\n D extends Did<infer N>\n ? DidDocument<N extends string ? M : N extends M ? N : never>\n : never\n\nexport interface DidResolver<M extends string = string> {\n resolve<D extends Did>(\n did: D,\n options?: ResolveDidOptions,\n ): Promise<ResolvedDocument<D, M>>\n}\n"]}
|
|
1
|
+
{"version":3,"file":"did-resolver.js","sourceRoot":"","sources":["../src/did-resolver.ts"],"names":[],"mappings":"","sourcesContent":["import type { Did, DidDocument } from '@atproto/did'\nimport type { ResolveDidOptions } from './did-method.js'\n\nexport type ResolvedDocument<D extends Did, M extends string = string> =\n D extends Did<infer N>\n ? DidDocument<N extends string ? M : N extends M ? N : never>\n : never\n\nexport interface DidResolver<M extends string = string> {\n resolve<D extends Did>(\n did: D,\n options?: ResolveDidOptions,\n ): Promise<ResolvedDocument<D, M>>\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto-labs/did-resolver",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"engines": {
|
|
5
|
-
"node": ">=22"
|
|
6
|
-
},
|
|
3
|
+
"version": "0.3.4",
|
|
7
4
|
"license": "MIT",
|
|
8
5
|
"description": "DID resolution and verification library",
|
|
9
6
|
"keywords": [
|
|
@@ -17,6 +14,10 @@
|
|
|
17
14
|
"url": "https://github.com/bluesky-social/atproto",
|
|
18
15
|
"directory": "packages/internal/did-resolver"
|
|
19
16
|
},
|
|
17
|
+
"files": [
|
|
18
|
+
"./dist",
|
|
19
|
+
"./CHANGELOG.md"
|
|
20
|
+
],
|
|
20
21
|
"type": "module",
|
|
21
22
|
"exports": {
|
|
22
23
|
".": {
|
|
@@ -24,15 +25,17 @@
|
|
|
24
25
|
"default": "./dist/index.js"
|
|
25
26
|
}
|
|
26
27
|
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22"
|
|
30
|
+
},
|
|
27
31
|
"dependencies": {
|
|
28
32
|
"zod": "^3.23.8",
|
|
29
|
-
"@atproto-labs/fetch": "^0.3.
|
|
30
|
-
"@atproto-labs/pipe": "^0.2.
|
|
31
|
-
"@atproto-labs/simple-store": "^0.4.
|
|
32
|
-
"@atproto/did": "^0.5.
|
|
33
|
-
"@atproto-labs/simple-store-memory": "^0.2.
|
|
33
|
+
"@atproto-labs/fetch": "^0.3.3",
|
|
34
|
+
"@atproto-labs/pipe": "^0.2.3",
|
|
35
|
+
"@atproto-labs/simple-store": "^0.4.3",
|
|
36
|
+
"@atproto/did": "^0.5.3",
|
|
37
|
+
"@atproto-labs/simple-store-memory": "^0.2.3"
|
|
34
38
|
},
|
|
35
|
-
"devDependencies": {},
|
|
36
39
|
"scripts": {
|
|
37
40
|
"build": "tsgo --build tsconfig.build.json"
|
|
38
41
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { AtprotoIdentityDidMethods } from '@atproto/did'
|
|
2
|
-
import { DidCache, DidResolverCached } from './did-cache.js'
|
|
3
|
-
import {
|
|
4
|
-
DidResolverCommon,
|
|
5
|
-
DidResolverCommonOptions,
|
|
6
|
-
} from './did-resolver-common.js'
|
|
7
|
-
import { DidResolver } from './did-resolver.js'
|
|
8
|
-
|
|
9
|
-
export type { AtprotoIdentityDidMethods }
|
|
10
|
-
|
|
11
|
-
export type CreateDidResolverOptions = {
|
|
12
|
-
didResolver?: DidResolver<AtprotoIdentityDidMethods>
|
|
13
|
-
didCache?: DidCache
|
|
14
|
-
} & Partial<DidResolverCommonOptions>
|
|
15
|
-
|
|
16
|
-
export function createDidResolver(
|
|
17
|
-
options: CreateDidResolverOptions,
|
|
18
|
-
): DidResolver<AtprotoIdentityDidMethods> {
|
|
19
|
-
const { didResolver, didCache } = options
|
|
20
|
-
|
|
21
|
-
if (didResolver instanceof DidResolverCached && !didCache) {
|
|
22
|
-
return didResolver
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return new DidResolverCached(
|
|
26
|
-
didResolver ?? new DidResolverCommon(options),
|
|
27
|
-
didCache,
|
|
28
|
-
)
|
|
29
|
-
}
|
package/src/did-cache-memory.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Did, DidDocument } from '@atproto/did'
|
|
2
|
-
import {
|
|
3
|
-
SimpleStoreMemory,
|
|
4
|
-
SimpleStoreMemoryOptions,
|
|
5
|
-
} from '@atproto-labs/simple-store-memory'
|
|
6
|
-
import { DidCache } from './did-cache.js'
|
|
7
|
-
|
|
8
|
-
const DEFAULT_TTL = 3600 * 1000 // 1 hour
|
|
9
|
-
const DEFAULT_MAX_SIZE = 50 * 1024 * 1024 // ~50MB
|
|
10
|
-
|
|
11
|
-
export type DidCacheMemoryOptions = SimpleStoreMemoryOptions<Did, DidDocument>
|
|
12
|
-
|
|
13
|
-
export class DidCacheMemory
|
|
14
|
-
extends SimpleStoreMemory<Did, DidDocument>
|
|
15
|
-
implements DidCache
|
|
16
|
-
{
|
|
17
|
-
constructor(options?: DidCacheMemoryOptions) {
|
|
18
|
-
super(
|
|
19
|
-
options?.max == null
|
|
20
|
-
? { ttl: DEFAULT_TTL, maxSize: DEFAULT_MAX_SIZE, ...options }
|
|
21
|
-
: { ttl: DEFAULT_TTL, ...options },
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/did-cache.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Did, DidDocument } from '@atproto/did'
|
|
2
|
-
import { CachedGetter, SimpleStore } from '@atproto-labs/simple-store'
|
|
3
|
-
import { DidCacheMemory } from './did-cache-memory.js'
|
|
4
|
-
import { DidMethod, ResolveDidOptions } from './did-method.js'
|
|
5
|
-
import { DidResolver, ResolvedDocument } from './did-resolver.js'
|
|
6
|
-
|
|
7
|
-
export type { DidMethod, ResolveDidOptions, ResolvedDocument }
|
|
8
|
-
|
|
9
|
-
export type DidCache = SimpleStore<Did, DidDocument>
|
|
10
|
-
|
|
11
|
-
export type DidResolverCachedOptions = { cache?: DidCache }
|
|
12
|
-
|
|
13
|
-
export class DidResolverCached<M extends string = string>
|
|
14
|
-
implements DidResolver<M>
|
|
15
|
-
{
|
|
16
|
-
protected readonly getter: CachedGetter<Did, DidDocument>
|
|
17
|
-
constructor(
|
|
18
|
-
resolver: DidResolver<M>,
|
|
19
|
-
cache: DidCache = new DidCacheMemory(),
|
|
20
|
-
) {
|
|
21
|
-
this.getter = new CachedGetter<Did, DidDocument>(
|
|
22
|
-
(did, options) => resolver.resolve(did, options),
|
|
23
|
-
cache,
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public async resolve<D extends Did>(did: D, options?: ResolveDidOptions) {
|
|
28
|
-
return this.getter.get(did, options) as Promise<ResolvedDocument<D, M>>
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/did-method.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Did, DidDocument } from '@atproto/did'
|
|
2
|
-
|
|
3
|
-
export type ResolveDidOptions = {
|
|
4
|
-
signal?: AbortSignal
|
|
5
|
-
noCache?: boolean
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface DidMethod<Method extends string> {
|
|
9
|
-
resolve: (
|
|
10
|
-
did: Did<Method>,
|
|
11
|
-
options?: ResolveDidOptions,
|
|
12
|
-
) => DidDocument | PromiseLike<DidDocument>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type DidMethods<M extends string> = {
|
|
16
|
-
[K in M]: DidMethod<K>
|
|
17
|
-
}
|
package/src/did-resolver-base.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { ZodError } from 'zod'
|
|
2
|
-
import { Did, DidError, extractDidMethod } from '@atproto/did'
|
|
3
|
-
import { FetchError, FetchResponseError } from '@atproto-labs/fetch'
|
|
4
|
-
import { DidMethod, DidMethods, ResolveDidOptions } from './did-method.js'
|
|
5
|
-
import { DidResolver, ResolvedDocument } from './did-resolver.js'
|
|
6
|
-
|
|
7
|
-
export type { DidMethod, ResolveDidOptions, ResolvedDocument }
|
|
8
|
-
|
|
9
|
-
export class DidResolverBase<M extends string = string>
|
|
10
|
-
implements DidResolver<M>
|
|
11
|
-
{
|
|
12
|
-
protected readonly methods: Map<string, DidMethod<M>>
|
|
13
|
-
|
|
14
|
-
constructor(methods: DidMethods<M>) {
|
|
15
|
-
this.methods = new Map(Object.entries(methods))
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async resolve<D extends Did>(
|
|
19
|
-
did: D,
|
|
20
|
-
options?: ResolveDidOptions,
|
|
21
|
-
): Promise<ResolvedDocument<D, M>> {
|
|
22
|
-
options?.signal?.throwIfAborted()
|
|
23
|
-
|
|
24
|
-
const method = extractDidMethod(did)
|
|
25
|
-
const resolver = this.methods.get(method)
|
|
26
|
-
if (!resolver) {
|
|
27
|
-
throw new DidError(
|
|
28
|
-
did,
|
|
29
|
-
`Unsupported DID method`,
|
|
30
|
-
'did-method-invalid',
|
|
31
|
-
400,
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
const document = await resolver.resolve(did as Did<M>, options)
|
|
37
|
-
if (document.id !== did) {
|
|
38
|
-
throw new DidError(
|
|
39
|
-
did,
|
|
40
|
-
`DID document id (${document.id}) does not match DID`,
|
|
41
|
-
'did-document-id-mismatch',
|
|
42
|
-
400,
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return document as ResolvedDocument<D, M>
|
|
47
|
-
} catch (err) {
|
|
48
|
-
if (err instanceof FetchResponseError) {
|
|
49
|
-
const status = err.response.status >= 500 ? 502 : err.response.status
|
|
50
|
-
throw new DidError(did, err.message, 'did-fetch-error', status, err)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (err instanceof FetchError) {
|
|
54
|
-
throw new DidError(did, err.message, 'did-fetch-error', 400, err)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (err instanceof ZodError) {
|
|
58
|
-
throw new DidError(
|
|
59
|
-
did,
|
|
60
|
-
err.message,
|
|
61
|
-
'did-document-format-error',
|
|
62
|
-
503,
|
|
63
|
-
err,
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
throw DidError.from(err, did)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { DidResolverBase } from './did-resolver-base.js'
|
|
2
|
-
import { DidPlcMethod, DidPlcMethodOptions } from './methods/plc.js'
|
|
3
|
-
import { DidWebMethod, DidWebMethodOptions } from './methods/web.js'
|
|
4
|
-
import { Simplify } from './util.js'
|
|
5
|
-
|
|
6
|
-
export type DidResolverCommonOptions = Simplify<
|
|
7
|
-
DidPlcMethodOptions & DidWebMethodOptions
|
|
8
|
-
>
|
|
9
|
-
|
|
10
|
-
export class DidResolverCommon
|
|
11
|
-
extends DidResolverBase<'plc' | 'web'>
|
|
12
|
-
implements DidResolverBase<'plc' | 'web'>
|
|
13
|
-
{
|
|
14
|
-
constructor(options?: DidResolverCommonOptions) {
|
|
15
|
-
super({
|
|
16
|
-
plc: new DidPlcMethod(options),
|
|
17
|
-
web: new DidWebMethod(options),
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/did-resolver.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Did, DidDocument } from '@atproto/did'
|
|
2
|
-
import { ResolveDidOptions } from './did-method.js'
|
|
3
|
-
|
|
4
|
-
export type ResolvedDocument<D extends Did, M extends string = string> =
|
|
5
|
-
D extends Did<infer N>
|
|
6
|
-
? DidDocument<N extends string ? M : N extends M ? N : never>
|
|
7
|
-
: never
|
|
8
|
-
|
|
9
|
-
export interface DidResolver<M extends string = string> {
|
|
10
|
-
resolve<D extends Did>(
|
|
11
|
-
did: D,
|
|
12
|
-
options?: ResolveDidOptions,
|
|
13
|
-
): Promise<ResolvedDocument<D, M>>
|
|
14
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from '@atproto/did'
|
|
2
|
-
|
|
3
|
-
export * from './create-did-resolver.js'
|
|
4
|
-
export * from './did-cache-memory.js'
|
|
5
|
-
export * from './did-cache.js'
|
|
6
|
-
export * from './did-method.js'
|
|
7
|
-
export * from './did-resolver-common.js'
|
|
8
|
-
export * from './did-resolver.js'
|
|
9
|
-
export * from './methods.js'
|
package/src/methods/plc.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Did, assertDidPlc, didDocumentValidator } from '@atproto/did'
|
|
2
|
-
import {
|
|
3
|
-
Fetch,
|
|
4
|
-
bindFetch,
|
|
5
|
-
fetchJsonProcessor,
|
|
6
|
-
fetchJsonZodProcessor,
|
|
7
|
-
fetchOkProcessor,
|
|
8
|
-
} from '@atproto-labs/fetch'
|
|
9
|
-
import { pipe } from '@atproto-labs/pipe'
|
|
10
|
-
import { DidMethod, ResolveDidOptions } from '../did-method.js'
|
|
11
|
-
|
|
12
|
-
const fetchSuccessHandler = pipe(
|
|
13
|
-
fetchOkProcessor(),
|
|
14
|
-
fetchJsonProcessor(/^application\/(did\+ld\+)?json$/),
|
|
15
|
-
fetchJsonZodProcessor(didDocumentValidator),
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
export type DidPlcMethodOptions = {
|
|
19
|
-
/**
|
|
20
|
-
* @default globalThis.fetch
|
|
21
|
-
*/
|
|
22
|
-
fetch?: Fetch
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @default 'https://plc.directory/'
|
|
26
|
-
*/
|
|
27
|
-
plcDirectoryUrl?: string | URL
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class DidPlcMethod implements DidMethod<'plc'> {
|
|
31
|
-
protected readonly fetch: Fetch<unknown>
|
|
32
|
-
|
|
33
|
-
public readonly plcDirectoryUrl: URL
|
|
34
|
-
|
|
35
|
-
constructor(options?: DidPlcMethodOptions) {
|
|
36
|
-
this.plcDirectoryUrl = new URL(
|
|
37
|
-
options?.plcDirectoryUrl || 'https://plc.directory/',
|
|
38
|
-
)
|
|
39
|
-
this.fetch = bindFetch(options?.fetch)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async resolve(did: Did<'plc'>, options?: ResolveDidOptions) {
|
|
43
|
-
// Although the did should start with `did:plc:` (thanks to typings), we
|
|
44
|
-
// should still check if the msid is valid.
|
|
45
|
-
assertDidPlc(did)
|
|
46
|
-
|
|
47
|
-
// Should never throw
|
|
48
|
-
const url = new URL(`/${encodeURIComponent(did)}`, this.plcDirectoryUrl)
|
|
49
|
-
|
|
50
|
-
return this.fetch(url, {
|
|
51
|
-
redirect: 'error',
|
|
52
|
-
headers: { accept: 'application/did+ld+json,application/json' },
|
|
53
|
-
signal: options?.signal,
|
|
54
|
-
}).then(fetchSuccessHandler)
|
|
55
|
-
}
|
|
56
|
-
}
|
package/src/methods/web.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { Did, DidError, didDocumentValidator, didWebToUrl } from '@atproto/did'
|
|
2
|
-
import {
|
|
3
|
-
Fetch,
|
|
4
|
-
bindFetch,
|
|
5
|
-
fetchJsonProcessor,
|
|
6
|
-
fetchJsonZodProcessor,
|
|
7
|
-
fetchOkProcessor,
|
|
8
|
-
} from '@atproto-labs/fetch'
|
|
9
|
-
import { pipe } from '@atproto-labs/pipe'
|
|
10
|
-
import { DidMethod, ResolveDidOptions } from '../did-method.js'
|
|
11
|
-
|
|
12
|
-
const fetchSuccessHandler = pipe(
|
|
13
|
-
fetchOkProcessor(),
|
|
14
|
-
fetchJsonProcessor(/^application\/(did\+ld\+)?json$/),
|
|
15
|
-
fetchJsonZodProcessor(didDocumentValidator),
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
export type DidWebMethodOptions = {
|
|
19
|
-
fetch?: Fetch
|
|
20
|
-
/** @default true */
|
|
21
|
-
allowHttp?: boolean
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class DidWebMethod implements DidMethod<'web'> {
|
|
25
|
-
protected readonly fetch: Fetch<unknown>
|
|
26
|
-
protected readonly allowHttp: boolean
|
|
27
|
-
|
|
28
|
-
constructor({
|
|
29
|
-
fetch = globalThis.fetch,
|
|
30
|
-
allowHttp = true,
|
|
31
|
-
}: DidWebMethodOptions = {}) {
|
|
32
|
-
this.fetch = bindFetch(fetch)
|
|
33
|
-
this.allowHttp = allowHttp
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async resolve(did: Did<'web'>, options?: ResolveDidOptions) {
|
|
37
|
-
const didDocumentUrl = buildDidWebDocumentUrl(did)
|
|
38
|
-
|
|
39
|
-
if (!this.allowHttp && didDocumentUrl.protocol === 'http:') {
|
|
40
|
-
throw new DidError(
|
|
41
|
-
did,
|
|
42
|
-
'Resolution of "http" did:web is not allowed',
|
|
43
|
-
'did-web-http-not-allowed',
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Note we do not explicitly check for "localhost" here. Instead, we rely on
|
|
48
|
-
// the injected 'fetch' function to handle the URL. If the URL is
|
|
49
|
-
// "localhost", or resolves to a private IP address, the fetch function is
|
|
50
|
-
// responsible for handling it.
|
|
51
|
-
|
|
52
|
-
return this.fetch(didDocumentUrl, {
|
|
53
|
-
redirect: 'error',
|
|
54
|
-
headers: { accept: 'application/did+ld+json,application/json' },
|
|
55
|
-
signal: options?.signal,
|
|
56
|
-
}).then(fetchSuccessHandler)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @see {@link https://datatracker.ietf.org/doc/html/rfc8615}
|
|
62
|
-
* @see {@link https://w3c-ccg.github.io/did-method-web/#create-register}
|
|
63
|
-
*/
|
|
64
|
-
export function buildDidWebDocumentUrl(did: Did<'web'>) {
|
|
65
|
-
const url = didWebToUrl(did) // Will throw if the DID is invalid
|
|
66
|
-
|
|
67
|
-
// Note: DID cannot end with an `:`, so they cannot end with a `/`. This is
|
|
68
|
-
// true unless when there is no path at all, in which case the URL constructor
|
|
69
|
-
// will set the pathname to `/`.
|
|
70
|
-
|
|
71
|
-
// https://w3c-ccg.github.io/did-method-web/#read-resolve
|
|
72
|
-
if (url.pathname === '/') {
|
|
73
|
-
return new URL(`/.well-known/did.json`, url)
|
|
74
|
-
} else {
|
|
75
|
-
return new URL(`${url.pathname}/did.json`, url)
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/methods.ts
DELETED
package/src/util.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type Simplify<T> = { [K in keyof T]: T[K] } & NonNullable<unknown>
|
package/tsconfig.build.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"7.0.0-dev.20260614.1","root":["./src/create-did-resolver.ts","./src/did-cache-memory.ts","./src/did-cache.ts","./src/did-method.ts","./src/did-resolver-base.ts","./src/did-resolver-common.ts","./src/did-resolver.ts","./src/index.ts","./src/methods.ts","./src/util.ts","./src/methods/plc.ts","./src/methods/web.ts"]}
|
package/tsconfig.json
DELETED