Skip to content

Commit 732e468

Browse files
authored
Merge pull request #134 from achingbrain/feat/update-to-new-interfaces-and-esm
feat: update to new libp2p interfaces
2 parents 790b039 + c04e40d commit 732e468

39 files changed

+3360
-1534
lines changed

.aegir.js renamed to .aegir.cjs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
const path = require('path')
21

32
/** @type {import('aegir').PartialOptions} */
43
const config = {
5-
tsRepo: true,
64
docs: {
75
entryPoint: "src/index.ts"
8-
},
9-
build: {
10-
bundlesizeMax: '231KB'
116
}
127
}
138

.github/workflows/ci.yml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ jobs:
3030
- run: yarn --prefer-offline --frozen-lockfile
3131
- run: yarn run build
3232
- run: yarn run check
33-
- uses: ipfs/aegir/actions/bundle-size@master
34-
name: Check bundle size
35-
with:
36-
github_token: ${{ secrets.GITHUB_TOKEN }}
3733

3834
test-node:
3935
name: Test Nodejs
@@ -59,7 +55,8 @@ jobs:
5955
restore-keys: |
6056
${{ runner.os }}-yarn-
6157
- run: yarn --prefer-offline --frozen-lockfile
62-
- run: npx aegir test -t node --bail --cov
58+
- run: yarn run build
59+
- run: npm run test:node -- --bail --cov
6360
- uses: codecov/codecov-action@v1
6461

6562
test-chrome:
@@ -82,7 +79,8 @@ jobs:
8279
restore-keys: |
8380
${{ runner.os }}-yarn-
8481
- run: yarn --prefer-offline --frozen-lockfile
85-
- run: npx aegir test -t browser -t webworker --bail
82+
- run: yarn run build
83+
- run: npm run test:browser -- --bail
8684

8785
test-firefox:
8886
name: Test Firefox
@@ -104,7 +102,8 @@ jobs:
104102
restore-keys: |
105103
${{ runner.os }}-yarn-
106104
- run: yarn --prefer-offline --frozen-lockfile
107-
- run: npx aegir test -t browser -t webworker --bail -- --browser firefox
105+
- run: yarn run build
106+
- run: npm run test:browser -- --bail -- --browser firefox
108107

109108
test-webkit:
110109
name: Test Webkit
@@ -127,7 +126,8 @@ jobs:
127126
restore-keys: |
128127
${{ runner.os }}-yarn-
129128
- run: yarn --prefer-offline --frozen-lockfile
130-
- run: npx aegir test -t browser -t webworker --bail -- --browser webkit
129+
- run: yarn run build
130+
- run: npm run test:browser -- --bail -- --browser webkit
131131

132132
test-electron-main:
133133
name: Test Electron Main
@@ -149,7 +149,8 @@ jobs:
149149
restore-keys: |
150150
${{ runner.os }}-yarn-
151151
- run: yarn --prefer-offline --frozen-lockfile
152-
- run: npx xvfb-maybe aegir test -t electron-main --bail
152+
- run: yarn run build
153+
- run: npx xvfb-maybe npm run test:electron-main -- --bail
153154

154155
test-electron-renderer:
155156
name: Test Electron Renderer
@@ -170,7 +171,4 @@ jobs:
170171
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
171172
restore-keys: |
172173
${{ runner.os }}-yarn-
173-
- run: yarn --prefer-offline --frozen-lockfile
174-
- run: npx xvfb-maybe aegir test -t electron-renderer --bail
175-
env:
176-
ESBUILD_WORKER_THREADS: 0
174+
- run: yarn --prefer-offline --frozen-lockfile

benchmarks/benchmark.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/* eslint-disable */
22

3-
const { Noise } = require('../dist/src/index')
4-
const benchmark = require('benchmark')
5-
const DuplexPair = require('it-pair/duplex')
6-
const PeerId = require('peer-id')
3+
import { Noise } from '../dist/src/index.js'
4+
import benchmark from 'benchmark'
5+
import { duplexPair } from 'it-pair/duplex'
6+
import { createFromJSON } from '@libp2p/peer-id-factory'
77

