Skip to content

Commit 55bbd8c

Browse files
authored
deps: update p-event, p-wait-for and noble deps (#3302)
Updates deps to the latest version.
1 parent 47a0b06 commit 55bbd8c

File tree

45 files changed

+124
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+124
-83
lines changed

.github/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ incrby
1313
microtask
1414
nothrow
1515
peerStore
16+
prehash
1617
reprovide
1718
reprovided
1819
reprovider

interop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@multiformats/multiaddr": "^13.0.1",
2727
"aegir": "^47.0.22",
2828
"libp2p": "^3.0.0",
29-
"p-event": "^6.0.1",
29+
"p-event": "^7.0.0",
3030
"redis": "^4.7.1"
3131
}
3232
}

packages/connection-encrypter-noise/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
"@libp2p/interface": "^3.0.0",
5959
"@libp2p/peer-id": "^6.0.0",
6060
"@libp2p/utils": "^7.0.0",
61-
"@noble/ciphers": "^1.3.0",
62-
"@noble/curves": "^1.9.7",
63-
"@noble/hashes": "^1.8.0",
61+
"@noble/ciphers": "^2.0.1",
62+
"@noble/curves": "^2.0.1",
63+
"@noble/hashes": "^2.0.1",
6464
"protons-runtime": "^5.6.0",
6565
"uint8arraylist": "^2.4.8",
6666
"uint8arrays": "^5.1.0",

packages/connection-encrypter-noise/src/crypto/js.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { chacha20poly1305 } from '@noble/ciphers/chacha'
2-
import { x25519 } from '@noble/curves/ed25519'
3-
import { extract, expand } from '@noble/hashes/hkdf'
4-
import { sha256 } from '@noble/hashes/sha2'
1+
import { chacha20poly1305 } from '@noble/ciphers/chacha.js'
2+
import { x25519 } from '@noble/curves/ed25519.js'
3+
import { extract, expand } from '@noble/hashes/hkdf.js'
4+
import { sha256 } from '@noble/hashes/sha2.js'
55
import type { ICryptoInterface } from '../crypto.js'
66
import type { KeyPair } from '../types.js'
77
import type { Uint8ArrayList } from 'uint8arraylist'

packages/connection-encrypter-tls/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@peculiar/webcrypto": "^1.5.0",
5151
"@peculiar/x509": "^1.13.0",
5252
"asn1js": "^3.0.6",
53-
"p-event": "^6.0.1",
53+
"p-event": "^7.0.0",
5454
"protons-runtime": "^5.6.0",
5555
"uint8arraylist": "^2.4.8",
5656
"uint8arrays": "^5.1.0"

