@helia/interop 10.2.4 → 10.2.5-1361bfa5
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 +9 -19
- 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 +9 -17
- 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/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 +42 -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 +13 -25
- package/src/fixtures/create-helia.ts +13 -23
- 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/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,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { withBitswap } from '@helia/bitswap'
|
|
2
|
+
import { withLibp2p, libp2pDefaults } from '@helia/libp2p'
|
|
3
3
|
import { kadDHT, removePublicAddressesMapper } from '@libp2p/kad-dht'
|
|
4
4
|
import { sha3512 } from '@multiformats/sha3'
|
|
5
|
-
import { createHelia
|
|
6
|
-
import type {
|
|
7
|
-
import type { DefaultLibp2pServices, Helia } from 'helia'
|
|
8
|
-
import type { Libp2pOptions } from 'libp2p'
|
|
5
|
+
import { createHelia } from 'helia'
|
|
6
|
+
import type { HeliaWithLibp2p, DefaultLibp2pServices, CreateLibp2pOptions } from '@helia/libp2p'
|
|
9
7
|
|
|
10
|
-
export async function createHeliaNode (): Promise<
|
|
11
|
-
export async function createHeliaNode <Services extends Record<string, unknown>> (libp2pOptions:
|
|
12
|
-
export async function createHeliaNode (libp2pOptions?:
|
|
8
|
+
export async function createHeliaNode (): Promise<HeliaWithLibp2p<DefaultLibp2pServices>>
|
|
9
|
+
export async function createHeliaNode <Services extends Record<string, unknown>> (libp2pOptions: CreateLibp2pOptions<Services>): Promise<HeliaWithLibp2p<Services & DefaultLibp2pServices>>
|
|
10
|
+
export async function createHeliaNode (libp2pOptions?: CreateLibp2pOptions<any>): Promise<HeliaWithLibp2p<DefaultLibp2pServices>> {
|
|
13
11
|
const defaults = libp2pDefaults()
|
|
14
12
|
defaults.addresses = {
|
|
15
13
|
listen: [
|
|
@@ -20,12 +18,6 @@ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<H
|
|
|
20
18
|
...(defaults.services ?? {}),
|
|
21
19
|
...(libp2pOptions?.services ?? {}),
|
|
22
20
|
dht: kadDHT({
|
|
23
|
-
validators: {
|
|
24
|
-
ipns: ipnsValidator
|
|
25
|
-
},
|
|
26
|
-
selectors: {
|
|
27
|
-
ipns: ipnsSelector
|
|
28
|
-
},
|
|
29
21
|
protocol: '/ipfs/lan/kad/1.0.0',
|
|
30
22
|
peerInfoMapper: removePublicAddressesMapper,
|
|
31
23
|
clientMode: false
|
|
@@ -42,18 +34,16 @@ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<H
|
|
|
42
34
|
delete defaults.services.upnp
|
|
43
35
|
// @ts-expect-error services.dcutr is not optional
|
|
44
36
|
delete defaults.services.dcutr
|
|
45
|
-
// @ts-expect-error services.
|
|
46
|
-
delete defaults.services.
|
|
37
|
+
// @ts-expect-error services.delegatedContentRouting is not optional
|
|
38
|
+
delete defaults.services.delegatedContentRouting
|
|
39
|
+
// @ts-expect-error services.delegatedPeerRouting is not optional
|
|
40
|
+
delete defaults.services.delegatedPeerRouting
|
|
47
41
|
// @ts-expect-error services.autoTLS is not optional
|
|
48
42
|
delete defaults.services.autoTLS
|
|
49
43
|
|
|
50
|
-
return createHelia
|
|
51
|
-
blockBrokers: [
|
|
52
|
-
bitswap()
|
|
53
|
-
],
|
|
54
|
-
libp2p: defaults,
|
|
44
|
+
return withBitswap(withLibp2p(createHelia({
|
|
55
45
|
hashers: [
|
|
56
46
|
sha3512
|
|
57
47
|
]
|
|
58
|
-
})
|
|
48
|
+
}), defaults)).start()
|
|
59
49
|
}
|
|
@@ -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
|
|
package/src/providers.spec.ts
CHANGED
|
@@ -13,7 +13,6 @@ import { multiaddr } from 'kubo-rpc-client'
|
|
|
13
13
|
import { CID } from 'multiformats/cid'
|
|
14
14
|
import { createHeliaNode } from './fixtures/create-helia.ts'
|
|
15
15
|
import { createKuboNode } from './fixtures/create-kubo.ts'
|
|
16
|
-
import type { PeerId } from '@libp2p/interface'
|
|
17
16
|
import type { Helia } from 'helia'
|
|
18
17
|
import type { FileCandidate } from 'ipfs-unixfs-importer'
|
|
19
18
|
import type { KuboInfo, KuboNode } from 'ipfsd-ctl'
|
|
@@ -68,7 +67,7 @@ describe('providers', () => {
|
|
|
68
67
|
})
|
|
69
68
|
|
|
70
69
|
it('should fetch raw using a provider', async () => {
|
|
71
|
-
let sender:
|
|
70
|
+
let sender: CID | undefined
|
|
72
71
|
|
|
73
72
|
const buf = await toBuffer(helia.blockstore.get(cid, {
|
|
74
73
|
providers: [
|
|
@@ -82,11 +81,11 @@ describe('providers', () => {
|
|
|
82
81
|
}))
|
|
83
82
|
|
|
84
83
|
expect(buf).to.have.lengthOf(1930)
|
|
85
|
-
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
|
|
84
|
+
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? '').toCID())
|
|
86
85
|
})
|
|
87
86
|
|
|
88
87
|
it('should fetch dag-cbor using a provider', async () => {
|
|
89
|
-
let sender:
|
|
88
|
+
let sender: CID | undefined
|
|
90
89
|
const obj = { hello: 'world' }
|
|
91
90
|
const cid = await kubo.api.dag.put(obj, {
|
|
92
91
|
storeCodec: 'dag-cbor'
|
|
@@ -104,11 +103,11 @@ describe('providers', () => {
|
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
105
|
})).to.eventually.deep.equal(obj)
|
|
107
|
-
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
|
|
106
|
+
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? '').toCID())
|
|
108
107
|
})
|
|
109
108
|
|
|
110
109
|
it('should fetch dag-json using a provider', async () => {
|
|
111
|
-
let sender:
|
|
110
|
+
let sender: CID | undefined
|
|
112
111
|
const obj = { hello: 'world' }
|
|
113
112
|
const cid = await kubo.api.dag.put(obj, {
|
|
114
113
|
storeCodec: 'dag-json'
|
|
@@ -126,11 +125,11 @@ describe('providers', () => {
|
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
127
|
})).to.eventually.deep.equal(obj)
|
|
129
|
-
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
|
|
128
|
+
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? '').toCID())
|
|
130
129
|
})
|
|
131
130
|
|
|
132
131
|
it('should fetch string using a provider', async () => {
|
|
133
|
-
let sender:
|
|
132
|
+
let sender: CID | undefined
|
|
134
133
|
const obj = 'hello world'
|
|
135
134
|
const cid = await kubo.api.dag.put(obj, {
|
|
136
135
|
storeCodec: 'dag-json'
|
|
@@ -148,11 +147,11 @@ describe('providers', () => {
|
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
149
|
})).to.eventually.equal(JSON.stringify(obj))
|
|
151
|
-
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
|
|
150
|
+
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? '').toCID())
|
|
152
151
|
})
|
|
153
152
|
|
|
154
153
|
it('should fetch via unixfs using a provider', async () => {
|
|
155
|
-
let sender:
|
|
154
|
+
let sender: CID | undefined
|
|
156
155
|
const fs = unixfs(helia)
|
|
157
156
|
|
|
158
157
|
const bytes = await toBuffer(fs.cat(cid, {
|
|
@@ -167,11 +166,11 @@ describe('providers', () => {
|
|
|
167
166
|
}))
|
|
168
167
|
|
|
169
168
|
expect(bytes).to.equalBytes(toBuffer(input))
|
|
170
|
-
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
|
|
169
|
+
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? '').toCID())
|
|
171
170
|
})
|
|
172
171
|
|
|
173
172
|
it('should fetch via mfs using a provider', async () => {
|
|
174
|
-
let sender:
|
|
173
|
+
let sender: CID | undefined
|
|
175
174
|
const fs = mfs(helia)
|
|
176
175
|
|
|
177
176
|
await fs.cp(cid, '/file.txt', {
|
|
@@ -188,11 +187,11 @@ describe('providers', () => {
|
|
|
188
187
|
const bytes = await toBuffer(fs.cat('/file.txt'))
|
|
189
188
|
|
|
190
189
|
expect(bytes).to.equalBytes(toBuffer(input))
|
|
191
|
-
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
|
|
190
|
+
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? '').toCID())
|
|
192
191
|
})
|
|
193
192
|
|
|
194
193
|
it('should fetch via car using a provider', async () => {
|
|
195
|
-
let sender:
|
|
194
|
+
let sender: CID | undefined
|
|
196
195
|
const c = car(helia)
|
|
197
196
|
|
|
198
197
|
expect(await toBuffer(
|
|
@@ -210,6 +209,6 @@ describe('providers', () => {
|
|
|
210
209
|
).to.equalBytes(await toBuffer(
|
|
211
210
|
kubo.api.dag.export(cid)
|
|
212
211
|
))
|
|
213
|
-
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? ''))
|
|
212
|
+
expect(sender).to.deep.equal(peerIdFromString(kuboInfo.peerId?.toString() ?? '').toCID())
|
|
214
213
|
})
|
|
215
214
|
})
|
package/src/strings.spec.ts
CHANGED
|
@@ -5,13 +5,13 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
|
5
5
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
6
6
|
import { createHeliaNode } from './fixtures/create-helia.ts'
|
|
7
7
|
import { createKuboNode } from './fixtures/create-kubo.ts'
|
|
8
|
+
import type { HeliaWithLibp2p } from '@helia/libp2p'
|
|
8
9
|
import type { Strings, AddOptions } from '@helia/strings'
|
|
9
|
-
import type { Helia } from 'helia'
|
|
10
10
|
import type { KuboNode } from 'ipfsd-ctl'
|
|
11
11
|
import type { BlockPutOptions as KuboAddOptions } from 'kubo-rpc-client'
|
|
12
12
|
|
|
13
13
|
describe('@helia/strings', () => {
|
|
14
|
-
let helia:
|
|
14
|
+
let helia: HeliaWithLibp2p
|
|
15
15
|
let str: Strings
|
|
16
16
|
let kubo: KuboNode
|
|
17
17
|
|
|
@@ -4,13 +4,13 @@ import toBuffer from 'it-to-buffer'
|
|
|
4
4
|
import { CID } from 'multiformats/cid'
|
|
5
5
|
import { createHeliaNode } from './fixtures/create-helia.ts'
|
|
6
6
|
import { createKuboNode } from './fixtures/create-kubo.ts'
|
|
7
|
+
import type { HeliaWithLibp2p } from '@helia/libp2p'
|
|
7
8
|
import type { UnixFS } from '@helia/unixfs'
|
|
8
|
-
import type { Helia } from 'helia'
|
|
9
9
|
import type { ByteStream, FileCandidate } from 'ipfs-unixfs-importer'
|
|
10
10
|
import type { KuboNode } from 'ipfsd-ctl'
|
|
11
11
|
|
|
12
12
|
describe('@helia/unixfs - bitswap', () => {
|
|
13
|
-
let helia:
|
|
13
|
+
let helia: HeliaWithLibp2p
|
|
14
14
|
let unixFs: UnixFS
|
|
15
15
|
let kubo: KuboNode
|
|
16
16
|
|
package/src/unixfs-files.spec.ts
CHANGED
|
@@ -11,14 +11,14 @@ import { CID } from 'multiformats/cid'
|
|
|
11
11
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
12
12
|
import { createHeliaNode } from './fixtures/create-helia.ts'
|
|
13
13
|
import { createKuboNode } from './fixtures/create-kubo.ts'
|
|
14
|
+
import type { HeliaWithLibp2p } from '@helia/libp2p'
|
|
14
15
|
import type { AddOptions, UnixFS } from '@helia/unixfs'
|
|
15
|
-
import type { Helia } from 'helia'
|
|
16
16
|
import type { ByteStream, ImportCandidateStream } from 'ipfs-unixfs-importer'
|
|
17
17
|
import type { KuboNode } from 'ipfsd-ctl'
|
|
18
18
|
import type { AddOptions as KuboAddOptions } from 'kubo-rpc-client'
|
|
19
19
|
|
|
20
20
|
describe('@helia/unixfs - files', () => {
|
|
21
|
-
let helia:
|
|
21
|
+
let helia: HeliaWithLibp2p
|
|
22
22
|
let unixFs: UnixFS
|
|
23
23
|
let kubo: KuboNode
|
|
24
24
|
|
package/.aegir.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import getPort from 'aegir/get-port'
|
|
2
|
-
import { createServer } from 'ipfsd-ctl'
|
|
3
|
-
import { create } from 'kubo-rpc-client'
|
|
4
|
-
import { path } from 'kubo'
|
|
5
|
-
|
|
6
|
-
/** @type {import('aegir').PartialOptions} */
|
|
7
|
-
export default {
|
|
8
|
-
test: {
|
|
9
|
-
files: './dist/src/*.spec.js',
|
|
10
|
-
before: async (options) => {
|
|
11
|
-
if (options.runner !== 'node') {
|
|
12
|
-
const ipfsdPort = await getPort()
|
|
13
|
-
const ipfsdServer = await createServer({
|
|
14
|
-
host: '127.0.0.1',
|
|
15
|
-
port: ipfsdPort
|
|
16
|
-
}, {
|
|
17
|
-
type: 'kubo',
|
|
18
|
-
bin: path(),
|
|
19
|
-
rpc: create,
|
|
20
|
-
test: true,
|
|
21
|
-
init: {
|
|
22
|
-
config: {
|
|
23
|
-
Addresses: {
|
|
24
|
-
Swarm: [
|
|
25
|
-
"/ip4/0.0.0.0/tcp/0",
|
|
26
|
-
"/ip4/0.0.0.0/tcp/0/ws"
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}).start()
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
env: {
|
|
35
|
-
IPFSD_SERVER: `http://127.0.0.1:${ipfsdPort}`
|
|
36
|
-
},
|
|
37
|
-
ipfsdServer
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return {}
|
|
42
|
-
},
|
|
43
|
-
after: async (options, beforeResult) => {
|
|
44
|
-
if (options.runner !== 'node') {
|
|
45
|
-
await beforeResult.ipfsdServer.stop()
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|