88
const bench = async function () {
99
console.log('Initializing handshake benchmark')
1010
const initiator = new Noise()
11-
const initiatorPeer = await PeerId.createFromJSON({
11+
const initiatorPeer = await createFromJSON({
1212
id: '12D3KooWH45PiqBjfnEfDfCD6TqJrpqTBJvQDwGHvjGpaWwms46D',
1313
privKey: 'CAESYBtKXrMwawAARmLScynQUuSwi/gGSkwqDPxi15N3dqDHa4T4iWupkMe5oYGwGH3Hyfvd/QcgSTqg71oYZJadJ6prhPiJa6mQx7mhgbAYfcfJ+939ByBJOqDvWhhklp0nqg==',
1414
pubKey: 'CAESIGuE+IlrqZDHuaGBsBh9x8n73f0HIEk6oO9aGGSWnSeq'
1515
})
1616
const responder = new Noise()
17-
const responderPeer = await PeerId.createFromJSON({
17+
const responderPeer = await createFromJSON({
1818
id: '12D3KooWP63uzL78BRMpkQ7augMdNi1h3VBrVWZucKjyhzGVaSi1',
1919
privKey: 'CAESYPxO3SHyfc2578hDmfkGGBY255JjiLuVavJWy+9ivlpsxSyVKf36ipyRGL6szGzHuFs5ceEuuGVrPMg/rW2Ch1bFLJUp/fqKnJEYvqzMbMe4Wzlx4S64ZWs8yD+tbYKHVg==',
2020
pubKey: 'CAESIMUslSn9+oqckRi+rMxsx7hbOXHhLrhlazzIP61tgodW'
@@ -23,7 +23,7 @@ const bench = async function () {
2323
const bench = new benchmark('handshake', {
2424
defer: true,
2525
fn: async function (deffered) {
26-
const [inboundConnection, outboundConnection] = DuplexPair()
26+
const [inboundConnection, outboundConnection] = duplexPair()
2727
await Promise.all([
2828
initiator.secureOutbound(initiatorPeer, outboundConnection, responderPeer),
2929
responder.secureInbound(responderPeer, inboundConnection, initiatorPeer)

package.json

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{
22
"name": "@chainsafe/libp2p-noise",
33
"version": "5.0.3",
4-
"main": "dist/src/index.js",
4+
"type": "module",
55
"types": "dist/src/index.d.ts",
6+
"exports": {
7+
".": {
8+
"import": "./dist/src/index.js"
9+
}
10+
},
611
"files": [
712
"dist",
813
"src"
@@ -22,49 +27,49 @@
2227
"bench": "node benchmarks/benchmark.js",
2328
"clean": "rm -rf dist",
2429
"check": "aegir dep-check && aegir ts -p check",
25-
"build": "aegir build",
30+
"build": "tsc",
31+
"postbuild": "cp -R src/proto dist/src",
2632
"lint": "aegir lint",
2733
"lint:fix": "aegir lint --fix",
2834
"pretest": "yarn run check",
29-
"test": "aegir test",
30-
"test:node": "aegir test -t node",
31-
"test:browser": "aegir test -t browser",
35+
"test": "aegir test -f \"./dist/test/**/*.spec.js\"",
36+
"test:node": "npm run test -- -t node",
37+
"test:browser": "npm run test -- -t browser -t webworker",
38+
"test:electron-main": "npm run test -- -t electron-main",
3239
"docs": "aegir docs",
33-
"proto:gen": "pbjs -t static-module -r libp2p-noise -o ./src/proto/payload.js ./src/proto/payload.proto && pbts -o ./src/proto/payload.d.ts ./src/proto/payload.js && yarn run lint --fix"
40+
"proto:gen": "pbjs -t static-module -w es6 -r libp2p-noise -o ./src/proto/payload.js ./src/proto/payload.proto && pbts -o ./src/proto/payload.d.ts ./src/proto/payload.js"
3441
},
3542
"browser": {
3643
"./dist/src/alloc-unsafe.js": "./dist/src/alloc-unsafe-browser.js",
3744
"util": false
3845
},
39-
"devDependencies": {
40-
"@types/bl": "^5.0.2",
41-
"aegir": "^36.1.1",
42-
"benchmark": "^2.1.4",
43-
"buffer": "^6.0.3",
44-
"chai": "^4.3.4",
45-
"events": "^3.3.0",
46-
"libp2p-crypto": "^0.21.0",
47-
"microtime": "^3.0.0",
48-
"mocha": "^9.0.2",
49-
"sinon": "^12.0.1",
50-
"util": "^0.12.4"
51-
},
5246
"dependencies": {
47+
"@libp2p/interfaces": "^1.3.14",
48+
"@libp2p/logger": "^1.1.2",
49+
"@libp2p/peer-collections": "^1.0.0",
50+
"@libp2p/peer-id": "^1.1.8",
5351
"@stablelib/chacha20poly1305": "^1.0.1",
5452
"@stablelib/hkdf": "^1.0.1",
5553
"@stablelib/sha256": "^1.0.1",
5654
"@stablelib/x25519": "^1.0.1",
57-
"bl": "^5.0.0",
58-
"debug": "^4.3.1",
59-
"it-buffer": "^0.1.3",
60-
"it-length-prefixed": "^5.0.3",
61-
"it-pair": "^1.0.0",
62-
"it-pb-rpc": "^0.2.0",
63-
"it-pipe": "^1.1.0",
64-
"peer-id": "^0.16.0",
55+
"it-length-prefixed": "^7.0.1",
56+
"it-pair": "^2.0.2",
57+
"it-pb-stream": "^1.0.2",
58+
"it-pipe": "^2.0.3",
6559
"protobufjs": "^6.11.2",
60+
"uint8arraylist": "^1.4.0",
6661
"uint8arrays": "^3.0.0"
6762
},
63+
"devDependencies": {
64+
"@libp2p/crypto": "^0.22.9",
65+
"@libp2p/peer-id-factory": "^1.0.8",
66+
"aegir": "^36.1.3",
67+
"benchmark": "^2.1.4",
68+
"events": "^3.3.0",
69+
"microtime": "^3.0.0",
70+
"sinon": "^13.0.1",
71+
"util": "^0.12.4"
72+
},
6873
"resolutions": {
6974
"bn.js": "4.4.0"
7075
},
File renamed without changes.

src/@types/handshake-interface.d.ts renamed to src/@types/handshake-interface.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { bytes } from './basic'
2-
import { NoiseSession } from './handshake'
3-
import PeerId from 'peer-id'
1+
import type { bytes } from './basic.js'
2+
import type { NoiseSession } from './handshake.js'
3+
import type { PeerId } from '@libp2p/interfaces/peer-id'
44

55
export interface IHandshake {
66
session: NoiseSession

src/@types/handshake.d.ts renamed to src/@types/handshake.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { bytes, bytes32, uint64 } from './basic'
2-
import { KeyPair } from './libp2p'
1+
import type { bytes, bytes32, uint64 } from './basic.js'
2+
import type { KeyPair } from './libp2p.js'
33

44
export type Hkdf = [bytes, bytes, bytes]
55

src/@types/it-length-prefixed/index.d.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/@types/it-pair/index.d.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/@types/libp2p.d.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)