packages/crypto/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
},
8787
"dependencies": {
8888
"@libp2p/interface": "^3.0.0",
89-
"@noble/curves": "^1.9.7",
90-
"@noble/hashes": "^1.8.0",
89+
"@noble/curves": "^2.0.1",
90+
"@noble/hashes": "^2.0.1",
9191
"multiformats": "^13.4.0",
9292
"protons-runtime": "^5.6.0",
9393
"uint8arraylist": "^2.4.8",

packages/crypto/src/keys/ed25519/index.browser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ed25519 as ed } from '@noble/curves/ed25519'
1+
import { ed25519 as ed } from '@noble/curves/ed25519.js'
22
import { toString as uint8arrayToString } from 'uint8arrays/to-string'
33
import crypto from '../../webcrypto/index.js'
44
import type { Uint8ArrayKeyPair } from '../interface.js'
@@ -24,7 +24,7 @@ const webCryptoEd25519SupportedPromise = (async () => {
2424

2525
export function generateKey (): Uint8ArrayKeyPair {
2626
// the actual private key (32 bytes)
27-
const privateKeyRaw = ed.utils.randomPrivateKey()
27+
const privateKeyRaw = ed.utils.randomSecretKey()
2828
const publicKey = ed.getPublicKey(privateKeyRaw)
2929

3030
// concatenated the public key to the private key
@@ -78,7 +78,7 @@ async function hashAndSignWebCrypto (privateKey: Uint8Array, msg: Uint8Array | U
7878
return new Uint8Array(sig, 0, sig.byteLength)
7979
}
8080

81-
function hashAndSignNoble (privateKey: Uint8Array, msg: Uint8Array | Uint8ArrayList): Uint8Array {
81+
export function hashAndSignNoble (privateKey: Uint8Array, msg: Uint8Array | Uint8ArrayList): Uint8Array {
8282
const privateKeyRaw = privateKey.subarray(0, KEYS_BYTE_LENGTH)
8383

8484
return ed.sign(msg instanceof Uint8Array ? msg : msg.subarray(), privateKeyRaw)
@@ -106,7 +106,7 @@ async function hashAndVerifyWebCrypto (publicKey: Uint8Array, sig: Uint8Array, m
106106
throw new TypeError('WebCrypto does not support SharedArrayBuffer for Ed25519 keys')
107107
}
108108

109-
function hashAndVerifyNoble (publicKey: Uint8Array, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): boolean {
109+
export function hashAndVerifyNoble (publicKey: Uint8Array, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): boolean {
110110
return ed.verify(sig, msg instanceof Uint8Array ? msg : msg.subarray(), publicKey)
111111
}
112112

packages/crypto/src/keys/rsa/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { InvalidParametersError, InvalidPublicKeyError } from '@libp2p/interface'
2-
import { sha256 } from '@noble/hashes/sha256'
2+
import { sha256 } from '@noble/hashes/sha2.js'
33
import { create } from 'multiformats/hashes/digest'
44
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
55
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'

packages/crypto/src/keys/secp256k1/index.browser.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { secp256k1 as secp } from '@noble/curves/secp256k1'
1+
import { secp256k1 as secp } from '@noble/curves/secp256k1.js'
22
import { sha256 } from 'multiformats/hashes/sha2'
33
import { SigningError, VerificationError } from '../../errors.js'
44
import { isPromise } from '../../util.js'
@@ -21,7 +21,10 @@ export function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8ArrayList,
2121
return p
2222
.then(({ digest }) => {
2323
options?.signal?.throwIfAborted()
24-
return secp.sign(digest, key).toDERRawBytes()
24+
return secp.sign(digest, key, {
25+
prehash: false,
26+
format: 'der'
27+
})
2528
})
2629
.catch(err => {
2730
if (err.name === 'AbortError') {
@@ -33,7 +36,10 @@ export function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8ArrayList,
3336
}
3437

3538
try {
36-
return secp.sign(p.digest, key).toDERRawBytes()
39+
return secp.sign(p.digest, key, {
40+
prehash: false,
41+
format: 'der'
42+
})
3743
} catch (err) {
3844
throw new SigningError(String(err))
3945
}
@@ -49,7 +55,10 @@ export function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint8Array
4955
return p
5056
.then(({ digest }) => {
5157
options?.signal?.throwIfAborted()
52-
return secp.verify(sig, digest, key)
58+
return secp.verify(sig, digest, key, {
59+
prehash: false,
60+
format: 'der'
61+
})
5362
})
5463
.catch(err => {
5564
if (err.name === 'AbortError') {
@@ -62,7 +71,10 @@ export function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint8Array
6271

6372
try {
6473
options?.signal?.throwIfAborted()
65-
return secp.verify(sig, p.digest, key)
74+
return secp.verify(sig, p.digest, key, {
75+
prehash: false,
76+
format: 'der'
77+
})
6678
} catch (err) {
6779
throw new VerificationError(String(err))
6880
}

packages/crypto/src/keys/secp256k1/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import crypto from 'node:crypto'
2-
import { secp256k1 as secp } from '@noble/curves/secp256k1'
2+
import { secp256k1 as secp } from '@noble/curves/secp256k1.js'
33
import { SigningError, VerificationError } from '../../errors.js'
44
import type { AbortOptions } from '@libp2p/interface'
55
import type { Uint8ArrayList } from 'uint8arraylist'
@@ -29,8 +29,10 @@ export function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8ArrayList,
2929
const digest = hash.digest()
3030

3131
try {
32-
const signature = secp.sign(digest, key)
33-
return signature.toDERRawBytes()
32+
return secp.sign(digest, key, {
33+
prehash: false,
34+
format: 'der'
35+
})
3436
} catch (err) {
3537
throw new SigningError(String(err))
3638
}
@@ -54,7 +56,10 @@ export function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint8Array
5456
const digest = hash.digest()
5557

5658
try {
57-
return secp.verify(sig, digest, key)
59+
return secp.verify(sig, digest, key, {
60+
prehash: false,
61+
format: 'der'
62+
})
5863
} catch (err) {
5964
throw new VerificationError(String(err))
6065
}

0 commit comments

Comments
 (0)