@helia/ipns 2.0.3 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +92 -25
  2. package/dist/index.min.js +24 -24
  3. package/dist/src/dns-resolvers/default.d.ts +3 -0
  4. package/dist/src/dns-resolvers/default.d.ts.map +1 -0
  5. package/dist/src/dns-resolvers/default.js +8 -0
  6. package/dist/src/dns-resolvers/default.js.map +1 -0
  7. package/dist/src/dns-resolvers/dns-json-over-https.d.ts +18 -0
  8. package/dist/src/dns-resolvers/dns-json-over-https.d.ts.map +1 -0
  9. package/dist/src/dns-resolvers/dns-json-over-https.js +72 -0
  10. package/dist/src/dns-resolvers/dns-json-over-https.js.map +1 -0
  11. package/dist/src/dns-resolvers/dns-over-https.d.ts +16 -0
  12. package/dist/src/dns-resolvers/dns-over-https.d.ts.map +1 -0
  13. package/dist/src/dns-resolvers/dns-over-https.js +123 -0
  14. package/dist/src/dns-resolvers/dns-over-https.js.map +1 -0
  15. package/dist/src/dns-resolvers/index.d.ts +3 -0
  16. package/dist/src/dns-resolvers/index.d.ts.map +1 -0
  17. package/dist/src/dns-resolvers/index.js +3 -0
  18. package/dist/src/dns-resolvers/index.js.map +1 -0
  19. package/dist/src/dns-resolvers/resolver.browser.d.ts +4 -0
  20. package/dist/src/dns-resolvers/resolver.browser.d.ts.map +1 -0
  21. package/dist/src/dns-resolvers/resolver.browser.js +39 -0
  22. package/dist/src/dns-resolvers/resolver.browser.js.map +1 -0
  23. package/dist/src/dns-resolvers/resolver.d.ts +4 -0
  24. package/dist/src/dns-resolvers/resolver.d.ts.map +1 -0
  25. package/dist/src/dns-resolvers/resolver.js +21 -0
  26. package/dist/src/dns-resolvers/resolver.js.map +1 -0
  27. package/dist/src/index.d.ts +105 -10
  28. package/dist/src/index.d.ts.map +1 -1
  29. package/dist/src/index.js +84 -12
  30. package/dist/src/index.js.map +1 -1
  31. package/dist/src/routing/dht.js.map +1 -1
  32. package/dist/src/routing/local-store.js.map +1 -1
  33. package/dist/src/routing/pubsub.js.map +1 -1
  34. package/dist/src/utils/dns.d.ts +35 -0
  35. package/dist/src/utils/dns.d.ts.map +1 -0
  36. package/dist/src/utils/dns.js +79 -0
  37. package/dist/src/utils/dns.js.map +1 -0
  38. package/dist/src/utils/tlru.js.map +1 -1
  39. package/dist/typedoc-urls.json +8 -0
  40. package/package.json +14 -4
  41. package/src/dns-resolvers/default.ts +9 -0
  42. package/src/dns-resolvers/dns-json-over-https.ts +90 -0
  43. package/src/dns-resolvers/dns-over-https.ts +146 -0
  44. package/src/dns-resolvers/index.ts +2 -0
  45. package/src/dns-resolvers/resolver.browser.ts +50 -0
  46. package/src/dns-resolvers/resolver.ts +25 -0
  47. package/src/index.ts +124 -14
  48. package/src/utils/dns.ts +126 -0
  49. package/dist/src/utils/resolve-dns-link.browser.d.ts +0 -6
  50. package/dist/src/utils/resolve-dns-link.browser.d.ts.map +0 -1
  51. package/dist/src/utils/resolve-dns-link.browser.js +0 -46
  52. package/dist/src/utils/resolve-dns-link.browser.js.map +0 -1
  53. package/dist/src/utils/resolve-dns-link.d.ts +0 -3
  54. package/dist/src/utils/resolve-dns-link.d.ts.map +0 -1
  55. package/dist/src/utils/resolve-dns-link.js +0 -54
  56. package/dist/src/utils/resolve-dns-link.js.map +0 -1
  57. package/src/utils/resolve-dns-link.browser.ts +0 -61
  58. package/src/utils/resolve-dns-link.ts +0 -65
package/README.md CHANGED
@@ -13,47 +13,114 @@
13
13
 
14
14
  > An implementation of IPNS for Helia
15
15
 
16
- ## Table of contents <!-- omit in toc -->
16
+ # About
17
17
 
