@atproto/identity 0.3.3 → 0.4.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/did/atproto-data.d.ts +1 -0
  3. package/dist/did/atproto-data.d.ts.map +1 -0
  4. package/dist/did/atproto-data.js +92 -0
  5. package/dist/did/atproto-data.js.map +1 -0
  6. package/dist/did/base-resolver.d.ts +1 -0
  7. package/dist/did/base-resolver.d.ts.map +1 -0
  8. package/dist/did/base-resolver.js +105 -0
  9. package/dist/did/base-resolver.js.map +1 -0
  10. package/dist/did/did-resolver.d.ts +1 -0
  11. package/dist/did/did-resolver.d.ts.map +1 -0
  12. package/dist/did/did-resolver.js +41 -0
  13. package/dist/did/did-resolver.js.map +1 -0
  14. package/dist/did/index.d.ts +1 -0
  15. package/dist/did/index.d.ts.map +1 -0
  16. package/dist/did/index.js +22 -0
  17. package/dist/did/index.js.map +1 -0
  18. package/dist/did/memory-cache.d.ts +1 -0
  19. package/dist/did/memory-cache.d.ts.map +1 -0
  20. package/dist/did/memory-cache.js +59 -0
  21. package/dist/did/memory-cache.js.map +1 -0
  22. package/dist/did/plc-resolver.d.ts +1 -0
  23. package/dist/did/plc-resolver.d.ts.map +1 -0
  24. package/dist/did/plc-resolver.js +70 -0
  25. package/dist/did/plc-resolver.js.map +1 -0
  26. package/dist/did/web-resolver.d.ts +1 -0
  27. package/dist/did/web-resolver.d.ts.map +1 -0
  28. package/dist/did/web-resolver.js +85 -0
  29. package/dist/did/web-resolver.js.map +1 -0
  30. package/dist/errors.d.ts +1 -0
  31. package/dist/errors.d.ts.map +1 -0
  32. package/dist/errors.js +70 -0
  33. package/dist/errors.js.map +1 -0
  34. package/dist/handle/index.d.ts +1 -0
  35. package/dist/handle/index.d.ts.map +1 -0
  36. package/dist/handle/index.js +112 -0
  37. package/dist/handle/index.js.map +1 -0
  38. package/dist/id-resolver.d.ts +1 -0
  39. package/dist/id-resolver.d.ts.map +1 -0
  40. package/dist/id-resolver.js +32 -0
  41. package/dist/id-resolver.js.map +1 -0
  42. package/dist/index.d.ts +1 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +21 -28503
  45. package/dist/index.js.map +1 -7
  46. package/dist/types.d.ts +1 -0
  47. package/dist/types.d.ts.map +1 -0
  48. package/dist/types.js +6 -0
  49. package/dist/types.js.map +1 -0
  50. package/jest.config.js +4 -3
  51. package/package.json +8 -9
  52. package/src/did/web-resolver.ts +4 -1
  53. package/src/errors.ts +4 -1
  54. package/tsconfig.build.json +6 -2
  55. package/tsconfig.json +3 -9
  56. package/tsconfig.tests.json +7 -0
  57. package/babel.config.js +0 -3
  58. package/build.js +0 -15
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atproto/identity
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`ebb318325`](https://github.com/bluesky-social/atproto/commit/ebb318325b6e80c4ea1a93a617569da2698afe31)]:
8
+ - @atproto/crypto@0.4.1
9
+
10
+ ## 0.4.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [#2169](https://github.com/bluesky-social/atproto/pull/2169) [`f689bd51a`](https://github.com/bluesky-social/atproto/commit/f689bd51a2f4e02d4eca40eb2568a1fcb95494e9) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Build system rework, stop bundling dependencies.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [[`f689bd51a`](https://github.com/bluesky-social/atproto/commit/f689bd51a2f4e02d4eca40eb2568a1fcb95494e9)]:
19
+ - @atproto/common-web@0.3.0
20
+ - @atproto/crypto@0.4.0
21
+
3
22
  ## 0.3.3
4
23
 
5
24
  ### Patch Changes
@@ -9,3 +9,4 @@ export declare const getDidKeyFromMultibase: (key: {
9
9
  export declare const parseToAtprotoDocument: (doc: DidDocument) => Partial<AtprotoData>;
10
10
  export declare const ensureAtpDocument: (doc: DidDocument) => AtprotoData;
11
11
  export declare const ensureAtprotoKey: (doc: DidDocument) => string;
12
+ //# sourceMappingURL=atproto-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atproto-data.d.ts","sourceRoot":"","sources":["../../src/did/atproto-data.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EACL,MAAM,EACN,SAAS,EACT,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAEjB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EACL,MAAM,EACN,SAAS,EACT,cAAc,IAAI,MAAM,EACxB,kBAAkB,IAAI,UAAU,EAChC,gBAAgB,IAAI,QAAQ,GAC7B,CAAA;AAED,eAAO,MAAM,MAAM,QAAS,WAAW,KAAG,MAAM,GAAG,SAIlD,CAAA;AAED,eAAO,MAAM,sBAAsB,QAAS;IAC1C,IAAI,EAAE,MAAM,CAAA;IACZ,kBAAkB,EAAE,MAAM,CAAA;CAC3B,KAAG,MAAM,GAAG,SAYZ,CAAA;AAED,eAAO,MAAM,sBAAsB,QAC5B,WAAW,KACf,QAAQ,WAAW,CAQrB,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAS,WAAW,KAAG,WAepD,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAS,WAAW,KAAG,MAMnD,CAAA"}
@@ -0,0 +1,92 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ensureAtprotoKey = exports.ensureAtpDocument = exports.parseToAtprotoDocument = exports.getDidKeyFromMultibase = exports.getKey = exports.getNotif = exports.getFeedGen = exports.getPds = exports.getHandle = exports.getDid = void 0;
27
+ const crypto = __importStar(require("@atproto/crypto"));
28
+ const common_web_1 = require("@atproto/common-web");
29
+ Object.defineProperty(exports, "getDid", { enumerable: true, get: function () { return common_web_1.getDid; } });
30
+ Object.defineProperty(exports, "getHandle", { enumerable: true, get: function () { return common_web_1.getHandle; } });
31
+ Object.defineProperty(exports, "getPds", { enumerable: true, get: function () { return common_web_1.getPdsEndpoint; } });
32
+ Object.defineProperty(exports, "getFeedGen", { enumerable: true, get: function () { return common_web_1.getFeedGenEndpoint; } });
33
+ Object.defineProperty(exports, "getNotif", { enumerable: true, get: function () { return common_web_1.getNotifEndpoint; } });
34
+ const getKey = (doc) => {
35
+ const key = (0, common_web_1.getSigningKey)(doc);
36
+ if (!key)
37
+ return undefined;
38
+ return (0, exports.getDidKeyFromMultibase)(key);
39
+ };
40
+ exports.getKey = getKey;
41
+ const getDidKeyFromMultibase = (key) => {
42
+ const keyBytes = crypto.multibaseToBytes(key.publicKeyMultibase);
43
+ let didKey = undefined;
44
+ if (key.type === 'EcdsaSecp256r1VerificationKey2019') {
45
+ didKey = crypto.formatDidKey(crypto.P256_JWT_ALG, keyBytes);
46
+ }
47
+ else if (key.type === 'EcdsaSecp256k1VerificationKey2019') {
48
+ didKey = crypto.formatDidKey(crypto.SECP256K1_JWT_ALG, keyBytes);
49
+ }
50
+ else if (key.type === 'Multikey') {
51
+ const parsed = crypto.parseMultikey(key.publicKeyMultibase);
52
+ didKey = crypto.formatDidKey(parsed.jwtAlg, parsed.keyBytes);
53
+ }
54
+ return didKey;
55
+ };
56
+ exports.getDidKeyFromMultibase = getDidKeyFromMultibase;
57
+ const parseToAtprotoDocument = (doc) => {
58
+ const did = (0, common_web_1.getDid)(doc);
59
+ return {
60
+ did,
61
+ signingKey: (0, exports.getKey)(doc),
62
+ handle: (0, common_web_1.getHandle)(doc),
63
+ pds: (0, common_web_1.getPdsEndpoint)(doc),
64
+ };
65
+ };
66
+ exports.parseToAtprotoDocument = parseToAtprotoDocument;
67
+ const ensureAtpDocument = (doc) => {
68
+ const { did, signingKey, handle, pds } = (0, exports.parseToAtprotoDocument)(doc);
69
+ if (!did) {
70
+ throw new Error(`Could not parse id from doc: ${doc}`);
71
+ }
72
+ if (!signingKey) {
73
+ throw new Error(`Could not parse signingKey from doc: ${doc}`);
74
+ }
75
+ if (!handle) {
76
+ throw new Error(`Could not parse handle from doc: ${doc}`);
77
+ }
78
+ if (!pds) {
79
+ throw new Error(`Could not parse pds from doc: ${doc}`);
80
+ }
81
+ return { did, signingKey, handle, pds };
82
+ };
83
+ exports.ensureAtpDocument = ensureAtpDocument;
84
+ const ensureAtprotoKey = (doc) => {
85
+ const { signingKey } = (0, exports.parseToAtprotoDocument)(doc);
86
+ if (!signingKey) {
87
+ throw new Error(`Could not parse signingKey from doc: ${doc}`);
88
+ }
89
+ return signingKey;
90
+ };
91
+ exports.ensureAtprotoKey = ensureAtprotoKey;
92
+ //# sourceMappingURL=atproto-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atproto-data.js","sourceRoot":"","sources":["../../src/did/atproto-data.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAyC;AAEzC,oDAO4B;AAG1B,uFATA,mBAAM,OASA;AACN,0FATA,sBAAS,O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CAAC,CAAA;AANY,QAAA,gBAAgB,oBAM5B"}
@@ -13,3 +13,4 @@ export declare abstract class BaseResolver {
13
13
  verifySignature(did: string, data: Uint8Array, sig: Uint8Array, forceRefresh?: boolean): Promise<boolean>;
14
14
  }
15
15
  export default BaseResolver;
16
+ //# sourceMappingURL=base-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-resolver.d.ts","sourceRoot":"","sources":["../../src/did/base-resolver.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,WAAW,EAEX,WAAW,EACZ,MAAM,UAAU,CAAA;AAIjB,8BAAsB,YAAY;IACb,KAAK,CAAC;gBAAN,KAAK,CAAC,sBAAU;IAEnC,QAAQ,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAE7D,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,WAAW;IAUhD,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAMxD,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAQlE,OAAO,CACX,GAAG,EAAE,MAAM,EACX,YAAY,UAAQ,GACnB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAqBxB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,UAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;IAQtE,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,YAAY,UAAQ,GACnB,OAAO,CAAC,WAAW,CAAC;IAKjB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,UAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IASrE,eAAe,CACnB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,UAAU,EACf,YAAY,UAAQ,GACnB,OAAO,CAAC,OAAO,CAAC;CAIpB;AAED,eAAe,YAAY,CAAA"}
@@ -0,0 +1,105 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.BaseResolver = void 0;
27
+ const crypto = __importStar(require("@atproto/crypto"));
28
+ const common_web_1 = require("@atproto/common-web");
29
+ const types_1 = require("../types");
30
+ const atprotoData = __importStar(require("./atproto-data"));
31
+ const errors_1 = require("../errors");
32
+ class BaseResolver {
33
+ constructor(cache) {
34
+ Object.defineProperty(this, "cache", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true,
38
+ value: cache
39
+ });
40
+ }
41
+ validateDidDoc(did, val) {
42
+ if (!common_web_1.check.is(val, types_1.didDocument)) {
43
+ throw new errors_1.PoorlyFormattedDidDocumentError(did, val);
44
+ }
45
+ if (val.id !== did) {
46
+ throw new errors_1.PoorlyFormattedDidDocumentError(did, val);
47
+ }
48
+ return val;
49
+ }
50
+ async resolveNoCache(did) {
51
+ const got = await this.resolveNoCheck(did);
52
+ if (got === null)
53
+ return null;
54
+ return this.validateDidDoc(did, got);
55
+ }
56
+ async refreshCache(did, prevResult) {
57
+ await this.cache?.refreshCache(did, () => this.resolveNoCache(did), prevResult);
58
+ }
59
+ async resolve(did, forceRefresh = false) {
60
+ let fromCache = null;
61
+ if (this.cache && !forceRefresh) {
62
+ fromCache = await this.cache.checkCache(did);
63
+ if (fromCache && !fromCache.expired) {
64
+ if (fromCache?.stale) {
65
+ await this.refreshCache(did, fromCache);
66
+ }
67
+ return fromCache.doc;
68
+ }
69
+ }
70
+ const got = await this.resolveNoCache(did);
71
+ if (got === null) {
72
+ await this.cache?.clearEntry(did);
73
+ return null;
74
+ }
75
+ await this.cache?.cacheDid(did, got, fromCache ?? undefined);
76
+ return got;
77
+ }
78
+ async ensureResolve(did, forceRefresh = false) {
79
+ const result = await this.resolve(did, forceRefresh);
80
+ if (result === null) {
81
+ throw new errors_1.DidNotFoundError(did);
82
+ }
83
+ return result;
84
+ }
85
+ async resolveAtprotoData(did, forceRefresh = false) {
86
+ const didDocument = await this.ensureResolve(did, forceRefresh);
87
+ return atprotoData.ensureAtpDocument(didDocument);
88
+ }
89
+ async resolveAtprotoKey(did, forceRefresh = false) {
90
+ if (did.startsWith('did:key:')) {
91
+ return did;
92
+ }
93
+ else {
94
+ const didDocument = await this.ensureResolve(did, forceRefresh);
95
+ return atprotoData.ensureAtprotoKey(didDocument);
96
+ }
97
+ }
98
+ async verifySignature(did, data, sig, forceRefresh = false) {
99
+ const signingKey = await this.resolveAtprotoKey(did, forceRefresh);
100
+ return crypto.verifySignature(signingKey, data, sig);
101
+ }
102
+ }
103
+ exports.BaseResolver = BaseResolver;
104
+ exports.default = BaseResolver;
105
+ //# sourceMappingURL=base-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-resolver.js","sourceRoot":"","sources":["../../src/did/base-resolver.ts"],"names":[],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A;QACZ,CAAC;aAAM,CAAC;YACN,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,YAAY,CAAC,CAAA;YAC/D,OAAO,WAAW,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAA;QAClD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,GAAW,EACX,IAAgB,EAChB,GAAe,EACf,YAAY,GAAG,KAAK;QAEpB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAA;QAClE,OAAO,MAAM,CAAC,eAAe,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;IACtD,CAAC;CACF;AAvFD,oCAuFC;AAED,kBAAe,YAAY,CAAA"}
@@ -6,3 +6,4 @@ export declare class DidResolver extends BaseResolver {
6
6
  resolveNoCheck(did: string): Promise<unknown>;
7
7
  }
8
8
  export default DidResolver;
9
+ //# sourceMappingURL=did-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did-resolver.d.ts","sourceRoot":"","sources":["../../src/did/did-resolver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,YAAY,MAAM,iBAAiB,CAAA;AAG1C,qBAAa,WAAY,SAAQ,YAAY;IAC3C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;gBAEzB,IAAI,EAAE,eAAe;IAU3B,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAWpD;AAED,eAAe,WAAW,CAAA"}
@@ -0,0 +1,41 @@
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.DidResolver = void 0;
7
+ const web_resolver_1 = require("./web-resolver");
8
+ const plc_resolver_1 = require("./plc-resolver");
9
+ const base_resolver_1 = __importDefault(require("./base-resolver"));
10
+ const errors_1 = require("../errors");
11
+ class DidResolver extends base_resolver_1.default {
12
+ constructor(opts) {
13
+ super(opts.didCache);
14
+ Object.defineProperty(this, "methods", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: void 0
19
+ });
20
+ const { timeout = 3000, plcUrl = 'https://plc.directory' } = opts;
21
+ // do not pass cache to sub-methods or we will be double caching
22
+ this.methods = {
23
+ plc: new plc_resolver_1.DidPlcResolver(plcUrl, timeout),
24
+ web: new web_resolver_1.DidWebResolver(timeout),
25
+ };
26
+ }
27
+ async resolveNoCheck(did) {
28
+ const split = did.split(':');
29
+ if (split[0] !== 'did') {
30
+ throw new errors_1.PoorlyFormattedDidError(did);
31
+ }
32
+ const method = this.methods[split[1]];
33
+ if (!method) {
34
+ throw new errors_1.UnsupportedDidMethodError(did);
35
+ }
36
+ return method.resolveNoCheck(did);
37
+ }
38
+ }
39
+ exports.DidResolver = DidResolver;
40
+ exports.default = DidResolver;
41
+ //# sourceMappingURL=did-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did-resolver.js","sourceRoot":"","sources":["../../src/did/did-resolver.ts"],"names":[],"mappings":";;;;;;AAAA,iDAA+C;AAC/C,iDAA+C;AAE/C,oEAA0C;AAC1C,sCAA8E;AAE9E,MAAa,WAAY,SAAQ,uBAAY;IAG3C,YAAY,IAAqB;QAC/B,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAHtB;;;;;WAAqC;QAInC,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,MAAM,GAAG,uBAAuB,EAAE,GAAG,IAAI,CAAA;QACjE,gEAAgE;QAChE,IAAI,CAAC,OAAO,GAAG;YACb,GAAG,EAAE,IAAI,6BAAc,CAAC,MAAM,EAAE,OAAO,CAAC;YACxC,GAAG,EAAE,IAAI,6BAAc,CAAC,OAAO,CAAC;SACjC,CAAA;IACH,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAW;QAC9B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC5B,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC;YACvB,MAAM,IAAI,gCAAuB,CAAC,GAAG,CAAC,CAAA;QACxC,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QACrC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,kCAAyB,CAAC,GAAG,CAAC,CAAA;QAC1C,CAAC;QACD,OAAO,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;IACnC,CAAC;CACF;AAxBD,kCAwBC;AAED,kBAAe,WAAW,CAAA"}
@@ -3,3 +3,4 @@ export * from './plc-resolver';
3
3
  export * from './did-resolver';
4
4
  export * from './atproto-data';
5
5
  export * from './memory-cache';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/did/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,22 @@
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("./web-resolver"), exports);
18
+ __exportStar(require("./plc-resolver"), exports);
19
+ __exportStar(require("./did-resolver"), exports);
20
+ __exportStar(require("./atproto-data"), exports);
21
+ __exportStar(require("./memory-cache"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/did/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,iDAA8B;AAC9B,iDAA8B;AAC9B,iDAA8B;AAC9B,iDAA8B"}
@@ -15,3 +15,4 @@ export declare class MemoryCache implements DidCache {
15
15
  clear(): Promise<void>;
16
16
  }
17
17
  export {};
18
+ //# sourceMappingURL=memory-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-cache.d.ts","sourceRoot":"","sources":["../../src/did/memory-cache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE7D,KAAK,QAAQ,GAAG;IACd,GAAG,EAAE,WAAW,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,qBAAa,WAAY,YAAW,QAAQ;IACnC,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;gBACT,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAKvC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAY;IAEzC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,YAAY,CAChB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,GACxC,OAAO,CAAC,IAAI,CAAC;IAOV,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAcpD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoryCache = void 0;
4
+ const common_web_1 = require("@atproto/common-web");
5
+ class MemoryCache {
6
+ constructor(staleTTL, maxTTL) {
7
+ Object.defineProperty(this, "staleTTL", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: void 0
12
+ });
13
+ Object.defineProperty(this, "maxTTL", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: void 0
18
+ });
19
+ Object.defineProperty(this, "cache", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: new Map()
24
+ });
25
+ this.staleTTL = staleTTL ?? common_web_1.HOUR;
26
+ this.maxTTL = maxTTL ?? common_web_1.DAY;
27
+ }
28
+ async cacheDid(did, doc) {
29
+ this.cache.set(did, { doc, updatedAt: Date.now() });
30
+ }
31
+ async refreshCache(did, getDoc) {
32
+ const doc = await getDoc();
33
+ if (doc) {
34
+ await this.cacheDid(did, doc);
35
+ }
36
+ }
37
+ async checkCache(did) {
38
+ const val = this.cache.get(did);
39
+ if (!val)
40
+ return null;
41
+ const now = Date.now();
42
+ const expired = now > val.updatedAt + this.maxTTL;
43
+ const stale = now > val.updatedAt + this.staleTTL;
44
+ return {
45
+ ...val,
46
+ did,
47
+ stale,
48
+ expired,
49
+ };
50
+ }
51
+ async clearEntry(did) {
52
+ this.cache.delete(did);
53
+ }
54
+ async clear() {
55
+ this.cache.clear();
56
+ }
57
+ }
58
+ exports.MemoryCache = MemoryCache;
59
+ //# sourceMappingURL=memory-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-cache.js","sourceRoot":"","sources":["../../src/did/memory-cache.ts"],"names":[],"mappings":";;;AAAA,oDAA+C;AAQ/C,MAAa,WAAW;IAGtB,YAAY,QAAiB,EAAE,MAAe;QAFvC;;;;;WAAgB;QAChB;;;;;WAAc;QAMd;;;;mBAA+B,IAAI,GAAG,EAAE;WAAA;QAJ7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,iBAAI,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,gBAAG,CAAA;IAC7B,CAAC;IAID,KAAK,CAAC,QAAQ,CAAC,GAAW,EAAE,GAAgB;QAC1C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IACrD,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,GAAW,EACX,MAAyC;QAEzC,MAAM,GAAG,GAAG,MAAM,MAAM,EAAE,CAAA;QAC1B,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC/B,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAA;QACrB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,MAAM,OAAO,GAAG,GAAG,GAAG,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAA;QACjD,MAAM,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAA;QACjD,OAAO;YACL,GAAG,GAAG;YACN,GAAG;YACH,KAAK;YACL,OAAO;SACR,CAAA;IACH,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;CACF;AA7CD,kCA6CC"}
@@ -7,3 +7,4 @@ export declare class DidPlcResolver extends BaseResolver {
7
7
  constructor(plcUrl: string, timeout: number, cache?: DidCache | undefined);
8
8
  resolveNoCheck(did: string): Promise<unknown>;
9
9
  }
