@helia/interop 6.1.7 → 6.1.8-ec8bf66
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/fixtures/create-peer-ids.js +1 -1
- package/dist/src/fixtures/create-peer-ids.js.map +1 -1
- package/dist/src/ipns-http.spec.js +4 -3
- package/dist/src/ipns-http.spec.js.map +1 -1
- package/dist/src/ipns-pubsub.spec.js +34 -25
- package/dist/src/ipns-pubsub.spec.js.map +1 -1
- package/dist/src/ipns.spec.js +11 -16
- package/dist/src/ipns.spec.js.map +1 -1
- package/package.json +27 -25
- package/src/fixtures/create-peer-ids.ts +1 -1
- package/src/ipns-http.spec.ts +4 -4
- package/src/ipns-pubsub.spec.ts +35 -29
- package/src/ipns.spec.ts +13 -18
|
@@ -25,7 +25,7 @@ export async function sortClosestPeers(buf, peers) {
|
|
|
25
25
|
* Creates a DHT ID by hashing a Peer ID
|
|
26
26
|
*/
|
|
27
27
|
export async function convertPeerId(peerId) {
|
|
28
|
-
return convertBuffer(peerId.
|
|
28
|
+
return convertBuffer(peerId.toMultihash().bytes);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Creates a DHT ID by hashing a given Uint8Array
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-peer-ids.js","sourceRoot":"","sources":["../../../src/fixtures/create-peer-ids.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,EAAE,GAAG,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAGtD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAE,GAAe,EAAE,KAAe;IACtE,MAAM,KAAK,GAAG,M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EAAE,EAAE;QACxB,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,CAAA;QAEpC,OAAO;YACL,IAAI;YACJ,QAAQ,EAAE,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC;SACnC,CAAA;IACH,CAAC,CAAC,CACH,CAAA;IAED,OAAO,SAAS;SACb,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,OAAO,iBAAiB,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAA;IAClD,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAE,MAAc;IACjD,OAAO,aAAa,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAA;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAE,GAAe;IAClD,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAE1C,OAAO,SAAS,CAAC,MAAM,CAAA;AACzB,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* eslint-env mocha */
|
|
2
2
|
import { ipns } from '@helia/ipns';
|
|
3
3
|
import { delegatedHTTPRouting } from '@helia/routers';
|
|
4
|
-
import {
|
|
4
|
+
import { peerIdFromCID } from '@libp2p/peer-id';
|
|
5
5
|
import { expect } from 'aegir/chai';
|
|
6
|
+
import { CID } from 'multiformats/cid';
|
|
6
7
|
import { isNode } from 'wherearewe';
|
|
7
8
|
import { createHeliaHTTP } from './fixtures/create-helia-http.js';
|
|
8
9
|
import { createKuboNode } from './fixtures/create-kubo.js';
|
|
@@ -45,8 +46,8 @@ describe('@helia/ipns - http', () => {
|
|
|
45
46
|
const res = await kubo.api.name.publish(cid, {
|
|
46
47
|
key: keyName
|
|
47
48
|
});
|
|
48
|
-
const key =
|
|
49
|
-
const { cid: resolvedCid } = await name.resolve(key);
|
|
49
|
+
const key = peerIdFromCID(CID.parse(res.name));
|
|
50
|
+
const { cid: resolvedCid } = await name.resolve(key.toMultihash());
|
|
50
51
|
expect(resolvedCid.toString()).to.equal(cid.toString());
|
|
51
52
|
});
|
|
52
53
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipns-http.spec.js","sourceRoot":"","sources":["../../src/ipns-http.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ipns-http.spec.js","sourceRoot":"","sources":["../../src/ipns-http.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAK1D,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,IAAI,KAAY,CAAA;IAChB,IAAI,IAAc,CAAA;IAClB,IAAI,IAAU,CAAA;IAEd;;;;OAIG;IACH,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,IAAI,GAAG,MAAM,cAAc,EAAE,CAAA;QAC7B,KAAK,GAAG,MAAM,eAA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A;QAClE,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAA;IACzD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
import { gossipsub } from '@chainsafe/libp2p-gossipsub';
|
|
4
4
|
import { ipns } from '@helia/ipns';
|
|
5
5
|
import { pubsub } from '@helia/ipns/routing';
|
|
6
|
-
import {
|
|
6
|
+
import { hasCode } from '@helia/utils';
|
|
7
|
+
import { generateKeyPair } from '@libp2p/crypto/keys';
|
|
8
|
+
import { peerIdFromCID } from '@libp2p/peer-id';
|
|
7
9
|
import { expect } from 'aegir/chai';
|
|
8
10
|
import last from 'it-last';
|
|
9
11
|
import { base36 } from 'multiformats/bases/base36';
|
|
10
12
|
import { CID } from 'multiformats/cid';
|
|
11
13
|
import * as raw from 'multiformats/codecs/raw';
|
|
12
|
-
import { identity } from 'multiformats/hashes/identity';
|
|
13
14
|
import { sha256 } from 'multiformats/hashes/sha2';
|
|
14
15
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
15
16
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
@@ -19,7 +20,6 @@ import { createHeliaNode } from './fixtures/create-helia.js';
|
|
|
19
20
|
import { createKuboNode } from './fixtures/create-kubo.js';
|
|
20
21
|
import { keyTypes } from './fixtures/key-types.js';
|
|
21
22
|
import { waitFor } from './fixtures/wait-for.js';
|
|
22
|
-
const LIBP2P_KEY_CODEC = 0x72;
|
|
23
23
|
// skip RSA tests because we need the DHT enabled to find the public key
|
|
24
24
|
// component of the keypair, but that means we can't test pubsub
|
|
25
25
|
// resolution because Kubo will use the DHT as well
|
|
@@ -55,32 +55,38 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
55
55
|
const input = Uint8Array.from([0, 1, 2, 3, 4]);
|
|
56
56
|
const digest = await sha256.digest(input);
|
|
57
57
|
const cid = CID.createV1(raw.code, digest);
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
throw new Error('No public key present');
|
|
63
|
-
}
|
|
64
|
-
// first publish should fail because kubo isn't subscribed to key update channel
|
|
65
|
-
await expect(name.publish(peerId, cid)).to.eventually.be.rejected()
|
|
66
|
-
.with.property('message', 'PublishError.NoPeersSubscribedToTopic');
|
|
67
|
-
// should fail to resolve the first time as kubo was not subscribed to the pubsub channel
|
|
68
|
-
await expect(last(kubo.api.name.resolve(peerId, {
|
|
58
|
+
const privateKey = await generateKeyPair('Ed25519');
|
|
59
|
+
// first call to pubsub resolver will fail but we should trigger
|
|
60
|
+
// subscribing pubsub for updates
|
|
61
|
+
await expect(last(kubo.api.name.resolve(privateKey.publicKey.toString(), {
|
|
69
62
|
timeout: 100
|
|
70
63
|
}))).to.eventually.be.undefined();
|
|
71
|
-
// magic pubsub subscription name
|
|
72
|
-
const subscriptionName = `/ipns/${CID.createV1(LIBP2P_KEY_CODEC, identity.digest(peerId.publicKey)).toString(base36)}`;
|
|
73
64
|
// wait for kubo to be subscribed to updates
|
|
65
|
+
const kuboSubscriptionName = `/ipns/${privateKey.publicKey.toCID().toString(base36)}`;
|
|
74
66
|
await waitFor(async () => {
|
|
75
67
|
const subs = await kubo.api.name.pubsub.subs();
|
|
76
|
-
return subs.includes(
|
|
68
|
+
return subs.includes(kuboSubscriptionName);
|
|
69
|
+
}, {
|
|
70
|
+
timeout: 30000,
|
|
71
|
+
message: 'Kubo did not register for record updates'
|
|
72
|
+
});
|
|
73
|
+
// wait for helia to see that kubo is subscribed to the topic for record updates
|
|
74
|
+
const heliaSubscriptionName = `/record/${uint8ArrayToString(uint8ArrayConcat([
|
|
75
|
+
uint8ArrayFromString('/ipns/'),
|
|
76
|
+
privateKey.publicKey.toMultihash().bytes
|
|
77
|
+
]), 'base64url')}`;
|
|
78
|
+
const kuboPeerId = (await kubo.api.id()).id.toString();
|
|
79
|
+
await waitFor(async () => {
|
|
80
|
+
const peers = helia.libp2p.services.pubsub.getSubscribers(heliaSubscriptionName);
|
|
81
|
+
return peers.map(p => p.toString()).includes(kuboPeerId);
|
|
77
82
|
}, {
|
|
78
|
-
timeout: 30000
|
|
83
|
+
timeout: 30000,
|
|
84
|
+
message: 'Helia did not see that Kubo was registered for record updates'
|
|
79
85
|
});
|
|
80
86
|
// publish should now succeed
|
|
81
|
-
await name.publish(
|
|
82
|
-
// kubo should now be able to resolve IPNS name
|
|
83
|
-
const resolved = await last(kubo.api.name.resolve(
|
|
87
|
+
await name.publish(privateKey, cid);
|
|
88
|
+
// kubo should now be able to resolve IPNS name instantly
|
|
89
|
+
const resolved = await last(kubo.api.name.resolve(privateKey.publicKey.toString(), {
|
|
84
90
|
timeout: 100
|
|
85
91
|
}));
|
|
86
92
|
expect(resolved).to.equal(`/ipfs/${cid.toString()}`);
|
|
@@ -98,13 +104,16 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
98
104
|
});
|
|
99
105
|
// the generated id is libp2p-key CID with the public key as an identity multihash
|
|
100
106
|
const peerCid = CID.parse(result.id, base36);
|
|
101
|
-
const peerId =
|
|
107
|
+
const peerId = peerIdFromCID(peerCid);
|
|
108
|
+
if (!hasCode(peerCid.multihash, 0)) {
|
|
109
|
+
throw new Error('Incorrect hash type');
|
|
110
|
+
}
|
|
102
111
|
// first call to pubsub resolver should fail but we should now be subscribed for updates
|
|
103
|
-
await expect(name.resolve(
|
|
112
|
+
await expect(name.resolve(peerCid.multihash)).to.eventually.be.rejected();
|
|
104
113
|
// actual pubsub subscription name
|
|
105
114
|
const subscriptionName = `/record/${uint8ArrayToString(uint8ArrayConcat([
|
|
106
115
|
uint8ArrayFromString('/ipns/'),
|
|
107
|
-
peerId.
|
|
116
|
+
peerId.toMultihash().bytes
|
|
108
117
|
]), 'base64url')}`;
|
|
109
118
|
// wait for helia to be subscribed to the topic for record updates
|
|
110
119
|
await waitFor(async () => {
|
|
@@ -129,7 +138,7 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
129
138
|
// we should get an update eventually
|
|
130
139
|
await waitFor(async () => {
|
|
131
140
|
try {
|
|
132
|
-
resolveResult = await name.resolve(peerId);
|
|
141
|
+
resolveResult = await name.resolve(peerId.toMultihash());
|
|
133
142
|
return true;
|
|
134
143
|
}
|
|
135
144
|
catch {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipns-pubsub.spec.js","sourceRoot":"","sources":["../../src/ipns-pubsub.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,+CAA+C;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"ipns-pubsub.spec.js","sourceRoot":"","sources":["../../src/ipns-pubsub.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,+CAA+C;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,IAAI,MAAM,SAAS,CAAA;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CA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B,CAAC,CAAA;YAC1C,CAAC;YAED,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC/D,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/src/ipns.spec.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/* eslint-env mocha */
|
|
2
2
|
import { ipns } from '@helia/ipns';
|
|
3
|
+
import { generateKeyPair, privateKeyToProtobuf } from '@libp2p/crypto/keys';
|
|
3
4
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
4
|
-
import { createEd25519PeerId, createRSAPeerId, createSecp256k1PeerId } from '@libp2p/peer-id-factory';
|
|
5
5
|
import { expect } from 'aegir/chai';
|
|
6
|
+
import { multihashToIPNSRoutingKey } from 'ipns';
|
|
6
7
|
import last from 'it-last';
|
|
7
8
|
import { CID } from 'multiformats/cid';
|
|
8
9
|
import * as raw from 'multiformats/codecs/raw';
|
|
9
10
|
import { sha256 } from 'multiformats/hashes/sha2';
|
|
10
|
-
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
11
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
12
11
|
import { isElectronMain } from 'wherearewe';
|
|
13
12
|
import { connect } from './fixtures/connect.js';
|
|
14
13
|
import { createHeliaNode } from './fixtures/create-helia.js';
|
|
@@ -39,18 +38,15 @@ keyTypes.forEach(type => {
|
|
|
39
38
|
// find a PeerId that is KAD-closer to the resolver than the publisher when used as an IPNS key
|
|
40
39
|
while (true) {
|
|
41
40
|
if (type === 'Ed25519') {
|
|
42
|
-
key = await
|
|
41
|
+
key = await generateKeyPair('Ed25519');
|
|
43
42
|
}
|
|
44
43
|
else if (type === 'secp256k1') {
|
|
45
|
-
key = await
|
|
44
|
+
key = await generateKeyPair('secp256k1');
|
|
46
45
|
}
|
|
47
46
|
else {
|
|
48
|
-
key = await
|
|
47
|
+
key = await generateKeyPair('RSA', 2048);
|
|
49
48
|
}
|
|
50
|
-
const routingKey =
|
|
51
|
-
uint8ArrayFromString('/ipns/'),
|
|
52
|
-
key.toBytes()
|
|
53
|
-
]);
|
|
49
|
+
const routingKey = multihashToIPNSRoutingKey(key.publicKey?.toMultihash());
|
|
54
50
|
const [closest] = await sortClosestPeers(routingKey, [
|
|
55
51
|
helia.libp2p.peerId,
|
|
56
52
|
peerIdFromString((await kubo.api.id()).id.toString())
|
|
@@ -103,10 +99,9 @@ keyTypes.forEach(type => {
|
|
|
103
99
|
});
|
|
104
100
|
it(`should publish on helia and resolve on kubo using a ${type} key`, async () => {
|
|
105
101
|
await createNodes('kubo');
|
|
106
|
-
const
|
|
107
|
-
await
|
|
108
|
-
await name.
|
|
109
|
-
const resolved = await last(kubo.api.name.resolve(key.toString()));
|
|
102
|
+
const privateKey = await generateKeyPair('Ed25519');
|
|
103
|
+
await name.publish(privateKey, value);
|
|
104
|
+
const resolved = await last(kubo.api.name.resolve(privateKey.publicKey.toString()));
|
|
110
105
|
if (resolved == null) {
|
|
111
106
|
throw new Error('kubo failed to resolve name');
|
|
112
107
|
}
|
|
@@ -127,7 +122,7 @@ keyTypes.forEach(type => {
|
|
|
127
122
|
const { cid } = await kubo.api.add(Uint8Array.from([0, 1, 2, 3, 4]));
|
|
128
123
|
// ensure the key is in the kubo keychain so we can use it to publish the IPNS record
|
|
129
124
|
const body = new FormData();
|
|
130
|
-
body.append('key', new Blob([key
|
|
125
|
+
body.append('key', new Blob([privateKeyToProtobuf(key)]));
|
|
131
126
|
// can't use the kubo-rpc-api for this call yet
|
|
132
127
|
const config = kubo.api.getEndpointConfig();
|
|
133
128
|
const response = await fetch(`http://${config.host}:${config.port}${config.pathname}/key/import?arg=${keyName}`, {
|
|
@@ -140,7 +135,7 @@ keyTypes.forEach(type => {
|
|
|
140
135
|
key: keyName,
|
|
141
136
|
ttl: '1h'
|
|
142
137
|
});
|
|
143
|
-
const { cid: resolvedCid, record } = await name.resolve(key);
|
|
138
|
+
const { cid: resolvedCid, record } = await name.resolve(key.publicKey);
|
|
144
139
|
expect(resolvedCid.toString()).to.equal(cid.toString());
|
|
145
140
|
expect(record.ttl).to.equal(oneHourNS);
|
|
146
141
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipns.spec.js","sourceRoot":"","sources":["../../src/ipns.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ipns.spec.js","sourceRoot":"","sources":["../../src/ipns.spec.ts"],"names":[],"mappings":"AAAA,sBAAsB;AAEtB,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,MAAM,CAAA;AAChD,OAAO,IAAI,MAAM,SAAS,CAAA;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,y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,QAAQ,EAAE,GAAG,CAAC,CAAA;YAEhD,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;YAExC,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;gBAC/B,GAAG,EAAE,OAAO;gBACZ,GAAG,EAAE,IAAI;aACV,CAAC,CAAA;YAEF,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YACtE,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAA;YACvD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QACxC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/interop",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.8-ec8bf66",
|
|
4
4
|
"description": "Interop tests for Helia",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/interop#readme",
|
|
@@ -57,40 +57,42 @@
|
|
|
57
57
|
"test:electron-main": "aegir test -t electron-main"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@chainsafe/libp2p-gossipsub": "^
|
|
61
|
-
"@helia/block-brokers": "
|
|
62
|
-
"@helia/car": "
|
|
63
|
-
"@helia/dag-cbor": "
|
|
64
|
-
"@helia/dag-json": "
|
|
65
|
-
"@helia/http": "
|
|
66
|
-
"@helia/interface": "
|
|
67
|
-
"@helia/ipns": "
|
|
68
|
-
"@helia/json": "
|
|
69
|
-
"@helia/mfs": "
|
|
70
|
-
"@helia/routers": "
|
|
71
|
-
"@helia/strings": "
|
|
72
|
-
"@helia/
|
|
60
|
+
"@chainsafe/libp2p-gossipsub": "^14.0.0",
|
|
61
|
+
"@helia/block-brokers": "3.0.4-ec8bf66",
|
|
62
|
+
"@helia/car": "3.2.1-ec8bf66",
|
|
63
|
+
"@helia/dag-cbor": "3.0.6-ec8bf66",
|
|
64
|
+
"@helia/dag-json": "3.0.6-ec8bf66",
|
|
65
|
+
"@helia/http": "1.0.11-ec8bf66",
|
|
66
|
+
"@helia/interface": "4.3.1-ec8bf66",
|
|
67
|
+
"@helia/ipns": "7.2.3-ec8bf66",
|
|
68
|
+
"@helia/json": "3.0.6-ec8bf66",
|
|
69
|
+
"@helia/mfs": "3.0.8-ec8bf66",
|
|
70
|
+
"@helia/routers": "1.1.1-ec8bf66",
|
|
71
|
+
"@helia/strings": "3.0.6-ec8bf66",
|
|
72
|
+
"@helia/utils": "0.3.3-ec8bf66",
|
|
73
|
+
"@helia/unixfs": "3.0.7-ec8bf66",
|
|
73
74
|
"@ipld/car": "^5.3.0",
|
|
74
75
|
"@ipld/dag-cbor": "^9.2.0",
|
|
75
|
-
"@libp2p/
|
|
76
|
-
"@libp2p/
|
|
77
|
-
"@libp2p/
|
|
78
|
-
"@libp2p/
|
|
79
|
-
"@libp2p/peer-id
|
|
80
|
-
"@libp2p/websockets": "^
|
|
76
|
+
"@libp2p/crypto": "^5.0.0",
|
|
77
|
+
"@libp2p/interface": "^2.0.0",
|
|
78
|
+
"@libp2p/kad-dht": "^13.0.0",
|
|
79
|
+
"@libp2p/keychain": "^5.0.2",
|
|
80
|
+
"@libp2p/peer-id": "^5.0.0",
|
|
81
|
+
"@libp2p/websockets": "^9.0.0",
|
|
81
82
|
"@multiformats/sha3": "^3.0.2",
|
|
82
83
|
"aegir": "^44.0.1",
|
|
83
|
-
"helia": "
|
|
84
|
+
"helia": "4.2.6-ec8bf66",
|
|
84
85
|
"ipfs-unixfs-importer": "^15.2.4",
|
|
85
|
-
"ipfsd-ctl": "^
|
|
86
|
+
"ipfsd-ctl": "^15.0.0",
|
|
87
|
+
"ipns": "^10.0.0",
|
|
86
88
|
"it-all": "^3.0.4",
|
|
87
89
|
"it-drain": "^3.0.5",
|
|
88
90
|
"it-last": "^3.0.4",
|
|
89
91
|
"it-map": "^3.0.5",
|
|
90
92
|
"it-to-buffer": "^4.0.5",
|
|
91
|
-
"kubo": "^0.
|
|
92
|
-
"kubo-rpc-client": "^
|
|
93
|
-
"libp2p": "^
|
|
93
|
+
"kubo": "^0.30.0",
|
|
94
|
+
"kubo-rpc-client": "^5.0.0",
|
|
95
|
+
"libp2p": "^2.0.0",
|
|
94
96
|
"multiformats": "^13.1.0",
|
|
95
97
|
"p-defer": "^4.0.0",
|
|
96
98
|
"uint8arrays": "^5.0.2",
|
|
@@ -33,7 +33,7 @@ export async function sortClosestPeers (buf: Uint8Array, peers: PeerId[]): Promi
|
|
|
33
33
|
* Creates a DHT ID by hashing a Peer ID
|
|
34
34
|
*/
|
|
35
35
|
export async function convertPeerId (peerId: PeerId): Promise<Uint8Array> {
|
|
36
|
-
return convertBuffer(peerId.
|
|
36
|
+
return convertBuffer(peerId.toMultihash().bytes)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
package/src/ipns-http.spec.ts
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import { ipns } from '@helia/ipns'
|
|
4
4
|
import { delegatedHTTPRouting } from '@helia/routers'
|
|
5
|
-
import {
|
|
5
|
+
import { peerIdFromCID } from '@libp2p/peer-id'
|
|
6
6
|
import { expect } from 'aegir/chai'
|
|
7
|
+
import { CID } from 'multiformats/cid'
|
|
7
8
|
import { isNode } from 'wherearewe'
|
|
8
9
|
import { createHeliaHTTP } from './fixtures/create-helia-http.js'
|
|
9
10
|
import { createKuboNode } from './fixtures/create-kubo.js'
|
|
@@ -58,9 +59,8 @@ describe('@helia/ipns - http', () => {
|
|
|
58
59
|
key: keyName
|
|
59
60
|
})
|
|
60
61
|
|
|
61
|
-
const key =
|
|
62
|
-
|
|
63
|
-
const { cid: resolvedCid } = await name.resolve(key)
|
|
62
|
+
const key = peerIdFromCID(CID.parse(res.name))
|
|
63
|
+
const { cid: resolvedCid } = await name.resolve(key.toMultihash())
|
|
64
64
|
expect(resolvedCid.toString()).to.equal(cid.toString())
|
|
65
65
|
})
|
|
66
66
|
})
|
package/src/ipns-pubsub.spec.ts
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
|
|
5
5
|
import { ipns } from '@helia/ipns'
|
|
6
6
|
import { pubsub } from '@helia/ipns/routing'
|
|
7
|
-
import {
|
|
7
|
+
import { hasCode } from '@helia/utils'
|
|
8
|
+
import { generateKeyPair } from '@libp2p/crypto/keys'
|
|
9
|
+
import { peerIdFromCID } from '@libp2p/peer-id'
|
|
8
10
|
import { expect } from 'aegir/chai'
|
|
9
11
|
import last from 'it-last'
|
|
10
12
|
import { base36 } from 'multiformats/bases/base36'
|
|
11
13
|
import { CID } from 'multiformats/cid'
|
|
12
14
|
import * as raw from 'multiformats/codecs/raw'
|
|
13
|
-
import { identity } from 'multiformats/hashes/identity'
|
|
14
15
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
15
16
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
16
17
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
@@ -26,8 +27,6 @@ import type { Keychain } from '@libp2p/keychain'
|
|
|
26
27
|
import type { HeliaLibp2p } from 'helia'
|
|
27
28
|
import type { KuboNode } from 'ipfsd-ctl'
|
|
28
29
|
|
|
29
|
-
const LIBP2P_KEY_CODEC = 0x72
|
|
30
|
-
|
|
31
30
|
// skip RSA tests because we need the DHT enabled to find the public key
|
|
32
31
|
// component of the keypair, but that means we can't test pubsub
|
|
33
32
|
// resolution because Kubo will use the DHT as well
|
|
@@ -70,40 +69,43 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
70
69
|
const digest = await sha256.digest(input)
|
|
71
70
|
const cid = CID.createV1(raw.code, digest)
|
|
72
71
|
|
|
73
|
-
const
|
|
74
|
-
await helia.libp2p.services.keychain.createKey(keyName, keyType)
|
|
75
|
-
const peerId = await helia.libp2p.services.keychain.exportPeerId(keyName)
|
|
76
|
-
|
|
77
|
-
if (peerId.publicKey == null) {
|
|
78
|
-
throw new Error('No public key present')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// first publish should fail because kubo isn't subscribed to key update channel
|
|
82
|
-
await expect(name.publish(peerId, cid)).to.eventually.be.rejected()
|
|
83
|
-
.with.property('message', 'PublishError.NoPeersSubscribedToTopic')
|
|
72
|
+
const privateKey = await generateKeyPair('Ed25519')
|
|
84
73
|
|
|
85
|
-
//
|
|
86
|
-
|
|
74
|
+
// first call to pubsub resolver will fail but we should trigger
|
|
75
|
+
// subscribing pubsub for updates
|
|
76
|
+
await expect(last(kubo.api.name.resolve(privateKey.publicKey.toString(), {
|
|
87
77
|
timeout: 100
|
|
88
78
|
}))).to.eventually.be.undefined()
|
|
89
79
|
|
|
90
|
-
// magic pubsub subscription name
|
|
91
|
-
const subscriptionName = `/ipns/${CID.createV1(LIBP2P_KEY_CODEC, identity.digest(peerId.publicKey)).toString(base36)}`
|
|
92
|
-
|
|
93
80
|
// wait for kubo to be subscribed to updates
|
|
81
|
+
const kuboSubscriptionName = `/ipns/${privateKey.publicKey.toCID().toString(base36)}`
|
|
94
82
|
await waitFor(async () => {
|
|
95
83
|
const subs = await kubo.api.name.pubsub.subs()
|
|
84
|
+
return subs.includes(kuboSubscriptionName)
|
|
85
|
+
}, {
|
|
86
|
+
timeout: 30000,
|
|
87
|
+
message: 'Kubo did not register for record updates'
|
|
88
|
+
})
|
|
96
89
|
|
|
97
|
-
|
|
90
|
+
// wait for helia to see that kubo is subscribed to the topic for record updates
|
|
91
|
+
const heliaSubscriptionName = `/record/${uint8ArrayToString(uint8ArrayConcat([
|
|
92
|
+
uint8ArrayFromString('/ipns/'),
|
|
93
|
+
privateKey.publicKey.toMultihash().bytes
|
|
94
|
+
]), 'base64url')}`
|
|
95
|
+
const kuboPeerId = (await kubo.api.id()).id.toString()
|
|
96
|
+
await waitFor(async () => {
|
|
97
|
+
const peers = helia.libp2p.services.pubsub.getSubscribers(heliaSubscriptionName)
|
|
98
|
+
return peers.map(p => p.toString()).includes(kuboPeerId)
|
|
98
99
|
}, {
|
|
99
|
-
timeout: 30000
|
|
100
|
+
timeout: 30000,
|
|
101
|
+
message: 'Helia did not see that Kubo was registered for record updates'
|
|
100
102
|
})
|
|
101
103
|
|
|
102
104
|
// publish should now succeed
|
|
103
|
-
await name.publish(
|
|
105
|
+
await name.publish(privateKey, cid)
|
|
104
106
|
|
|
105
|
-
// kubo should now be able to resolve IPNS name
|
|
106
|
-
const resolved = await last(kubo.api.name.resolve(
|
|
107
|
+
// kubo should now be able to resolve IPNS name instantly
|
|
108
|
+
const resolved = await last(kubo.api.name.resolve(privateKey.publicKey.toString(), {
|
|
107
109
|
timeout: 100
|
|
108
110
|
}))
|
|
109
111
|
|
|
@@ -125,15 +127,19 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
125
127
|
|
|
126
128
|
// the generated id is libp2p-key CID with the public key as an identity multihash
|
|
127
129
|
const peerCid = CID.parse(result.id, base36)
|
|
128
|
-
const peerId =
|
|
130
|
+
const peerId = peerIdFromCID(peerCid)
|
|
131
|
+
|
|
132
|
+
if (!hasCode(peerCid.multihash, 0)) {
|
|
133
|
+
throw new Error('Incorrect hash type')
|
|
134
|
+
}
|
|
129
135
|
|
|
130
136
|
// first call to pubsub resolver should fail but we should now be subscribed for updates
|
|
131
|
-
await expect(name.resolve(
|
|
137
|
+
await expect(name.resolve(peerCid.multihash)).to.eventually.be.rejected()
|
|
132
138
|
|
|
133
139
|
// actual pubsub subscription name
|
|
134
140
|
const subscriptionName = `/record/${uint8ArrayToString(uint8ArrayConcat([
|
|
135
141
|
uint8ArrayFromString('/ipns/'),
|
|
136
|
-
peerId.
|
|
142
|
+
peerId.toMultihash().bytes
|
|
137
143
|
]), 'base64url')}`
|
|
138
144
|
|
|
139
145
|
// wait for helia to be subscribed to the topic for record updates
|
|
@@ -164,7 +170,7 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
164
170
|
// we should get an update eventually
|
|
165
171
|
await waitFor(async () => {
|
|
166
172
|
try {
|
|
167
|
-
resolveResult = await name.resolve(peerId)
|
|
173
|
+
resolveResult = await name.resolve(peerId.toMultihash())
|
|
168
174
|
|
|
169
175
|
return true
|
|
170
176
|
} catch {
|
package/src/ipns.spec.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/* eslint-env mocha */
|
|
2
2
|
|
|
3
3
|
import { ipns } from '@helia/ipns'
|
|
4
|
+
import { generateKeyPair, privateKeyToProtobuf } from '@libp2p/crypto/keys'
|
|
4
5
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
5
|
-
import { createEd25519PeerId, createRSAPeerId, createSecp256k1PeerId } from '@libp2p/peer-id-factory'
|
|
6
6
|
import { expect } from 'aegir/chai'
|
|
7
|
+
import { multihashToIPNSRoutingKey } from 'ipns'
|
|
7
8
|
import last from 'it-last'
|
|
8
9
|
import { CID } from 'multiformats/cid'
|
|
9
10
|
import * as raw from 'multiformats/codecs/raw'
|
|
10
11
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
11
|
-
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
12
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
13
12
|
import { isElectronMain } from 'wherearewe'
|
|
14
13
|
import { connect } from './fixtures/connect.js'
|
|
15
14
|
import { createHeliaNode } from './fixtures/create-helia.js'
|
|
@@ -18,7 +17,7 @@ import { sortClosestPeers } from './fixtures/create-peer-ids.js'
|
|
|
18
17
|
import { keyTypes } from './fixtures/key-types.js'
|
|
19
18
|
import { waitFor } from './fixtures/wait-for.js'
|
|
20
19
|
import type { IPNS } from '@helia/ipns'
|
|
21
|
-
import type {
|
|
20
|
+
import type { PrivateKey } from '@libp2p/interface'
|
|
22
21
|
import type { HeliaLibp2p } from 'helia'
|
|
23
22
|
import type { KuboNode } from 'ipfsd-ctl'
|
|
24
23
|
|
|
@@ -32,7 +31,7 @@ keyTypes.forEach(type => {
|
|
|
32
31
|
let value: CID
|
|
33
32
|
|
|
34
33
|
// the public key we will use to publish the value
|
|
35
|
-
let key:
|
|
34
|
+
let key: PrivateKey
|
|
36
35
|
|
|
37
36
|
/**
|
|
38
37
|
* Ensure that for the CID we are going to publish, the resolver has a peer ID that
|
|
@@ -50,17 +49,14 @@ keyTypes.forEach(type => {
|
|
|
50
49
|
// find a PeerId that is KAD-closer to the resolver than the publisher when used as an IPNS key
|
|
51
50
|
while (true) {
|
|
52
51
|
if (type === 'Ed25519') {
|
|
53
|
-
key = await
|
|
52
|
+
key = await generateKeyPair('Ed25519')
|
|
54
53
|
} else if (type === 'secp256k1') {
|
|
55
|
-
key = await
|
|
54
|
+
key = await generateKeyPair('secp256k1')
|
|
56
55
|
} else {
|
|
57
|
-
key = await
|
|
56
|
+
key = await generateKeyPair('RSA', 2048)
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
const routingKey =
|
|
61
|
-
uint8ArrayFromString('/ipns/'),
|
|
62
|
-
key.toBytes()
|
|
63
|
-
])
|
|
59
|
+
const routingKey = multihashToIPNSRoutingKey(key.publicKey?.toMultihash())
|
|
64
60
|
|
|
65
61
|
const [closest] = await sortClosestPeers(routingKey, [
|
|
66
62
|
helia.libp2p.peerId,
|
|
@@ -128,12 +124,11 @@ keyTypes.forEach(type => {
|
|
|
128
124
|
it(`should publish on helia and resolve on kubo using a ${type} key`, async () => {
|
|
129
125
|
await createNodes('kubo')
|
|
130
126
|
|
|
131
|
-
const
|
|
132
|
-
await helia.libp2p.services.keychain.importPeer(keyName, key)
|
|
127
|
+
const privateKey = await generateKeyPair('Ed25519')
|
|
133
128
|
|
|
134
|
-
await name.publish(
|
|
129
|
+
await name.publish(privateKey, value)
|
|
135
130
|
|
|
136
|
-
const resolved = await last(kubo.api.name.resolve(
|
|
131
|
+
const resolved = await last(kubo.api.name.resolve(privateKey.publicKey.toString()))
|
|
137
132
|
|
|
138
133
|
if (resolved == null) {
|
|
139
134
|
throw new Error('kubo failed to resolve name')
|
|
@@ -161,7 +156,7 @@ keyTypes.forEach(type => {
|
|
|
161
156
|
|
|
162
157
|
// ensure the key is in the kubo keychain so we can use it to publish the IPNS record
|
|
163
158
|
const body = new FormData()
|
|
164
|
-
body.append('key', new Blob([key
|
|
159
|
+
body.append('key', new Blob([privateKeyToProtobuf(key)]))
|
|
165
160
|
|
|
166
161
|
// can't use the kubo-rpc-api for this call yet
|
|
167
162
|
const config = kubo.api.getEndpointConfig()
|
|
@@ -179,7 +174,7 @@ keyTypes.forEach(type => {
|
|
|
179
174
|
ttl: '1h'
|
|
180
175
|
})
|
|
181
176
|
|
|
182
|
-
const { cid: resolvedCid, record } = await name.resolve(key)
|
|
177
|
+
const { cid: resolvedCid, record } = await name.resolve(key.publicKey)
|
|
183
178
|
expect(resolvedCid.toString()).to.equal(cid.toString())
|
|
184
179
|
expect(record.ttl).to.equal(oneHourNS)
|
|
185
180
|
})
|