@helia/interop 6.1.8 → 7.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/fixtures/create-helia.js +0 -2
- package/dist/src/fixtures/create-helia.js.map +1 -1
- 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 +18 -18
- 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-helia.ts +0 -3
- package/src/fixtures/create-peer-ids.ts +1 -1
- package/src/ipns-http.spec.ts +4 -4
- package/src/ipns-pubsub.spec.ts +19 -20
- package/src/ipns.spec.ts +13 -18
|
@@ -20,8 +20,6 @@ export async function createHeliaNode(libp2pOptions) {
|
|
|
20
20
|
selectors: {
|
|
21
21
|
ipns: ipnsSelector
|
|
22
22
|
},
|
|
23
|
-
// skips waiting for the initial self-query to find peers
|
|
24
|
-
allowQueryWithZeroPeers: true,
|
|
25
23
|
protocol: '/ipfs/lan/kad/1.0.0',
|
|
26
24
|
peerInfoMapper: removePublicAddressesMapper,
|
|
27
25
|
clientMode: false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-helia.js","sourceRoot":"","sources":["../../../src/fixtures/create-helia.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MA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ACD,SAAS,EAAE;gBACT,IAAI,EAAE,YAAY;aACnB;YACD,QAAQ,EAAE,qBAAqB;YAC/B,cAAc,EAAE,2BAA2B;YAC3C,UAAU,EAAE,KAAK;SAClB,CAAC;KACH,CAAA;IAED,kCAAkC;IAClC,QAAQ,CAAC,aAAa,GAAG,EAAE,CAAA;IAE3B,6CAA6C;IAC7C,oDAAoD;IACpD,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAA;IAChC,kDAAkD;IAClD,OAAO,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAA;IAC9B,6DAA6D;IAC7D,OAAO,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAA;IAEzC,OAAO,WAAW,CAAgC;QAChD,YAAY,EAAE;YACZ,OAAO,EAAE;SACV;QACD,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE;YACP,OAAO;SACR;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -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;AAC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AEtC,MAAM,SAAS,GAAG,MAAM,GAAG,CACzB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,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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E,WAAW,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA;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,12 +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 { generateKeyPair } from '@libp2p/crypto/keys';
|
|
7
|
+
import { peerIdFromCID } from '@libp2p/peer-id';
|
|
7
8
|
import { expect } from 'aegir/chai';
|
|
8
9
|
import last from 'it-last';
|
|
9
10
|
import { base36 } from 'multiformats/bases/base36';
|
|
10
11
|
import { CID } from 'multiformats/cid';
|
|
11
12
|
import * as raw from 'multiformats/codecs/raw';
|
|
13
|
+
import { hasCode } from 'multiformats/hashes/digest';
|
|
12
14
|
import { identity } from 'multiformats/hashes/identity';
|
|
13
15
|
import { sha256 } from 'multiformats/hashes/sha2';
|
|
14
16
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
@@ -19,7 +21,6 @@ import { createHeliaNode } from './fixtures/create-helia.js';
|
|
|
19
21
|
import { createKuboNode } from './fixtures/create-kubo.js';
|
|
20
22
|
import { keyTypes } from './fixtures/key-types.js';
|
|
21
23
|
import { waitFor } from './fixtures/wait-for.js';
|
|
22
|
-
const LIBP2P_KEY_CODEC = 0x72;
|
|
23
24
|
// skip RSA tests because we need the DHT enabled to find the public key
|
|
24
25
|
// component of the keypair, but that means we can't test pubsub
|
|
25
26
|
// resolution because Kubo will use the DHT as well
|
|
@@ -55,18 +56,14 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
55
56
|
const input = Uint8Array.from([0, 1, 2, 3, 4]);
|
|
56
57
|
const digest = await sha256.digest(input);
|
|
57
58
|
const cid = CID.createV1(raw.code, digest);
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
throw new Error('No public key present');
|
|
63
|
-
}
|
|
64
|
-
// first call to pubsub resolver will fail but we should trigger subscribing pubsub for updates
|
|
65
|
-
await expect(last(kubo.api.name.resolve(peerId, {
|
|
59
|
+
const privateKey = await generateKeyPair('Ed25519');
|
|
60
|
+
// first call to pubsub resolver will fail but we should trigger
|
|
61
|
+
// subscribing pubsub for updates
|
|
62
|
+
await expect(last(kubo.api.name.resolve(privateKey.publicKey.toString(), {
|
|
66
63
|
timeout: 100
|
|
67
64
|
}))).to.eventually.be.undefined();
|
|
68
65
|
// wait for kubo to be subscribed to updates
|
|
69
|
-
const kuboSubscriptionName = `/ipns/${
|
|
66
|
+
const kuboSubscriptionName = `/ipns/${privateKey.publicKey.toCID().toString(base36)}`;
|
|
70
67
|
await waitFor(async () => {
|
|
71
68
|
const subs = await kubo.api.name.pubsub.subs();
|
|
72
69
|
return subs.includes(kuboSubscriptionName);
|
|
@@ -77,7 +74,7 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
77
74
|
// wait for helia to see that kubo is subscribed to the topic for record updates
|
|
78
75
|
const heliaSubscriptionName = `/record/${uint8ArrayToString(uint8ArrayConcat([
|
|
79
76
|
uint8ArrayFromString('/ipns/'),
|
|
80
|
-
|
|
77
|
+
privateKey.publicKey.toMultihash().bytes
|
|
81
78
|
]), 'base64url')}`;
|
|
82
79
|
const kuboPeerId = (await kubo.api.id()).id.toString();
|
|
83
80
|
await waitFor(async () => {
|
|
@@ -88,9 +85,9 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
88
85
|
message: 'Helia did not see that Kubo was registered for record updates'
|
|
89
86
|
});
|
|
90
87
|
// publish should now succeed
|
|
91
|
-
await name.publish(
|
|
88
|
+
await name.publish(privateKey, cid);
|
|
92
89
|
// kubo should now be able to resolve IPNS name instantly
|
|
93
|
-
const resolved = await last(kubo.api.name.resolve(
|
|
90
|
+
const resolved = await last(kubo.api.name.resolve(privateKey.publicKey.toString(), {
|
|
94
91
|
timeout: 100
|
|
95
92
|
}));
|
|
96
93
|
expect(resolved).to.equal(`/ipfs/${cid.toString()}`);
|
|
@@ -108,13 +105,16 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
108
105
|
});
|
|
109
106
|
// the generated id is libp2p-key CID with the public key as an identity multihash
|
|
110
107
|
const peerCid = CID.parse(result.id, base36);
|
|
111
|
-
const peerId =
|
|
108
|
+
const peerId = peerIdFromCID(peerCid);
|
|
109
|
+
if (!hasCode(peerCid.multihash, identity.code)) {
|
|
110
|
+
throw new Error('Incorrect hash type');
|
|
111
|
+
}
|
|
112
112
|
// first call to pubsub resolver should fail but we should now be subscribed for updates
|
|
113
|
-
await expect(name.resolve(
|
|
113
|
+
await expect(name.resolve(peerCid.multihash)).to.eventually.be.rejected();
|
|
114
114
|
// actual pubsub subscription name
|
|
115
115
|
const subscriptionName = `/record/${uint8ArrayToString(uint8ArrayConcat([
|
|
116
116
|
uint8ArrayFromString('/ipns/'),
|
|
117
|
-
peerId.
|
|
117
|
+
peerId.toMultihash().bytes
|
|
118
118
|
]), 'base64url')}`;
|
|
119
119
|
// wait for helia to be subscribed to the topic for record updates
|
|
120
120
|
await waitFor(async () => {
|
|
@@ -139,7 +139,7 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
139
139
|
// we should get an update eventually
|
|
140
140
|
await waitFor(async () => {
|
|
141
141
|
try {
|
|
142
|
-
resolveResult = await name.resolve(peerId);
|
|
142
|
+
resolveResult = await name.resolve(peerId.toMultihash());
|
|
143
143
|
return true;
|
|
144
144
|
}
|
|
145
145
|
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,
|
|
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,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,CAAA;AACtC,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OA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
|
/* 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"],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E,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": "
|
|
3
|
+
"version": "7.0.0",
|
|
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",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"clean": "aegir clean",
|
|
48
48
|
"lint": "aegir lint",
|
|
49
49
|
"dep-check": "aegir dep-check",
|
|
50
|
+
"doc-check": "aegir doc-check",
|
|
50
51
|
"build": "aegir build",
|
|
51
52
|
"test": "aegir test",
|
|
52
53
|
"test:chrome": "aegir test -t browser --cov",
|
|
@@ -57,40 +58,41 @@
|
|
|
57
58
|
"test:electron-main": "aegir test -t electron-main"
|
|
58
59
|
},
|
|
59
60
|
"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/unixfs": "^
|
|
61
|
+
"@chainsafe/libp2p-gossipsub": "^14.0.0",
|
|
62
|
+
"@helia/block-brokers": "^4.0.0",
|
|
63
|
+
"@helia/car": "^4.0.0",
|
|
64
|
+
"@helia/dag-cbor": "^4.0.0",
|
|
65
|
+
"@helia/dag-json": "^4.0.0",
|
|
66
|
+
"@helia/http": "^2.0.0",
|
|
67
|
+
"@helia/interface": "^5.0.0",
|
|
68
|
+
"@helia/ipns": "^8.0.0",
|
|
69
|
+
"@helia/json": "^4.0.0",
|
|
70
|
+
"@helia/mfs": "^4.0.0",
|
|
71
|
+
"@helia/routers": "^2.0.0",
|
|
72
|
+
"@helia/strings": "^4.0.0",
|
|
73
|
+
"@helia/unixfs": "^4.0.0",
|
|
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": "^14.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": "^5.0.0",
|
|
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",
|
|
@@ -26,9 +26,6 @@ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<H
|
|
|
26
26
|
selectors: {
|
|
27
27
|
ipns: ipnsSelector
|
|
28
28
|
},
|
|
29
|
-
// skips waiting for the initial self-query to find peers
|
|
30
|
-
allowQueryWithZeroPeers: true,
|
|
31
|
-
|
|
32
29
|
protocol: '/ipfs/lan/kad/1.0.0',
|
|
33
30
|
peerInfoMapper: removePublicAddressesMapper,
|
|
34
31
|
clientMode: false
|
|
@@ -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,12 +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 { generateKeyPair } from '@libp2p/crypto/keys'
|
|
8
|
+
import { peerIdFromCID } from '@libp2p/peer-id'
|
|
8
9
|
import { expect } from 'aegir/chai'
|
|
9
10
|
import last from 'it-last'
|
|
10
11
|
import { base36 } from 'multiformats/bases/base36'
|
|
11
12
|
import { CID } from 'multiformats/cid'
|
|
12
13
|
import * as raw from 'multiformats/codecs/raw'
|
|
14
|
+
import { hasCode } from 'multiformats/hashes/digest'
|
|
13
15
|
import { identity } from 'multiformats/hashes/identity'
|
|
14
16
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
15
17
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
@@ -26,8 +28,6 @@ import type { Keychain } from '@libp2p/keychain'
|
|
|
26
28
|
import type { HeliaLibp2p } from 'helia'
|
|
27
29
|
import type { KuboNode } from 'ipfsd-ctl'
|
|
28
30
|
|
|
29
|
-
const LIBP2P_KEY_CODEC = 0x72
|
|
30
|
-
|
|
31
31
|
// skip RSA tests because we need the DHT enabled to find the public key
|
|
32
32
|
// component of the keypair, but that means we can't test pubsub
|
|
33
33
|
// resolution because Kubo will use the DHT as well
|
|
@@ -70,21 +70,16 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
70
70
|
const digest = await sha256.digest(input)
|
|
71
71
|
const cid = CID.createV1(raw.code, digest)
|
|
72
72
|
|
|
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
|
-
}
|
|
73
|
+
const privateKey = await generateKeyPair('Ed25519')
|
|
80
74
|
|
|
81
|
-
// first call to pubsub resolver will fail but we should trigger
|
|
82
|
-
|
|
75
|
+
// first call to pubsub resolver will fail but we should trigger
|
|
76
|
+
// subscribing pubsub for updates
|
|
77
|
+
await expect(last(kubo.api.name.resolve(privateKey.publicKey.toString(), {
|
|
83
78
|
timeout: 100
|
|
84
79
|
}))).to.eventually.be.undefined()
|
|
85
80
|
|
|
86
81
|
// wait for kubo to be subscribed to updates
|
|
87
|
-
const kuboSubscriptionName = `/ipns/${
|
|
82
|
+
const kuboSubscriptionName = `/ipns/${privateKey.publicKey.toCID().toString(base36)}`
|
|
88
83
|
await waitFor(async () => {
|
|
89
84
|
const subs = await kubo.api.name.pubsub.subs()
|
|
90
85
|
return subs.includes(kuboSubscriptionName)
|
|
@@ -96,7 +91,7 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
96
91
|
// wait for helia to see that kubo is subscribed to the topic for record updates
|
|
97
92
|
const heliaSubscriptionName = `/record/${uint8ArrayToString(uint8ArrayConcat([
|
|
98
93
|
uint8ArrayFromString('/ipns/'),
|
|
99
|
-
|
|
94
|
+
privateKey.publicKey.toMultihash().bytes
|
|
100
95
|
]), 'base64url')}`
|
|
101
96
|
const kuboPeerId = (await kubo.api.id()).id.toString()
|
|
102
97
|
await waitFor(async () => {
|
|
@@ -108,10 +103,10 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
108
103
|
})
|
|
109
104
|
|
|
110
105
|
// publish should now succeed
|
|
111
|
-
await name.publish(
|
|
106
|
+
await name.publish(privateKey, cid)
|
|
112
107
|
|
|
113
108
|
// kubo should now be able to resolve IPNS name instantly
|
|
114
|
-
const resolved = await last(kubo.api.name.resolve(
|
|
109
|
+
const resolved = await last(kubo.api.name.resolve(privateKey.publicKey.toString(), {
|
|
115
110
|
timeout: 100
|
|
116
111
|
}))
|
|
117
112
|
|
|
@@ -133,15 +128,19 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
133
128
|
|
|
134
129
|
// the generated id is libp2p-key CID with the public key as an identity multihash
|
|
135
130
|
const peerCid = CID.parse(result.id, base36)
|
|
136
|
-
const peerId =
|
|
131
|
+
const peerId = peerIdFromCID(peerCid)
|
|
132
|
+
|
|
133
|
+
if (!hasCode(peerCid.multihash, identity.code)) {
|
|
134
|
+
throw new Error('Incorrect hash type')
|
|
135
|
+
}
|
|
137
136
|
|
|
138
137
|
// first call to pubsub resolver should fail but we should now be subscribed for updates
|
|
139
|
-
await expect(name.resolve(
|
|
138
|
+
await expect(name.resolve(peerCid.multihash)).to.eventually.be.rejected()
|
|
140
139
|
|
|
141
140
|
// actual pubsub subscription name
|
|
142
141
|
const subscriptionName = `/record/${uint8ArrayToString(uint8ArrayConcat([
|
|
143
142
|
uint8ArrayFromString('/ipns/'),
|
|
144
|
-
peerId.
|
|
143
|
+
peerId.toMultihash().bytes
|
|
145
144
|
]), 'base64url')}`
|
|
146
145
|
|
|
147
146
|
// wait for helia to be subscribed to the topic for record updates
|
|
@@ -172,7 +171,7 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
|
|
|
172
171
|
// we should get an update eventually
|
|
173
172
|
await waitFor(async () => {
|
|
174
173
|
try {
|
|
175
|
-
resolveResult = await name.resolve(peerId)
|
|
174
|
+
resolveResult = await name.resolve(peerId.toMultihash())
|
|
176
175
|
|
|
177
176
|
return true
|
|
178
177
|
} 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
|
})
|