diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4b3d6ad7..ff8e94d7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,6 +12,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Use Node.js 14 + uses: actions/setup-node@v1 + with: + node-version: 14 - run: npm install - run: npx aegir lint - uses: gozala/typescript-error-reporter-action@v1.0.8 diff --git a/examples/libp2p-in-the-browser/package.json b/examples/libp2p-in-the-browser/package.json index 9b928e8f..bb997142 100644 --- a/examples/libp2p-in-the-browser/package.json +++ b/examples/libp2p-in-the-browser/package.json @@ -17,11 +17,11 @@ "dependencies": { "@babel/preset-env": "^7.13.0", "libp2p": "../../", - "libp2p-bootstrap": "^0.12.1", - "libp2p-mplex": "^0.10.0", - "libp2p-noise": "^2.0.0", - "libp2p-webrtc-star": "^0.22.0", - "libp2p-websockets": "^0.15.0" + "libp2p-bootstrap": "^0.13.0", + "libp2p-mplex": "^0.10.4", + "libp2p-noise": "^4.0.0", + "libp2p-webrtc-star": "^0.23.0", + "libp2p-websockets": "^0.16.1" }, "devDependencies": { "@babel/cli": "^7.13.10", diff --git a/examples/peer-and-content-routing/2.js b/examples/peer-and-content-routing/2.js index 14f513ec..928234b2 100644 --- a/examples/peer-and-content-routing/2.js +++ b/examples/peer-and-content-routing/2.js @@ -5,7 +5,7 @@ const Libp2p = require('../../') const TCP = require('libp2p-tcp') const Mplex = require('libp2p-mplex') const { NOISE } = require('libp2p-noise') -const CID = require('cids') +const { CID } = require('multiformats/cid') const KadDHT = require('libp2p-kad-dht') const all = require('it-all') @@ -51,10 +51,10 @@ const createNode = async () => { // Wait for onConnect handlers in the DHT await delay(100) - const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSySnL') + const cid = CID.parse('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSySnL') await node1.contentRouting.provide(cid) - console.log('Node %s is providing %s', node1.peerId.toB58String(), cid.toBaseEncodedString()) + console.log('Node %s is providing %s', node1.peerId.toB58String(), cid.toString()) // wait for propagation await delay(300) diff --git a/examples/peer-and-content-routing/README.md b/examples/peer-and-content-routing/README.md index 9832003e..197ecf32 100644 --- a/examples/peer-and-content-routing/README.md +++ b/examples/peer-and-content-routing/README.md @@ -81,7 +81,7 @@ Instead of calling `peerRouting.findPeer`, we will use `contentRouting.provide` ```JavaScript await node1.contentRouting.provide(cid) -console.log('Node %s is providing %s', node1.peerId.toB58String(), cid.toBaseEncodedString()) +console.log('Node %s is providing %s', node1.peerId.toB58String(), cid.toString()) const provs = await all(node3.contentRouting.findProviders(cid, { timeout: 5000 })) diff --git a/examples/webrtc-direct/package.json b/examples/webrtc-direct/package.json index d96c2aed..c04ad84f 100644 --- a/examples/webrtc-direct/package.json +++ b/examples/webrtc-direct/package.json @@ -21,11 +21,11 @@ }, "dependencies": { "libp2p": "../../", - "libp2p-bootstrap": "^0.12.1", - "libp2p-mplex": "^0.10.1", - "libp2p-noise": "^2.0.1", - "libp2p-webrtc-direct": "^0.6.0", - "peer-id": "^0.14.3" + "libp2p-bootstrap": "^0.13.0", + "libp2p-mplex": "^0.10.4", + "libp2p-noise": "^4.0.0", + "libp2p-webrtc-direct": "^0.7.0", + "peer-id": "^0.15.0" }, "browser": { "ipfs": "ipfs/dist/index.min.js" diff --git a/package.json b/package.json index 74c158c1..28ec8e66 100644 --- a/package.json +++ b/package.json @@ -84,14 +84,13 @@ "aggregate-error": "^3.1.0", "any-signal": "^2.1.1", "bignumber.js": "^9.0.1", - "cids": "^1.1.5", "class-is": "^1.1.0", "debug": "^4.3.1", "err-code": "^3.0.0", "es6-promisify": "^6.1.1", "events": "^3.3.0", "hashlru": "^2.3.0", - "interface-datastore": "^4.0.0", + "interface-datastore": "^5.1.1", "it-all": "^1.0.4", "it-buffer": "^0.1.2", "it-drain": "^1.0.3", @@ -100,17 +99,17 @@ "it-handshake": "^2.0.0", "it-length-prefixed": "^5.0.2", "it-map": "^1.0.4", - "it-merge": "1.0.0", + "it-merge": "^1.0.0", "it-pipe": "^1.1.0", - "it-take": "1.0.0", + "it-take": "^1.0.0", "libp2p-crypto": "^0.19.4", - "libp2p-interfaces": "^0.10.4", - "libp2p-utils": "^0.3.1", - "mafmt": "^9.0.0", + "libp2p-interfaces": "^1.0.0", + "libp2p-interfaces-compliance-tests": "^1.0.0", + "libp2p-utils": "^0.4.0", + "mafmt": "^10.0.0", "merge-options": "^3.0.4", - "multiaddr": "^9.0.1", - "multicodec": "^3.0.1", - "multihashing-async": "^2.1.2", + "multiaddr": "^10.0.0", + "multiformats": "^9.0.0", "multistream-select": "^2.0.0", "mutable-proxy": "^1.0.0", "node-forge": "^0.10.0", @@ -118,13 +117,13 @@ "p-fifo": "^1.0.0", "p-retry": "^4.4.0", "p-settle": "^4.1.1", - "peer-id": "^0.14.2", + "peer-id": "^0.15.0", "private-ip": "^2.1.0", "protobufjs": "^6.10.2", "retimer": "^3.0.0", "sanitize-filename": "^1.6.3", "set-delayed-interval": "^1.0.0", - "streaming-iterables": "^5.0.2", + "streaming-iterables": "^6.0.0", "timeout-abort-controller": "^1.1.1", "varint": "^6.0.0", "wherearewe": "^1.0.0", @@ -133,7 +132,8 @@ "devDependencies": { "@nodeutils/defaults-deep": "^1.1.0", "@types/es6-promisify": "^6.0.0", - "@types/node-forge": "^0.9.7", + "@types/node": "^16.0.1", + "@types/node-forge": "^0.10.1", "@types/varint": "^6.0.0", "abortable-iterator": "^3.0.0", "aegir": "^33.1.1", @@ -142,29 +142,29 @@ "interop-libp2p": "^0.4.0", "into-stream": "^6.0.0", "ipfs-http-client": "^50.1.1", - "it-concat": "^1.0.0", + "it-concat": "^2.0.0", "it-pair": "^1.0.0", "it-pushable": "^1.4.0", "libp2p": ".", - "libp2p-bootstrap": "^0.12.3", - "libp2p-delegated-content-routing": "^0.10.0", - "libp2p-delegated-peer-routing": "^0.9.0", - "libp2p-floodsub": "^0.25.0", - "libp2p-gossipsub": "^0.9.0", - "libp2p-kad-dht": "^0.22.0", - "libp2p-mdns": "^0.16.0", + "libp2p-bootstrap": "^0.13.0", + "libp2p-delegated-content-routing": "^0.11.0", + "libp2p-delegated-peer-routing": "^0.10.0", + "libp2p-floodsub": "^0.26.0", + "libp2p-gossipsub": "^0.10.0", + "libp2p-kad-dht": "^0.23.0", + "libp2p-mdns": "^0.17.0", "libp2p-mplex": "^0.10.1", - "libp2p-noise": "^3.0.0", - "libp2p-tcp": "^0.16.0", - "libp2p-webrtc-star": "^0.22.2", - "libp2p-websockets": "^0.15.8", + "libp2p-noise": "^4.0.0", + "libp2p-tcp": "^0.17.0", + "libp2p-webrtc-star": "^0.23.0", + "libp2p-websockets": "^0.16.0", "multihashes": "^4.0.2", "nock": "^13.0.3", "p-defer": "^3.0.0", "p-times": "^3.0.0", "p-wait-for": "^3.2.0", "rimraf": "^3.0.2", - "sinon": "^10.0.0", + "sinon": "^11.1.1", "uint8arrays": "^2.1.3", "util": "^0.12.3" }, diff --git a/src/circuit/auto-relay.js b/src/circuit/auto-relay.js index 20174e99..69fc0f76 100644 --- a/src/circuit/auto-relay.js +++ b/src/circuit/auto-relay.js @@ -222,7 +222,7 @@ class AutoRelay { continue } - const peerId = PeerId.createFromCID(id) + const peerId = PeerId.createFromB58String(id) const connection = this._connectionManager.get(peerId) // If not connected, store for possible later use. diff --git a/src/circuit/transport.js b/src/circuit/transport.js index b2206203..1dc284ca 100644 --- a/src/circuit/transport.js +++ b/src/circuit/transport.js @@ -136,8 +136,8 @@ class Circuit { throw errCode(new Error(errMsg), codes.ERR_RELAYED_DIAL) } - const relayPeer = PeerId.createFromCID(relayId) - const destinationPeer = PeerId.createFromCID(destinationId) + const relayPeer = PeerId.createFromB58String(relayId) + const destinationPeer = PeerId.createFromB58String(destinationId) let disconnectOnFailure = false let relayConnection = this._connectionManager.get(relayPeer) diff --git a/src/circuit/utils.js b/src/circuit/utils.js index 3e4ae4c5..7f681a54 100644 --- a/src/circuit/utils.js +++ b/src/circuit/utils.js @@ -1,7 +1,7 @@ 'use strict' -const CID = require('cids') -const multihashing = require('multihashing-async') +const { CID } = require('multiformats/cid') +const { sha256 } = require('multiformats/hashes/sha2') /** * Convert a namespace string into a cid. @@ -11,7 +11,7 @@ const multihashing = require('multihashing-async') */ module.exports.namespaceToCid = async (namespace) => { const bytes = new TextEncoder().encode(namespace) - const hash = await multihashing(bytes, 'sha2-256') + const hash = await sha256.digest(bytes) - return new CID(hash) + return CID.createV0(hash) } diff --git a/src/content-routing/index.js b/src/content-routing/index.js index 00211f71..7fc4b4fb 100644 --- a/src/content-routing/index.js +++ b/src/content-routing/index.js @@ -15,7 +15,7 @@ const { pipe } = require('it-pipe') /** * @typedef {import('peer-id')} PeerId * @typedef {import('multiaddr').Multiaddr} Multiaddr - * @typedef {import('cids')} CID + * @typedef {import('multiformats/cid').CID} CID * @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRoutingModule */ diff --git a/src/peer-store/index.js b/src/peer-store/index.js index b3df1bbb..72fd9043 100644 --- a/src/peer-store/index.js +++ b/src/peer-store/index.js @@ -99,7 +99,7 @@ class PeerStore extends EventEmitter { const peersData = new Map() storedPeers.forEach((idStr) => { - peersData.set(idStr, this.get(PeerId.createFromCID(idStr))) + peersData.set(idStr, this.get(PeerId.createFromB58String(idStr))) }) return peersData diff --git a/src/peer-store/persistent/index.js b/src/peer-store/persistent/index.js index 8d7d50ea..d0bd3dcc 100644 --- a/src/peer-store/persistent/index.js +++ b/src/peer-store/persistent/index.js @@ -7,6 +7,7 @@ const log = Object.assign(debug('libp2p:persistent-peer-store'), { const { Key } = require('interface-datastore') const { Multiaddr } = require('multiaddr') const PeerId = require('peer-id') +const { base32 } = require('multiformats/bases/base32') const PeerStore = require('..') @@ -195,7 +196,7 @@ class PersistentPeerStore extends PeerStore { const batch = this._datastore.batch() for (const peerIdStr of commitPeers) { // PeerId - const peerId = this.keyBook.data.get(peerIdStr) || PeerId.createFromCID(peerIdStr) + const peerId = this.keyBook.data.get(peerIdStr) || PeerId.createFromB58String(peerIdStr) // Address Book this._batchAddressBook(peerId, batch) @@ -346,7 +347,7 @@ class PersistentPeerStore extends PeerStore { async _processDatastoreEntry ({ key, value }) { try { const keyParts = key.toString().split('/') - const peerId = PeerId.createFromCID(keyParts[3]) + const peerId = PeerId.createFromBytes(base32.decode(keyParts[3])) let decoded switch (keyParts[2]) { diff --git a/src/record/peer-record/consts.js b/src/record/peer-record/consts.js index 9a83e030..9b35427e 100644 --- a/src/record/peer-record/consts.js +++ b/src/record/peer-record/consts.js @@ -1,9 +1,7 @@ 'use strict' -const multicodec = require('multicodec') - // The domain string used for peer records contained in a Envelope. -const domain = multicodec.getName(multicodec.LIBP2P_PEER_RECORD) || 'libp2p-peer-record' +const domain = 'libp2p-peer-record' // The type hint used to identify peer records in a Envelope. // Defined in https://github.com/multiformats/multicodec/blob/master/table.csv diff --git a/test/content-routing/content-routing.node.js b/test/content-routing/content-routing.node.js index 68612309..0a8db15b 100644 --- a/test/content-routing/content-routing.node.js +++ b/test/content-routing/content-routing.node.js @@ -8,7 +8,7 @@ const sinon = require('sinon') const pDefer = require('p-defer') const mergeOptions = require('merge-options') -const CID = require('cids') +const { CID } = require('multiformats/cid') const ipfsHttpClient = require('ipfs-http-client') const DelegatedContentRouter = require('libp2p-delegated-content-routing') const { Multiaddr } = require('multiaddr') @@ -164,7 +164,7 @@ describe('content-routing', () => { }) it('should be able to register as a provider', async () => { - const cid = new CID('QmU621oD8AhHw6t25vVyfYKmL9VV3PTgc52FngEhTGACFB') + const cid = CID.parse('QmU621oD8AhHw6t25vVyfYKmL9VV3PTgc52FngEhTGACFB') const provider = 'QmZNgCqZCvTsi3B4Vt7gsSqpkqDpE7M2Y9TDmEhbDb4ceF' const mockBlockApi = nock('http://0.0.0.0:60197') @@ -191,7 +191,7 @@ describe('content-routing', () => { }) it('should handle errors when registering as a provider', async () => { - const cid = new CID('QmU621oD8AhHw6t25vVyfYKmL9VV3PTgc52FngEhTGACFB') + const cid = CID.parse('QmU621oD8AhHw6t25vVyfYKmL9VV3PTgc52FngEhTGACFB') const mockApi = nock('http://0.0.0.0:60197') // mock the block/stat call .post('/api/v0/block/stat') @@ -205,7 +205,7 @@ describe('content-routing', () => { }) it('should be able to find providers', async () => { - const cid = new CID('QmU621oD8AhHw6t25vVyfYKmL9VV3PTgc52FngEhTGACFB') + const cid = CID.parse('QmU621oD8AhHw6t25vVyfYKmL9VV3PTgc52FngEhTGACFB') const provider = 'QmZNgCqZCvTsi3B4Vt7gsSqpkqDpE7M2Y9TDmEhbDb4ceF' const mockApi = nock('http://0.0.0.0:60197') @@ -227,7 +227,7 @@ describe('content-routing', () => { }) it('should handle errors when finding providers', async () => { - const cid = new CID('QmU621oD8AhHw6t25vVyfYKmL9VV3PTgc52FngEhTGACFB') + const cid = CID.parse('QmU621oD8AhHw6t25vVyfYKmL9VV3PTgc52FngEhTGACFB') const mockApi = nock('http://0.0.0.0:60197') .post('/api/v0/dht/findprovs') .query(true) diff --git a/test/insecure/compliance.spec.js b/test/insecure/compliance.spec.js index 74fdf207..f124dde9 100644 --- a/test/insecure/compliance.spec.js +++ b/test/insecure/compliance.spec.js @@ -1,7 +1,7 @@ 'use strict' /* eslint-env mocha */ -const tests = require('libp2p-interfaces/src/crypto/tests') +const tests = require('libp2p-interfaces-compliance-tests/src/crypto') const plaintext = require('../../src/insecure/plaintext') describe('plaintext compliance', () => { diff --git a/test/keychain/peerid.spec.js b/test/keychain/peerid.spec.js index fd393d6a..50d42e13 100644 --- a/test/keychain/peerid.spec.js +++ b/test/keychain/peerid.spec.js @@ -3,7 +3,7 @@ const { expect } = require('aegir/utils/chai') const PeerId = require('peer-id') -const multihash = require('multihashes') +const { base58btc } = require('multiformats/bases/base58') const crypto = require('libp2p-crypto') const rsaUtils = require('libp2p-crypto/src/keys/rsa-utils') const rsaClass = require('libp2p-crypto/src/keys/rsa-class') @@ -40,7 +40,7 @@ describe('peer ID', () => { const jwk = rsaUtils.pkixToJwk(publicKeyDer) const rsa = new rsaClass.RsaPublicKey(jwk) const keyId = await rsa.hash() - const kids = multihash.toB58String(keyId) + const kids = base58btc.encode(keyId).substring(1) expect(kids).to.equal(peer.toB58String()) }) @@ -54,7 +54,7 @@ describe('peer ID', () => { } const rsa = new rsaClass.RsaPublicKey(jwk) const keyId = await rsa.hash() - const kids = multihash.toB58String(keyId) + const kids = base58btc.encode(keyId).substring(1) expect(kids).to.equal(peer.toB58String()) }) diff --git a/test/record/peer-record.spec.js b/test/record/peer-record.spec.js index 7865e2df..532c79a5 100644 --- a/test/record/peer-record.spec.js +++ b/test/record/peer-record.spec.js @@ -3,7 +3,7 @@ const { expect } = require('aegir/utils/chai') -const tests = require('libp2p-interfaces/src/record/tests') +const tests = require('libp2p-interfaces-compliance-tests/src/record') const { Multiaddr } = require('multiaddr') const PeerId = require('peer-id') diff --git a/test/relay/relay.node.js b/test/relay/relay.node.js index 033f21a3..b75fb1cd 100644 --- a/test/relay/relay.node.js +++ b/test/relay/relay.node.js @@ -52,7 +52,7 @@ describe('Dialing (via relay, TCP)', () => { await libp2p.stop() // Clear the peer stores for (const peerIdStr of libp2p.peerStore.peers.keys()) { - const peerId = PeerId.createFromCID(peerIdStr) + const peerId = PeerId.createFromB58String(peerIdStr) libp2p.peerStore.delete(peerId) } })) diff --git a/test/ts-use/package.json b/test/ts-use/package.json index 6caaeca3..8a0670c6 100644 --- a/test/ts-use/package.json +++ b/test/ts-use/package.json @@ -2,21 +2,21 @@ "name": "ts-use", "private": true, "dependencies": { - "datastore-level": "^4.0.0", - "ipfs-http-client": "^49.0.4", + "datastore-level": "^6.0.0", + "ipfs-http-client": "^50.1.2", "libp2p": "file:../..", - "libp2p-bootstrap": "^0.12.2", - "libp2p-delegated-content-routing": "^0.9.0", - "libp2p-delegated-peer-routing": "^0.8.2", + "libp2p-bootstrap": "^0.13.0", + "libp2p-delegated-content-routing": "^0.11.0", + "libp2p-delegated-peer-routing": "^0.10.0", "libp2p-gossipsub": "^0.9.0", - "libp2p-interfaces": "^0.10.1", - "libp2p-kad-dht": "^0.21.0", - "libp2p-mplex": "^0.10.2", - "libp2p-noise": "^2.0.5", - "libp2p-record": "^0.10.2", - "libp2p-tcp": "^0.16.0", - "libp2p-websockets": "^0.15.3", - "peer-id": "^0.14.3" + "libp2p-interfaces": "^1.0.1", + "libp2p-kad-dht": "^0.23.1", + "libp2p-mplex": "^0.10.4", + "libp2p-noise": "^4.0.0", + "libp2p-record": "^0.10.4", + "libp2p-tcp": "^0.17.1", + "libp2p-websockets": "^0.16.1", + "peer-id": "^0.15.0" }, "scripts": { "build": "npx tsc",