mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 02:22:14 +00:00
chore: update to new multiformats (#948)
BREAKING CHANGE: uses the CID class from the new multiformats module Co-authored-by: Vasco Santos <vasco.santos@moxy.studio>
This commit is contained in:
parent
39b03586e8
commit
13cf476148
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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)
|
||||
|
@ -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 }))
|
||||
|
||||
|
@ -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"
|
||||
|
52
package.json
52
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"
|
||||
},
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
||||
|
@ -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
|
||||
|
@ -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]) {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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', () => {
|
||||
|
@ -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())
|
||||
})
|
||||
|
||||
|
@ -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')
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}))
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user