@atproto/identity 0.0.0-spaces-alpha-20260818021221

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 (56) hide show
  1. package/CHANGELOG.md +265 -0
  2. package/LICENSE.txt +7 -0
  3. package/README.md +45 -0
  4. package/dist/did/atproto-data.d.ts +12 -0
  5. package/dist/did/atproto-data.d.ts.map +1 -0
  6. package/dist/did/atproto-data.js +57 -0
  7. package/dist/did/atproto-data.js.map +1 -0
  8. package/dist/did/base-resolver.d.ts +15 -0
  9. package/dist/did/base-resolver.d.ts.map +1 -0
  10. package/dist/did/base-resolver.js +72 -0
  11. package/dist/did/base-resolver.js.map +1 -0
  12. package/dist/did/did-resolver.d.ts +8 -0
  13. package/dist/did/did-resolver.d.ts.map +1 -0
  14. package/dist/did/did-resolver.js +31 -0
  15. package/dist/did/did-resolver.js.map +1 -0
  16. package/dist/did/index.d.ts +6 -0
  17. package/dist/did/index.d.ts.map +1 -0
  18. package/dist/did/index.js +6 -0
  19. package/dist/did/index.js.map +1 -0
  20. package/dist/did/memory-cache.d.ts +18 -0
  21. package/dist/did/memory-cache.d.ts.map +1 -0
  22. package/dist/did/memory-cache.js +38 -0
  23. package/dist/did/memory-cache.js.map +1 -0
  24. package/dist/did/plc-resolver.d.ts +10 -0
  25. package/dist/did/plc-resolver.d.ts.map +1 -0
  26. package/dist/did/plc-resolver.js +28 -0
  27. package/dist/did/plc-resolver.js.map +1 -0
  28. package/dist/did/util.d.ts +2 -0
  29. package/dist/did/util.d.ts.map +1 -0
  30. package/dist/did/util.js +13 -0
  31. package/dist/did/util.js.map +1 -0
  32. package/dist/did/web-resolver.d.ts +10 -0
  33. package/dist/did/web-resolver.d.ts.map +1 -0
  34. package/dist/did/web-resolver.js +43 -0
  35. package/dist/did/web-resolver.js.map +1 -0
  36. package/dist/errors.d.ts +22 -0
  37. package/dist/errors.d.ts.map +1 -0
  38. package/dist/errors.js +32 -0
  39. package/dist/errors.js.map +1 -0
  40. package/dist/handle/index.d.ts +14 -0
  41. package/dist/handle/index.d.ts.map +1 -0
  42. package/dist/handle/index.js +87 -0
  43. package/dist/handle/index.js.map +1 -0
  44. package/dist/id-resolver.d.ts +9 -0
  45. package/dist/id-resolver.d.ts.map +1 -0
  46. package/dist/id-resolver.js +13 -0
  47. package/dist/id-resolver.js.map +1 -0
  48. package/dist/index.d.ts +6 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +6 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/types.d.ts +39 -0
  53. package/dist/types.d.ts.map +1 -0
  54. package/dist/types.js +2 -0
  55. package/dist/types.js.map +1 -0
  56. package/package.json +52 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,265 @@
