Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

feat: upgrade to the new multiformats #3556

Merged
merged 36 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
215c57f
feat: add new BlockService
vmx Mar 12, 2021
14e9e43
WIP: typechecker in ipfs-core passes
vmx Mar 31, 2021
7b2161f
fix: file interface tests work
vmx Apr 5, 2021
93d8c6d
chore: make the linter happy
vmx Apr 7, 2021
1d5de7d
test: revive block storage tests
vmx Apr 7, 2021
70dad2b
chore: use git dependencies
vmx Apr 7, 2021
e1a8142
chore: use gitpkg dependencies for dag-pb
rvagg Apr 24, 2021
07d93b7
Merge remote-tracking branch 'origin/master' into js-dag-pb
achingbrain Jun 21, 2021
09aa573
chore: use branches with new multiformats
achingbrain Jun 21, 2021
74f2707
chore: use node 16 for actions
achingbrain Jun 21, 2021
08f05e4
chore: fix some tests
achingbrain Jun 21, 2021
354ab7b
chore: types and linting. that is it, right?
achingbrain Jun 30, 2021
0fbbf01
chore: tests passing for core and cli
achingbrain Jul 2, 2021
8ebacf2
chore: http server tests passing
achingbrain Jul 3, 2021
ccc8d81
chore: remove redundant deps
achingbrain Jul 3, 2021
a5b438e
chore: fix up message port protocol tests
achingbrain Jul 3, 2021
2ed3060
chore: tests and linting
achingbrain Jul 3, 2021
959a2a6
chore: interface tests passing for core and http client against js
achingbrain Jul 5, 2021
be2af4d
chore: tests passing, locally at least
achingbrain Jul 6, 2021
cc79f12
chore: linting and types
achingbrain Jul 6, 2021
3d7bd41
chore: update deps
achingbrain Jul 10, 2021
96fe36d
chore: fix dep check
achingbrain Jul 10, 2021
49a1544
chore: remove cids/multicodec/multihash-* from the dep tree
achingbrain Jul 10, 2021
394606d
chore: use peerid parse
achingbrain Jul 10, 2021
1619d92
chore: update more deps
achingbrain Jul 12, 2021
67f2875
chore: fix http-go tests
achingbrain Jul 12, 2021
99ac034
chore: fix up go-http tests and unskip a few new ones
achingbrain Jul 12, 2021
af808a5
chore: update deps
achingbrain Jul 12, 2021
b7961f3
chore: fix up example tests, pending ipjs prs
achingbrain Jul 14, 2021
34698ae
chore: update multiformats and fix linting
achingbrain Jul 15, 2021
d9e06b0
chore: add project reference
achingbrain Jul 15, 2021
2b02515
chore: update deps
achingbrain Jul 15, 2021
766fc78
chore: update project references
achingbrain Jul 15, 2021
fc94459
chore: update bundle sizes
achingbrain Jul 15, 2021
d0e31f2
chore: fix leaf node tests
achingbrain Jul 17, 2021
d40524f
chore: update interop version
achingbrain Jul 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/bundlesize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest # https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu1804-README.md
strategy:
matrix:
node-version: [14.x]
node-version: [16.x]
project:
- packages/ipfs
- packages/ipfs-core
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
node-version: [16.x]
project:
- packages/ipfs
- packages/ipfs-cli
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dist
build
bundle.js
tsconfig-types.aegir.json
tsconfig-check.aegir.json
.tsbuildinfo

# Deployment files
Expand Down
31 changes: 19 additions & 12 deletions README.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/MIGRATION-TO-ASYNC-AWAIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ Libp2p `PeerId` instances are no longer returned from the API. If your applicati
Peer ID strings are also CIDs so converting them is simple:

```js
const peerId = PeerId.createFromCID(peerIdStr)
const peerId = PeerId.createFromB58String(peerIdStr)
```

You can get hold of the `PeerId` class using npm or in a script tag:

```js
const PeerId = require('peer-id')
const peerId = PeerId.createFromCID(peerIdStr)
const peerId = PeerId.createFromB58String(peerIdStr)
```

```html
<script src="https://unpkg.com/peer-id/dist/index.min.js"></script>
<script>
const peerId = window.PeerId.createFromCID(peerIdStr)
const peerId = window.PeerId.createFromB58String(peerIdStr)
</script>
```

Expand All @@ -120,7 +120,7 @@ Libp2p `PeerInfo` instances are no longer returned from the API. Instead, plain
Instantiate a new `PeerInfo` and add addresses to it:

```js
const peerInfo = new PeerInfo(PeerId.createFromCID(info.id))
const peerInfo = new PeerInfo(PeerId.createFromB58String(info.id))
info.addrs.forEach(addr => peerInfo.multiaddrs.add(addr))
```

Expand All @@ -129,15 +129,15 @@ You can get hold of the `PeerInfo` class using npm or in a script tag:
```js
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const peerInfo = new PeerInfo(PeerId.createFromCID(info.id))
const peerInfo = new PeerInfo(PeerId.createFromB58String(info.id))
info.addrs.forEach(addr => peerInfo.multiaddrs.add(addr))
```

