@helia/interop 10.2.5-f6cc7640 → 11.0.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.
Files changed (66) hide show
  1. package/dist/src/car.spec.js.map +1 -1
  2. package/dist/src/dag-cbor.spec.js.map +1 -1
  3. package/dist/src/dag-json.spec.js.map +1 -1
  4. package/dist/src/dnslink.spec.js.map +1 -1
  5. package/dist/src/fixtures/connect.d.ts +2 -2
  6. package/dist/src/fixtures/connect.d.ts.map +1 -1
  7. package/dist/src/fixtures/connect.js.map +1 -1
  8. package/dist/src/fixtures/create-helia.browser.d.ts +3 -4
  9. package/dist/src/fixtures/create-helia.browser.d.ts.map +1 -1
  10. package/dist/src/fixtures/create-helia.browser.js +18 -18
  11. package/dist/src/fixtures/create-helia.browser.js.map +1 -1
  12. package/dist/src/fixtures/create-helia.d.ts +3 -5
  13. package/dist/src/fixtures/create-helia.d.ts.map +1 -1
  14. package/dist/src/fixtures/create-helia.js +18 -16
  15. package/dist/src/fixtures/create-helia.js.map +1 -1
  16. package/dist/src/fixtures/key-types.d.ts.map +1 -1
  17. package/dist/src/fixtures/key-types.js +0 -1
  18. package/dist/src/fixtures/key-types.js.map +1 -1
  19. package/dist/src/helia-blockstore-sessions.spec.js +1 -1
  20. package/dist/src/helia-blockstore-sessions.spec.js.map +1 -1
  21. package/dist/src/helia-blockstore.spec.js +2 -3
  22. package/dist/src/helia-blockstore.spec.js.map +1 -1
  23. package/dist/src/helia-hashes.spec.js.map +1 -1
  24. package/dist/src/helia-pins.spec.js.map +1 -1
  25. package/dist/src/helia-progress-events.spec.js +2 -3
  26. package/dist/src/helia-progress-events.spec.js.map +1 -1
  27. package/dist/src/ipns-http.spec.js +11 -8
  28. package/dist/src/ipns-http.spec.js.map +1 -1
  29. package/dist/src/ipns-pubsub.spec.js +5 -8
  30. package/dist/src/ipns-pubsub.spec.js.map +1 -1
  31. package/dist/src/ipns.spec.js +29 -23
  32. package/dist/src/ipns.spec.js.map +1 -1
  33. package/dist/src/json.spec.js.map +1 -1
  34. package/dist/src/libp2p.spec.d.ts +2 -0
  35. package/dist/src/libp2p.spec.d.ts.map +1 -0
  36. package/dist/src/libp2p.spec.js +80 -0
  37. package/dist/src/libp2p.spec.js.map +1 -0
  38. package/dist/src/providers.spec.js +7 -7
  39. package/dist/src/providers.spec.js.map +1 -1
  40. package/dist/src/strings.spec.js.map +1 -1
  41. package/dist/src/unixfs-bitswap.spec.js.map +1 -1
  42. package/dist/src/unixfs-files.spec.js.map +1 -1
  43. package/package.json +39 -40
  44. package/src/car.spec.ts +2 -2
  45. package/src/dag-cbor.spec.ts +2 -2
  46. package/src/dag-json.spec.ts +2 -2
  47. package/src/dnslink.spec.ts +2 -3
  48. package/src/fixtures/connect.ts +2 -2
  49. package/src/fixtures/create-helia.browser.ts +22 -24
  50. package/src/fixtures/create-helia.ts +22 -22
  51. package/src/fixtures/key-types.ts +0 -1
  52. package/src/helia-blockstore-sessions.spec.ts +4 -4
  53. package/src/helia-blockstore.spec.ts +4 -5
  54. package/src/helia-hashes.spec.ts +2 -2
  55. package/src/helia-pins.spec.ts +2 -2
  56. package/src/helia-progress-events.spec.ts +2 -3
  57. package/src/ipns-http.spec.ts +15 -10
  58. package/src/ipns-pubsub.spec.ts +7 -11
  59. package/src/ipns.spec.ts +37 -24
  60. package/src/json.spec.ts +2 -2
  61. package/src/libp2p.spec.ts +107 -0
  62. package/src/providers.spec.ts +14 -15
  63. package/src/strings.spec.ts +2 -2
  64. package/src/unixfs-bitswap.spec.ts +2 -2
  65. package/src/unixfs-files.spec.ts +2 -2
  66. package/.aegir.js +0 -49