1
+ # @atproto/identity
2
+
3
+ ## 0.0.0-spaces-alpha-20260818021221
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`2f77206`](https://github.com/bluesky-social/atproto/commit/2f77206ff8010710db5733c454abff9eb5ebb96b), [`5db8f3d`](https://github.com/bluesky-social/atproto/commit/5db8f3db807b1a37793b86521e833a843ada0b15)]:
8
+ - @atproto/crypto@0.0.0-spaces-alpha-20260818021221
9
+ - @atproto/common-web@0.0.0-spaces-alpha-20260818021221
10
+
11
+ ## 0.5.9
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies []:
16
+ - @atproto/common-web@0.5.9
17
+
18
+ ## 0.5.8
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies []:
23
+ - @atproto/common-web@0.5.8
24
+
25
+ ## 0.5.7
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies []:
30
+ - @atproto/common-web@0.5.7
31
+
32
+ ## 0.5.6
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies []:
37
+ - @atproto/common-web@0.5.6
38
+
39
+ ## 0.5.5
40
+
41
+ ### Patch Changes
42
+
43
+ - [#5197](https://github.com/bluesky-social/atproto/pull/5197) [`a0c49d9`](https://github.com/bluesky-social/atproto/commit/a0c49d9e8bc685c5a747a8d3b2775c73c63fdb6f) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rewrite import statements to be compatible with TypeScript's `verbatimModuleSyntax` config.
44
+
45
+ - Updated dependencies [[`a0c49d9`](https://github.com/bluesky-social/atproto/commit/a0c49d9e8bc685c5a747a8d3b2775c73c63fdb6f)]:
46
+ - @atproto/common-web@0.5.5
47
+ - @atproto/crypto@0.5.4
48
+
49
+ ## 0.5.4
50
+
51
+ ### Patch Changes
52
+
53
+ - Updated dependencies []:
54
+ - @atproto/common-web@0.5.4
55
+
56
+ ## 0.5.3
57
+
58
+ ### Patch Changes
59
+
60
+ - [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add missing `@types` dependencies
61
+
62
+ - [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update TypeScript build to rely on references to composite internal projects
63
+
64
+ - [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Bundle only necessary files in the NPM tarball, including the `CHANGELOG.md` and `README.md` files (if present).
65
+
66
+ - [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Build with `noImplicitAny` enabled
67
+
68
+ - Updated dependencies [[`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07)]:
69
+ - @atproto/common-web@0.5.3
70
+ - @atproto/crypto@0.5.3
71
+
72
+ ## 0.5.2
73
+
74
+ ### Patch Changes
75
+
76
+ - [#5151](https://github.com/bluesky-social/atproto/pull/5151) [`a51c45d`](https://github.com/bluesky-social/atproto/commit/a51c45d38f6bd7b8765f640e564cf921d52162e7) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update dependencies
77
+
78
+ - Updated dependencies [[`a51c45d`](https://github.com/bluesky-social/atproto/commit/a51c45d38f6bd7b8765f640e564cf921d52162e7)]:
79
+ - @atproto/common-web@0.5.2
80
+ - @atproto/crypto@0.5.2
81
+
82
+ ## 0.5.1
83
+
84
+ ### Patch Changes
85
+
86
+ - [#4967](https://github.com/bluesky-social/atproto/pull/4967) [`9fc720c`](https://github.com/bluesky-social/atproto/commit/9fc720ce75f3ee88a5e48a9be919b07c7647f6f5) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Use TypeScript 7 to build package
87
+
88
+ - Updated dependencies [[`9fc720c`](https://github.com/bluesky-social/atproto/commit/9fc720ce75f3ee88a5e48a9be919b07c7647f6f5)]:
89
+ - @atproto/common-web@0.5.1
90
+ - @atproto/crypto@0.5.1
91
+
92
+ ## 0.5.0
93
+
94
+ ### Minor Changes
95
+
96
+ - [#4929](https://github.com/bluesky-social/atproto/pull/4929) [`f01c59f`](https://github.com/bluesky-social/atproto/commit/f01c59f5bd3f75fb8b47a9eecd4858b84033fb7c) 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.
97
+
98
+ - [#4943](https://github.com/bluesky-social/atproto/pull/4943) [`c459153`](https://github.com/bluesky-social/atproto/commit/c459153395a30ce89e050892c8fab7dc98e019b9) 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.
99
+
100
+ Node.js 22's `require()` compatibility layer can still load these packages in CommonJS code.
101
+
102
+ - [#4930](https://github.com/bluesky-social/atproto/pull/4930) [`908bece`](https://github.com/bluesky-social/atproto/commit/908bece169258bff5ad121e5eec157d6ded6f705) Thanks [@devinivy](https://github.com/devinivy)! - Build with TypeScript 6.0.
103
+
104
+ ### Patch Changes
105
+
106
+ - Updated dependencies [[`f01c59f`](https://github.com/bluesky-social/atproto/commit/f01c59f5bd3f75fb8b47a9eecd4858b84033fb7c), [`c459153`](https://github.com/bluesky-social/atproto/commit/c459153395a30ce89e050892c8fab7dc98e019b9), [`908bece`](https://github.com/bluesky-social/atproto/commit/908bece169258bff5ad121e5eec157d6ded6f705)]:
107
+ - @atproto/common-web@0.5.0
108
+ - @atproto/crypto@0.5.0
109
+
110
+ ## 0.4.12
111
+
112
+ ### Patch Changes
113
+
114
+ - [#4669](https://github.com/bluesky-social/atproto/pull/4669) [`dc9644b`](https://github.com/bluesky-social/atproto/commit/dc9644bbeb1892931809568895162d823e4743d2) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Fix lint warning
115
+
116
+ ## 0.4.11
117
+
118
+ ### Patch Changes
119
+
120
+ - [#4609](https://github.com/bluesky-social/atproto/pull/4609) [`00e6dbd`](https://github.com/bluesky-social/atproto/commit/00e6dbdcea295cfa3dff7eb7517420039cc3e821) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Fix `method.resolveNoCheck is not a function` error when using speciallt forged did method
121
+
122
+ - Updated dependencies []:
123
+ - @atproto/common-web@0.4.16
124
+
125
+ ## 0.4.10
126
+
127
+ ### Patch Changes
128
+
129
+ - Updated dependencies [[`261968fd6`](https://github.com/bluesky-social/atproto/commit/261968fd65014ded613e2bf085d61a7864b8fba7), [`261968fd6`](https://github.com/bluesky-social/atproto/commit/261968fd65014ded613e2bf085d61a7864b8fba7), [`261968fd6`](https://github.com/bluesky-social/atproto/commit/261968fd65014ded613e2bf085d61a7864b8fba7)]:
130
+ - @atproto/common-web@0.4.4
131
+ - @atproto/crypto@0.4.4
132
+
133
+ ## 0.4.9
134
+
135
+ ### Patch Changes
136
+
137
+ - Updated dependencies [[`055a413fb`](https://github.com/bluesky-social/atproto/commit/055a413fba4fab510ec899377154f1204ab12099)]:
138
+ - @atproto/common-web@0.4.3
139
+ - @atproto/crypto@0.4.4
140
+
141
+ ## 0.4.8
142
+
143
+ ### Patch Changes
144
+
145
+ - Updated dependencies [[`cc485d296`](https://github.com/bluesky-social/atproto/commit/cc485d29638488928b5efec3d4b0627040589812)]:
146
+ - @atproto/common-web@0.4.2
147
+ - @atproto/crypto@0.4.4
148
+
149
+ ## 0.4.7
150
+
151
+ ### Patch Changes
152
+
153
+ - Updated dependencies [[`4db923ca1`](https://github.com/bluesky-social/atproto/commit/4db923ca1c4fadd31d41c851933659e5186ee144)]:
154
+ - @atproto/common-web@0.4.1
155
+ - @atproto/crypto@0.4.4
156
+
157
+ ## 0.4.6
158
+
159
+ ### Patch Changes
160
+
161
+ - [#3220](https://github.com/bluesky-social/atproto/pull/3220) [`61dc0d60e`](https://github.com/bluesky-social/atproto/commit/61dc0d60e19b88c6427a54c6d95a391b5f4da7bd) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Apply new linting rules regarding import order
162
+
163
+ - [#3220](https://github.com/bluesky-social/atproto/pull/3220) [`61dc0d60e`](https://github.com/bluesky-social/atproto/commit/61dc0d60e19b88c6427a54c6d95a391b5f4da7bd) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update NodeJS engine requirement to >=18.7.0
164
+
165
+ - Updated dependencies [[`61dc0d60e`](https://github.com/bluesky-social/atproto/commit/61dc0d60e19b88c6427a54c6d95a391b5f4da7bd), [`8a30e0ed9`](https://github.com/bluesky-social/atproto/commit/8a30e0ed9239cb2037d54fb98e70e8b0cfbc3e39), [`61dc0d60e`](https://github.com/bluesky-social/atproto/commit/61dc0d60e19b88c6427a54c6d95a391b5f4da7bd)]:
166
+ - @atproto/common-web@0.4.0
167
+ - @atproto/crypto@0.4.4
168
+
169
+ ## 0.4.5
170
+
171
+ ### Patch Changes
172
+
173
+ - Updated dependencies [[`1abfd74ec`](https://github.com/bluesky-social/atproto/commit/1abfd74ec7114e5d8e2411f7a4fa10bdce97e277)]:
174
+ - @atproto/crypto@0.4.3
175
+
176
+ ## 0.4.4
177
+
178
+ ### Patch Changes
179
+
180
+ - [#3177](https://github.com/bluesky-social/atproto/pull/3177) [`72eba67af`](https://github.com/bluesky-social/atproto/commit/72eba67af1af8320b5400bcb9319d5c3c8407d99) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Remove dependency on Axios
181
+
182
+ - Updated dependencies [[`72eba67af`](https://github.com/bluesky-social/atproto/commit/72eba67af1af8320b5400bcb9319d5c3c8407d99), [`72eba67af`](https://github.com/bluesky-social/atproto/commit/72eba67af1af8320b5400bcb9319d5c3c8407d99)]:
183
+ - @atproto/common-web@0.3.2
184
+ - @atproto/crypto@0.4.2
185
+
186
+ ## 0.4.3
187
+
188
+ ### Patch Changes
189
+
190
+ - Updated dependencies [[`1982693e3`](https://github.com/bluesky-social/atproto/commit/1982693e3ea1fef4db76ac9aca3db8dc5ebf3fe0)]:
191
+ - @atproto/crypto@0.4.2
192
+
193
+ ## 0.4.2
194
+
195
+ ### Patch Changes
196
+
197
+ - Updated dependencies [[`a07b21151`](https://github.com/bluesky-social/atproto/commit/a07b21151f1850340c4b7797ebb11521b1a6cdf3), [`a07b21151`](https://github.com/bluesky-social/atproto/commit/a07b21151f1850340c4b7797ebb11521b1a6cdf3), [`eb20ff64a`](https://github.com/bluesky-social/atproto/commit/eb20ff64a2d8e3061c652e1e247bf9b0fe3c41a6)]:
198
+ - @atproto/common-web@0.3.1
199
+ - @atproto/crypto@0.4.1
200
+
201
+ ## 0.4.1
202
+
203
+ ### Patch Changes
204
+
205
+ - Updated dependencies [[`ebb318325`](https://github.com/bluesky-social/atproto/commit/ebb318325b6e80c4ea1a93a617569da2698afe31)]:
206
+ - @atproto/crypto@0.4.1
207
+
208
+ ## 0.4.0
209
+
210
+ ### Minor Changes
211
+
212
+ - [#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.
213
+
214
+ ### Patch Changes
215
+
216
+ - Updated dependencies [[`f689bd51a`](https://github.com/bluesky-social/atproto/commit/f689bd51a2f4e02d4eca40eb2568a1fcb95494e9)]:
217
+ - @atproto/common-web@0.3.0
218
+ - @atproto/crypto@0.4.0
219
+
220
+ ## 0.3.3
221
+
222
+ ### Patch Changes
223
+
224
+ - [#2302](https://github.com/bluesky-social/atproto/pull/2302) [`4eaadc0ac`](https://github.com/bluesky-social/atproto/commit/4eaadc0acb6b73b9745dd7a2b929d02e58083ab0) Thanks [@dholms](https://github.com/dholms)! - Added methods for parsing labeler verification methods and services in DID Documents
225
+
226
+ - Updated dependencies [[`4eaadc0ac`](https://github.com/bluesky-social/atproto/commit/4eaadc0acb6b73b9745dd7a2b929d02e58083ab0)]:
227
+ - @atproto/common-web@0.2.4
228
+ - @atproto/crypto@0.3.0
229
+
230
+ ## 0.3.2
231
+
232
+ ### Patch Changes
233
+
234
+ - Updated dependencies [[`e1b5f253`](https://github.com/bluesky-social/atproto/commit/e1b5f2537a5ba4d8b951a741269b604856028ae5)]:
235
+ - @atproto/crypto@0.3.0
236
+
237
+ ## 0.3.1
238
+
239
+ ### Patch Changes
240
+
241
+ - [#1788](https://github.com/bluesky-social/atproto/pull/1788) [`84e2d4d2`](https://github.com/bluesky-social/atproto/commit/84e2d4d2b6694f344d80c18672c78b650189d423) Thanks [@bnewbold](https://github.com/bnewbold)! - update license to "MIT or Apache2"
242
+
243
+ - Updated dependencies [[`84e2d4d2`](https://github.com/bluesky-social/atproto/commit/84e2d4d2b6694f344d80c18672c78b650189d423)]:
244
+ - @atproto/common-web@0.2.3
245
+ - @atproto/crypto@0.2.3
246
+
247
+ ## 0.3.0
248
+
249
+ ### Minor Changes
250
+
251
+ - [#1773](https://github.com/bluesky-social/atproto/pull/1773) [`bb039d8e`](https://github.com/bluesky-social/atproto/commit/bb039d8e4ce5b7f70c4f3e86d1327e210ef24dc3) Thanks [@dholms](https://github.com/dholms)! - Pass stale did doc into refresh cache functions
252
+
253
+ ### Patch Changes
254
+
255
+ - [`35d108ce`](https://github.com/bluesky-social/atproto/commit/35d108ce94866ce1b3d147cd0620a0ba1c4ebcd7) Thanks [@devinivy](https://github.com/devinivy)! - Allow pds to serve did doc with credentials, API client to respect PDS listed in the did doc.
256
+
257
+ - Updated dependencies [[`35d108ce`](https://github.com/bluesky-social/atproto/commit/35d108ce94866ce1b3d147cd0620a0ba1c4ebcd7)]:
258
+ - @atproto/common-web@0.2.2
259
+
260
+ ## 0.2.1
261
+
262
+ ### Patch Changes
263
+
264
+ - Updated dependencies [[`41ee177f`](https://github.com/bluesky-social/atproto/commit/41ee177f5a440490280d17acd8a89bcddaffb23b)]:
265
+ - @atproto/common-web@0.2.1
package/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Dual MIT/Apache-2.0 License
2
+
3
+ Copyright (c) 2022-2026 Bluesky Social 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.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @atproto/identity
2
+
3
+ TypeScript library for decentralized identities in [atproto](https://atproto.com) using DIDs and handles
4
+
5
+ [![NPM](https://img.shields.io/npm/v/@atproto/identity)](https://www.npmjs.com/package/@atproto/identity)
6
+ [![Github CI Status](https://github.com/bluesky-social/atproto/actions/workflows/repo.yaml/badge.svg)](https://github.com/bluesky-social/atproto/actions/workflows/repo.yaml)
7
+
8
+ ## Example
9
+
10
+ Resolving a Handle and verifying against DID document:
11
+
12
+ ```typescript
13
+ const didres = new DidResolver({})
14
+ const hdlres = new HandleResolver({})
15
+
16
+ const handle = 'atproto.com'
17
+ const did = await hdlres.resolve(handle)
18
+
19
+ if (did == undefined) {
20
+ throw new Error('expected handle to resolve')
21
+ }
22
+ console.log(did) // did:plc:ewvi7nxzyoun6zhxrhs64oiz
23
+
24
+ const doc = await didres.resolve(did)
25
+ console.log(doc)
26
+
27
+ // additional resolutions of same DID will be cached for some time, unless forceRefresh flag is used
28
+ const doc2 = await didres.resolve(did, true)
29
+
30
+ // helper methods use the same cache
31
+ const data = await didres.resolveAtprotoData(did)
32
+
33
+ if (data.handle != handle) {
34
+ throw new Error('invalid handle (did not match DID document)')
35
+ }
36
+ ```
37
+
38
+ ## License
39
+
40
+ This project is dual-licensed under MIT and Apache 2.0 terms:
41
+
42
+ - MIT license ([LICENSE-MIT.txt](https://github.com/bluesky-social/atproto/blob/main/LICENSE-MIT.txt) or http://opensource.org/licenses/MIT)
43
+ - Apache License, Version 2.0, ([LICENSE-APACHE.txt](https://github.com/bluesky-social/atproto/blob/main/LICENSE-APACHE.txt) or http://www.apache.org/licenses/LICENSE-2.0)
44
+
45
+ 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,12 @@
1
+ import { getDid, getFeedGenEndpoint, getHandle, getNotifEndpoint, getPdsEndpoint } from '@atproto/common-web';
2
+ import type { AtprotoData, DidDocument } from '../types.js';
3
+ export { getDid, getFeedGenEndpoint as getFeedGen, getHandle, getNotifEndpoint as getNotif, getPdsEndpoint as getPds, };
4
+ export declare const getKey: (doc: DidDocument) => string | undefined;
5
+ export declare const getDidKeyFromMultibase: (key: {
6
+ type: string;
7
+ publicKeyMultibase: string;
8
+ }) => string | undefined;
9
+ export declare const parseToAtprotoDocument: (doc: DidDocument) => Partial<AtprotoData>;
10
+ export declare const ensureAtpDocument: (doc: DidDocument) => AtprotoData;
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":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,cAAc,EAEf,MAAM,qBAAqB,CAAA;AAE5B,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE3D,OAAO,EACL,MAAM,EACN,kBAAkB,IAAI,UAAU,EAChC,SAAS,EACT,gBAAgB,IAAI,QAAQ,EAC5B,cAAc,IAAI,MAAM,GACzB,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,OAAO,CAAC,WAAW,CAQrB,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAS,WAAW,KAAG,WAepD,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAS,WAAW,KAAG,MAMnD,CAAA"}
@@ -0,0 +1,57 @@
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);
6
+ if (!key)
7
+ return undefined;
8
+ return getDidKeyFromMultibase(key);
9
+ };
10
+ export const getDidKeyFromMultibase = (key) => {
11
+ const keyBytes = crypto.multibaseToBytes(key.publicKeyMultibase);
12
+ let didKey = undefined;
13
+ if (key.type === 'EcdsaSecp256r1VerificationKey2019') {
14
+ didKey = crypto.formatDidKey(crypto.P256_JWT_ALG, keyBytes);
15
+ }
16
+ else if (key.type === 'EcdsaSecp256k1VerificationKey2019') {
17
+ didKey = crypto.formatDidKey(crypto.SECP256K1_JWT_ALG, keyBytes);
18
+ }
19
+ else if (key.type === 'Multikey') {
20
+ const parsed = crypto.parseMultikey(key.publicKeyMultibase);
21
+ didKey = crypto.formatDidKey(parsed.jwtAlg, parsed.keyBytes);
22
+ }
23
+ return didKey;
24
+ };
25
+ export const parseToAtprotoDocument = (doc) => {
26
+ const did = getDid(doc);
27
+ return {
28
+ did,
29
+ signingKey: getKey(doc),
30
+ handle: getHandle(doc),
31
+ pds: getPdsEndpoint(doc),
32
+ };
33
+ };
34
+ export const ensureAtpDocument = (doc) => {
35
+ const { did, signingKey, handle, pds } = parseToAtprotoDocument(doc);
36
+ if (!did) {
37
+ throw new Error(`Could not parse id from doc: ${doc}`);
38
+ }
39
+ if (!signingKey) {
40
+ throw new Error(`Could not parse signingKey from doc: ${doc}`);
41
+ }
42
+ if (!handle) {
43
+ throw new Error(`Could not parse handle from doc: ${doc}`);
44
+ }
45
+ if (!pds) {
46
+ throw new Error(`Could not parse pds from doc: ${doc}`);
47
+ }
48
+ return { did, signingKey, handle, pds };
49
+ };
50
+ export const ensureAtprotoKey = (doc) => {
51
+ const { signingKey } = parseToAtprotoDocument(doc);
52
+ if (!signingKey) {
53
+ throw new Error(`Could not parse signingKey from doc: ${doc}`);
54
+ }
55
+ return signingKey;
56
+ };
57
+ //# 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,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,aAAa,G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ACnB,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 type { 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"]}
@@ -0,0 +1,15 @@
1
+ import { type AtprotoData, type CacheResult, type DidCache, type DidDocument } from '../types.js';
2
+ export declare abstract class BaseResolver {
3
+ cache?: DidCache | undefined;
4
+ constructor(cache?: DidCache | undefined);
5
+ abstract resolveNoCheck(did: string): Promise<unknown | null>;
6
+ validateDidDoc(did: string, val: unknown): DidDocument;
7
+ resolveNoCache(did: string): Promise<DidDocument | null>;
8
+ refreshCache(did: string, prevResult?: CacheResult): Promise<void>;
9
+ resolve(did: string, forceRefresh?: boolean): Promise<DidDocument | null>;
10
+ ensureResolve(did: string, forceRefresh?: boolean): Promise<DidDocument>;
11
+ resolveAtprotoData(did: string, forceRefresh?: boolean): Promise<AtprotoData>;
12
+ resolveAtprotoKey(did: string, forceRefresh?: boolean): Promise<string>;
13
+ verifySignature(did: string, data: Uint8Array, sig: Uint8Array, forceRefresh?: boolean): Promise<boolean>;
14
+ }
15
+ //# 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":"AAGA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAA;AAGpB,8BAAsB,YAAY;IACb,KAAK,CAAC,EAAE,QAAQ;IAAnC,YAAmB,KAAK,CAAC,EAAE,QAAQ,YAAA,EAAI;IAEvC,QAAQ,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAE7D,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,WAAW,CAQrD;IAEK,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAI7D;IAEK,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAMvE;IAEK,OAAO,CACX,GAAG,EAAE,MAAM,EACX,YAAY,UAAQ,GACnB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAmB7B;IAEK,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,UAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CAM3E;IAEK,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,YAAY,UAAQ,GACnB,OAAO,CAAC,WAAW,CAAC,CAGtB;IAEK,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,UAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAO1E;IAEK,eAAe,CACnB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,UAAU,EACf,YAAY,UAAQ,GACnB,OAAO,CAAC,OAAO,CAAC,CAGlB;CACF"}
@@ -0,0 +1,72 @@
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 {
7
+ constructor(cache) {
8
+ this.cache = cache;
9
+ }
10
+ validateDidDoc(did, val) {
11
+ if (!check.is(val, didDocument)) {
12
+ throw new PoorlyFormattedDidDocumentError(did, val);
13
+ }
14
+ if (val.id !== did) {
15
+ throw new PoorlyFormattedDidDocumentError(did, val);
16
+ }
17
+ return val;
18
+ }
19
+ async resolveNoCache(did) {
20
+ const got = await this.resolveNoCheck(did);
21
+ if (got === null)
22
+ return null;
23
+ return this.validateDidDoc(did, got);
24
+ }
25
+ async refreshCache(did, prevResult) {
26
+ await this.cache?.refreshCache(did, () => this.resolveNoCache(did), prevResult);
27
+ }
28
+ async resolve(did, forceRefresh = false) {
29
+ let fromCache = null;
30
+ if (this.cache && !forceRefresh) {
31
+ fromCache = await this.cache.checkCache(did);
32
+ if (fromCache && !fromCache.expired) {
33
+ if (fromCache?.stale) {
34
+ await this.refreshCache(did, fromCache);
35
+ }
36
+ return fromCache.doc;
37
+ }
38
+ }
39
+ const got = await this.resolveNoCache(did);
40
+ if (got === null) {
41
+ await this.cache?.clearEntry(did);
42
+ return null;
43
+ }
44
+ await this.cache?.cacheDid(did, got, fromCache ?? undefined);
45
+ return got;
46
+ }
47
+ async ensureResolve(did, forceRefresh = false) {
48
+ const result = await this.resolve(did, forceRefresh);
49
+ if (result === null) {
50
+ throw new DidNotFoundError(did);
51
+ }
52
+ return result;
53
+ }
54
+ async resolveAtprotoData(did, forceRefresh = false) {
55
+ const didDocument = await this.ensureResolve(did, forceRefresh);
56
+ return atprotoData.ensureAtpDocument(didDocument);
57
+ }
58
+ async resolveAtprotoKey(did, forceRefresh = false) {
59
+ if (did.startsWith('did:key:')) {
60
+ return did;
61
+ }
62
+ else {
63
+ const didDocument = await this.ensureResolve(did, forceRefresh);
64
+ return atprotoData.ensureAtprotoKey(didDocument);
65
+ }
66
+ }
67
+ async verifySignature(did, data, sig, forceRefresh = false) {
68
+ const signingKey = await this.resolveAtprotoKey(did, forceRefresh);
69
+ return crypto.verifySignature(signingKey, data, sig);
70
+ }
71
+ }
72
+ //# sourceMappingURL=base-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-resolver.js","sourceRoot":"","sources":["../../src/did/base-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAA;AAChF,OAAO,EAKL,WAAW,GACZ,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,W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AAC,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 type AtprotoData,\n type CacheResult,\n type DidCache,\n type 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"]}
@@ -0,0 +1,8 @@
1
+ import type { DidResolverOpts } from '../types.js';
2
+ import { BaseResolver } from './base-resolver.js';
3
+ export declare class DidResolver extends BaseResolver {
4
+ methods: Map<string, BaseResolver>;
5
+ constructor(opts: DidResolverOpts);
6
+ resolveNoCheck(did: string): Promise<unknown>;
7
+ }
8
+ //# 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":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAIjD,qBAAa,WAAY,SAAQ,YAAY;IAC3C,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IAElC,YAAY,IAAI,EAAE,eAAe,EAQhC;IAEK,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAclD;CACF"}
@@ -0,0 +1,31 @@
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 {
6
+ constructor(opts) {
7
+ super(opts.didCache);
8
+ const { timeout = 3000, plcUrl = 'https://plc.directory' } = opts;
9
+ // do not pass cache to sub-methods or we will be double caching
10
+ this.methods = new Map([
11
+ ['plc', new DidPlcResolver(plcUrl, timeout)],
12
+ ['web', new DidWebResolver(timeout)],
13
+ ]);
14
+ }
15
+ async resolveNoCheck(did) {
16
+ if (!did.startsWith('did:')) {
17
+ throw new PoorlyFormattedDidError(did);
18
+ }
19
+ const methodSepIdx = did.indexOf(':', 4);
20
+ if (methodSepIdx === -1) {
21
+ throw new PoorlyFormattedDidError(did);
22
+ }
23
+ const methodName = did.slice(4, methodSepIdx);
24
+ const method = this.methods.get(methodName);
25
+ if (!method) {
26
+ throw new UnsupportedDidMethodError(did);
27
+ }
28
+ return method.resolveNoCheck(did);
29
+ }
30
+ }
31
+ //# 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,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 type { 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"]}
@@ -0,0 +1,6 @@
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
+ //# 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,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,6 @@
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
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,18 @@
1
+ import type { CacheResult, DidCache, DidDocument } from '../types.js';
2
+ type CacheVal = {
3
+ doc: DidDocument;
4
+ updatedAt: number;
5
+ };
6
+ export declare class MemoryCache implements DidCache {
7
+ staleTTL: number;
8
+ maxTTL: number;
9
+ constructor(staleTTL?: number, maxTTL?: number);
10
+ cache: Map<string, CacheVal>;
11
+ cacheDid(did: string, doc: DidDocument): Promise<void>;
12
+ refreshCache(did: string, getDoc: () => Promise<DidDocument | null>): Promise<void>;
13
+ checkCache(did: string): Promise<CacheResult | null>;
14
+ clearEntry(did: string): Promise<void>;
15
+ clear(): Promise<void>;
16
+ }
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,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAErE,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;IACrB,YAAY,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAG7C;IAEM,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAY;IAEzC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3D;IAEK,YAAY,CAChB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,GACxC,OAAO,CAAC,IAAI,CAAC,CAKf;IAEK,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAYzD;IAEK,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3C;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;CACF"}
@@ -0,0 +1,38 @@
1
+ import { DAY, HOUR } from '@atproto/common-web';
2
+ export class MemoryCache {
3
+ constructor(staleTTL, maxTTL) {
4
+ this.cache = new Map();
5
+ this.staleTTL = staleTTL ?? HOUR;
6
+ this.maxTTL = maxTTL ?? DAY;
7
+ }
8
+ async cacheDid(did, doc) {
9
+ this.cache.set(did, { doc, updatedAt: Date.now() });
10
+ }
11
+ async refreshCache(did, getDoc) {
12
+ const doc = await getDoc();
13
+ if (doc) {
14
+ await this.cacheDid(did, doc);
15
+ }
16
+ }
17
+ async checkCache(did) {
18
+ const val = this.cache.get(did);
19
+ if (!val)
20
+ return null;
21
+ const now = Date.now();
22
+ const expired = now > val.updatedAt + this.maxTTL;
23
+ const stale = now > val.updatedAt + this.staleTTL;
24
+ return {
25
+ ...val,
26
+ did,
27
+ stale,
28
+ expired,
29
+ };
30
+ }
31
+ async clearEntry(did) {
32
+ this.cache.delete(did);
33
+ }
34
+ async clear() {
35
+ this.cache.clear();
36
+ }
37
+ }
38
+ //# 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,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 type { 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"]}
@@ -0,0 +1,10 @@
1
+ import type { DidCache } from '../types.js';
2
+ import { BaseResolver } from './base-resolver.js';
3
+ export declare class DidPlcResolver extends BaseResolver {
4
+ plcUrl: string;
5
+ timeout: number;
6
+ cache?: DidCache | undefined;
7
+ constructor(plcUrl: string, timeout: number, cache?: DidCache | undefined);
8
+ resolveNoCheck(did: string): Promise<unknown>;
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":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,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;IAHzB,YACS,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,QAAQ,YAAA,EAGxB;IAEK,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAkBlD;CACF"}
@@ -0,0 +1,28 @@
1
+ import { BaseResolver } from './base-resolver.js';
2
+ import { timed } from './util.js';
3
+ export class DidPlcResolver extends BaseResolver {
4
+ constructor(plcUrl, timeout, cache) {
5
+ super(cache);
6
+ this.plcUrl = plcUrl;
7
+ this.timeout = timeout;
8
+ this.cache = cache;
9
+ }
10
+ async resolveNoCheck(did) {
11
+ return timed(this.timeout, async (signal) => {
12
+ const url = new URL(`/${encodeURIComponent(did)}`, this.plcUrl);
13
+ const res = await fetch(url, {
14
+ redirect: 'error',
15
+ headers: { accept: 'application/did+ld+json,application/json' },
16
+ signal,
17
+ });
18
+ // Positively not found, versus due to e.g. network error
19
+ if (res.status === 404)
20
+ return null;
21
+ if (!res.ok) {
22
+ throw Object.assign(new Error(res.statusText), { status: res.status });
23
+ }
24
+ return res.json();
25
+ });
26
+ }
27
+ }
28
+ //# sourceMappingURL=plc-resolver.js.map
@@ -0,0 +1 @@
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;sBAJL,MAAM;uBACN,OAAO;qBACP,KAAK;IAGd,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 type { 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"]}
@@ -0,0 +1,2 @@
1
+ export declare function timed<F extends (signal: AbortSignal) => unknown>(ms: number, fn: F): Promise<Awaited<ReturnType<F>>>;
2
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/did/util.ts"],"names":[],"mappings":"AAAA,wBAAsB,KAAK,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,EACpE,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,CAAC,GACJ,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAWjC"}
@@ -0,0 +1,13 @@
1
+ export async function timed(ms, fn) {
2
+ const abortController = new AbortController();
3
+ const timer = setTimeout(() => abortController.abort(), ms);
4
+ const signal = abortController.signal;
5
+ try {
6
+ return (await fn(signal));
7
+ }
8
+ finally {
9
+ clearTimeout(timer);
10
+ abortController.abort();
11
+ }
12
+ }
13
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,10 @@
1
+ import type { DidCache } from '../types.js';
2
+ import { BaseResolver } from './base-resolver.js';
3
+ export declare const DOC_PATH = "/.well-known/did.json";
4
+ export declare class DidWebResolver extends BaseResolver {
5
+ timeout: number;
6
+ cache?: DidCache | undefined;
7
+ constructor(timeout: number, cache?: DidCache | undefined);
8
+ resolveNoCheck(did: string): Promise<unknown>;
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":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGjD,eAAO,MAAM,QAAQ,0BAA0B,CAAA;AAE/C,qBAAa,cAAe,SAAQ,YAAY;IAErC,OAAO,EAAE,MAAM;IACf,KAAK,CAAC,EAAE,QAAQ;IAFzB,YACS,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,QAAQ,YAAA,EAGxB;IAEK,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA+BlD;CACF"}
@@ -0,0 +1,43 @@
1
+ import { PoorlyFormattedDidError, UnsupportedDidWebPathError, } from '../errors.js';
2
+ import { BaseResolver } from './base-resolver.js';
3
+ import { timed } from './util.js';
4
+ export const DOC_PATH = '/.well-known/did.json';
5
+ export class DidWebResolver extends BaseResolver {
6
+ constructor(timeout, cache) {
7
+ super(cache);
8
+ this.timeout = timeout;
9
+ this.cache = cache;
10
+ }
11
+ async resolveNoCheck(did) {
12
+ const parsedId = did.split(':').slice(2).join(':');
13
+ const parts = parsedId.split(':').map(decodeURIComponent);
14
+ let path;
15
+ if (parts.length < 1) {
16
+ throw new PoorlyFormattedDidError(did);
17
+ }
18
+ else if (parts.length === 1) {
19
+ path = parts[0] + DOC_PATH;
20
+ }
21
+ else {
22
+ // how we *would* resolve a did:web with path, if atproto supported it
23
+ //path = parts.join('/') + '/did.json'
24
+ throw new UnsupportedDidWebPathError(did);
25
+ }
26
+ const url = new URL(`https://${path}`);
27
+ if (url.hostname === 'localhost') {
28
+ url.protocol = 'http';
29
+ }
30
+ return timed(this.timeout, async (signal) => {
31
+ const res = await fetch(url, {
32
+ signal,
33
+ redirect: 'error',
34
+ headers: { accept: 'application/did+ld+json,application/json' },
35
+ });
36
+ // Positively not found, versus due to e.g. network error
37
+ if (!res.ok)
38
+ return null;
39
+ return res.json();
40
+ });
41
+ }
42
+ }
43
+ //# 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,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEjC,MAAM,CAAC,MAAM,QAAQ,GAAG,uBAAuB,CAAA;AAE/C,MAAM,OAAO,cAAe,SAAQ,YAAY;IAC9C,YACS,OAAe,EACf,KAAgB;QAEvB,KAAK,CAAC,KAAK,CAAC,CAAA;uBAHL,OAAO;qBACP,KAAK;IAGd,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAW;QAC9B,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAClD,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;QACzD,IAAI,IAAY,CAAA;QAChB,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,uBAAuB,CAAC,GAAG,CAAC,CAAA;QACxC,CAAC;aAAM,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9B,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAA;QAC5B,CAAC;aAAM,CAAC;YACN,sEAAsE;YACtE,sCAAsC;YACtC,MAAM,IAAI,0BAA0B,CAAC,GAAG,CAAC,CAAA;QAC3C,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,CAAA;QACtC,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;YACjC,GAAG,CAAC,QAAQ,GAAG,MAAM,CAAA;QACvB,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC1C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAC3B,MAAM;gBACN,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,EAAE,MAAM,EAAE,0CAA0C,EAAE;aAChE,CAAC,CAAA;YAEF,yDAAyD;YACzD,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,OAAO,IAAI,CAAA;YAExB,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;QACnB,CAAC,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import {\n PoorlyFormattedDidError,\n UnsupportedDidWebPathError,\n} from '../errors.js'\nimport type { DidCache } from '../types.js'\nimport { BaseResolver } from './base-resolver.js'\nimport { timed } from './util.js'\n\nexport const DOC_PATH = '/.well-known/did.json'\n\nexport class DidWebResolver extends BaseResolver {\n constructor(\n public timeout: number,\n public cache?: DidCache,\n ) {\n super(cache)\n }\n\n async resolveNoCheck(did: string): Promise<unknown> {\n const parsedId = did.split(':').slice(2).join(':')\n const parts = parsedId.split(':').map(decodeURIComponent)\n let path: string\n if (parts.length < 1) {\n throw new PoorlyFormattedDidError(did)\n } else if (parts.length === 1) {\n path = parts[0] + DOC_PATH\n } else {\n // how we *would* resolve a did:web with path, if atproto supported it\n //path = parts.join('/') + '/did.json'\n throw new UnsupportedDidWebPathError(did)\n }\n\n const url = new URL(`https://${path}`)\n if (url.hostname === 'localhost') {\n url.protocol = 'http'\n }\n\n return timed(this.timeout, async (signal) => {\n const res = await fetch(url, {\n signal,\n redirect: 'error',\n headers: { accept: 'application/did+ld+json,application/json' },\n })\n\n // Positively not found, versus due to e.g. network error\n if (!res.ok) return null\n\n return res.json()\n })\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ export declare class DidNotFoundError extends Error {
2
+ did: string;
3
+ constructor(did: string);
4
+ }
5
+ export declare class PoorlyFormattedDidError extends Error {
6
+ did: string;
7
+ constructor(did: string);
8
+ }
9
+ export declare class UnsupportedDidMethodError extends Error {
10
+ did: string;
11
+ constructor(did: string);
12
+ }
13
+ export declare class PoorlyFormattedDidDocumentError extends Error {
14
+ did: string;
15
+ doc: unknown;
16
+ constructor(did: string, doc: unknown);
17
+ }
18
+ export declare class UnsupportedDidWebPathError extends Error {
19
+ did: string;
20
+ constructor(did: string);
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;IAA9B,YAAmB,GAAG,EAAE,MAAM,EAE7B;CACF;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAC7B,GAAG,EAAE,MAAM;IAA9B,YAAmB,GAAG,EAAE,MAAM,EAE7B;CACF;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IAC/B,GAAG,EAAE,MAAM;IAA9B,YAAmB,GAAG,EAAE,MAAM,EAE7B;CACF;AAED,qBAAa,+BAAgC,SAAQ,KAAK;IAE/C,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,OAAO;IAFrB,YACS,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,OAAO,EAGpB;CACF;AAED,qBAAa,0BAA2B,SAAQ,KAAK;IAChC,GAAG,EAAE,MAAM;IAA9B,YAAmB,GAAG,EAAE,MAAM,EAE7B;CACF"}
package/dist/errors.js ADDED
@@ -0,0 +1,32 @@
1
+ export class DidNotFoundError extends Error {
2
+ constructor(did) {
3
+ super(`Could not resolve DID: ${did}`);
4
+ this.did = did;
5
+ }
6
+ }
7
+ export class PoorlyFormattedDidError extends Error {
8
+ constructor(did) {
9
+ super(`Poorly formatted DID: ${did}`);
10
+ this.did = did;
11
+ }
12
+ }
13
+ export class UnsupportedDidMethodError extends Error {
14
+ constructor(did) {
15
+ super(`Unsupported DID method: ${did}`);
16
+ this.did = did;
17
+ }
18
+ }
19
+ export class PoorlyFormattedDidDocumentError extends Error {
20
+ constructor(did, doc) {
21
+ super(`Poorly formatted DID Document: ${doc}`);
22
+ this.did = did;
23
+ this.doc = doc;
24
+ }
25
+ }
26
+ export class UnsupportedDidWebPathError extends Error {
27
+ constructor(did) {
28
+ super(`Unsupported did:web paths: ${did}`);
29
+ this.did = did;
30
+ }
31
+ }
32
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAmB,GAAW;QAC5B,KAAK,CAAC,0BAA0B,GAAG,EAAE,CAAC,CAAA;mBADrB,GAAG;IAEtB,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,YAAmB,GAAW;QAC5B,KAAK,CAAC,yBAAyB,GAAG,EAAE,CAAC,CAAA;mBADpB,GAAG;IAEtB,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,YAAmB,GAAW;QAC5B,KAAK,CAAC,2BAA2B,GAAG,EAAE,CAAC,CAAA;mBADtB,GAAG;IAEtB,CAAC;CACF;AAED,MAAM,OAAO,+BAAgC,SAAQ,KAAK;IACxD,YACS,GAAW,EACX,GAAY;QAEnB,KAAK,CAAC,kCAAkC,GAAG,EAAE,CAAC,CAAA;mBAHvC,GAAG;mBACH,GAAG;IAGZ,CAAC;CACF;AAED,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,YAAmB,GAAW;QAC5B,KAAK,CAAC,8BAA8B,GAAG,EAAE,CAAC,CAAA;mBADzB,GAAG;IAEtB,CAAC;CACF","sourcesContent":["export class DidNotFoundError extends Error {\n constructor(public did: string) {\n super(`Could not resolve DID: ${did}`)\n }\n}\n\nexport class PoorlyFormattedDidError extends Error {\n constructor(public did: string) {\n super(`Poorly formatted DID: ${did}`)\n }\n}\n\nexport class UnsupportedDidMethodError extends Error {\n constructor(public did: string) {\n super(`Unsupported DID method: ${did}`)\n }\n}\n\nexport class PoorlyFormattedDidDocumentError extends Error {\n constructor(\n public did: string,\n public doc: unknown,\n ) {\n super(`Poorly formatted DID Document: ${doc}`)\n }\n}\n\nexport class UnsupportedDidWebPathError extends Error {\n constructor(public did: string) {\n super(`Unsupported did:web paths: ${did}`)\n }\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import type { HandleResolverOpts } from '../types.js';
2
+ export declare class HandleResolver {
3
+ timeout: number;
4
+ private backupNameservers;
5
+ private backupNameserverIps;
6
+ constructor(opts?: HandleResolverOpts);
7
+ resolve(handle: string): Promise<string | undefined>;
8
+ resolveDns(handle: string): Promise<string | undefined>;
9
+ resolveHttp(handle: string, signal?: AbortSignal): Promise<string | undefined>;
10
+ resolveDnsBackup(handle: string): Promise<string | undefined>;
11
+ parseDnsResult(chunkedResults: string[][]): string | undefined;
12
+ private getBackupNameserverIps;
13
+ }
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handle/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAKrD,qBAAa,cAAc;IAClB,OAAO,EAAE,MAAM,CAAA;IACtB,OAAO,CAAC,iBAAiB,CAAsB;IAC/C,OAAO,CAAC,mBAAmB,CAAsB;IAEjD,YAAY,IAAI,GAAE,kBAAuB,EAGxC;IAEK,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAiBzD;IAEK,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAQ5D;IAEK,WAAW,CACf,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAY7B;IAEK,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAYlE;IAED,cAAc,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,GAAG,SAAS,CAO7D;YAEa,sBAAsB;CAgBrC"}
@@ -0,0 +1,87 @@
1
+ import * as dns from 'node:dns/promises';
2
+ const SUBDOMAIN = '_atproto';
3
+ const PREFIX = 'did=';
4
+ export class HandleResolver {
5
+ constructor(opts = {}) {
6
+ this.timeout = opts.timeout ?? 3000;
7
+ this.backupNameservers = opts.backupNameservers;
8
+ }
9
+ async resolve(handle) {
10
+ const dnsPromise = this.resolveDns(handle);
11
+ const httpAbort = new AbortController();
12
+ const httpPromise = this.resolveHttp(handle, httpAbort.signal).catch(() => undefined);
13
+ const dnsRes = await dnsPromise;
14
+ if (dnsRes) {
15
+ httpAbort.abort();
16
+ return dnsRes;
17
+ }
18
+ const res = await httpPromise;
19
+ if (res) {
20
+ return res;
21
+ }
22
+ return this.resolveDnsBackup(handle);
23
+ }
24
+ async resolveDns(handle) {
25
+ let chunkedResults;
26
+ try {
27
+ chunkedResults = await dns.resolveTxt(`${SUBDOMAIN}.${handle}`);
28
+ }
29
+ catch (err) {
30
+ return undefined;
31
+ }
32
+ return this.parseDnsResult(chunkedResults);
33
+ }
34
+ async resolveHttp(handle, signal) {
35
+ const url = new URL('/.well-known/atproto-did', `https://${handle}`);
36
+ try {
37
+ const res = await fetch(url, { signal });
38
+ const did = (await res.text()).split('\n')[0].trim();
39
+ if (typeof did === 'string' && did.startsWith('did:')) {
40
+ return did;
41
+ }
42
+ return undefined;
43
+ }
44
+ catch (err) {
45
+ return undefined;
46
+ }
47
+ }
48
+ async resolveDnsBackup(handle) {
49
+ let chunkedResults;
50
+ try {
51
+ const backupIps = await this.getBackupNameserverIps();
52
+ if (!backupIps || backupIps.length < 1)
53
+ return undefined;
54
+ const resolver = new dns.Resolver();
55
+ resolver.setServers(backupIps);
56
+ chunkedResults = await resolver.resolveTxt(`${SUBDOMAIN}.${handle}`);
57
+ }
58
+ catch (err) {
59
+ return undefined;
60
+ }
61
+ return this.parseDnsResult(chunkedResults);
62
+ }
63
+ parseDnsResult(chunkedResults) {
64
+ const results = chunkedResults.map((chunks) => chunks.join(''));
65
+ const found = results.filter((i) => i.startsWith(PREFIX));
66
+ if (found.length !== 1) {
67
+ return undefined;
68
+ }
69
+ return found[0].slice(PREFIX.length);
70
+ }
71
+ async getBackupNameserverIps() {
72
+ if (!this.backupNameservers) {
73
+ return undefined;
74
+ }
75
+ else if (!this.backupNameserverIps) {
76
+ const responses = await Promise.allSettled(this.backupNameservers.map((h) => dns.lookup(h)));
77
+ for (const res of responses) {
78
+ if (res.status === 'fulfilled') {
79
+ this.backupNameserverIps ??= [];
80
+ this.backupNameserverIps.push(res.value.address);
81
+ }
82
+ }
83
+ }
84
+ return this.backupNameserverIps;
85
+ }
86
+ }
87
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/handle/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAA;AAGxC,MAAM,SAAS,GAAG,UAAU,CAAA;AAC5B,MAAM,MAAM,GAAG,MAAM,CAAA;AAErB,MAAM,OAAO,cAAc;IAKzB,YAAY,IAAI,GAAuB,EAAE;QACvC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAA;QACnC,IAAI,CAAC,iBAAi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AAK,CAAC,EAAE,CAAC;YACvB,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACtC,CAAC;IAEO,KAAK,CAAC,sBAAsB;QAClC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC5B,OAAO,SAAS,CAAA;QAClB,CAAC;aAAM,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACrC,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,UAAU,CACxC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CACjD,CAAA;YACD,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;gBAC5B,IAAI,GAAG,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;oBAC/B,IAAI,CAAC,mBAAmB,KAAK,EAAE,CAAA;oBAC/B,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;gBAClD,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,mBAAmB,CAAA;IACjC,CAAC;CACF","sourcesContent":["import * as dns from 'node:dns/promises'\nimport type { HandleResolverOpts } from '../types.js'\n\nconst SUBDOMAIN = '_atproto'\nconst PREFIX = 'did='\n\nexport class HandleResolver {\n public timeout: number\n private backupNameservers: string[] | undefined\n private backupNameserverIps: string[] | undefined\n\n constructor(opts: HandleResolverOpts = {}) {\n this.timeout = opts.timeout ?? 3000\n this.backupNameservers = opts.backupNameservers\n }\n\n async resolve(handle: string): Promise<string | undefined> {\n const dnsPromise = this.resolveDns(handle)\n const httpAbort = new AbortController()\n const httpPromise = this.resolveHttp(handle, httpAbort.signal).catch(\n () => undefined,\n )\n\n const dnsRes = await dnsPromise\n if (dnsRes) {\n httpAbort.abort()\n return dnsRes\n }\n const res = await httpPromise\n if (res) {\n return res\n }\n return this.resolveDnsBackup(handle)\n }\n\n async resolveDns(handle: string): Promise<string | undefined> {\n let chunkedResults: string[][]\n try {\n chunkedResults = await dns.resolveTxt(`${SUBDOMAIN}.${handle}`)\n } catch (err) {\n return undefined\n }\n return this.parseDnsResult(chunkedResults)\n }\n\n async resolveHttp(\n handle: string,\n signal?: AbortSignal,\n ): Promise<string | undefined> {\n const url = new URL('/.well-known/atproto-did', `https://${handle}`)\n try {\n const res = await fetch(url, { signal })\n const did = (await res.text()).split('\\n')[0].trim()\n if (typeof did === 'string' && did.startsWith('did:')) {\n return did\n }\n return undefined\n } catch (err) {\n return undefined\n }\n }\n\n async resolveDnsBackup(handle: string): Promise<string | undefined> {\n let chunkedResults: string[][]\n try {\n const backupIps = await this.getBackupNameserverIps()\n if (!backupIps || backupIps.length < 1) return undefined\n const resolver = new dns.Resolver()\n resolver.setServers(backupIps)\n chunkedResults = await resolver.resolveTxt(`${SUBDOMAIN}.${handle}`)\n } catch (err) {\n return undefined\n }\n return this.parseDnsResult(chunkedResults)\n }\n\n parseDnsResult(chunkedResults: string[][]): string | undefined {\n const results = chunkedResults.map((chunks) => chunks.join(''))\n const found = results.filter((i) => i.startsWith(PREFIX))\n if (found.length !== 1) {\n return undefined\n }\n return found[0].slice(PREFIX.length)\n }\n\n private async getBackupNameserverIps(): Promise<string[] | undefined> {\n if (!this.backupNameservers) {\n return undefined\n } else if (!this.backupNameserverIps) {\n const responses = await Promise.allSettled(\n this.backupNameservers.map((h) => dns.lookup(h)),\n )\n for (const res of responses) {\n if (res.status === 'fulfilled') {\n this.backupNameserverIps ??= []\n this.backupNameserverIps.push(res.value.address)\n }\n }\n }\n return this.backupNameserverIps\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import { DidResolver } from './did/did-resolver.js';
2
+ import { HandleResolver } from './handle/index.js';
3
+ import type { IdentityResolverOpts } from './types.js';
4
+ export declare class IdResolver {
5
+ handle: HandleResolver;
6
+ did: DidResolver;
7
+ constructor(opts?: IdentityResolverOpts);
8
+ }
9
+ //# sourceMappingURL=id-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-resolver.d.ts","sourceRoot":"","sources":["../src/id-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD,qBAAa,UAAU;IACd,MAAM,EAAE,cAAc,CAAA;IACtB,GAAG,EAAE,WAAW,CAAA;IAEvB,YAAY,IAAI,GAAE,oBAAyB,EAO1C;CACF"}
@@ -0,0 +1,13 @@
1
+ import { DidResolver } from './did/did-resolver.js';
2
+ import { HandleResolver } from './handle/index.js';
3
+ export class IdResolver {
4
+ constructor(opts = {}) {
5
+ const { timeout = 3000, plcUrl, didCache } = opts;
6
+ this.handle = new HandleResolver({
7
+ timeout,
8
+ backupNameservers: opts.backupNameservers,
9
+ });
10
+ this.did = new DidResolver({ timeout, plcUrl, didCache });
11
+ }
12
+ }
13
+ //# sourceMappingURL=id-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-resolver.js","sourceRoot":"","sources":["../src/id-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAGlD,MAAM,OAAO,UAAU;IAIrB,YAAY,IAAI,GAAyB,EAAE;QACzC,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;QACjD,IAAI,CAAC,MAAM,GAAG,IAAI,cAAc,CAAC;YAC/B,OAAO;YACP,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;SAC1C,CAAC,CAAA;QACF,IAAI,CAAC,GAAG,GAAG,IAAI,WAAW,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC3D,CAAC;CACF","sourcesContent":["import { DidResolver } from './did/did-resolver.js'\nimport { HandleResolver } from './handle/index.js'\nimport type { IdentityResolverOpts } from './types.js'\n\nexport class IdResolver {\n public handle: HandleResolver\n public did: DidResolver\n\n constructor(opts: IdentityResolverOpts = {}) {\n const { timeout = 3000, plcUrl, didCache } = opts\n this.handle = new HandleResolver({\n timeout,\n backupNameservers: opts.backupNameservers,\n })\n this.did = new DidResolver({ timeout, plcUrl, didCache })\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export * from './did/index.js';
2
+ export * from './handle/index.js';
3
+ export * from './id-resolver.js';
4
+ export * from './errors.js';
5
+ export * from './types.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from './did/index.js';
2
+ export * from './handle/index.js';
3
+ export * from './id-resolver.js';
4
+ export * from './errors.js';
5
+ export * from './types.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA","sourcesContent":["export * from './did/index.js'\nexport * from './handle/index.js'\nexport * from './id-resolver.js'\nexport * from './errors.js'\nexport * from './types.js'\n"]}
@@ -0,0 +1,39 @@
1
+ import type { DidDocument } from '@atproto/common-web';
2
+ export { didDocument } from '@atproto/common-web';
3
+ export type { DidDocument } from '@atproto/common-web';
4
+ export type IdentityResolverOpts = {
5
+ timeout?: number;
6
+ plcUrl?: string;
7
+ didCache?: DidCache;
8
+ backupNameservers?: string[];
9
+ };
10
+ export type HandleResolverOpts = {
11
+ timeout?: number;
12
+ backupNameservers?: string[];
13
+ };
14
+ export type DidResolverOpts = {
15
+ timeout?: number;
16
+ plcUrl?: string;
17
+ didCache?: DidCache;
18
+ };
19
+ export type AtprotoData = {
20
+ did: string;
21
+ signingKey: string;
22
+ handle: string;
23
+ pds: string;
24
+ };
25
+ export type CacheResult = {
26
+ did: string;
27
+ doc: DidDocument;
28
+ updatedAt: number;
29
+ stale: boolean;
30
+ expired: boolean;
31
+ };
32
+ export interface DidCache {
33
+ cacheDid(did: string, doc: DidDocument, prevResult?: CacheResult): Promise<void>;
34
+ checkCache(did: string): Promise<CacheResult | null>;
35
+ refreshCache(did: string, getDoc: () => Promise<DidDocument | null>, prevResult?: CacheResult): Promise<void>;
36
+ clearEntry(did: string): Promise<void>;
37
+ clear(): Promise<void>;
38
+ }
39
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEtD,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,WAAW,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CACN,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,WAAW,EAChB,UAAU,CAAC,EAAE,WAAW,GACvB,OAAO,CAAC,IAAI,CAAC,CAAA;IAChB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACpD,YAAY,CACV,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,EACzC,UAAU,CAAC,EAAE,WAAW,GACvB,OAAO,CAAC,IAAI,CAAC,CAAA;IAChB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACtC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export { didDocument } from '@atproto/common-web';
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA","sourcesContent":["import type { DidDocument } from '@atproto/common-web'\n\nexport { didDocument } from '@atproto/common-web'\nexport type { DidDocument } from '@atproto/common-web'\n\nexport type IdentityResolverOpts = {\n timeout?: number\n plcUrl?: string\n didCache?: DidCache\n backupNameservers?: string[]\n}\n\nexport type HandleResolverOpts = {\n timeout?: number\n backupNameservers?: string[]\n}\n\nexport type DidResolverOpts = {\n timeout?: number\n plcUrl?: string\n didCache?: DidCache\n}\n\nexport type AtprotoData = {\n did: string\n signingKey: string\n handle: string\n pds: string\n}\n\nexport type CacheResult = {\n did: string\n doc: DidDocument\n updatedAt: number\n stale: boolean\n expired: boolean\n}\n\nexport interface DidCache {\n cacheDid(\n did: string,\n doc: DidDocument,\n prevResult?: CacheResult,\n ): Promise<void>\n checkCache(did: string): Promise<CacheResult | null>\n refreshCache(\n did: string,\n getDoc: () => Promise<DidDocument | null>,\n prevResult?: CacheResult,\n ): Promise<void>\n clearEntry(did: string): Promise<void>\n clear(): Promise<void>\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@atproto/identity",
3
+ "version": "0.0.0-spaces-alpha-20260818021221",
4
+ "license": "MIT",
5
+ "description": "Library for decentralized identities in atproto using DIDs and handles",
6
+ "keywords": [
7
+ "atproto",
8
+ "did",
9
+ "identity"
10
+ ],
11
+ "homepage": "https://atproto.com",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/bluesky-social/atproto",
15
+ "directory": "packages/identity"
16
+ },
17
+ "files": [
18
+ "./dist",
19
+ "./README.md",
20
+ "./CHANGELOG.md"
21
+ ],
22
+ "type": "module",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ }
28
+ },
29
+ "engines": {
30
+ "node": ">=22"
31
+ },
32
+ "dependencies": {
33
+ "@atproto/common-web": "^0.0.0-spaces-alpha-20260818021221",
34
+ "@atproto/crypto": "^0.0.0-spaces-alpha-20260818021221"
35
+ },
36
+ "devDependencies": {
37
+ "@did-plc/lib": "^0.0.1",
38
+ "@did-plc/server": "^0.0.1",
39
+ "@jest/globals": "^30.0.0",
40
+ "@types/express": "^4.17.21",
41
+ "@types/cors": "^2.8.19",
42
+ "cors": "^2.8.5",
43
+ "express": "^4.18.2",
44
+ "get-port": "^6.1.2",
45
+ "jest": "^30.0.0"
46
+ },
47
+ "scripts": {
48
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
49
+ "test:log": "cat test.log | pino-pretty",
50
+ "build": "tsc --build tsconfig.build.json"
51
+ }
52
+ }