@atproto/identity 0.4.12 → 0.5.0-next.0
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 +20 -0
- package/dist/did/atproto-data.d.ts +1 -1
- package/dist/did/atproto-data.d.ts.map +1 -1
- package/dist/did/atproto-data.js +16 -61
- package/dist/did/atproto-data.js.map +1 -1
- package/dist/did/base-resolver.d.ts +1 -1
- package/dist/did/base-resolver.d.ts.map +1 -1
- package/dist/did/base-resolver.js +11 -53
- package/dist/did/base-resolver.js.map +1 -1
- package/dist/did/did-resolver.d.ts +2 -2
- package/dist/did/did-resolver.d.ts.map +1 -1
- package/dist/did/did-resolver.js +10 -20
- package/dist/did/did-resolver.js.map +1 -1
- package/dist/did/index.d.ts +5 -5
- package/dist/did/index.d.ts.map +1 -1
- package/dist/did/index.js +5 -21
- package/dist/did/index.js.map +1 -1
- package/dist/did/memory-cache.d.ts +1 -1
- package/dist/did/memory-cache.d.ts.map +1 -1
- package/dist/did/memory-cache.js +5 -26
- package/dist/did/memory-cache.js.map +1 -1
- package/dist/did/plc-resolver.d.ts +2 -2
- package/dist/did/plc-resolver.d.ts.map +1 -1
- package/dist/did/plc-resolver.js +7 -26
- package/dist/did/plc-resolver.js.map +1 -1
- package/dist/did/util.js +1 -4
- package/dist/did/util.js.map +1 -1
- package/dist/did/web-resolver.d.ts +2 -2
- package/dist/did/web-resolver.d.ts.map +1 -1
- package/dist/did/web-resolver.js +11 -25
- package/dist/did/web-resolver.js.map +1 -1
- package/dist/errors.js +11 -49
- package/dist/errors.js.map +1 -1
- package/dist/handle/index.d.ts +1 -1
- package/dist/handle/index.d.ts.map +1 -1
- package/dist/handle/index.js +6 -31
- package/dist/handle/index.js.map +1 -1
- package/dist/id-resolver.d.ts +3 -3
- package/dist/id-resolver.d.ts.map +1 -1
- package/dist/id-resolver.js +5 -21
- package/dist/id-resolver.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -21
- package/dist/index.js.map +1 -1
- package/dist/types.js +1 -5
- package/dist/types.js.map +1 -1
- package/{jest.config.js → jest.config.cjs} +8 -2
- package/package.json +15 -9
- package/src/did/atproto-data.ts +1 -1
- package/src/did/base-resolver.ts +3 -3
- package/src/did/did-resolver.ts +8 -5
- package/src/did/index.ts +5 -5
- package/src/did/memory-cache.ts +1 -1
- package/src/did/plc-resolver.ts +3 -3
- package/src/did/web-resolver.ts +7 -4
- package/src/handle/index.ts +2 -2
- package/src/id-resolver.ts +3 -3
- package/src/index.ts +5 -5
- package/test.log +60 -0
- package/tests/did-cache.test.ts +2 -2
- package/tests/did-document.test.ts +1 -1
- package/tests/did-resolver.test.ts +3 -3
- package/tests/handle-resolver.test.ts +5 -3
- package/tests/web/db.ts +1 -1
- package/tests/web/server.ts +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @atproto/identity
|
|
2
2
|
|
|
3
|
+
## 0.5.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#4929](https://github.com/bluesky-social/atproto/pull/4929) [`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Drop support for Node.js 18 and 20. Node.js 22 is now the minimum supported version. Docker images now use Node.js 24.
|
|
8
|
+
|
|
9
|
+
- [#4943](https://github.com/bluesky-social/atproto/pull/4943) [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Convert to pure ESM. All packages now ship `"type": "module"` with ES module output and Node16 module resolution.
|
|
10
|
+
|
|
11
|
+
Node.js 22's `require()` compatibility layer can still load these packages in CommonJS code.
|
|
12
|
+
|
|
13
|
+
- [#4930](https://github.com/bluesky-social/atproto/pull/4930) [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9) Thanks [@devinivy](https://github.com/devinivy)! - Build with TypeScript 6.0. Emitted `.d.ts` files now use TypeScript 6's stricter `Uint8Array<ArrayBuffer>` typing in places where Web/Node APIs require buffer-backed (not shared-memory) byte arrays. Consumers compiling against these types on older TypeScript should see no runtime impact, but may need to widen or cast in spots that previously relied on `Uint8Array` defaulting to `<ArrayBufferLike>`.
|
|
14
|
+
|
|
15
|
+
Internal: tsconfig `moduleResolution: "node"` is silenced via `ignoreDeprecations: "6.0"` for now; the proper migration to `node16`/`bundler` resolution is deferred.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b), [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028), [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9)]:
|
|
20
|
+
- @atproto/common-web@0.5.0-next.0
|
|
21
|
+
- @atproto/crypto@0.5.0-next.0
|
|
22
|
+
|
|
3
23
|
## 0.4.12
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getDid, getFeedGenEndpoint, getHandle, getNotifEndpoint, getPdsEndpoint } from '@atproto/common-web';
|
|
2
|
-
import { AtprotoData, DidDocument } from '../types';
|
|
2
|
+
import { AtprotoData, DidDocument } from '../types.js';
|
|
3
3
|
export { getDid, getFeedGenEndpoint as getFeedGen, getHandle, getNotifEndpoint as getNotif, getPdsEndpoint as getPds, };
|
|
4
4
|
export declare const getKey: (doc: DidDocument) => string | undefined;
|
|
5
5
|
export declare const getDidKeyFromMultibase: (key: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atproto-data.d.ts","sourceRoot":"","sources":["../../src/did/atproto-data.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,cAAc,EAEf,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"atproto-data.d.ts","sourceRoot":"","sources":["../../src/did/atproto-data.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,cAAc,EAEf,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEtD,OAAO,EACL,MAAM,EACN,kBAAkB,IAAI,UAAU,EAChC,SAAS,EACT,gBAAgB,IAAI,QAAQ,EAC5B,cAAc,IAAI,MAAM,GACzB,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,KAAK,WAAW,KAAG,MAAM,GAAG,SAIlD,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,KAAK;IAC1C,IAAI,EAAE,MAAM,CAAA;IACZ,kBAAkB,EAAE,MAAM,CAAA;CAC3B,KAAG,MAAM,GAAG,SAYZ,CAAA;AAED,eAAO,MAAM,sBAAsB,GACjC,KAAK,WAAW,KACf,OAAO,CAAC,WAAW,CAQrB,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,KAAK,WAAW,KAAG,WAepD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,KAAK,WAAW,KAAG,MAMnD,CAAA"}
|
package/dist/did/atproto-data.js
CHANGED
|
@@ -1,54 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ensureAtprotoKey = exports.ensureAtpDocument = exports.parseToAtprotoDocument = exports.getDidKeyFromMultibase = exports.getKey = exports.getPds = exports.getNotif = exports.getHandle = exports.getFeedGen = exports.getDid = void 0;
|
|
37
|
-
const common_web_1 = require("@atproto/common-web");
|
|
38
|
-
Object.defineProperty(exports, "getDid", { enumerable: true, get: function () { return common_web_1.getDid; } });
|
|
39
|
-
Object.defineProperty(exports, "getFeedGen", { enumerable: true, get: function () { return common_web_1.getFeedGenEndpoint; } });
|
|
40
|
-
Object.defineProperty(exports, "getHandle", { enumerable: true, get: function () { return common_web_1.getHandle; } });
|
|
41
|
-
Object.defineProperty(exports, "getNotif", { enumerable: true, get: function () { return common_web_1.getNotifEndpoint; } });
|
|
42
|
-
Object.defineProperty(exports, "getPds", { enumerable: true, get: function () { return common_web_1.getPdsEndpoint; } });
|
|
43
|
-
const crypto = __importStar(require("@atproto/crypto"));
|
|
44
|
-
const getKey = (doc) => {
|
|
45
|
-
const key = (0, common_web_1.getSigningKey)(doc);
|
|
1
|
+
import { getDid, getFeedGenEndpoint, getHandle, getNotifEndpoint, getPdsEndpoint, getSigningKey, } from '@atproto/common-web';
|
|
2
|
+
import * as crypto from '@atproto/crypto';
|
|
3
|
+
export { getDid, getFeedGenEndpoint as getFeedGen, getHandle, getNotifEndpoint as getNotif, getPdsEndpoint as getPds, };
|
|
4
|
+
export const getKey = (doc) => {
|
|
5
|
+
const key = getSigningKey(doc);
|
|
46
6
|
if (!key)
|
|
47
7
|
return undefined;
|
|
48
|
-
return
|
|
8
|
+
return getDidKeyFromMultibase(key);
|
|
49
9
|
};
|
|
50
|
-
|
|
51
|
-
const getDidKeyFromMultibase = (key) => {
|
|
10
|
+
export const getDidKeyFromMultibase = (key) => {
|
|
52
11
|
const keyBytes = crypto.multibaseToBytes(key.publicKeyMultibase);
|
|
53
12
|
let didKey = undefined;
|
|
54
13
|
if (key.type === 'EcdsaSecp256r1VerificationKey2019') {
|
|
@@ -63,19 +22,17 @@ const getDidKeyFromMultibase = (key) => {
|
|
|
63
22
|
}
|
|
64
23
|
return didKey;
|
|
65
24
|
};
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
const did = (0, common_web_1.getDid)(doc);
|
|
25
|
+
export const parseToAtprotoDocument = (doc) => {
|
|
26
|
+
const did = getDid(doc);
|
|
69
27
|
return {
|
|
70
28
|
did,
|
|
71
|
-
signingKey:
|
|
72
|
-
handle:
|
|
73
|
-
pds:
|
|
29
|
+
signingKey: getKey(doc),
|
|
30
|
+
handle: getHandle(doc),
|
|
31
|
+
pds: getPdsEndpoint(doc),
|
|
74
32
|
};
|
|
75
33
|
};
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
const { did, signingKey, handle, pds } = (0, exports.parseToAtprotoDocument)(doc);
|
|
34
|
+
export const ensureAtpDocument = (doc) => {
|
|
35
|
+
const { did, signingKey, handle, pds } = parseToAtprotoDocument(doc);
|
|
79
36
|
if (!did) {
|
|
80
37
|
throw new Error(`Could not parse id from doc: ${doc}`);
|
|
81
38
|
}
|
|
@@ -90,13 +47,11 @@ const ensureAtpDocument = (doc) => {
|
|
|
90
47
|
}
|
|
91
48
|
return { did, signingKey, handle, pds };
|
|
92
49
|
};
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
const { signingKey } = (0, exports.parseToAtprotoDocument)(doc);
|
|
50
|
+
export const ensureAtprotoKey = (doc) => {
|
|
51
|
+
const { signingKey } = parseToAtprotoDocument(doc);
|
|
96
52
|
if (!signingKey) {
|
|
97
53
|
throw new Error(`Could not parse signingKey from doc: ${doc}`);
|
|
98
54
|
}
|
|
99
55
|
return signingKey;
|
|
100
56
|
};
|
|
101
|
-
exports.ensureAtprotoKey = ensureAtprotoKey;
|
|
102
57
|
//# sourceMappingURL=atproto-data.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atproto-data.js","sourceRoot":"","sources":["../../src/did/atproto-data.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"atproto-data.js","sourceRoot":"","sources":["../../src/did/atproto-data.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,aAAa,GACd,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,MAAM,MAAM,iBAAiB,CAAA;AAGzC,OAAO,EACL,MAAM,EACN,kBAAkB,IAAI,UAAU,EAChC,SAAS,EACT,gBAAgB,IAAI,QAAQ,EAC5B,cAAc,IAAI,MAAM,GACzB,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAgB,EAAsB,EAAE;IAC7D,MAAM,GAAG,GA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AM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAgB,EAAe,EAAE;IACjE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAA;IACpE,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,gCAAgC,GAAG,EAAE,CAAC,CAAA;IACxD,CAAC;IACD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,wCAAwC,GAAG,EAAE,CAAC,CAAA;IAChE,CAAC;IACD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,oCAAoC,GAAG,EAAE,CAAC,CAAA;IAC5D,CAAC;IACD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,EAAE,CAAC,CAAA;IACzD,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,CAAA;AACzC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAgB,EAAU,EAAE;IAC3D,MAAM,EAAE,UAAU,EAAE,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAA;IAClD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,wCAAwC,GAAG,EAAE,CAAC,CAAA;IAChE,CAAC;IACD,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA","sourcesContent":["import {\n getDid,\n getFeedGenEndpoint,\n getHandle,\n getNotifEndpoint,\n getPdsEndpoint,\n getSigningKey,\n} from '@atproto/common-web'\nimport * as crypto from '@atproto/crypto'\nimport { AtprotoData, DidDocument } from '../types.js'\n\nexport {\n getDid,\n getFeedGenEndpoint as getFeedGen,\n getHandle,\n getNotifEndpoint as getNotif,\n getPdsEndpoint as getPds,\n}\n\nexport const getKey = (doc: DidDocument): string | undefined => {\n const key = getSigningKey(doc)\n if (!key) return undefined\n return getDidKeyFromMultibase(key)\n}\n\nexport const getDidKeyFromMultibase = (key: {\n type: string\n publicKeyMultibase: string\n}): string | undefined => {\n const keyBytes = crypto.multibaseToBytes(key.publicKeyMultibase)\n let didKey: string | undefined = undefined\n if (key.type === 'EcdsaSecp256r1VerificationKey2019') {\n didKey = crypto.formatDidKey(crypto.P256_JWT_ALG, keyBytes)\n } else if (key.type === 'EcdsaSecp256k1VerificationKey2019') {\n didKey = crypto.formatDidKey(crypto.SECP256K1_JWT_ALG, keyBytes)\n } else if (key.type === 'Multikey') {\n const parsed = crypto.parseMultikey(key.publicKeyMultibase)\n didKey = crypto.formatDidKey(parsed.jwtAlg, parsed.keyBytes)\n }\n return didKey\n}\n\nexport const parseToAtprotoDocument = (\n doc: DidDocument,\n): Partial<AtprotoData> => {\n const did = getDid(doc)\n return {\n did,\n signingKey: getKey(doc),\n handle: getHandle(doc),\n pds: getPdsEndpoint(doc),\n }\n}\n\nexport const ensureAtpDocument = (doc: DidDocument): AtprotoData => {\n const { did, signingKey, handle, pds } = parseToAtprotoDocument(doc)\n if (!did) {\n throw new Error(`Could not parse id from doc: ${doc}`)\n }\n if (!signingKey) {\n throw new Error(`Could not parse signingKey from doc: ${doc}`)\n }\n if (!handle) {\n throw new Error(`Could not parse handle from doc: ${doc}`)\n }\n if (!pds) {\n throw new Error(`Could not parse pds from doc: ${doc}`)\n }\n return { did, signingKey, handle, pds }\n}\n\nexport const ensureAtprotoKey = (doc: DidDocument): string => {\n const { signingKey } = parseToAtprotoDocument(doc)\n if (!signingKey) {\n throw new Error(`Could not parse signingKey from doc: ${doc}`)\n }\n return signingKey\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AtprotoData, CacheResult, DidCache, DidDocument } from '../types';
|
|
1
|
+
import { AtprotoData, CacheResult, DidCache, DidDocument } from '../types.js';
|
|
2
2
|
export declare abstract class BaseResolver {
|
|
3
3
|
cache?: DidCache | undefined;
|
|
4
4
|
constructor(cache?: DidCache | undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-resolver.d.ts","sourceRoot":"","sources":["../../src/did/base-resolver.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EACR,WAAW,EAEZ,MAAM,
|
|
1
|
+
{"version":3,"file":"base-resolver.d.ts","sourceRoot":"","sources":["../../src/did/base-resolver.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EACR,WAAW,EAEZ,MAAM,aAAa,CAAA;AAGpB,8BAAsB,YAAY;IACb,KAAK,CAAC,EAAE,QAAQ;gBAAhB,KAAK,CAAC,EAAE,QAAQ,YAAA;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"}
|
|
@@ -1,59 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.BaseResolver = void 0;
|
|
37
|
-
const common_web_1 = require("@atproto/common-web");
|
|
38
|
-
const crypto = __importStar(require("@atproto/crypto"));
|
|
39
|
-
const errors_1 = require("../errors");
|
|
40
|
-
const types_1 = require("../types");
|
|
41
|
-
const atprotoData = __importStar(require("./atproto-data"));
|
|
42
|
-
class BaseResolver {
|
|
1
|
+
import { check } from '@atproto/common-web';
|
|
2
|
+
import * as crypto from '@atproto/crypto';
|
|
3
|
+
import { DidNotFoundError, PoorlyFormattedDidDocumentError } from '../errors.js';
|
|
4
|
+
import { didDocument, } from '../types.js';
|
|
5
|
+
import * as atprotoData from './atproto-data.js';
|
|
6
|
+
export class BaseResolver {
|
|
43
7
|
constructor(cache) {
|
|
44
|
-
|
|
45
|
-
enumerable: true,
|
|
46
|
-
configurable: true,
|
|
47
|
-
writable: true,
|
|
48
|
-
value: cache
|
|
49
|
-
});
|
|
8
|
+
this.cache = cache;
|
|
50
9
|
}
|
|
51
10
|
validateDidDoc(did, val) {
|
|
52
|
-
if (!
|
|
53
|
-
throw new
|
|
11
|
+
if (!check.is(val, didDocument)) {
|
|
12
|
+
throw new PoorlyFormattedDidDocumentError(did, val);
|
|
54
13
|
}
|
|
55
14
|
if (val.id !== did) {
|
|
56
|
-
throw new
|
|
15
|
+
throw new PoorlyFormattedDidDocumentError(did, val);
|
|
57
16
|
}
|
|
58
17
|
return val;
|
|
59
18
|
}
|
|
@@ -88,7 +47,7 @@ class BaseResolver {
|
|
|
88
47
|
async ensureResolve(did, forceRefresh = false) {
|
|
89
48
|
const result = await this.resolve(did, forceRefresh);
|
|
90
49
|
if (result === null) {
|
|
91
|
-
throw new
|
|
50
|
+
throw new DidNotFoundError(did);
|
|
92
51
|
}
|
|
93
52
|
return result;
|
|
94
53
|
}
|
|
@@ -110,5 +69,4 @@ class BaseResolver {
|
|
|
110
69
|
return crypto.verifySignature(signingKey, data, sig);
|
|
111
70
|
}
|
|
112
71
|
}
|
|
113
|
-
exports.BaseResolver = BaseResolver;
|
|
114
72
|
//# sourceMappingURL=base-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-resolver.js","sourceRoot":"","sources":["../../src/did/base-resolver.ts"],"names":[],"mappings":"
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Y,CAAC,CAAA;QAC/D,OAAO,WAAW,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAA;IACnD,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,GAAW,EAAE,YAAY,GAAG,KAAK;QACvD,IAAI,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,OAAO,GAAG,CAAA;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","sourcesContent":["import { check } from '@atproto/common-web'\nimport * as crypto from '@atproto/crypto'\nimport { DidNotFoundError, PoorlyFormattedDidDocumentError } from '../errors.js'\nimport {\n AtprotoData,\n CacheResult,\n DidCache,\n DidDocument,\n didDocument,\n} from '../types.js'\nimport * as atprotoData from './atproto-data.js'\n\nexport abstract class BaseResolver {\n constructor(public cache?: DidCache) {}\n\n abstract resolveNoCheck(did: string): Promise<unknown | null>\n\n validateDidDoc(did: string, val: unknown): DidDocument {\n if (!check.is(val, didDocument)) {\n throw new PoorlyFormattedDidDocumentError(did, val)\n }\n if (val.id !== did) {\n throw new PoorlyFormattedDidDocumentError(did, val)\n }\n return val\n }\n\n async resolveNoCache(did: string): Promise<DidDocument | null> {\n const got = await this.resolveNoCheck(did)\n if (got === null) return null\n return this.validateDidDoc(did, got)\n }\n\n async refreshCache(did: string, prevResult?: CacheResult): Promise<void> {\n await this.cache?.refreshCache(\n did,\n () => this.resolveNoCache(did),\n prevResult,\n )\n }\n\n async resolve(\n did: string,\n forceRefresh = false,\n ): Promise<DidDocument | null> {\n let fromCache: CacheResult | null = null\n if (this.cache && !forceRefresh) {\n fromCache = await this.cache.checkCache(did)\n if (fromCache && !fromCache.expired) {\n if (fromCache?.stale) {\n await this.refreshCache(did, fromCache)\n }\n return fromCache.doc\n }\n }\n\n const got = await this.resolveNoCache(did)\n if (got === null) {\n await this.cache?.clearEntry(did)\n return null\n }\n await this.cache?.cacheDid(did, got, fromCache ?? undefined)\n return got\n }\n\n async ensureResolve(did: string, forceRefresh = false): Promise<DidDocument> {\n const result = await this.resolve(did, forceRefresh)\n if (result === null) {\n throw new DidNotFoundError(did)\n }\n return result\n }\n\n async resolveAtprotoData(\n did: string,\n forceRefresh = false,\n ): Promise<AtprotoData> {\n const didDocument = await this.ensureResolve(did, forceRefresh)\n return atprotoData.ensureAtpDocument(didDocument)\n }\n\n async resolveAtprotoKey(did: string, forceRefresh = false): Promise<string> {\n if (did.startsWith('did:key:')) {\n return did\n } else {\n const didDocument = await this.ensureResolve(did, forceRefresh)\n return atprotoData.ensureAtprotoKey(didDocument)\n }\n }\n\n async verifySignature(\n did: string,\n data: Uint8Array,\n sig: Uint8Array,\n forceRefresh = false,\n ): Promise<boolean> {\n const signingKey = await this.resolveAtprotoKey(did, forceRefresh)\n return crypto.verifySignature(signingKey, data, sig)\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DidResolverOpts } from '../types';
|
|
2
|
-
import { BaseResolver } from './base-resolver';
|
|
1
|
+
import { DidResolverOpts } from '../types.js';
|
|
2
|
+
import { BaseResolver } from './base-resolver.js';
|
|
3
3
|
export declare class DidResolver extends BaseResolver {
|
|
4
4
|
methods: Map<string, BaseResolver>;
|
|
5
5
|
constructor(opts: DidResolverOpts);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-resolver.d.ts","sourceRoot":"","sources":["../../src/did/did-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"did-resolver.d.ts","sourceRoot":"","sources":["../../src/did/did-resolver.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAIjD,qBAAa,WAAY,SAAQ,YAAY;IAC3C,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;gBAEtB,IAAI,EAAE,eAAe;IAU3B,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAepD"}
|
package/dist/did/did-resolver.js
CHANGED
|
@@ -1,41 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const plc_resolver_1 = require("./plc-resolver");
|
|
7
|
-
const web_resolver_1 = require("./web-resolver");
|
|
8
|
-
class DidResolver extends base_resolver_1.BaseResolver {
|
|
1
|
+
import { PoorlyFormattedDidError, UnsupportedDidMethodError, } from '../errors.js';
|
|
2
|
+
import { BaseResolver } from './base-resolver.js';
|
|
3
|
+
import { DidPlcResolver } from './plc-resolver.js';
|
|
4
|
+
import { DidWebResolver } from './web-resolver.js';
|
|
5
|
+
export class DidResolver extends BaseResolver {
|
|
9
6
|
constructor(opts) {
|
|
10
7
|
super(opts.didCache);
|
|
11
|
-
Object.defineProperty(this, "methods", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: void 0
|
|
16
|
-
});
|
|
17
8
|
const { timeout = 3000, plcUrl = 'https://plc.directory' } = opts;
|
|
18
9
|
// do not pass cache to sub-methods or we will be double caching
|
|
19
10
|
this.methods = new Map([
|
|
20
|
-
['plc', new
|
|
21
|
-
['web', new
|
|
11
|
+
['plc', new DidPlcResolver(plcUrl, timeout)],
|
|
12
|
+
['web', new DidWebResolver(timeout)],
|
|
22
13
|
]);
|
|
23
14
|
}
|
|
24
15
|
async resolveNoCheck(did) {
|
|
25
16
|
if (!did.startsWith('did:')) {
|
|
26
|
-
throw new
|
|
17
|
+
throw new PoorlyFormattedDidError(did);
|
|
27
18
|
}
|
|
28
19
|
const methodSepIdx = did.indexOf(':', 4);
|
|
29
20
|
if (methodSepIdx === -1) {
|
|
30
|
-
throw new
|
|
21
|
+
throw new PoorlyFormattedDidError(did);
|
|
31
22
|
}
|
|
32
23
|
const methodName = did.slice(4, methodSepIdx);
|
|
33
24
|
const method = this.methods.get(methodName);
|
|
34
25
|
if (!method) {
|
|
35
|
-
throw new
|
|
26
|
+
throw new UnsupportedDidMethodError(did);
|
|
36
27
|
}
|
|
37
28
|
return method.resolveNoCheck(did);
|
|
38
29
|
}
|
|
39
30
|
}
|
|
40
|
-
exports.DidResolver = DidResolver;
|
|
41
31
|
//# sourceMappingURL=did-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-resolver.js","sourceRoot":"","sources":["../../src/did/did-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"did-resolver.js","sourceRoot":"","sources":["../../src/did/did-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,MAAM,OAAO,WAAY,SAAQ,YAAY;IAG3C,YAAY,IAAqB;QAC/B,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACpB,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,MAAM,GAAG,uBAAuB,EAAE,GAAG,IAAI,CAAA;QACjE,gEAAgE;QAChE,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC;YACrB,CAAC,KAAK,EAAE,IAAI,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC5C,CAAC,KAAK,EAAE,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;SACrC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAW;QAC9B,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,uBAAuB,CAAC,GAAG,CAAC,CAAA;QACxC,CAAC;QACD,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QACxC,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,uBAAuB,CAAC,GAAG,CAAC,CAAA;QACxC,CAAC;QACD,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAA;QAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QAC3C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,yBAAyB,CAAC,GAAG,CAAC,CAAA;QAC1C,CAAC;QACD,OAAO,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;IACnC,CAAC;CACF","sourcesContent":["import {\n PoorlyFormattedDidError,\n UnsupportedDidMethodError,\n} from '../errors.js'\nimport { DidResolverOpts } from '../types.js'\nimport { BaseResolver } from './base-resolver.js'\nimport { DidPlcResolver } from './plc-resolver.js'\nimport { DidWebResolver } from './web-resolver.js'\n\nexport class DidResolver extends BaseResolver {\n methods: Map<string, BaseResolver>\n\n constructor(opts: DidResolverOpts) {\n super(opts.didCache)\n const { timeout = 3000, plcUrl = 'https://plc.directory' } = opts\n // do not pass cache to sub-methods or we will be double caching\n this.methods = new Map([\n ['plc', new DidPlcResolver(plcUrl, timeout)],\n ['web', new DidWebResolver(timeout)],\n ])\n }\n\n async resolveNoCheck(did: string): Promise<unknown> {\n if (!did.startsWith('did:')) {\n throw new PoorlyFormattedDidError(did)\n }\n const methodSepIdx = did.indexOf(':', 4)\n if (methodSepIdx === -1) {\n throw new PoorlyFormattedDidError(did)\n }\n const methodName = did.slice(4, methodSepIdx)\n const method = this.methods.get(methodName)\n if (!method) {\n throw new UnsupportedDidMethodError(did)\n }\n return method.resolveNoCheck(did)\n }\n}\n"]}
|
package/dist/did/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './web-resolver';
|
|
2
|
-
export * from './plc-resolver';
|
|
3
|
-
export * from './did-resolver';
|
|
4
|
-
export * from './atproto-data';
|
|
5
|
-
export * from './memory-cache';
|
|
1
|
+
export * from './web-resolver.js';
|
|
2
|
+
export * from './plc-resolver.js';
|
|
3
|
+
export * from './did-resolver.js';
|
|
4
|
+
export * from './atproto-data.js';
|
|
5
|
+
export * from './memory-cache.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/did/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/did/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/did/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA"}
|
package/dist/did/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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);
|
|
1
|
+
export * from './web-resolver.js';
|
|
2
|
+
export * from './plc-resolver.js';
|
|
3
|
+
export * from './did-resolver.js';
|
|
4
|
+
export * from './atproto-data.js';
|
|
5
|
+
export * from './memory-cache.js';
|
|
22
6
|
//# sourceMappingURL=index.js.map
|
package/dist/did/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/did/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/did/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA","sourcesContent":["export * from './web-resolver.js'\nexport * from './plc-resolver.js'\nexport * from './did-resolver.js'\nexport * from './atproto-data.js'\nexport * from './memory-cache.js'\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-cache.d.ts","sourceRoot":"","sources":["../../src/did/memory-cache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"memory-cache.d.ts","sourceRoot":"","sources":["../../src/did/memory-cache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEhE,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"}
|
package/dist/did/memory-cache.js
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.MemoryCache = void 0;
|
|
4
|
-
const common_web_1 = require("@atproto/common-web");
|
|
5
|
-
class MemoryCache {
|
|
1
|
+
import { DAY, HOUR } from '@atproto/common-web';
|
|
2
|
+
export class MemoryCache {
|
|
6
3
|
constructor(staleTTL, maxTTL) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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;
|
|
4
|
+
this.cache = new Map();
|
|
5
|
+
this.staleTTL = staleTTL ?? HOUR;
|
|
6
|
+
this.maxTTL = maxTTL ?? DAY;
|
|
27
7
|
}
|
|
28
8
|
async cacheDid(did, doc) {
|
|
29
9
|
this.cache.set(did, { doc, updatedAt: Date.now() });
|
|
@@ -55,5 +35,4 @@ class MemoryCache {
|
|
|
55
35
|
this.cache.clear();
|
|
56
36
|
}
|
|
57
37
|
}
|
|
58
|
-
exports.MemoryCache = MemoryCache;
|
|
59
38
|
//# sourceMappingURL=memory-cache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-cache.js","sourceRoot":"","sources":["../../src/did/memory-cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory-cache.js","sourceRoot":"","sources":["../../src/did/memory-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAQ/C,MAAM,OAAO,WAAW;IAGtB,YAAY,QAAiB,EAAE,MAAe;QAKvC,UAAK,GAA0B,IAAI,GAAG,EAAE,CAAA;QAJ7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,IAAI,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,GAAG,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","sourcesContent":["import { DAY, HOUR } from '@atproto/common-web'\nimport { CacheResult, DidCache, DidDocument } from '../types.js'\n\ntype CacheVal = {\n doc: DidDocument\n updatedAt: number\n}\n\nexport class MemoryCache implements DidCache {\n public staleTTL: number\n public maxTTL: number\n constructor(staleTTL?: number, maxTTL?: number) {\n this.staleTTL = staleTTL ?? HOUR\n this.maxTTL = maxTTL ?? DAY\n }\n\n public cache: Map<string, CacheVal> = new Map()\n\n async cacheDid(did: string, doc: DidDocument): Promise<void> {\n this.cache.set(did, { doc, updatedAt: Date.now() })\n }\n\n async refreshCache(\n did: string,\n getDoc: () => Promise<DidDocument | null>,\n ): Promise<void> {\n const doc = await getDoc()\n if (doc) {\n await this.cacheDid(did, doc)\n }\n }\n\n async checkCache(did: string): Promise<CacheResult | null> {\n const val = this.cache.get(did)\n if (!val) return null\n const now = Date.now()\n const expired = now > val.updatedAt + this.maxTTL\n const stale = now > val.updatedAt + this.staleTTL\n return {\n ...val,\n did,\n stale,\n expired,\n }\n }\n\n async clearEntry(did: string): Promise<void> {\n this.cache.delete(did)\n }\n\n async clear(): Promise<void> {\n this.cache.clear()\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DidCache } from '../types';
|
|
2
|
-
import { BaseResolver } from './base-resolver';
|
|
1
|
+
import { DidCache } from '../types.js';
|
|
2
|
+
import { BaseResolver } from './base-resolver.js';
|
|
3
3
|
export declare class DidPlcResolver extends BaseResolver {
|
|
4
4
|
plcUrl: string;
|
|
5
5
|
timeout: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plc-resolver.d.ts","sourceRoot":"","sources":["../../src/did/plc-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"plc-resolver.d.ts","sourceRoot":"","sources":["../../src/did/plc-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGjD,qBAAa,cAAe,SAAQ,YAAY;IAErC,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,MAAM;IACf,KAAK,CAAC,EAAE,QAAQ;gBAFhB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,QAAQ,YAAA;IAKnB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAmBpD"}
|
package/dist/did/plc-resolver.js
CHANGED
|
@@ -1,32 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const base_resolver_1 = require("./base-resolver");
|
|
5
|
-
const util_1 = require("./util");
|
|
6
|
-
class DidPlcResolver extends base_resolver_1.BaseResolver {
|
|
1
|
+
import { BaseResolver } from './base-resolver.js';
|
|
2
|
+
import { timed } from './util.js';
|
|
3
|
+
export class DidPlcResolver extends BaseResolver {
|
|
7
4
|
constructor(plcUrl, timeout, cache) {
|
|
8
5
|
super(cache);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
writable: true,
|
|
13
|
-
value: plcUrl
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(this, "timeout", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: timeout
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(this, "cache", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: cache
|
|
26
|
-
});
|
|
6
|
+
this.plcUrl = plcUrl;
|
|
7
|
+
this.timeout = timeout;
|
|
8
|
+
this.cache = cache;
|
|
27
9
|
}
|
|
28
10
|
async resolveNoCheck(did) {
|
|
29
|
-
return
|
|
11
|
+
return timed(this.timeout, async (signal) => {
|
|
30
12
|
const url = new URL(`/${encodeURIComponent(did)}`, this.plcUrl);
|
|
31
13
|
const res = await fetch(url, {
|
|
32
14
|
redirect: 'error',
|
|
@@ -43,5 +25,4 @@ class DidPlcResolver extends base_resolver_1.BaseResolver {
|
|
|
43
25
|
});
|
|
44
26
|
}
|
|
45
27
|
}
|
|
46
|
-
exports.DidPlcResolver = DidPlcResolver;
|
|
47
28
|
//# sourceMappingURL=plc-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plc-resolver.js","sourceRoot":"","sources":["../../src/did/plc-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plc-resolver.js","sourceRoot":"","sources":["../../src/did/plc-resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEjC,MAAM,OAAO,cAAe,SAAQ,YAAY;IAC9C,YACS,MAAc,EACd,OAAe,EACf,KAAgB;QAEvB,KAAK,CAAC,KAAK,CAAC,CAAA;QAJL,WAAM,GAAN,MAAM,CAAQ;QACd,YAAO,GAAP,OAAO,CAAQ;QACf,UAAK,GAAL,KAAK,CAAW;IAGzB,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAW;QAC9B,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC1C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,kBAAkB,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;YAC/D,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAC3B,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,EAAE,MAAM,EAAE,0CAA0C,EAAE;gBAC/D,MAAM;aACP,CAAC,CAAA;YAEF,yDAAyD;YACzD,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG;gBAAE,OAAO,IAAI,CAAA;YAEnC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACZ,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAA;YACxE,CAAC;YAED,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;QACnB,CAAC,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import { DidCache } from '../types.js'\nimport { BaseResolver } from './base-resolver.js'\nimport { timed } from './util.js'\n\nexport class DidPlcResolver extends BaseResolver {\n constructor(\n public plcUrl: string,\n public timeout: number,\n public cache?: DidCache,\n ) {\n super(cache)\n }\n\n async resolveNoCheck(did: string): Promise<unknown> {\n return timed(this.timeout, async (signal) => {\n const url = new URL(`/${encodeURIComponent(did)}`, this.plcUrl)\n const res = await fetch(url, {\n redirect: 'error',\n headers: { accept: 'application/did+ld+json,application/json' },\n signal,\n })\n\n // Positively not found, versus due to e.g. network error\n if (res.status === 404) return null\n\n if (!res.ok) {\n throw Object.assign(new Error(res.statusText), { status: res.status })\n }\n\n return res.json()\n })\n }\n}\n"]}
|
package/dist/did/util.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.timed = timed;
|
|
4
|
-
async function timed(ms, fn) {
|
|
1
|
+
export async function timed(ms, fn) {
|
|
5
2
|
const abortController = new AbortController();
|
|
6
3
|
const timer = setTimeout(() => abortController.abort(), ms);
|
|
7
4
|
const signal = abortController.signal;
|
package/dist/did/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/did/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/did/util.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,EAAU,EACV,EAAK;IAEL,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;IAC7C,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,EAAE,EAAE,CAAC,CAAA;IAC3D,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAA;IAErC,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAA2B,CAAA;IACrD,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAA;QACnB,eAAe,CAAC,KAAK,EAAE,CAAA;IACzB,CAAC;AACH,CAAC","sourcesContent":["export async function timed<F extends (signal: AbortSignal) => unknown>(\n ms: number,\n fn: F,\n): Promise<Awaited<ReturnType<F>>> {\n const abortController = new AbortController()\n const timer = setTimeout(() => abortController.abort(), ms)\n const signal = abortController.signal\n\n try {\n return (await fn(signal)) as Awaited<ReturnType<F>>\n } finally {\n clearTimeout(timer)\n abortController.abort()\n }\n}\n"]}
|