10
+ //# sourceMappingURL=plc-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plc-resolver.d.ts","sourceRoot":"","sources":["../../src/did/plc-resolver.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,qBAAa,cAAe,SAAQ,YAAY;IAErC,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,MAAM;IACf,KAAK,CAAC;gBAFN,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,sBAAU;IAKnB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAapD"}
@@ -0,0 +1,70 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.DidPlcResolver = void 0;
30
+ const axios_1 = __importStar(require("axios"));
31
+ const base_resolver_1 = __importDefault(require("./base-resolver"));
32
+ class DidPlcResolver extends base_resolver_1.default {
33
+ constructor(plcUrl, timeout, cache) {
34
+ super(cache);
35
+ Object.defineProperty(this, "plcUrl", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: plcUrl
40
+ });
41
+ Object.defineProperty(this, "timeout", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: timeout
46
+ });
47
+ Object.defineProperty(this, "cache", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: cache
52
+ });
53
+ }
54
+ async resolveNoCheck(did) {
55
+ try {
56
+ const res = await axios_1.default.get(`${this.plcUrl}/${encodeURIComponent(did)}`, {
57
+ timeout: this.timeout,
58
+ });
59
+ return res.data;
60
+ }
61
+ catch (err) {
62
+ if (err instanceof axios_1.AxiosError && err.response?.status === 404) {
63
+ return null; // Positively not found, versus due to e.g. network error
64
+ }
65
+ throw err;
66
+ }
67
+ }
68
+ }
69
+ exports.DidPlcResolver = DidPlcResolver;
70
+ //# sourceMappingURL=plc-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plc-resolver.js","sourceRoot":"","sources":["../../src/did/plc-resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAyC;AACzC,oEAA0C;AAG1C,MAAa,cAAe,SAAQ,uBAAY;IAC9C,YACS,MAAc,EACd,OAAe,EACf,KAAgB;QAEvB,KAAK,CAAC,KAAK,CAAC,CAAA;QAJZ;;;;mBAAO,MAAM;WAAQ;QACrB;;;;mBAAO,OAAO;WAAQ;QACtB;;;;mBAAO,KAAK;WAAW;IAGzB,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAW;QAC9B,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,kBAAkB,CAAC,GAAG,CAAC,EAAE,EAAE;gBACvE,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAA;YACF,OAAO,GAAG,CAAC,IAAI,CAAA;QACjB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,kBAAU,IAAI,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC;gBAC9D,OAAO,IAAI,CAAA,CAAC,yDAAyD;YACvE,CAAC;YACD,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;CACF;AAtBD,wCAsBC"}
@@ -7,3 +7,4 @@ export declare class DidWebResolver extends BaseResolver {
7
7
  constructor(timeout: number, cache?: DidCache | undefined);
8
8
  resolveNoCheck(did: string): Promise<unknown>;
9
9
  }
