Skip to content

Commit

Permalink
Merge branch 'master' into marco/perf
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Aug 10, 2023
2 parents 0a4eae5 + a1fbb7e commit b2da056
Show file tree
Hide file tree
Showing 17 changed files with 361 additions and 356 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ List of packages currently in existence for libp2p
| [`@libp2p/mdns`](/libp2p/js-libp2p-mdns) | [![npm](https://img.shields.io/npm/v/%40libp2p%2Fmdns.svg?maxAge=86400\&style=flat-square)](/libp2p/js-libp2p-mdns/releases) | [![Deps](https://img.shields.io/librariesio/release/npm/%40libp2p%2Fmdns?logo=Libraries.io\&logoColor=white\&style=flat-square)](//libraries.io/npm/%40libp2p%2Fmdns) | [![GitHub CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-mdns/js-test-and-release.yml?branch=master\&label=ci\&style=flat-square)](/libp2p/js-libp2p-mdns/actions?query=branch%3Amaster+workflow%3Aci+) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-mdns/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-mdns) |
| [`@chainsafe/discv5`](/ChainSafe/discv5) | [![npm](https://img.shields.io/npm/v/%40chainsafe%2Fdiscv5.svg?maxAge=86400\&style=flat-square)](/ChainSafe/discv5/releases) | [![Deps](https://img.shields.io/librariesio/release/npm/%40chainsafe%2Fdiscv5?logo=Libraries.io\&logoColor=white\&style=flat-square)](//libraries.io/npm/%40chainsafe%2Fdiscv5) | [![GitHub CI](https://img.shields.io/github/actions/workflow/status/ChainSafe/discv5/test_and_release.yml?branch=master\&label=ci\&style=flat-square)](/ChainSafe/discv5/actions?query=branch%3Amaster+workflow%3Aci+) | [![codecov](https://codecov.io/gh/ChainSafe/discv5/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ChainSafe/discv5) |
| **content routing** | | | | |
| [`@libp2p/reframe-content-routing`](/libp2p/js-reframe-content-routing) | [![npm](https://img.shields.io/npm/v/%40libp2p%2Freframe-content-routing.svg?maxAge=86400\&style=flat-square)](/libp2p/js-reframe-content-routing/releases) | [![Deps](https://img.shields.io/librariesio/release/npm/%40libp2p%2Freframe-content-routing?logo=Libraries.io\&logoColor=white\&style=flat-square)](//libraries.io/npm/%40libp2p%2Freframe-content-routing) | [![GitHub CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-reframe-content-routing/js-test-and-release.yml?branch=main\&label=ci\&style=flat-square)](/libp2p/js-reframe-content-routing/actions?query=branch%3Amain+workflow%3Aci+) | [![codecov](https://codecov.io/gh/libp2p/js-reframe-content-routing/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-reframe-content-routing) |
| [`@libp2p/http-v1-content-routing`](/libp2p/js-http-v1-content-routing) | [![npm](https://img.shields.io/npm/v/%40libp2p%2Fhttp-v1-content-routing.svg?maxAge=86400\&style=flat-square)](/libp2p/js-http-v1-content-routing/releases) | [![Deps](https://img.shields.io/librariesio/release/npm/%40libp2p%2Fhttp-v1-content-routing?logo=Libraries.io\&logoColor=white\&style=flat-square)](//libraries.io/npm/%40libp2p%2Fhttp-v1-content-routing) | [![GitHub CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-http-v1-content-routing/js-test-and-release.yml?branch=main\&label=ci\&style=flat-square)](/libp2p/js-http-v1-content-routing/actions?query=branch%3Amain+workflow%3Aci+) | [![codecov](https://codecov.io/gh/libp2p/js-http-v1-content-routing/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-http-v1-content-routing) |
| [`@libp2p/ipni-content-routing`](/libp2p/js-ipni-content-routing) | [![npm](https://img.shields.io/npm/v/%40libp2p%2Fipni-content-routing.svg?maxAge=86400\&style=flat-square)](/libp2p/js-ipni-content-routing/releases) | [![Deps](https://img.shields.io/librariesio/release/npm/%40libp2p%2Fipni-content-routing?logo=Libraries.io\&logoColor=white\&style=flat-square)](//libraries.io/npm/%40libp2p%2Fipni-content-routing) | [![GitHub CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-ipni-content-routing/js-test-and-release.yml?branch=main\&label=ci\&style=flat-square)](/libp2p/js-ipni-content-routing/actions?query=branch%3Amain+workflow%3Aci+) | [![codecov](https://codecov.io/gh/libp2p/js-ipni-content-routing/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-ipni-content-routing) |
| [`@libp2p/delegated-content-routing`](/libp2p/js-libp2p-delegated-content-routing) | [![npm](https://img.shields.io/npm/v/%40libp2p%2Fdelegated-content-routing.svg?maxAge=86400\&style=flat-square)](/libp2p/js-libp2p-delegated-content-routing/releases) | [![Deps](https://img.shields.io/librariesio/release/npm/%40libp2p%2Fdelegated-content-routing?logo=Libraries.io\&logoColor=white\&style=flat-square)](//libraries.io/npm/%40libp2p%2Fdelegated-content-routing) | [![GitHub CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-delegated-content-routing/js-test-and-release.yml?branch=master\&label=ci\&style=flat-square)](/libp2p/js-libp2p-delegated-content-routing/actions?query=branch%3Amaster+workflow%3Aci+) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-delegated-content-routing/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-delegated-content-routing) |
| [`@libp2p/kad-dht`](/libp2p/js-libp2p-kad-dht) | [![npm](https://img.shields.io/npm/v/%40libp2p%2Fkad-dht.svg?maxAge=86400\&style=flat-square)](/libp2p/js-libp2p-kad-dht/releases) | [![Deps](https://img.shields.io/librariesio/release/npm/%40libp2p%2Fkad-dht?logo=Libraries.io\&logoColor=white\&style=flat-square)](//libraries.io/npm/%40libp2p%2Fkad-dht) | [![GitHub CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-kad-dht/js-test-and-release.yml?branch=master\&label=ci\&style=flat-square)](/libp2p/js-libp2p-kad-dht/actions?query=branch%3Amaster+workflow%3Aci+) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-kad-dht/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-kad-dht) |
Expand Down
1 change: 0 additions & 1 deletion packages/crypto/benchmark/ed25519/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
},
"license": "MIT",
"dependencies": {
"@noble/ed25519": "^1.3.0",
"@stablelib/ed25519": "^1.0.2",
"benchmark": "^2.1.4",
"ed25519": "^0.0.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
},
"dependencies": {
"@libp2p/interface": "^0.1.1",
"@noble/ed25519": "^1.6.0",
"@noble/secp256k1": "^1.5.4",
"@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1",
"multiformats": "^12.0.1",
"node-forge": "^1.1.0",
"protons-runtime": "^5.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/crypto/src/keys/ed25519-browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as ed from '@noble/ed25519'
import { ed25519 as ed } from '@noble/curves/ed25519'
import type { Uint8ArrayKeyPair } from './interface'

const PUBLIC_KEY_BYTE_LENGTH = 32
Expand All @@ -11,7 +11,7 @@ export { PRIVATE_KEY_BYTE_LENGTH as privateKeyLength }
export async function generateKey (): Promise<Uint8ArrayKeyPair> {
// the actual private key (32 bytes)
const privateKeyRaw = ed.utils.randomPrivateKey()
const publicKey = await ed.getPublicKey(privateKeyRaw)
const publicKey = ed.getPublicKey(privateKeyRaw)

// concatenated the public key to the private key
const privateKey = concatKeys(privateKeyRaw, publicKey)
Expand All @@ -34,7 +34,7 @@ export async function generateKeyFromSeed (seed: Uint8Array): Promise<Uint8Array

// based on node forges algorithm, the seed is used directly as private key
const privateKeyRaw = seed
const publicKey = await ed.getPublicKey(privateKeyRaw)
const publicKey = ed.getPublicKey(privateKeyRaw)

const privateKey = concatKeys(privateKeyRaw, publicKey)

Expand Down
11 changes: 6 additions & 5 deletions packages/crypto/src/keys/secp256k1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CodeError } from '@libp2p/interface/errors'
import * as secp from '@noble/secp256k1'
import { secp256k1 as secp } from '@noble/curves/secp256k1'
import { sha256 } from 'multiformats/hashes/sha2'

const PRIVATE_KEY_BYTE_LENGTH = 32
Expand All @@ -16,7 +16,8 @@ export function generateKey (): Uint8Array {
export async function hashAndSign (key: Uint8Array, msg: Uint8Array): Promise<Uint8Array> {
const { digest } = await sha256.digest(msg)
try {
return await secp.sign(digest, key)
const signature = secp.sign(digest, key)
return signature.toDERRawBytes()
} catch (err) {
throw new CodeError(String(err), 'ERR_INVALID_INPUT')
}
Expand All @@ -35,12 +36,12 @@ export async function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint
}

export function compressPublicKey (key: Uint8Array): Uint8Array {
const point = secp.Point.fromHex(key).toRawBytes(true)
const point = secp.ProjectivePoint.fromHex(key).toRawBytes(true)
return point
}

export function decompressPublicKey (key: Uint8Array): Uint8Array {
const point = secp.Point.fromHex(key).toRawBytes(false)
const point = secp.ProjectivePoint.fromHex(key).toRawBytes(false)
return point
}

Expand All @@ -54,7 +55,7 @@ export function validatePrivateKey (key: Uint8Array): void {

export function validatePublicKey (key: Uint8Array): void {
try {
secp.Point.fromHex(key)
secp.ProjectivePoint.fromHex(key)
} catch (err) {
throw new CodeError(String(err), 'ERR_INVALID_PUBLIC_KEY')
}
Expand Down
4 changes: 2 additions & 2 deletions packages/crypto/src/random-bytes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CodeError } from '@libp2p/interface/errors'
import { utils } from '@noble/secp256k1'
import { randomBytes as randB } from '@noble/hashes/utils'

export default function randomBytes (length: number): Uint8Array {
if (isNaN(length) || length <= 0) {
throw new CodeError('random bytes length must be a Number bigger than 0', 'ERR_INVALID_LENGTH')
}
return utils.randomBytes(length)
return randB(length)
}
20 changes: 8 additions & 12 deletions packages/transport-websockets/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbortError } from '@libp2p/interface/errors'
import { AbortError, CodeError } from '@libp2p/interface/errors'
import { type Transport, type MultiaddrFilter, symbol, type CreateListenerOptions, type DialOptions, type Listener } from '@libp2p/interface/transport'
import { logger } from '@libp2p/logger'
import { multiaddrToUri as toUri } from '@multiformats/multiaddr-to-uri'
Expand Down Expand Up @@ -55,19 +55,15 @@ class WebSockets implements Transport {
log('dialing %s:%s', cOpts.host, cOpts.port)

const errorPromise = pDefer()
const errfn = (err: any): void => {
const rawSocket = connect(toUri(ma), this.init)
rawSocket.socket.addEventListener('error', () => {
// the WebSocket.ErrorEvent type doesn't actually give us any useful
// information about what happened
// https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/error_event
const err = new CodeError(`Could not connect to ${ma.toString()}`, 'ERR_CONNECTION_FAILED')
log.error('connection error:', err)

errorPromise.reject(err)
}

const rawSocket = connect(toUri(ma), this.init)

if (rawSocket.socket.on != null) {
rawSocket.socket.on('error', errfn)
} else {
rawSocket.socket.onerror = errfn
}
})

if (options.signal == null) {
await Promise.race([rawSocket.connected(), errorPromise.promise])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/libp2p/js-libp2p-webtransport/go-libp2p-webtransport-server/m/
go 1.19

require (
github.com/libp2p/go-libp2p v0.27.1
github.com/libp2p/go-libp2p v0.27.8
github.com/multiformats/go-multiaddr v0.9.0
)

Expand Down Expand Up @@ -70,8 +70,8 @@ require (
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
github.com/quic-go/qtls-go1-19 v0.3.3 // indirect
github.com/quic-go/qtls-go1-20 v0.2.3 // indirect
github.com/quic-go/quic-go v0.33.0 // indirect
github.com/quic-go/webtransport-go v0.5.2 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38y
github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic=
github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM=
github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro=
github.com/libp2p/go-libp2p v0.27.1 h1:k1u6RHsX3hqKnslDjsSgLNURxJ3O1atIZCY4gpMbbus=
github.com/libp2p/go-libp2p v0.27.1/go.mod h1:FAvvfQa/YOShUYdiSS03IR9OXzkcJXwcNA2FUCh9ImE=
github.com/libp2p/go-libp2p v0.27.8 h1:IX5x/4yKwyPQeVS2AXHZ3J4YATM9oHBGH1gBc23jBAI=
github.com/libp2p/go-libp2p v0.27.8/go.mod h1:eCFFtd0s5i/EVKR7+5Ki8bM7qwkNW3TPTTSSW9sz8NE=
github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s=
github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w=
github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
Expand Down Expand Up @@ -270,10 +270,10 @@ github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJf
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U=
github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI=
github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E=
github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM=
github.com/quic-go/qtls-go1-19 v0.3.3 h1:wznEHvJwd+2X3PqftRha0SUKmGsnb6dfArMhy9PeJVE=
github.com/quic-go/qtls-go1-19 v0.3.3/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI=
github.com/quic-go/qtls-go1-20 v0.2.3 h1:m575dovXn1y2ATOb1XrRFcrv0F+EQmlowTkoraNkDPI=
github.com/quic-go/qtls-go1-20 v0.2.3/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM=
github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0=
github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA=
github.com/quic-go/webtransport-go v0.5.2 h1:GA6Bl6oZY+g/flt00Pnu0XtivSD8vukOu3lYhJjnGEk=
Expand Down
3 changes: 2 additions & 1 deletion packages/transport-webtransport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"@multiformats/multiaddr": "^12.1.3",
"it-stream-types": "^2.0.1",
"multiformats": "^12.0.1",
"uint8arraylist": "^2.4.3"
"uint8arraylist": "^2.4.3",
"uint8arrays": "^4.0.6"
},
"devDependencies": {
"aegir": "^40.0.1",
Expand Down
Loading

0 comments on commit b2da056

Please sign in to comment.