@atcute/identity-resolver 1.0.2 → 1.1.1
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/dist/did/methods/xrpc.d.ts +13 -0
- package/dist/did/methods/xrpc.js +35 -0
- package/dist/did/methods/xrpc.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/lib/did/methods/xrpc.ts +62 -0
- package/lib/index.ts +1 -0
- package/lib/types.ts +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type DidDocument } from '@atcute/identity';
|
|
2
|
+
import type { Did } from '@atcute/lexicons/syntax';
|
|
3
|
+
import type { DidDocumentResolver, ResolveDidDocumentOptions } from '../../types.js';
|
|
4
|
+
export interface XrpcDidDocumentResolverOptions {
|
|
5
|
+
serviceUrl: string;
|
|
6
|
+
fetch?: typeof fetch;
|
|
7
|
+
}
|
|
8
|
+
export declare class XrpcDidDocumentResolver implements DidDocumentResolver<string> {
|
|
9
|
+
#private;
|
|
10
|
+
readonly serviceUrl: string;
|
|
11
|
+
constructor({ serviceUrl, fetch: fetchThis }: XrpcDidDocumentResolverOptions);
|
|
12
|
+
resolve(did: Did, options?: ResolveDidDocumentOptions): Promise<DidDocument>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { defs } from '@atcute/identity';
|
|
2
|
+
import { FailedResponseError, isResponseOk, parseResponseAsJson, pipe, validateJsonWith, } from '@atcute/util-fetch';
|
|
3
|
+
import * as v from '@badrap/valita';
|
|
4
|
+
import * as err from '../../errors.js';
|
|
5
|
+
const fetchXrpcHandler = pipe(isResponseOk, parseResponseAsJson(/^application\/json$/, 20 * 1024 + 16), validateJsonWith(v.object({ didDoc: defs.didDocument }), { mode: 'passthrough' }));
|
|
6
|
+
export class XrpcDidDocumentResolver {
|
|
7
|
+
serviceUrl;
|
|
8
|
+
#fetch;
|
|
9
|
+
constructor({ serviceUrl, fetch: fetchThis = fetch }) {
|
|
10
|
+
this.serviceUrl = serviceUrl;
|
|
11
|
+
this.#fetch = fetchThis;
|
|
12
|
+
}
|
|
13
|
+
async resolve(did, options) {
|
|
14
|
+
let json;
|
|
15
|
+
try {
|
|
16
|
+
const url = new URL(`/xrpc/com.atproto.identity.resolveDid`, this.serviceUrl);
|
|
17
|
+
url.searchParams.set('did', did);
|
|
18
|
+
const response = await (0, this.#fetch)(url, {
|
|
19
|
+
signal: options?.signal,
|
|
20
|
+
cache: options?.noCache ? 'no-cache' : 'default',
|
|
21
|
+
headers: { accept: 'application/json' },
|
|
22
|
+
});
|
|
23
|
+
const handled = await fetchXrpcHandler(response);
|
|
24
|
+
json = handled.json.didDoc;
|
|
25
|
+
}
|
|
26
|
+
catch (cause) {
|
|
27
|
+
if (cause instanceof FailedResponseError && cause.status === 404) {
|
|
28
|
+
throw new err.DocumentNotFoundError(did);
|
|
29
|
+
}
|
|
30
|
+
throw new err.FailedDocumentResolutionError(did, { cause });
|
|
31
|
+
}
|
|
32
|
+
return json;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=xrpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xrpc.js","sourceRoot":"","sources":["../../../lib/did/methods/xrpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAoB,MAAM,kBAAkB,CAAC;AAE1D,OAAO,EACN,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,IAAI,EACJ,gBAAgB,GAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AAEpC,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAGvC,MAAM,gBAAgB,GAAG,IAAI,CAC5B,YAAY,EACZ,mBAAmB,CAAC,qBAAqB,EAAE,EAAE,GAAG,IAAI,GAAG,EAAE,C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AC1C,CAAC;YAED,MAAM,IAAI,GAAG,CAAC,6BAA6B,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC7D,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './did/composite.js';
|
|
2
2
|
export * from './did/methods/plc.js';
|
|
3
3
|
export * from './did/methods/web.js';
|
|
4
|
+
export * from './did/methods/xrpc.js';
|
|
4
5
|
export * from './handle/composite.js';
|
|
5
6
|
export * from './handle/methods/doh-json.js';
|
|
6
7
|
export * from './handle/methods/well-known.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './did/composite.js';
|
|
2
2
|
export * from './did/methods/plc.js';
|
|
3
3
|
export * from './did/methods/web.js';
|
|
4
|
+
export * from './did/methods/xrpc.js';
|
|
4
5
|
export * from './handle/composite.js';
|
|
5
6
|
export * from './handle/methods/doh-json.js';
|
|
6
7
|
export * from './handle/methods/well-known.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface ResolveDidDocumentOptions {
|
|
|
4
4
|
signal?: AbortSignal;
|
|
5
5
|
noCache?: boolean;
|
|
6
6
|
}
|
|
7
|
-
export interface DidDocumentResolver<TMethod extends string> {
|
|
7
|
+
export interface DidDocumentResolver<TMethod extends string = string> {
|
|
8
8
|
resolve(did: Did<TMethod>, options?: ResolveDidDocumentOptions): Promise<DidDocument>;
|
|
9
9
|
}
|
|
10
10
|
export interface ResolveHandleOptions {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { defs, type DidDocument } from '@atcute/identity';
|
|
2
|
+
import type { Did } from '@atcute/lexicons/syntax';
|
|
3
|
+
import {
|
|
4
|
+
FailedResponseError,
|
|
5
|
+
isResponseOk,
|
|
6
|
+
parseResponseAsJson,
|
|
7
|
+
pipe,
|
|
8
|
+
validateJsonWith,
|
|
9
|
+
} from '@atcute/util-fetch';
|
|
10
|
+
|
|
11
|
+
import * as v from '@badrap/valita';
|
|
12
|
+
|
|
13
|
+
import * as err from '../../errors.js';
|
|
14
|
+
import type { DidDocumentResolver, ResolveDidDocumentOptions } from '../../types.js';
|
|
15
|
+
|
|
16
|
+
const fetchXrpcHandler = pipe(
|
|
17
|
+
isResponseOk,
|
|
18
|
+
parseResponseAsJson(/^application\/json$/, 20 * 1024 + 16),
|
|
19
|
+
validateJsonWith(v.object({ didDoc: defs.didDocument }), { mode: 'passthrough' }),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export interface XrpcDidDocumentResolverOptions {
|
|
23
|
+
serviceUrl: string;
|
|
24
|
+
fetch?: typeof fetch;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class XrpcDidDocumentResolver implements DidDocumentResolver<string> {
|
|
28
|
+
readonly serviceUrl: string;
|
|
29
|
+
#fetch: typeof fetch;
|
|
30
|
+
|
|
31
|
+
constructor({ serviceUrl, fetch: fetchThis = fetch }: XrpcDidDocumentResolverOptions) {
|
|
32
|
+
this.serviceUrl = serviceUrl;
|
|
33
|
+
this.#fetch = fetchThis;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async resolve(did: Did, options?: ResolveDidDocumentOptions): Promise<DidDocument> {
|
|
37
|
+
let json: DidDocument;
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const url = new URL(`/xrpc/com.atproto.identity.resolveDid`, this.serviceUrl);
|
|
41
|
+
url.searchParams.set('did', did);
|
|
42
|
+
|
|
43
|
+
const response = await (0, this.#fetch)(url, {
|
|
44
|
+
signal: options?.signal,
|
|
45
|
+
cache: options?.noCache ? 'no-cache' : 'default',
|
|
46
|
+
headers: { accept: 'application/json' },
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const handled = await fetchXrpcHandler(response);
|
|
50
|
+
|
|
51
|
+
json = handled.json.didDoc;
|
|
52
|
+
} catch (cause) {
|
|
53
|
+
if (cause instanceof FailedResponseError && cause.status === 404) {
|
|
54
|
+
throw new err.DocumentNotFoundError(did);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
throw new err.FailedDocumentResolutionError(did, { cause });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return json;
|
|
61
|
+
}
|
|
62
|
+
}
|
package/lib/index.ts
CHANGED
package/lib/types.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface ResolveDidDocumentOptions {
|
|
|
6
6
|
noCache?: boolean;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export interface DidDocumentResolver<TMethod extends string> {
|
|
9
|
+
export interface DidDocumentResolver<TMethod extends string = string> {
|
|
10
10
|
resolve(did: Did<TMethod>, options?: ResolveDidDocumentOptions): Promise<DidDocument>;
|
|
11
11
|
}
|
|
12
12
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@atcute/identity-resolver",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"description": "atproto handle and DID document resolution",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"atproto",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@badrap/valita": "^0.4.4",
|
|
30
|
-
"@atcute/
|
|
31
|
-
"@atcute/
|
|
30
|
+
"@atcute/lexicons": "^1.0.4",
|
|
31
|
+
"@atcute/util-fetch": "^1.0.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/bun": "^1.2.13",
|