@helia/interop 10.2.5 → 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.
- package/dist/src/car.spec.js.map +1 -1
- package/dist/src/dag-cbor.spec.js.map +1 -1
- package/dist/src/dag-json.spec.js.map +1 -1
- package/dist/src/dnslink.spec.js.map +1 -1
- package/dist/src/fixtures/connect.d.ts +2 -2
- package/dist/src/fixtures/connect.d.ts.map +1 -1
- package/dist/src/fixtures/connect.js.map +1 -1
- package/dist/src/fixtures/create-helia.browser.d.ts +3 -4
- package/dist/src/fixtures/create-helia.browser.d.ts.map +1 -1
- package/dist/src/fixtures/create-helia.browser.js +18 -18
- package/dist/src/fixtures/create-helia.browser.js.map +1 -1
- package/dist/src/fixtures/create-helia.d.ts +3 -5
- package/dist/src/fixtures/create-helia.d.ts.map +1 -1
- package/dist/src/fixtures/create-helia.js +18 -16
- package/dist/src/fixtures/create-helia.js.map +1 -1
- package/dist/src/fixtures/key-types.d.ts.map +1 -1
- package/dist/src/fixtures/key-types.js +0 -1
- package/dist/src/fixtures/key-types.js.map +1 -1
- package/dist/src/helia-blockstore-sessions.spec.js +1 -1
- package/dist/src/helia-blockstore-sessions.spec.js.map +1 -1
- package/dist/src/helia-blockstore.spec.js +2 -3
- package/dist/src/helia-blockstore.spec.js.map +1 -1
- package/dist/src/helia-hashes.spec.js.map +1 -1
- package/dist/src/helia-pins.spec.js.map +1 -1
- package/dist/src/helia-progress-events.spec.js +2 -3
- package/dist/src/helia-progress-events.spec.js.map +1 -1
- package/dist/src/ipns-http.spec.js +11 -7
- package/dist/src/ipns-http.spec.js.map +1 -1
- package/dist/src/ipns-pubsub.spec.js +5 -7
- package/dist/src/ipns-pubsub.spec.js.map +1 -1
- package/dist/src/ipns.spec.js +29 -21
- package/dist/src/ipns.spec.js.map +1 -1
- package/dist/src/json.spec.js.map +1 -1
- package/dist/src/libp2p.spec.d.ts +2 -0
- package/dist/src/libp2p.spec.d.ts.map +1 -0
- package/dist/src/libp2p.spec.js +80 -0
- package/dist/src/libp2p.spec.js.map +1 -0
- package/dist/src/providers.spec.js +7 -7
- package/dist/src/providers.spec.js.map +1 -1
- package/dist/src/strings.spec.js.map +1 -1
- package/dist/src/unixfs-bitswap.spec.js.map +1 -1
- package/dist/src/unixfs-files.spec.js.map +1 -1
- package/package.json +44 -45
- package/src/car.spec.ts +2 -2
- package/src/dag-cbor.spec.ts +2 -2
- package/src/dag-json.spec.ts +2 -2
- package/src/dnslink.spec.ts +2 -3
- package/src/fixtures/connect.ts +2 -2
- package/src/fixtures/create-helia.browser.ts +22 -24
- package/src/fixtures/create-helia.ts +22 -22
- package/src/fixtures/key-types.ts +0 -1
- package/src/helia-blockstore-sessions.spec.ts +4 -4
- package/src/helia-blockstore.spec.ts +4 -5
- package/src/helia-hashes.spec.ts +2 -2
- package/src/helia-pins.spec.ts +2 -2
- package/src/helia-progress-events.spec.ts +2 -3
- package/src/ipns-http.spec.ts +15 -9
- package/src/ipns-pubsub.spec.ts +7 -10
- package/src/ipns.spec.ts +37 -22
- package/src/json.spec.ts +2 -2
- package/src/libp2p.spec.ts +107 -0
- package/src/providers.spec.ts +14 -15
- package/src/strings.spec.ts +2 -2
- package/src/unixfs-bitswap.spec.ts +2 -2
- package/src/unixfs-files.spec.ts +2 -2
- package/.aegir.js +0 -49
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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 {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
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<
|
|
12
|
-
export async function createHeliaNode <Services extends Record<string, unknown>> (libp2pOptions: Libp2pOptions<Services>): Promise<
|
|
13
|
-
export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<
|
|
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.
|
|
57
|
-
delete defaults.services.
|
|
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
|
|
60
|
-
|
|
61
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
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 {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import type {
|
|
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<
|
|
11
|
-
export async function createHeliaNode <Services extends Record<string, unknown>> (libp2pOptions:
|
|
12
|
-
export async function createHeliaNode (libp2pOptions?:
|
|
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.
|
|
46
|
-
delete defaults.services.
|
|
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
|
|
51
|
-
|
|
52
|
-
|
|
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
|
}
|
|
@@ -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/
|
|
10
|
-
import type {
|
|
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:
|
|
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 {
|
|
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:
|
|
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 =
|
|
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 =
|
|
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
|
package/src/helia-hashes.spec.ts
CHANGED
|
@@ -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 {
|
|
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:
|
|
13
|
+
let helia: HeliaWithLibp2p
|
|
14
14
|
let kubo: KuboNode
|
|
15
15
|
|
|
16
16
|
beforeEach(async () => {
|
package/src/helia-pins.spec.ts
CHANGED
|
@@ -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 {
|
|
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:
|
|
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 =
|
|
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 =
|
|
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
|
package/src/ipns-http.spec.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
|
27
|
+
helia = await createHelia({
|
|
28
28
|
routers: [
|
|
29
|
-
|
|
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,7 +63,12 @@ describe('@helia/ipns - http', () => {
|
|
|
62
63
|
})
|
|
63
64
|
|
|
64
65
|
const key = peerIdFromCID(CID.parse(res.name))
|
|
65
|
-
const
|
|
66
|
-
|
|
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}`)
|
|
67
73
|
})
|
|
68
74
|
})
|
package/src/ipns-pubsub.spec.ts
CHANGED
|
@@ -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 {
|
|
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:
|
|
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.
|
|
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
|
|
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,7 +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
|
-
resolveResult = await name.resolve(peerId.toMultihash())
|
|
173
|
+
resolveResult = await last(name.resolve(peerId.toMultihash()))
|
|
177
174
|
|
|
178
175
|
return true
|
|
179
176
|
} catch {
|
|
@@ -188,7 +185,7 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
188
185
|
throw new Error('Failed to resolve CID')
|
|
189
186
|
}
|
|
190
187
|
|
|
191
|
-
expect(resolveResult.
|
|
188
|
+
expect(resolveResult.record.value).to.equal(`/ipfs/${cid}`)
|
|
192
189
|
})
|
|
193
190
|
})
|
|
194
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 {
|
|
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:
|
|
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
|
|
40
|
+
// the key we will use to publish the value
|
|
32
41
|
let key: PrivateKey
|
|
33
42
|
|
|
34
43
|
/**
|
|
@@ -44,17 +53,16 @@ keyTypes.forEach(type => {
|
|
|
44
53
|
helia = await createHeliaNode()
|
|
45
54
|
kubo = await createKuboNode()
|
|
46
55
|
|
|
47
|
-
// find a
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
const routingKey = multihashToIPNSRoutingKey(key.publicKey
|
|
65
|
+
const routingKey = multihashToIPNSRoutingKey(key.publicKey.toMultihash())
|
|
58
66
|
|
|
59
67
|
const [closest] = await sortClosestPeers(routingKey, [
|
|
60
68
|
helia.libp2p.peerId,
|
|
@@ -119,12 +127,11 @@ keyTypes.forEach(type => {
|
|
|
119
127
|
}
|
|
120
128
|
})
|
|
121
129
|
|
|
122
|
-
it(
|
|
130
|
+
it('should publish on helia and resolve on kubo', async () => {
|
|
123
131
|
await createNodes('kubo')
|
|
124
132
|
|
|
125
|
-
const privateKey = await generateKeyPair('Ed25519')
|
|
126
133
|
const keyName = 'my-ipns-key'
|
|
127
|
-
await helia.
|
|
134
|
+
const privateKey = await helia.keychain.generateKey(keyName)
|
|
128
135
|
await name.publish(keyName, value)
|
|
129
136
|
|
|
130
137
|
const resolved = await last(kubo.api.name.resolve(privateKey.publicKey.toString()))
|
|
@@ -155,7 +162,7 @@ keyTypes.forEach(type => {
|
|
|
155
162
|
|
|
156
163
|
// ensure the key is in the kubo keychain so we can use it to publish the IPNS record
|
|
157
164
|
const body = new FormData()
|
|
158
|
-
body.append('key', new Blob([
|
|
165
|
+
body.append('key', new Blob([key.toProtobuf()]))
|
|
159
166
|
|
|
160
167
|
// can't use the kubo-rpc-api for this call yet
|
|
161
168
|
const config = kubo.api.getEndpointConfig()
|
|
@@ -166,6 +173,9 @@ keyTypes.forEach(type => {
|
|
|
166
173
|
|
|
167
174
|
expect(response).to.have.property('status', 200)
|
|
168
175
|
|
|
176
|
+
const json = await response.json()
|
|
177
|
+
expect(json.Id).to.equal(key.publicKey.toCID().toString(base36), 'did not import key correctly')
|
|
178
|
+
|
|
169
179
|
const oneHourNS = BigInt(60 * 60 * 1e+9)
|
|
170
180
|
|
|
171
181
|
await kubo.api.name.publish(cid, {
|
|
@@ -173,9 +183,14 @@ keyTypes.forEach(type => {
|
|
|
173
183
|
ttl: '1h'
|
|
174
184
|
})
|
|
175
185
|
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
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)
|
|
179
194
|
})
|
|
180
195
|
})
|
|
181
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 {
|
|
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:
|
|
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
|
+
})
|