@atproto-labs/identity-resolver 0.0.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/CHANGELOG.md +12 -0
- package/LICENSE.txt +7 -0
- package/dist/identity-resolver.d.ts +13 -0
- package/dist/identity-resolver.d.ts.map +1 -0
- package/dist/identity-resolver.js +34 -0
- package/dist/identity-resolver.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/universal-identity-resolver.d.ts +23 -0
- package/dist/universal-identity-resolver.d.ts.map +1 -0
- package/dist/universal-identity-resolver.js +24 -0
- package/dist/universal-identity-resolver.js.map +1 -0
- package/package.json +39 -0
- package/src/identity-resolver.ts +35 -0
- package/src/index.ts +2 -0
- package/src/universal-identity-resolver.ts +57 -0
- package/tsconfig.json +8 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @atproto-labs/identity-resolver
|
|
2
|
+
|
|
3
|
+
## 0.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`e134c79a0`](https://github.com/bluesky-social/atproto/commit/e134c79a0ffb000b2cb36437815673fa6bda664b) Thanks [@devinivy](https://github.com/devinivy)! - Initial publish of experimental oauth packages to @atproto-labs
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`e134c79a0`](https://github.com/bluesky-social/atproto/commit/e134c79a0ffb000b2cb36437815673fa6bda664b)]:
|
|
10
|
+
- @atproto-labs/handle-resolver@0.0.1
|
|
11
|
+
- @atproto-labs/fetch@0.0.1
|
|
12
|
+
- @atproto-labs/did@0.0.1
|
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Dual MIT/Apache-2.0 License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-2024 Bluesky PBC, and Contributors
|
|
4
|
+
|
|
5
|
+
Except as otherwise noted in individual files, this software is licensed under the MIT license (<http://opensource.org/licenses/MIT>), or the Apache License, Version 2.0 (<http://www.apache.org/licenses/LICENSE-2.0>).
|
|
6
|
+
|
|
7
|
+
Downstream projects and end users may chose either license individually, or both together, at their discretion. The motivation for this dual-licensing is the additional software patent assurance provided by Apache 2.0.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DidResolver } from '@atproto-labs/did';
|
|
2
|
+
import { HandleResolver, ResolvedHandle } from '@atproto-labs/handle-resolver';
|
|
3
|
+
export type ResolvedIdentity = {
|
|
4
|
+
did: NonNullable<ResolvedHandle>;
|
|
5
|
+
url: URL;
|
|
6
|
+
};
|
|
7
|
+
export declare class IdentityResolver {
|
|
8
|
+
readonly handleResolver: HandleResolver;
|
|
9
|
+
readonly didResolver: DidResolver<'plc' | 'web'>;
|
|
10
|
+
constructor(handleResolver: HandleResolver, didResolver: DidResolver<'plc' | 'web'>);
|
|
11
|
+
resolve(input: string, serviceType?: string): Promise<ResolvedIdentity>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=identity-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-resolver.d.ts","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EACL,cAAc,EACd,cAAc,EAEf,MAAM,+BAA+B,CAAA;AAGtC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,WAAW,CAAC,cAAc,CAAC,CAAA;IAChC,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAED,qBAAa,gBAAgB;IAEzB,QAAQ,CAAC,cAAc,EAAE,cAAc;IACvC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC;gBADvC,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC;IAGrC,OAAO,CAClB,KAAK,EAAE,MAAM,EACb,WAAW,SAA8B,GACxC,OAAO,CAAC,gBAAgB,CAAC;CAY7B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IdentityResolver = void 0;
|
|
4
|
+
const handle_resolver_1 = require("@atproto-labs/handle-resolver");
|
|
5
|
+
const syntax_1 = require("@atproto/syntax");
|
|
6
|
+
class IdentityResolver {
|
|
7
|
+
constructor(handleResolver, didResolver) {
|
|
8
|
+
Object.defineProperty(this, "handleResolver", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: handleResolver
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(this, "didResolver", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: didResolver
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async resolve(input, serviceType = 'AtprotoPersonalDataServer') {
|
|
22
|
+
const did = (0, handle_resolver_1.isResolvedHandle)(input)
|
|
23
|
+
? input // Already a did
|
|
24
|
+
: await this.handleResolver.resolve((0, syntax_1.normalizeAndEnsureValidHandle)(input));
|
|
25
|
+
if (!did)
|
|
26
|
+
throw new Error(`Handle ${input} does not resolve to a DID`);
|
|
27
|
+
const url = await this.didResolver.resolveServiceEndpoint(did, {
|
|
28
|
+
type: serviceType,
|
|
29
|
+
});
|
|
30
|
+
return { did, url };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.IdentityResolver = IdentityResolver;
|
|
34
|
+
//# sourceMappingURL=identity-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-resolver.js","sourceRoot":"","sources":["../src/identity-resolver.ts"],"names":[],"mappings":";;;AACA,mEAIsC;AACtC,4CAA+D;AAO/D,MAAa,gBAAgB;IAC3B,YACW,cAA8B,EAC9B,WAAuC;QADhD;;;;mBAAS,cAAc;WAAgB;QACvC;;;;mBAAS,WAAW;WAA4B;IAC/C,CAAC;IAEG,KAAK,CAAC,OAAO,CAClB,KAAa,EACb,WAAW,GAAG,2BAA2B;QAEzC,MAAM,GAAG,GAAG,IAAA,kCAAgB,EAAC,KAAK,CAAC;YACjC,CAAC,CAAC,KAAK,CAAC,gBAAgB;YACxB,CAAC,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAA,sCAA6B,EAAC,KAAK,CAAC,CAAC,CAAA;QAC3E,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,UAAU,KAAK,4BAA4B,CAAC,CAAA;QAEtE,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC,GAAG,EAAE;YAC7D,IAAI,EAAE,WAAW;SAClB,CAAC,CAAA;QAEF,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;IACrB,CAAC;CACF;AArBD,4CAqBC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,kCAAkC,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./identity-resolver.js"), exports);
|
|
18
|
+
__exportStar(require("./universal-identity-resolver.js"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAsC;AACtC,mEAAgD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DidCache, IsomorphicDidResolverOptions } from '@atproto-labs/did';
|
|
2
|
+
import { Fetch } from '@atproto-labs/fetch';
|
|
3
|
+
import { HandleResolverCache, UniversalHandleResolverOptions } from '@atproto-labs/handle-resolver';
|
|
4
|
+
import { IdentityResolver } from './identity-resolver.js';
|
|
5
|
+
export type { DidCache, DidDocument } from '@atproto-labs/did';
|
|
6
|
+
export type { HandleResolverCache, ResolvedHandle, } from '@atproto-labs/handle-resolver';
|
|
7
|
+
export type UniversalIdentityResolverOptions = {
|
|
8
|
+
fetch?: Fetch;
|
|
9
|
+
didCache?: DidCache;
|
|
10
|
+
handleCache?: HandleResolverCache;
|
|
11
|
+
/**
|
|
12
|
+
* @see {@link IsomorphicDidResolverOptions.plcDirectoryUrl}
|
|
13
|
+
*/
|
|
14
|
+
plcDirectoryUrl?: IsomorphicDidResolverOptions['plcDirectoryUrl'];
|
|
15
|
+
/**
|
|
16
|
+
* @see {@link UniversalHandleResolverOptions.atprotoLexiconUrl}
|
|
17
|
+
*/
|
|
18
|
+
atprotoLexiconUrl?: UniversalHandleResolverOptions['atprotoLexiconUrl'];
|
|
19
|
+
};
|
|
20
|
+
export declare class UniversalIdentityResolver extends IdentityResolver {
|
|
21
|
+
static from({ fetch, didCache, handleCache, plcDirectoryUrl, atprotoLexiconUrl, }: UniversalIdentityResolverOptions): UniversalIdentityResolver;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=universal-identity-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"universal-identity-resolver.d.ts","sourceRoot":"","sources":["../src/universal-identity-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,4BAA4B,EAC7B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAgC,EAC9B,mBAAmB,EACnB,8BAA8B,EAC/B,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAEzD,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC9D,YAAY,EACV,mBAAmB,EACnB,cAAc,GACf,MAAM,+BAA+B,CAAA;AAEtC,MAAM,MAAM,gCAAgC,GAAG;IAC7C,KAAK,CAAC,EAAE,KAAK,CAAA;IAEb,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,WAAW,CAAC,EAAE,mBAAmB,CAAA;IAEjC;;OAEG;IACH,eAAe,CAAC,EAAE,4BAA4B,CAAC,iBAAiB,CAAC,CAAA;IAEjE;;OAEG;IACH,iBAAiB,CAAC,EAAE,8BAA8B,CAAC,mBAAmB,CAAC,CAAA;CACxE,CAAA;AAED,qBAAa,yBAA0B,SAAQ,gBAAgB;IAC7D,MAAM,CAAC,IAAI,CAAC,EACV,KAAwB,EACxB,QAAQ,EACR,WAAW,EACX,eAAe,EACf,iBAAiB,GAClB,EAAE,gCAAgC;CAcpC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UniversalIdentityResolver = void 0;
|
|
7
|
+
const did_1 = require("@atproto-labs/did");
|
|
8
|
+
const handle_resolver_1 = __importDefault(require("@atproto-labs/handle-resolver"));
|
|
9
|
+
const identity_resolver_js_1 = require("./identity-resolver.js");
|
|
10
|
+
class UniversalIdentityResolver extends identity_resolver_js_1.IdentityResolver {
|
|
11
|
+
static from({ fetch = globalThis.fetch, didCache, handleCache, plcDirectoryUrl, atprotoLexiconUrl, }) {
|
|
12
|
+
return new this(new handle_resolver_1.default({
|
|
13
|
+
fetch,
|
|
14
|
+
cache: handleCache,
|
|
15
|
+
atprotoLexiconUrl,
|
|
16
|
+
}), new did_1.IsomorphicDidResolver({
|
|
17
|
+
fetch, //
|
|
18
|
+
cache: didCache,
|
|
19
|
+
plcDirectoryUrl,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.UniversalIdentityResolver = UniversalIdentityResolver;
|
|
24
|
+
//# sourceMappingURL=universal-identity-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"universal-identity-resolver.js","sourceRoot":"","sources":["../src/universal-identity-resolver.ts"],"names":[],"mappings":";;;;;;AAAA,2CAI0B;AAE1B,oFAGsC;AACtC,iEAAyD;AAyBzD,MAAa,yBAA0B,SAAQ,uCAAgB;IAC7D,MAAM,CAAC,IAAI,CAAC,EACV,KAAK,GAAG,UAAU,CAAC,KAAK,EACxB,QAAQ,EACR,WAAW,EACX,eAAe,EACf,iBAAiB,GACgB;QACjC,OAAO,IAAI,IAAI,CACb,IAAI,yBAAuB,CAAC;YAC1B,KAAK;YACL,KAAK,EAAE,WAAW;YAClB,iBAAiB;SAClB,CAAC,EACF,IAAI,2BAAqB,CAAC;YACxB,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,QAAQ;YACf,eAAe;SAChB,CAAC,CACH,CAAA;IACH,CAAC;CACF;AArBD,8DAqBC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atproto-labs/identity-resolver",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "A library resolving ATPROTO identities",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"atproto",
|
|
8
|
+
"identity",
|
|
9
|
+
"isomorphic",
|
|
10
|
+
"resolver"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://atproto.com",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/bluesky-social/atproto",
|
|
16
|
+
"directory": "packages/identity-resolver"
|
|
17
|
+
},
|
|
18
|
+
"type": "commonjs",
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@atproto-labs/did": "0.0.1",
|
|
29
|
+
"@atproto-labs/fetch": "0.0.1",
|
|
30
|
+
"@atproto-labs/handle-resolver": "0.0.1",
|
|
31
|
+
"@atproto/syntax": "0.3.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"typescript": "^5.3.3"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc --build tsconfig.json"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DidResolver } from '@atproto-labs/did'
|
|
2
|
+
import {
|
|
3
|
+
HandleResolver,
|
|
4
|
+
ResolvedHandle,
|
|
5
|
+
isResolvedHandle,
|
|
6
|
+
} from '@atproto-labs/handle-resolver'
|
|
7
|
+
import { normalizeAndEnsureValidHandle } from '@atproto/syntax'
|
|
8
|
+
|
|
9
|
+
export type ResolvedIdentity = {
|
|
10
|
+
did: NonNullable<ResolvedHandle>
|
|
11
|
+
url: URL
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class IdentityResolver {
|
|
15
|
+
constructor(
|
|
16
|
+
readonly handleResolver: HandleResolver,
|
|
17
|
+
readonly didResolver: DidResolver<'plc' | 'web'>,
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
public async resolve(
|
|
21
|
+
input: string,
|
|
22
|
+
serviceType = 'AtprotoPersonalDataServer',
|
|
23
|
+
): Promise<ResolvedIdentity> {
|
|
24
|
+
const did = isResolvedHandle(input)
|
|
25
|
+
? input // Already a did
|
|
26
|
+
: await this.handleResolver.resolve(normalizeAndEnsureValidHandle(input))
|
|
27
|
+
if (!did) throw new Error(`Handle ${input} does not resolve to a DID`)
|
|
28
|
+
|
|
29
|
+
const url = await this.didResolver.resolveServiceEndpoint(did, {
|
|
30
|
+
type: serviceType,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
return { did, url }
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DidCache,
|
|
3
|
+
IsomorphicDidResolver,
|
|
4
|
+
IsomorphicDidResolverOptions,
|
|
5
|
+
} from '@atproto-labs/did'
|
|
6
|
+
import { Fetch } from '@atproto-labs/fetch'
|
|
7
|
+
import UniversalHandleResolver, {
|
|
8
|
+
HandleResolverCache,
|
|
9
|
+
UniversalHandleResolverOptions,
|
|
10
|
+
} from '@atproto-labs/handle-resolver'
|
|
11
|
+
import { IdentityResolver } from './identity-resolver.js'
|
|
12
|
+
|
|
13
|
+
export type { DidCache, DidDocument } from '@atproto-labs/did'
|
|
14
|
+
export type {
|
|
15
|
+
HandleResolverCache,
|
|
16
|
+
ResolvedHandle,
|
|
17
|
+
} from '@atproto-labs/handle-resolver'
|
|
18
|
+
|
|
19
|
+
export type UniversalIdentityResolverOptions = {
|
|
20
|
+
fetch?: Fetch
|
|
21
|
+
|
|
22
|
+
didCache?: DidCache
|
|
23
|
+
handleCache?: HandleResolverCache
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @see {@link IsomorphicDidResolverOptions.plcDirectoryUrl}
|
|
27
|
+
*/
|
|
28
|
+
plcDirectoryUrl?: IsomorphicDidResolverOptions['plcDirectoryUrl']
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @see {@link UniversalHandleResolverOptions.atprotoLexiconUrl}
|
|
32
|
+
*/
|
|
33
|
+
atprotoLexiconUrl?: UniversalHandleResolverOptions['atprotoLexiconUrl']
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class UniversalIdentityResolver extends IdentityResolver {
|
|
37
|
+
static from({
|
|
38
|
+
fetch = globalThis.fetch,
|
|
39
|
+
didCache,
|
|
40
|
+
handleCache,
|
|
41
|
+
plcDirectoryUrl,
|
|
42
|
+
atprotoLexiconUrl,
|
|
43
|
+
}: UniversalIdentityResolverOptions) {
|
|
44
|
+
return new this(
|
|
45
|
+
new UniversalHandleResolver({
|
|
46
|
+
fetch,
|
|
47
|
+
cache: handleCache,
|
|
48
|
+
atprotoLexiconUrl,
|
|
49
|
+
}),
|
|
50
|
+
new IsomorphicDidResolver({
|
|
51
|
+
fetch, //
|
|
52
|
+
cache: didCache,
|
|
53
|
+
plcDirectoryUrl,
|
|
54
|
+
}),
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
}
|