Skip to content

Commit

Permalink
feat!: update helia to v3 and multiformats to v13 (#167)
Browse files Browse the repository at this point in the history
Updates all deps and fixes linting errors.

Renames the `dht` routing to `libp2p` since it's used any and all configured libp2p Content Routers instead of the low-level DHT interface for several releases now.

BREAKING CHANGE: uses multiformats v13 and helia v3, renames `dht` routing to `libp2p`
  • Loading branch information
achingbrain authored Jan 8, 2024
1 parent 546ecf0 commit a0381b9
Show file tree
Hide file tree
Showing 22 changed files with 210 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ updates:
schedule:
interval: daily
time: "10:00"
open-pull-requests-limit: 10
open-pull-requests-limit: 20
commit-message:
prefix: "deps"
prefix-development: "deps(dev)"
2 changes: 2 additions & 0 deletions .github/workflows/js-test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ on:

permissions:
contents: write
id-token: write
packages: write
pull-requests: write

concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }}
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/semantic-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Semantic PR

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
uses: pl-strflt/.github/.github/workflows/reusable-semantic-pull-request.yml@v0.3
13 changes: 13 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Close and mark stale issue

on:
schedule:
- cron: '0 0 * * *'

permissions:
issues: write
pull-requests: write

jobs:
stale:
uses: pl-strflt/.github/.github/workflows/reusable-stale-issue.yml@v0.3
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ node_modules
package-lock.json
yarn.lock
.vscode
.env
.envrc
.tool-versions
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,23 @@

> An implementation of IPNS for Helia
## Table of contents <!-- omit in toc -->