```html
<script src="https://unpkg.com/peer-info/dist/index.min.js"></script>
<script src="https://unpkg.com/peer-id/dist/index.min.js"></script>
<script>
const peerInfo = new window.PeerInfo(window.PeerId.createFromCID(info.id))
const peerInfo = new window.PeerInfo(window.PeerId.createFromB58String(info.id))
info.addrs.forEach(addr => peerInfo.multiaddrs.add(addr))
</script>
```
Expand Down
7 changes: 4 additions & 3 deletions docs/core-api/BLOCK.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ console.log(block.cid.toString())
// the CID of the object

// With custom format and hashtype through CID
const CID = require('cids')
const { CID } = require('multiformats/cid')
const dagPb = require('@ipld/dag-pb')
const buf = new TextEncoder().encode('another serialized object')
const cid = new CID(1, 'dag-pb', multihash)
const cid = CID.createV1(dagPb.code, multihash)

const block = await ipfs.block.put(blob, cid)

Expand Down Expand Up @@ -211,7 +212,7 @@ the returned object has the following keys:

```JavaScript
const multihashStr = 'QmQULBtTjNcMwMr4VMNknnVv3RpytrLSdgpvMcTnfNhrBJ'
const cid = new CID(multihashStr)
const cid = CID.parse(multihashStr)

const stats = await ipfs.block.stat(cid)
console.log(stats.cid.toString())
Expand Down
2 changes: 1 addition & 1 deletion docs/core-api/DAG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ An optional object which may have the following keys:

```JavaScript
const obj = { simple: 'object' }
const cid = await ipfs.dag.put(obj, { format: 'dag-cbor', hashAlg: 'sha3-512' })
const cid = await ipfs.dag.put(obj, { format: 'dag-cbor', hashAlg: 'sha2-512' })

console.log(cid.toString())
// zBwWX9ecx5F4X54WAjmFLErnBT6ByfNxStr5ovowTL7AhaUR98RWvXPS1V3HqV1qs3r5Ec5ocv7eCdbqYQREXNUfYNuKG
Expand Down
6 changes: 3 additions & 3 deletions docs/core-api/OBJECT.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ An optional object which may have the following keys:
const cid = await ipfs.object.patch.addLink(node, {
name: 'some-link',
size: 10,
cid: new CID('QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD')
cid: CID.parse('QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD')
})
```

Expand All @@ -357,7 +357,7 @@ The `DAGLink` to be added can also be passed as an object containing: `name`, `c
const link = {
name: 'Qmef7ScwzJUCg1zUSrCmPAz45m8uP5jU7SLgt2EffjBmbL',
size: 37,
cid: new CID('Qmef7ScwzJUCg1zUSrCmPAz45m8uP5jU7SLgt2EffjBmbL')
cid: CID.parse('Qmef7ScwzJUCg1zUSrCmPAz45m8uP5jU7SLgt2EffjBmbL')
};
```

Expand Down Expand Up @@ -400,7 +400,7 @@ An optional object which may have the following keys:
const cid = await ipfs.object.patch.rmLink(node, {
name: 'some-link',
size: 10,
cid: new CID('QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD')
cid: CID.parse('QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD')
})
```

Expand Down
14 changes: 7 additions & 7 deletions docs/core-api/PIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ An optional object which may have the following keys:
### Example