@@ -1,16 +1,19 @@
1
- import { bitswap } from '@helia/block-brokers'
2
- import { ipnsValidator, ipnsSelector } from '@helia/ipns'
1
+ import { withBitswap } from '@helia/bitswap'
2
+ import { libp2pDefaults, withLibp2p } from '@helia/libp2p'
3
+ import * as dagCbor from '@ipld/dag-cbor'
4
+ import * as dagJson from '@ipld/dag-json'
3
5
  import { kadDHT, removePublicAddressesMapper } from '@libp2p/kad-dht'
4
6
  import { webSockets } from '@libp2p/websockets'
5
7
  import { sha3512 } from '@multiformats/sha3'
6
- import { createHelia, libp2pDefaults } from 'helia'
7
- import type { Libp2p } from '@libp2p/interface'
8
- import type { DefaultLibp2pServices, Helia } from 'helia'
8
+ import { createHeliaLight } from 'helia'
9
+ import * as json from 'multiformats/codecs/json'
10
+ import { sha512 } from 'multiformats/hashes/sha2'
11
+ import type { DefaultLibp2pServices, HeliaWithLibp2p } from '@helia/libp2p'
9
12
  import type { Libp2pOptions } from 'libp2p'
10
13
 
11
- export async function createHeliaNode (): Promise<Helia<Libp2p<DefaultLibp2pServices>>>
12
- export async function createHeliaNode <Services extends Record<string, unknown>> (libp2pOptions: Libp2pOptions<Services>): Promise<Helia<Libp2p<Services & DefaultLibp2pServices>>>
13
- export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<Helia<Libp2p<DefaultLibp2pServices>>> {
14
+ export async function createHeliaNode (): Promise<HeliaWithLibp2p<DefaultLibp2pServices>>
15
+ export async function createHeliaNode <Services extends Record<string, unknown>> (libp2pOptions: Libp2pOptions<Services>): Promise<HeliaWithLibp2p<Services & DefaultLibp2pServices>>
16
+ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<HeliaWithLibp2p<DefaultLibp2pServices>> {
14
17
  const defaults = libp2pDefaults()
15
18
 
16
19
  // allow dialing insecure WebSockets
@@ -30,15 +33,6 @@ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<H
30
33
  ...(defaults.services ?? {}),
31
34
  ...(libp2pOptions?.services ?? {}),
32
35
  dht: kadDHT({
33
- validators: {
34
- ipns: ipnsValidator
35
- },
36
- selectors: {
37
- ipns: ipnsSelector
38
- },
39
- // skips waiting for the initial self-query to find peers
40
- allowQueryWithZeroPeers: true,
41
-
42
36
  protocol: '/ipfs/lan/kad/1.0.0',
43
37
  peerInfoMapper: removePublicAddressesMapper,
44
38
  clientMode: false
@@ -53,16 +47,20 @@ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<H
53
47
  delete defaults.services.autoNAT
54
48
  // @ts-expect-error services.dcutr is not optional
55
49
  delete defaults.services.dcutr
56
- // @ts-expect-error services.delegatedRouting is not optional
57
- delete defaults.services.delegatedRouting
50
+ // @ts-expect-error services.delegatedContentRouting is not optional
51
+ delete defaults.services.delegatedContentRouting
52
+ // @ts-expect-error services.delegatedPeerRouting is not optional
53
+ delete defaults.services.delegatedPeerRouting
58
54
 
59
- return createHelia<Libp2p<DefaultLibp2pServices>>({
60
- blockBrokers: [
61
- bitswap()
55
+ return withBitswap(withLibp2p(createHeliaLight({
56
+ codecs: [
57
+ dagCbor,
58
+ dagJson,
59
+ json
62
60
  ],
63
- libp2p: defaults,
64
61
  hashers: [
62
+ sha512,
65
63
  sha3512
66
64
  ]
67
- })
65
+ }), defaults)).start()
68
66
  }
@@ -1,15 +1,17 @@
1
- import { bitswap } from '@helia/block-brokers'
2
- import { ipnsValidator, ipnsSelector } from '@helia/ipns'
1
+ import { withBitswap } from '@helia/bitswap'
2
+ import { withLibp2p, libp2pDefaults } from '@helia/libp2p'
3
+ import * as dagCbor from '@ipld/dag-cbor'
4
+ import * as dagJson from '@ipld/dag-json'
3
5
  import { kadDHT, removePublicAddressesMapper } from '@libp2p/kad-dht'
4
6
  import { sha3512 } from '@multiformats/sha3'
5
- import { createHelia, libp2pDefaults } from 'helia'
6
- import type { Libp2p } from '@libp2p/interface'
7
- import type { DefaultLibp2pServices, Helia } from 'helia'
8
- import type { Libp2pOptions } from 'libp2p'
7
+ import { createHeliaLight } from 'helia'
8
+ import * as json from 'multiformats/codecs/json'
9
+ import { sha512 } from 'multiformats/hashes/sha2'
10
+ import type { HeliaWithLibp2p, DefaultLibp2pServices, CreateLibp2pOptions } from '@helia/libp2p'
9
11
 
10
- export async function createHeliaNode (): Promise<Helia<Libp2p<DefaultLibp2pServices>>>
11
- export async function createHeliaNode <Services extends Record<string, unknown>> (libp2pOptions: Libp2pOptions<Services>): Promise<Helia<Libp2p<Services & DefaultLibp2pServices>>>
12
- export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<Helia<Libp2p<DefaultLibp2pServices>>> {
12
+ export async function createHeliaNode (): Promise<HeliaWithLibp2p<DefaultLibp2pServices>>
13
+ export async function createHeliaNode <Services extends Record<string, unknown>> (libp2pOptions: CreateLibp2pOptions<Services>): Promise<HeliaWithLibp2p<Services & DefaultLibp2pServices>>
14
+ export async function createHeliaNode (libp2pOptions?: CreateLibp2pOptions<any>): Promise<HeliaWithLibp2p<DefaultLibp2pServices>> {
13
15
  const defaults = libp2pDefaults()
14
16
  defaults.addresses = {
15
17
  listen: [
@@ -20,12 +22,6 @@ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<H
20
22
  ...(defaults.services ?? {}),
21
23
  ...(libp2pOptions?.services ?? {}),
22
24
  dht: kadDHT({
23
- validators: {
24
- ipns: ipnsValidator
25
- },
26
- selectors: {
27
- ipns: ipnsSelector
28
- },
29
25
  protocol: '/ipfs/lan/kad/1.0.0',
30
26
  peerInfoMapper: removePublicAddressesMapper,
31
27
  clientMode: false
@@ -42,18 +38,22 @@ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<H
42
38
  delete defaults.services.upnp
43
39
  // @ts-expect-error services.dcutr is not optional
44
40
  delete defaults.services.dcutr
45
- // @ts-expect-error services.delegatedRouting is not optional
46
- delete defaults.services.delegatedRouting
41
+ // @ts-expect-error services.delegatedContentRouting is not optional
42
+ delete defaults.services.delegatedContentRouting
43
+ // @ts-expect-error services.delegatedPeerRouting is not optional
44
+ delete defaults.services.delegatedPeerRouting
47
45
  // @ts-expect-error services.autoTLS is not optional
48
46
  delete defaults.services.autoTLS
49
47
 
50
- return createHelia<Libp2p<DefaultLibp2pServices>>({
51
- blockBrokers: [
52
- bitswap()
48
+ return withBitswap(withLibp2p(createHeliaLight({
49
+ codecs: [
50
+ dagCbor,
51
+ dagJson,
52
+ json
53
53
  ],
54
- libp2p: defaults,
55
54
  hashers: [
55
+ sha512,
56
56
  sha3512
57
57
  ]
58
- })
58
+ }), defaults)).start()
59
59
  }
@@ -2,6 +2,5 @@ import type { KeyType } from '@libp2p/interface'
2
2
 
3
3
  export const keyTypes: KeyType[] = [
4
4
  'Ed25519',
5
- 'secp256k1',
6
5
  'RSA'
7
6
  ]
@@ -6,12 +6,12 @@ import toBuffer from 'it-to-buffer'
6
6
  import { CID } from 'multiformats/cid'
7
7
  import { createHeliaNode } from './fixtures/create-helia.ts'
8
8
  import { createKuboNode } from './fixtures/create-kubo.ts'
9
- import type { BitswapProvider } from '@helia/block-brokers'
10
- import type { Helia } from 'helia'
9
+ import type { BitswapProvider } from '@helia/bitswap'
10
+ import type { HeliaWithLibp2p } from '@helia/libp2p'
11
11
  import type { KuboInfo, KuboNode } from 'ipfsd-ctl'
12
12
 
13
13
  describe('helia - blockstore sessions', () => {
14
- let helia: Helia
14
+ let helia: HeliaWithLibp2p
15
15
  let kubo: KuboNode
16
16
  let kuboInfo: KuboInfo
17
17
  let kubo2: KuboNode
@@ -111,6 +111,6 @@ describe('helia - blockstore sessions', () => {
111
111
  }))
112
112
 
113
113
  expect(output).to.equalBytes(input)
114
- expect(foundProviders).to.have.deep.nested.property('[0].provider.id', peerIdFromString(kuboInfo.peerId ?? ''))
114
+ expect(foundProviders).to.have.deep.nested.property('[0].provider.id', peerIdFromString(kuboInfo.peerId ?? '').toCID())
115
115
  })
116
116
  })
@@ -1,4 +1,3 @@
1
- import { randomBytes } from '@libp2p/crypto'
2
1
  import { multiaddr } from '@multiformats/multiaddr'
3
2
  import { expect } from 'aegir/chai'
4
3
  import toBuffer from 'it-to-buffer'
@@ -7,11 +6,11 @@ import * as raw from 'multiformats/codecs/raw'
7
6
  import { sha256 } from 'multiformats/hashes/sha2'
8
7
  import { createHeliaNode } from './fixtures/create-helia.ts'
9
8
  import { createKuboNode } from './fixtures/create-kubo.ts'
10
- import type { Helia } from 'helia'
9
+ import type { HeliaWithLibp2p } from '@helia/libp2p'
11
10
  import type { KuboInfo, KuboNode } from 'ipfsd-ctl'
12
11
 
13
12
  describe('helia - blockstore', () => {
14
- let helia: Helia
13
+ let helia: HeliaWithLibp2p
15
14
  let kubo: KuboNode
16
15
  let kuboInfo: KuboInfo
17
16
 
@@ -35,7 +34,7 @@ describe('helia - blockstore', () => {
35
34
  })
36
35
 
37
36
  it('should be able to send a block', async () => {
38
- const input = randomBytes(10)
37
+ const input = crypto.getRandomValues(new Uint8Array(10))
39
38
  const digest = await sha256.digest(input)
40
39
  const cid = CID.createV1(raw.code, digest)
41
40
  await helia.blockstore.put(cid, input)
@@ -45,7 +44,7 @@ describe('helia - blockstore', () => {
45
44
  })
46
45
 
47
46
  it('should be able to receive a block', async () => {
48
- const input = randomBytes(10)
47
+ const input = crypto.getRandomValues(new Uint8Array(10))
49
48
  const { cid } = await kubo.api.add({ content: input }, {
50
49
  cidVersion: 1,
51
50
  rawLeaves: true
@@ -6,11 +6,11 @@ import * as raw from 'multiformats/codecs/raw'
6
6
  import { identity } from 'multiformats/hashes/identity'
7
7
  import { createHeliaNode } from './fixtures/create-helia.ts'
8
8
  import { createKuboNode } from './fixtures/create-kubo.ts'
9
- import type { Helia } from 'helia'
9
+ import type { HeliaWithLibp2p } from '@helia/libp2p'
10
10
  import type { KuboNode } from 'ipfsd-ctl'
11
11
 
12
12
  describe('helia - hashes', () => {
13
- let helia: Helia
13
+ let helia: HeliaWithLibp2p
14
14
  let kubo: KuboNode
15
15
 
16
16
  beforeEach(async () => {
@@ -6,11 +6,11 @@ import * as raw from 'multiformats/codecs/raw'
6
6
  import { sha256 } from 'multiformats/hashes/sha2'
7
7
  import { createHeliaNode } from './fixtures/create-helia.ts'
8
8
  import { createKuboNode } from './fixtures/create-kubo.ts'
9
- import type { Helia } from 'helia'
9
+ import type { HeliaWithLibp2p } from '@helia/libp2p'
10
10
  import type { KuboNode } from 'ipfsd-ctl'
11
11
 
12
12
  describe('helia - pins', () => {
13
- let helia: Helia
13
+ let helia: HeliaWithLibp2p
14
14
  let kubo: KuboNode
15
15
 
16
16
  beforeEach(async () => {
@@ -1,4 +1,3 @@
1
- import { randomBytes } from '@libp2p/crypto'
2
1
  import { contentRoutingSymbol } from '@libp2p/interface'
3
2
  import { peerIdFromString } from '@libp2p/peer-id'
4
3
  import { CODE_P2P, multiaddr } from '@multiformats/multiaddr'
@@ -62,7 +61,7 @@ describe('helia - progress events', () => {
62
61
  })
63
62
 
64
63
  it('should yield routing events', async () => {
65
- const input = randomBytes(10)
64
+ const input = crypto.getRandomValues(new Uint8Array(10))
66
65
  const { cid } = await kubo.api.add({ content: input }, {
67
66
  cidVersion: 1,
68
67
  rawLeaves: true
@@ -82,7 +81,7 @@ describe('helia - progress events', () => {
82
81
  })
83
82
 
84
83
  it('should yield block broker events', async () => {
85
- const input = randomBytes(10)
84
+ const input = crypto.getRandomValues(new Uint8Array(10))
86
85
  const { cid } = await kubo.api.add({ content: input }, {
87
86
  cidVersion: 1,
88
87
  rawLeaves: true
@@ -1,18 +1,18 @@
1
- import { createHeliaHTTP } from '@helia/http'
1
+ import { delegatedHTTPRouter } from '@helia/delegated-routing-client'
2
2
  import { ipns } from '@helia/ipns'
3
- import { delegatedHTTPRouting } from '@helia/routers'
4
3
  import { peerIdFromCID } from '@libp2p/peer-id'
5
4
  import { expect } from 'aegir/chai'
5
+ import { createHelia } from 'helia'
6
+ import last from 'it-last'
6
7
  import { CID } from 'multiformats/cid'
7
8
  import { isNode } from 'wherearewe'
8
9
  import { createKuboNode } from './fixtures/create-kubo.ts'
9
10
  import type { Helia } from '@helia/interface'
10
11
  import type { IPNS } from '@helia/ipns'
11
12
  import type { KuboNode } from 'ipfsd-ctl'
12
- import type { Libp2p } from 'libp2p'
13
13
 
14
14
  describe('@helia/ipns - http', () => {
15
- let helia: Helia<Libp2p<any>>
15
+ let helia: Helia
16
16
  let kubo: KuboNode
17
17
  let name: IPNS
18
18
 
@@ -24,13 +24,14 @@ describe('@helia/ipns - http', () => {
24
24
  beforeEach(async () => {
25
25
  kubo = await createKuboNode()
26
26
  const kuboInfo = await kubo.info()
27
- helia = await createHeliaHTTP({
27
+ helia = await createHelia({
28
28
  routers: [
29
- delegatedHTTPRouting({
29
+ delegatedHTTPRouter({
30
30
  url: kuboInfo.gateway
31
31
  })
32
32
  ]
33
- })
33
+ }).start()
34
+
34
35
  name = ipns(helia)
35
36
  })
36
37
 
@@ -62,8 +63,12 @@ describe('@helia/ipns - http', () => {
62
63
  })
63
64
 
64
65
  const key = peerIdFromCID(CID.parse(res.name))
65
- // @ts-expect-error @libp2p/peer-id needs dep updates
66
- const { cid: resolvedCid } = await name.resolve(key.toMultihash())
67
- expect(resolvedCid.toString()).to.equal(cid.toString())
66
+ const result = await last(name.resolve(key.toMultihash()))
67
+
68
+ if (result == null) {
69
+ throw new Error('No results found')
70
+ }
71
+
72
+ expect(result.record.value).to.equal(`/ipfs/${cid}`)
68
73
  })
69
74
  })
@@ -2,7 +2,6 @@
2
2
 
3
3
  import { ipns } from '@helia/ipns'
4
4
  import { pubsub } from '@helia/ipns/routing'
5
- import { generateKeyPair } from '@libp2p/crypto/keys'
6
5
  import { floodsub } from '@libp2p/floodsub'
7
6
  import { peerIdFromCID } from '@libp2p/peer-id'
8
7
  import { expect } from 'aegir/chai'
@@ -23,9 +22,8 @@ import { keyTypes } from './fixtures/key-types.ts'
23
22
  import { waitFor } from './fixtures/wait-for.ts'
24
23
  import type { IPNS, ResolveResult } from '@helia/ipns'
25
24
  import type { PubSub } from '@helia/ipns/routing'
26
- import type { Libp2p } from '@libp2p/interface'
25
+ import type { HeliaWithLibp2p } from '@helia/libp2p'
27
26
  import type { Keychain } from '@libp2p/keychain'
28
- import type { Helia } from 'helia'
29
27
  import type { KuboNode } from 'ipfsd-ctl'
30
28
 
31
29
  // skip RSA tests because we need the DHT enabled to find the public key
@@ -33,7 +31,7 @@ import type { KuboNode } from 'ipfsd-ctl'
33
31
  // resolution because Kubo will use the DHT as well
34
32
  keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
35
33
  describe(`@helia/ipns - pubsub routing with ${keyType} keys`, () => {
36
- let helia: Helia<Libp2p<{ pubsub: PubSub, keychain: Keychain }>>
34
+ let helia: HeliaWithLibp2p<{ pubsub: PubSub, keychain: Keychain }>
37
35
  let kubo: KuboNode
38
36
  let name: IPNS
39
37
 
@@ -70,13 +68,12 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
70
68
  const digest = await sha256.digest(input)
71
69
  const cid = CID.createV1(raw.code, digest)
72
70
 
73
- const privateKey = await generateKeyPair('Ed25519')
74
71
  const keyName = 'my-ipns-key'
75
- await helia.libp2p.services.keychain.importKey(keyName, privateKey)
72
+ const privateKey = await helia.keychain.generateKey(keyName)
76
73
 
77
74
  // first call to pubsub resolver will fail but we should trigger
78
75
  // subscribing pubsub for updates
79
- await expect(last(kubo.api.name.resolve(privateKey.publicKey.toString(), {
76
+ await expect(last(kubo.api.name.resolve(`${privateKey.publicKey}`, {
80
77
  timeout: 100
81
78
  }))).to.eventually.be.undefined()
82
79
 
@@ -137,7 +134,7 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
137
134
  }
138
135
 
139
136
  // first call to pubsub resolver should fail but we should now be subscribed for updates
140
- await expect(name.resolve(peerCid.multihash)).to.eventually.be.rejected()
137
+ await expect(last(name.resolve(peerCid.multihash))).to.eventually.be.rejected()
141
138
 
142
139
  // actual pubsub subscription name
143
140
  const subscriptionName = `/record/${uint8ArrayToString(uint8ArrayConcat([
@@ -173,8 +170,7 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
173
170
  // we should get an update eventually
174
171
  await waitFor(async () => {
175
172
  try {
176
- // @ts-expect-error @libp2p/peer-id needs dep updates
177
- resolveResult = await name.resolve(peerId.toMultihash())
173
+ resolveResult = await last(name.resolve(peerId.toMultihash()))
178
174
 
179
175
  return true
180
176
  } catch {
@@ -189,7 +185,7 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
189
185
  throw new Error('Failed to resolve CID')
190
186
  }
191
187
 
192
- expect(resolveResult.cid.toString()).to.equal(cid.toString())
188
+ expect(resolveResult.record.value).to.equal(`/ipfs/${cid}`)
193
189
  })
194
190
  })
195
191
  })
package/src/ipns.spec.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { ipns } from '@helia/ipns'
2
- import { generateKeyPair, privateKeyToProtobuf } from '@libp2p/crypto/keys'
3
2
  import { peerIdFromString } from '@libp2p/peer-id'
4
3
  import { expect } from 'aegir/chai'
5
- import { multihashToIPNSRoutingKey } from 'ipns'
6
4
  import last from 'it-last'
5
+ import { base36 } from 'multiformats/bases/base36'
7
6
  import { CID } from 'multiformats/cid'
8
7
  import * as raw from 'multiformats/codecs/raw'
9
8
  import { sha256 } from 'multiformats/hashes/sha2'
9
+ import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
10
+ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
10
11
  import { isElectronMain } from 'wherearewe'
11
12
  import { connect } from './fixtures/connect.ts'
12
13
  import { createHeliaNode } from './fixtures/create-helia.ts'
@@ -14,21 +15,29 @@ import { createKuboNode } from './fixtures/create-kubo.ts'
14
15
  import { sortClosestPeers } from './fixtures/create-peer-ids.ts'
15
16
  import { keyTypes } from './fixtures/key-types.ts'
16
17
  import { waitFor } from './fixtures/wait-for.ts'
18
+ import type { PrivateKey } from '@helia/interface'
17
19
  import type { IPNS } from '@helia/ipns'
18
- import type { Libp2p, PrivateKey } from '@libp2p/interface'
19
- import type { DefaultLibp2pServices, Helia } from 'helia'
20
+ import type { HeliaWithLibp2p } from '@helia/libp2p'
20
21
  import type { KuboNode } from 'ipfsd-ctl'
22
+ import type { MultihashDigest } from 'multiformats/cid'
23
+
24
+ function multihashToIPNSRoutingKey (digest: MultihashDigest): Uint8Array<ArrayBuffer> {
25
+ return uint8ArrayConcat([
26
+ uint8ArrayFromString('/ipns/'),
27
+ digest.bytes
28
+ ])
29
+ }
21
30
 
22
31
  keyTypes.forEach(type => {
23
32
  describe(`@helia/ipns - default routing with ${type} keys`, () => {
24
- let helia: Helia<Libp2p<DefaultLibp2pServices>>
33
+ let helia: HeliaWithLibp2p
25
34
  let kubo: KuboNode
26
35
  let name: IPNS
27
36
 
28
37
  // the CID we are going to publish
29
38
  let value: CID
30
39
 
31
- // the public key we will use to publish the value
40
+ // the key we will use to publish the value
32
41
  let key: PrivateKey
33
42
 
34
43
  /**
@@ -44,18 +53,16 @@ keyTypes.forEach(type => {
44
53
  helia = await createHeliaNode()
45
54
  kubo = await createKuboNode()
46
55
 
47
- // find a PeerId that is KAD-closer to the resolver than the publisher when used as an IPNS key
56
+ // find a key that is KAD-closer to the resolver than the publisher when
57
+ // used as an IPNS key
48
58
  while (true) {
49
- if (type === 'Ed25519') {
50
- key = await generateKeyPair('Ed25519')
51
- } else if (type === 'secp256k1') {
52
- key = await generateKeyPair('secp256k1')
53
- } else {
54
- key = await generateKeyPair('RSA', 2048)
55
- }
59
+ await helia.keychain.removeKey('test-key')
60
+ key = await helia.keychain.generateKey('test-key', {
61
+ type
62
+ })
63
+ await helia.keychain.removeKey('test-key')
56
64
 
57
- // @ts-expect-error @libp2p/crypto needs dep updates
58
- const routingKey = multihashToIPNSRoutingKey(key.publicKey?.toMultihash())
65
+ const routingKey = multihashToIPNSRoutingKey(key.publicKey.toMultihash())
59
66
 
60
67
  const [closest] = await sortClosestPeers(routingKey, [
61
68
  helia.libp2p.peerId,
@@ -120,12 +127,11 @@ keyTypes.forEach(type => {
120
127
  }
121
128
  })
122
129
 
123
- it(`should publish on helia and resolve on kubo using a ${type} key`, async () => {
130
+ it('should publish on helia and resolve on kubo', async () => {
124
131
  await createNodes('kubo')
125
132
 
126
- const privateKey = await generateKeyPair('Ed25519')
127
133
  const keyName = 'my-ipns-key'
128
- await helia.libp2p.services.keychain.importKey(keyName, privateKey)
134
+ const privateKey = await helia.keychain.generateKey(keyName)
129
135
  await name.publish(keyName, value)
130
136
 
131
137
  const resolved = await last(kubo.api.name.resolve(privateKey.publicKey.toString()))
@@ -156,8 +162,7 @@ keyTypes.forEach(type => {
156
162
 
157
163
  // ensure the key is in the kubo keychain so we can use it to publish the IPNS record
158
164
  const body = new FormData()
159
- // @ts-expect-error @libp2p/crypto needs dep updates
160
- body.append('key', new Blob([privateKeyToProtobuf(key)]))
165
+ body.append('key', new Blob([key.toProtobuf()]))
161
166
 
162
167
  // can't use the kubo-rpc-api for this call yet
163
168
  const config = kubo.api.getEndpointConfig()
@@ -168,6 +173,9 @@ keyTypes.forEach(type => {
168
173
 
169
174
  expect(response).to.have.property('status', 200)
170
175
 
176
+ const json = await response.json()
177
+ expect(json.Id).to.equal(key.publicKey.toCID().toString(base36), 'did not import key correctly')
178
+
171
179
  const oneHourNS = BigInt(60 * 60 * 1e+9)
172
180
 
173
181
  await kubo.api.name.publish(cid, {
@@ -175,9 +183,14 @@ keyTypes.forEach(type => {
175
183
  ttl: '1h'
176
184
  })
177
185
 
178
- const { cid: resolvedCid, record } = await name.resolve(key.publicKey)
179
- expect(resolvedCid.toString()).to.equal(cid.toString())
180
- expect(record.ttl).to.equal(oneHourNS)
186
+ const result = await last(name.resolve(key.publicKey))
187
+
188
+ if (result == null) {
189
+ throw new Error('No result found')
190
+ }
191
+
192
+ expect(result.record.value).to.equal(`/ipfs/${cid}`)
193
+ expect(result.record.ttl).to.equal(oneHourNS)
181
194
  })
182
195
  })
183
196
  })
package/src/json.spec.ts CHANGED
@@ -5,12 +5,12 @@ import * as jsonCodec from 'multiformats/codecs/json'
5
5
  import { createHeliaNode } from './fixtures/create-helia.ts'
6
6
  import { createKuboNode } from './fixtures/create-kubo.ts'
7
7
  import type { JSON, AddOptions } from '@helia/json'
8
- import type { Helia } from 'helia'
8
+ import type { HeliaWithLibp2p } from '@helia/libp2p'
9
9
  import type { KuboNode } from 'ipfsd-ctl'
10
10
  import type { BlockPutOptions as KuboAddOptions } from 'kubo-rpc-client'
11
11
 
12
12
  describe('@helia/json', () => {
13
- let helia: Helia
13
+ let helia: HeliaWithLibp2p
14
14
  let j: JSON
15
15
  let kubo: KuboNode
16
16
 
@@ -0,0 +1,107 @@
1
+ import { withLibp2p } from '@helia/libp2p'
2
+ import { identify } from '@libp2p/identify'
3
+ import { webSockets } from '@libp2p/websockets'
4
+ import { expect } from 'aegir/chai'
5
+ import { createHeliaLight } from 'helia'
6
+ import { createLibp2p, isLibp2p } from 'libp2p'
7
+ import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
8
+ import type { HeliaWithLibp2p } from '@helia/libp2p'
9
+
10
+ describe('@helia/libp2p', () => {
11
+ let helia: HeliaWithLibp2p<any>
12
+
13
+ beforeEach(() => {
14
+ helia = withLibp2p(createHeliaLight())
15
+ })
16
+
17
+ afterEach(async () => {
18
+ if (helia != null) {
19
+ await helia.stop()
20
+ }
21
+ })
22
+
23
+ it('should add a libp2p property', async () => {
24
+ await helia.start()
25
+ expect(isLibp2p(helia.libp2p)).to.be.true()
26
+ })
27
+
28
+ it('should start libp2p', async () => {
29
+ await helia.start()
30
+ await helia.stop()
31
+
32
+ expect(helia.libp2p.status).to.equal('stopped')
33
+
34
+ await helia.start()
35
+
36
+ expect(helia.libp2p.status).to.equal('started')
37
+ })
38
+
39
+ it('should stop libp2p', async () => {
40
+ await helia.start()
41
+
42
+ expect(helia.libp2p.status).to.equal('started')
43
+
44
+ await helia.stop()
45
+
46
+ expect(helia.libp2p.status).to.equal('stopped')
47
+ })
48
+
49
+ it('does not add helia details to the AgentVersion when it has been overridden', async () => {
50
+ helia = await withLibp2p(createHeliaLight(), await createLibp2p({
51
+ nodeInfo: {
52
+ userAgent: 'my custom user agent'
53
+ },
54
+ transports: [
55
+ webSockets()
56
+ ],
57
+ services: {
58
+ identify: identify()
59
+ }
60
+ })).start()
61
+
62
+ expect(helia).to.have.nested.property('libp2p.services.identify.host.agentVersion')
63
+ .that.does.not.include('helia/')
64
+
65
+ const peer = await helia.libp2p.peerStore.get(helia.libp2p.peerId)
66
+ const agentVersionBuf = peer.metadata.get('AgentVersion')
67
+
68
+ if (agentVersionBuf == null) {
69
+ throw new Error('AgentVersion not stored')
70
+ }
71
+
72
+ expect(agentVersionBuf).to.be.ok()
73
+ expect(uint8ArrayToString(agentVersionBuf)).to.not.include('helia/')
74
+ })
75
+
76
+ it('should have the same peer id after a restart', async () => {
77
+ await helia.start()
78
+
79
+ const datastore = helia.datastore
80
+ const peerId = helia.libp2p.peerId
81
+
82
+ await helia.stop()
83
+
84
+ helia = await withLibp2p(createHeliaLight({
85
+ datastore
86
+ }), {
87
+ datastore
88
+ }).start()
89
+
90
+ expect(helia.libp2p.peerId.toString()).to.equal(peerId.toString())
91
+ })
92
+
93
+ it('allows passing a libp2p node', async () => {
94
+ const libp2p = await createLibp2p()
95
+
96
+ helia = await withLibp2p(createHeliaLight(), libp2p).start()
97
+
98
+ expect(helia.libp2p).to.equal(libp2p)
99
+ })
100
+
101
+ it('adds helia details to the AgentVersion', async () => {
102
+ await helia.start()
103
+
104
+ expect(helia).to.have.nested.property('libp2p.services.identify.host.agentVersion')
105
+ .that.includes('helia/')
106
+ })
107
+ })