- [Structure](#structure)
- [API Docs](#api-docs)
- [License](#license)
- [Contribute](#contribute)

## Structure
# Packages

- [`/packages/interop`](./packages/interop) Interop tests for @helia/ipns
- [`/packages/ipns`](./packages/ipns) An implementation of IPNS for Helia

## API Docs
# API Docs

- <https://ipfs.github.io/helia-ipns>

## License
# License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

## Contribute
# Contribute

Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia-ipns/issues).

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"bugs": {
"url": "https://github.com/ipfs/helia-ipns/issues"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"keywords": [
"ipfs"
],
Expand All @@ -36,7 +40,7 @@
"docs:no-publish": "NODE_OPTIONS=--max_old_space_size=8192 aegir docs --publish false -- --exclude packages/interop"
},
"devDependencies": {
"aegir": "^41.1.14",
"aegir": "^42.0.1",
"npm-run-all": "^4.1.5"
},
"type": "module",
Expand Down
25 changes: 2 additions & 23 deletions packages/interop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,14 @@

> Interop tests for @helia/ipns
## Table of contents <!-- omit in toc -->

- [Install](#install)
- [Browser `<script>` tag](#browser-script-tag)
- [License](#license)
- [Contribute](#contribute)

## Install

```console
$ npm i @helia/ipns-interop
```

### Browser `<script>` tag

Loading this module through a script tag will make it's exports available as `HeliaIpnsInterop` in the global namespace.

```html
<script src="https://unpkg.com/@helia/ipns-interop/dist/index.min.js"></script>
```

## License
# License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

## Contribute
# Contribute

Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia-ipns/issues).

Expand Down
42 changes: 24 additions & 18 deletions packages/interop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
"version": "0.0.0",
"description": "Interop tests for @helia/ipns",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/ipfs/helia-ipns/tree/master/packages/interop#readme",
"homepage": "https://github.com/ipfs/helia-ipns/tree/main/packages/interop#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/ipfs/helia-ipns.git"
},
"bugs": {
"url": "https://github.com/ipfs/helia-ipns/issues"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"keywords": [
"IPFS"
],
Expand Down Expand Up @@ -49,32 +53,34 @@
"test:electron-main": "aegir test -t electron-main"
},
"devDependencies": {
"@chainsafe/libp2p-gossipsub": "^10.1.0",
"@chainsafe/libp2p-noise": "^13.0.0",
"@chainsafe/libp2p-yamux": "^5.0.0",
"@helia/interface": "^2.0.0",
"@chainsafe/libp2p-gossipsub": "^11.0.1",
"@chainsafe/libp2p-noise": "^14.1.0",
"@chainsafe/libp2p-yamux": "^6.0.1",
"@helia/interface": "^3.0.0",
"@helia/ipns": "^3.0.0",
"@libp2p/interface": "^0.1.2",
"@libp2p/kad-dht": "^10.0.4",
"@libp2p/peer-id": "^3.0.2",
"@libp2p/peer-id-factory": "^3.0.3",
"@libp2p/tcp": "^8.0.4",
"@libp2p/websockets": "^7.0.4",
"aegir": "^41.1.14",
"@libp2p/identify": "^1.0.9",
"@libp2p/interface": "^1.1.1",
"@libp2p/kad-dht": "^12.0.2",
"@libp2p/keychain": "^4.0.5",
"@libp2p/peer-id": "^4.0.4",
"@libp2p/peer-id-factory": "^4.0.3",
"@libp2p/tcp": "^9.0.10",
"@libp2p/websockets": "^8.0.10",
"aegir": "^42.0.1",
"blockstore-core": "^4.0.1",
"datastore-core": "^9.0.3",
"helia": "^2.0.1",
"helia": "^3.0.0",
"ipfsd-ctl": "^13.0.0",
"ipns": "^7.0.1",
"ipns": "^8.0.0",
"it-all": "^3.0.2",
"it-last": "^3.0.1",
"it-map": "^3.0.3",
"kubo": "^0.24.0",
"kubo": "^0.25.0",
"kubo-rpc-client": "^3.0.0",
"libp2p": "^0.46.6",
"libp2p": "^1.1.1",
"merge-options": "^3.0.4",
"multiformats": "^12.0.1",
"uint8arrays": "^4.0.3",
"multiformats": "^13.0.0",
"uint8arrays": "^5.0.1",
"wherearewe": "^2.0.1"
},
"browser": {
Expand Down
4 changes: 2 additions & 2 deletions packages/interop/test/fixtures/create-helia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { MemoryDatastore } from 'datastore-core'
import { createHelia } from 'helia'
import { createLibp2p, type Libp2pOptions } from 'libp2p'
import type { Helia } from '@helia/interface'
import type { Identify } from '@libp2p/identify'
import type { Libp2p } from '@libp2p/interface'
import type { IdentifyService } from 'libp2p/identify'

export async function createHeliaNode <T extends { identify: IdentifyService }> (config: Libp2pOptions<T> = {}): Promise<Helia<Libp2p<T>>> {
export async function createHeliaNode <T extends { identify: Identify }> (config: Libp2pOptions<T> = {}): Promise<Helia<Libp2p<T>>> {
const blockstore = new MemoryBlockstore()
const datastore = new MemoryDatastore()

Expand Down
2 changes: 1 addition & 1 deletion packages/interop/test/fixtures/create-peer-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import map from 'it-map'
import { sha256 } from 'multiformats/hashes/sha2'
import { compare as uint8ArrayCompare } from 'uint8arrays/compare'
import { xor as uint8ArrayXor } from 'uint8arrays/xor'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { PeerId } from '@libp2p/interface'

/**
* Sort peers by distance to the KadID of the passed buffer
Expand Down
2 changes: 1 addition & 1 deletion packages/interop/test/fixtures/key-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PeerIdType } from '@libp2p/interface/peer-id'
import type { PeerIdType } from '@libp2p/interface'

export const keyTypes: PeerIdType[] = [
'Ed25519',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/* eslint-env mocha */

import { ipns } from '@helia/ipns'
import { dht } from '@helia/ipns/routing'
import { kadDHT, type DualKadDHT } from '@libp2p/kad-dht'
import { libp2p } from '@helia/ipns/routing'
import { identify } from '@libp2p/identify'
import { kadDHT, removePublicAddressesMapper, type KadDHT } from '@libp2p/kad-dht'
import { keychain, type Keychain } from '@libp2p/keychain'
import { peerIdFromString } from '@libp2p/peer-id'
import { createEd25519PeerId, createRSAPeerId, createSecp256k1PeerId } from '@libp2p/peer-id-factory'
import { expect } from 'aegir/chai'
import { ipnsSelector } from 'ipns/selector'
import { ipnsValidator } from 'ipns/validator'
import last from 'it-last'
import { identifyService } from 'libp2p/identify'
import { CID } from 'multiformats/cid'
import * as raw from 'multiformats/codecs/raw'
import { sha256 } from 'multiformats/hashes/sha2'
Expand All @@ -23,13 +25,12 @@ import { keyTypes } from './fixtures/key-types.js'
import { waitFor } from './fixtures/wait-for.js'
import type { Helia } from '@helia/interface'
import type { IPNS } from '@helia/ipns'
import type { Libp2p } from '@libp2p/interface'
import type { Libp2p, PeerId } from '@libp2p/interface'
import type { Controller } from 'ipfsd-ctl'
import type { PeerId } from 'kubo-rpc-client/dist/src/types.js'

keyTypes.forEach(type => {
describe(`dht routing with ${type} keys`, () => {
let helia: Helia<Libp2p<{ dht: DualKadDHT }>>
describe(`libp2p routing with ${type} keys`, () => {
let helia: Helia<Libp2p<{ dht: KadDHT, keychain: Keychain }>>
let kubo: Controller
let name: IPNS

Expand All @@ -51,7 +52,7 @@ keyTypes.forEach(type => {

helia = await createHeliaNode({
services: {
identify: identifyService(),
identify: identify(),
dht: kadDHT({
validators: {
ipns: ipnsValidator
Expand All @@ -60,8 +61,14 @@ keyTypes.forEach(type => {
ipns: ipnsSelector
},
// skips waiting for the initial self-query to find peers
allowQueryWithZeroPeers: true
})
allowQueryWithZeroPeers: true,

// use lan-only mode
protocol: '/ipfs/lan/kad/1.0.0',
peerInfoMapper: removePublicAddressesMapper,
clientMode: false
}),
keychain: keychain()
}
})
kubo = await createKuboNode()
Expand All @@ -83,10 +90,10 @@ keyTypes.forEach(type => {

const [closest] = await sortClosestPeers(routingKey, [
helia.libp2p.peerId,
kubo.peer.id
peerIdFromString(kubo.peer.id.toString())
])

if (resolver === 'kubo' && closest.equals(kubo.peer.id)) {
if (resolver === 'kubo' && closest.equals(peerIdFromString(kubo.peer.id.toString()))) {
break
}

Expand All @@ -102,7 +109,7 @@ keyTypes.forEach(type => {
await waitFor(async () => {
let found = false

for await (const event of helia.libp2p.services.dht.findPeer(kubo.peer.id)) {
for await (const event of helia.libp2p.services.dht.findPeer(peerIdFromString(kubo.peer.id.toString()))) {
if (event.name === 'FINAL_PEER') {
found = true
}
Expand All @@ -118,6 +125,7 @@ keyTypes.forEach(type => {
await waitFor(async () => {
let found = false

// @ts-expect-error kubo deps are out of date
for await (const event of kubo.api.dht.findPeer(helia.libp2p.peerId)) {
if (event.name === 'FINAL_PEER') {
found = true
Expand All @@ -133,7 +141,7 @@ keyTypes.forEach(type => {

name = ipns(helia, {
routers: [
dht(helia)
libp2p(helia)
]
})
}
Expand All @@ -152,11 +160,11 @@ keyTypes.forEach(type => {
await createNodes('kubo')

const keyName = 'my-ipns-key'
await helia.libp2p.keychain.importPeer(keyName, key)
await helia.libp2p.services.keychain.importPeer(keyName, key)

await name.publish(key, value)

const resolved = await last(kubo.api.name.resolve(key))
const resolved = await last(kubo.api.name.resolve(key.toString()))

if (resolved == null) {
throw new Error('kubo failed to resolve name')
Expand Down
Loading

0 comments on commit a0381b9

Please sign in to comment.