10
+ //# sourceMappingURL=web-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-resolver.d.ts","sourceRoot":"","sources":["../../src/did/web-resolver.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAGnC,eAAO,MAAM,QAAQ,0BAA0B,CAAA;AAE/C,qBAAa,cAAe,SAAQ,YAAY;IAErC,OAAO,EAAE,MAAM;IACf,KAAK,CAAC;gBADN,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,sBAAU;IAKnB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAgCpD"}
@@ -0,0 +1,85 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.DidWebResolver = exports.DOC_PATH = void 0;
30
+ const axios_1 = __importStar(require("axios"));
31
+ const base_resolver_1 = __importDefault(require("./base-resolver"));
32
+ const errors_1 = require("../errors");
33
+ exports.DOC_PATH = '/.well-known/did.json';
34
+ class DidWebResolver extends base_resolver_1.default {
35
+ constructor(timeout, cache) {
36
+ super(cache);
37
+ Object.defineProperty(this, "timeout", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: timeout
42
+ });
43
+ Object.defineProperty(this, "cache", {
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true,
47
+ value: cache
48
+ });
49
+ }
50
+ async resolveNoCheck(did) {
51
+ const parsedId = did.split(':').slice(2).join(':');
52
+ const parts = parsedId.split(':').map(decodeURIComponent);
53
+ let path;
54
+ if (parts.length < 1) {
55
+ throw new errors_1.PoorlyFormattedDidError(did);
56
+ }
57
+ else if (parts.length === 1) {
58
+ path = parts[0] + exports.DOC_PATH;
59
+ }
60
+ else {
61
+ // how we *would* resolve a did:web with path, if atproto supported it
62
+ //path = parts.join('/') + '/did.json'
63
+ throw new errors_1.UnsupportedDidWebPathError(did);
64
+ }
65
+ const url = new URL(`https://${path}`);
66
+ if (url.hostname === 'localhost') {
67
+ url.protocol = 'http';
68
+ }
69
+ try {
70
+ const res = await axios_1.default.get(url.toString(), {
71
+ responseType: 'json',
72
+ timeout: this.timeout,
73
+ });
74
+ return res.data;
75
+ }
76
+ catch (err) {
77
+ if (err instanceof axios_1.AxiosError && err.response) {
78
+ return null; // Positively not found, versus due to e.g. network error
79
+ }
80
+ throw err;
81
+ }
82
+ }
83
+ }
84
+ exports.DidWebResolver = DidWebResolver;
85
+ //# sourceMappingURL=web-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-resolver.js","sourceRoot":"","sources":["../../src/did/web-resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAyC;AACzC,oEAA0C;AAE1C,sCAA+E;AAElE,QAAA,QAAQ,GAAG,uBAAuB,CAAA;AAE/C,MAAa,cAAe,SAAQ,uBAAY;IAC9C,YACS,OAAe,EACf,KAAgB;QAEvB,KAAK,CAAC,KAAK,CAAC,CAAA;QAHZ;;;;mBAAO,OAAO;WAAQ;QACtB;;;;mBAAO,KAAK;WAAW;IAGzB,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAW;QAC9B,MAAM,QAAQ,GAAG,GAAG,CA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,4 @@ export declare class UnsupportedDidWebPathError extends Error {
19
19
  did: string;
20
20
  constructor(did: string);
21
21
  }
22
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,gBAAiB,SAAQ,KAAK;IACtB,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM;CAG/B;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAC7B,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM;CAG/B;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IAC/B,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM;CAG/B;AAED,qBAAa,+BAAgC,SAAQ,KAAK;IAE/C,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,OAAO;gBADZ,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,OAAO;CAItB;AAED,qBAAa,0BAA2B,SAAQ,KAAK;IAChC,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM;CAG/B"}