```JavaScript
const cid of ipfs.pin.add(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))
const cid of ipfs.pin.add(CID.parse('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))
console.log(cid)
// Logs:
// CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
Expand Down Expand Up @@ -130,7 +130,7 @@ Each yielded object has the form:
### Example

```JavaScript
for await (const cid of ipfs.pin.addAll(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))) {
for await (const cid of ipfs.pin.addAll(CID.parse('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))) {
console.log(cid)
}
// Logs:
Expand Down Expand Up @@ -178,7 +178,7 @@ for await (const { cid, type } of ipfs.pin.ls()) {

```JavaScript
for await (const { cid, type } of ipfs.pin.ls({
paths: [ new CID('Qmc5..'), new CID('QmZb..'), new CID('QmSo..') ]
paths: [ CID.parse('Qmc5..'), CID.parse('QmZb..'), CID.parse('QmSo..') ]
})) {
console.log({ cid, type })
}
Expand Down Expand Up @@ -218,7 +218,7 @@ An optional object which may have the following keys:
### Example

```JavaScript
const cid of ipfs.pin.rm(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))
const cid of ipfs.pin.rm(CID.parse('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))
console.log(cid)
// prints the CID that was unpinned
// CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
Expand Down Expand Up @@ -254,7 +254,7 @@ An optional object which may have the following keys:
### Example

```JavaScript
for await (const cid of ipfs.pin.rmAll(new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))) {
for await (const cid of ipfs.pin.rmAll(CID.parse('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u'))) {
console.log(cid)
}
// prints the CIDs that were unpinned
Expand Down Expand Up @@ -320,7 +320,7 @@ An object may have the following optional fields:

| Name | Type | Default | Description |
| ---- | ---- | ------- | ----------- |
| stat | `boolean` | `false` | If `true` will include service stats. |
| stat | `boolean` | `false` | If `true` will include service stats. |
| timeout | `number` | `undefined` | A timeout in ms |
| signal | [AbortSignal][] | `undefined` | Can be used to cancel any long running requests started as a result of this call |

Expand Down Expand Up @@ -486,7 +486,7 @@ Status is one of the following string values:
### Example

```JavaScript
const cid = new CID('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
const cid = CID.parse('QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u')
const pin = await ipfs.pin.remote.add(cid, {
service: 'pinata',
name: 'block-party'
Expand Down
13 changes: 7 additions & 6 deletions examples/browser-add-readable-stream/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ const main = async () => {

const directoryHash = await streamFiles(ipfs, directoryName, inputFiles)

const fileList = await ipfs.ls(directoryHash)

log(`\n--\n\nDirectory contents:\n\n${directoryName}/ ${directoryHash}`)

fileList.forEach((file, index) => {
log(` ${index < fileList.length - 1 ? '\u251C' : '\u2514'}\u2500 ${file.name} ${file.path} ${file.hash}`)
})
let index = 0

for await (const file of ipfs.ls(directoryHash)) {
log(` ${index < inputFiles.length - 1 ? '\u251C' : '\u2514'}\u2500 ${file.name} ${file.path} ${file.cid}`)
index++
}
}

const createFiles = (directory) => {
Expand Down Expand Up @@ -54,7 +55,7 @@ const streamFiles = async (ipfs, directory, files) => {

const data = await ipfs.add(stream)

log(`Added ${data.path} hash: ${data.hash}`)
log(`Added ${data.path} hash: ${data.cid}`)

// The last data event will contain the directory hash
if (data.path === directory) {
Expand Down
4 changes: 2 additions & 2 deletions examples/browser-exchange-files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"execa": "^5.0.0",
"http-server": "^0.12.3",
"ipfs-http-client": "^50.1.2",
"uint8arrays": "^2.1.3"
"uint8arrays": "^2.1.6"
},
"dependencies": {
"ipfs": "^0.55.4",
"it-all": "^1.0.4",
"libp2p-websockets": "^0.15.6",
"libp2p-websockets": "^0.16.1",
"rimraf": "^3.0.2",
"test-ipfs-example": "^3.0.0"
}
Expand Down
6 changes: 3 additions & 3 deletions examples/browser-ipns-publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const last = require("it-last");
const cryptoKeys = require("human-crypto-keys"); // { getKeyPairFromSeed }
const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayFromString = require('uint8arrays/from-string')
const { sha256 } = require('multiformats/hashes/sha2')

const { sleep, Logger, onEnterPress, catchAndLog } = require("./util");

Expand Down Expand Up @@ -142,11 +143,10 @@ async function main() {
return new Promise(async (resolve, reject) => {
try {
// quick and dirty key gen, don't do this in real life
const key = await IPFS.multihashing.digest(
const key = await sha256.digest(
uint8ArrayFromString(keyName + Math.random().toString(36).substring(2)),
"sha2-256"
);
const keyPair = await cryptoKeys.getKeyPairFromSeed(key, "rsa");
const keyPair = await cryptoKeys.getKeyPairFromSeed(key.bytes, "rsa");

// put it on the browser IPNS keychain and name it
await ipfsBrowser.key.import(keyName, keyPair.privateKey);
Expand Down
8 changes: 4 additions & 4 deletions examples/browser-ipns-publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
"human-crypto-keys": "^0.1.4",
"ipfs": "^0.55.4",
"ipfs-http-client": "^50.1.2",
"ipfs-utils": "^8.1.2",
"ipns": "^0.12.0",
"ipfs-utils": "^8.1.4",
"ipns": "^0.13.2",
"it-last": "^1.0.4",
"p-retry": "^4.2.0",
"uint8arrays": "^2.1.3"
"uint8arrays": "^2.1.6"
},
"browserslist": [
"last 2 versions and not dead and > 2%"
],
"devDependencies": {
"delay": "^5.0.0",
"execa": "^5.0.0",
"ipfsd-ctl": "^8.0.1",
"ipfsd-ctl": "^9.0.0",
"go-ipfs": "0.8.0",
"parcel": "2.0.0-beta.2",
"path": "^0.12.7",
Expand Down
4 changes: 2 additions & 2 deletions examples/circuit-relaying/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"delay": "^5.0.0",
"ipfs": "^0.55.4",
"ipfs-pubsub-room": "^2.0.1",
"libp2p-websockets": "^0.15.6",
"uint8arrays": "^2.1.3"
"libp2p-websockets": "^0.16.1",
"uint8arrays": "^2.1.6"
},
"devDependencies": {
"execa": "^5.0.0",
Expand Down
Loading