18
- - [Install](#install)
19
- - [Browser `<script>` tag](#browser-script-tag)
20
- - [API Docs](#api-docs)
21
- - [License](#license)
22
- - [Contribute](#contribute)
18
+ IPNS operations using a Helia node
23
19
 
24
- ## Install
20
+ ## Example
25
21
 
26
- ```console
27
- $ npm i @helia/ipns
22
+ With IPNSRouting routers:
23
+
24
+ ```typescript
25
+ import { createHelia } from 'helia'
26
+ import { ipns } from '@helia/ipns'
27
+ import { dht, pubsub } from '@helia/ipns/routing'
28
+ import { unixfs } from '@helia/unixfs'
29
+
30
+ const helia = await createHelia()
31
+ const name = ipns(helia, {
32
+ routers: [
33
+ dht(helia),
34
+ pubsub(helia)
35
+ ]
36
+ })
37
+
38
+ // create a public key to publish as an IPNS name
39
+ const keyInfo = await helia.libp2p.keychain.createKey('my-key')
40
+ const peerId = await helia.libp2p.keychain.exportPeerId(keyInfo.name)
41
+
42
+ // store some data to publish
43
+ const fs = unixfs(helia)
44
+ const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
45
+
46
+ // publish the name
47
+ await name.publish(peerId, cid)
48
+
49
+ // resolve the name
50
+ const cid = name.resolve(peerId)
28
51
  ```
29
52
 
30
- ### Browser `<script>` tag
53
+ ## Example
54
+
55
+ With default DNSResolver resolvers:
31
56
 
32
- Loading this module through a script tag will make it's exports available as `HeliaIpns` in the global namespace.
57
+ ```typescript
58
+ import { createHelia } from 'helia'
59
+ import { ipns } from '@helia/ipns'
60
+ import { unixfs } from '@helia/unixfs'
61
+ import { dnsOverHttps } from '@helia/ipns/dns-resolvers'
33
62
 
34
- ```html
35
- <script src="https://unpkg.com/@helia/ipns/dist/index.min.js"></script>
63
+ const helia = await createHelia()
64
+ const name = ipns(helia, {
65
+ resolvers: [
66
+ dnsOverHttps('https://private-dns-server.me/dns-query'),
67
+ ]
68
+ })
69
+
70
+ const cid = name.resolveDns('some-domain-with-dnslink-entry.com')
36
71
  ```
37
72
 
38
- ## API Docs
73
+ ## Example
74
+
75
+ Calling `resolveDns` with the `@helia/ipns` instance:
39
76
 
40
- - <https://ipfs.github.io/helia-ipns/modules/_helia_ipns.html>
77
+ ```typescript
78
+ // resolve a CID from a TXT record in a DNS zone file, using the default
79
+ // resolver for the current platform eg:
80
+ // > dig _dnslink.ipfs.io TXT
81
+ // ;; ANSWER SECTION:
82
+ // _dnslink.ipfs.io. 60 IN TXT "dnslink=/ipns/website.ipfs.io"
83
+ // > dig _dnslink.website.ipfs.io TXT
84
+ // ;; ANSWER SECTION:
85
+ // _dnslink.website.ipfs.io. 60 IN TXT "dnslink=/ipfs/QmWebsite"
41
86
 
42
- ## License
87
+ const cid = name.resolveDns('ipfs.io')
43
88
 
44
- Licensed under either of
89
+ console.info(cid)
90
+ // QmWebsite
91
+ ```
45
92
 
46
- - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
47
- - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
93
+ ## Example
48
94
 
49
- ## Contribute
95
+ This example uses the Mozilla provided RFC 1035 DNS over HTTPS service. This
96
+ uses binary DNS records so requires extra dependencies to process the
97
+ response which can increase browser bundle sizes.
50
98
 
51
- Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia-ipns/issues).
99
+ If this is a concern, use the DNS-JSON-Over-HTTPS resolver instead.
52
100
 
53
- Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.
101
+ ```typescript
102
+ // use DNS-Over-HTTPS
103
+ import { dnsOverHttps } from '@helia/ipns/dns-resolvers'
54
104
 
55
- Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
105
+ const cid = name.resolveDns('ipfs.io', {
106
+ resolvers: [
107
+ dnsOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
108
+ ]
109
+ })
110
+ ```
56
111
 
57
- Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
112
+ ## Example
58
113
 
59
- [![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
114
+ DNS-JSON-Over-HTTPS resolvers use the RFC 8427 `application/dns-json` and can
115
+ result in a smaller browser bundle due to the response being plain JSON.
116
+
117
+ ```typescript
118
+ // use DNS-JSON-Over-HTTPS
119
+ import { dnsJsonOverHttps } from '@helia/ipns/dns-resolvers'
120
+
121
+ const cid = name.resolveDns('ipfs.io', {
122
+ resolvers: [
123
+ dnsJsonOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
124
+ ]
125
+ })
126
+ ```