Skip to content

Commit 73cc41c

Browse files
committed
change hashing library
Signed-off-by: Marin Petrunic <marin.petrunic@gmail.com>
1 parent de40989 commit 73cc41c

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

benchmarks/benchmark.js

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

3-
import { Noise } from '../dist/src/index.js'
3+
import { noise } from '../dist/src/index.js'
44
import benchmark from 'benchmark'
55
import { duplexPair } from 'it-pair/duplex'
66
import { createFromJSON } from '@libp2p/peer-id-factory'
77

88
const bench = async function () {
99
console.log('Initializing handshake benchmark')
10-
const initiator = new Noise()
10+
const initiator = noise()()
1111
const initiatorPeer = await createFromJSON({
1212
id: '12D3KooWH45PiqBjfnEfDfCD6TqJrpqTBJvQDwGHvjGpaWwms46D',
1313
privKey: 'CAESYBtKXrMwawAARmLScynQUuSwi/gGSkwqDPxi15N3dqDHa4T4iWupkMe5oYGwGH3Hyfvd/QcgSTqg71oYZJadJ6prhPiJa6mQx7mhgbAYfcfJ+939ByBJOqDvWhhklp0nqg==',
1414
pubKey: 'CAESIGuE+IlrqZDHuaGBsBh9x8n73f0HIEk6oO9aGGSWnSeq'
1515
})
16-
const responder = new Noise()
16+
const responder = noise()()
1717
const responderPeer = await createFromJSON({
1818
id: '12D3KooWP63uzL78BRMpkQ7augMdNi1h3VBrVWZucKjyhzGVaSi1',
1919
privKey: 'CAESYPxO3SHyfc2578hDmfkGGBY255JjiLuVavJWy+9ivlpsxSyVKf36ipyRGL6szGzHuFs5ceEuuGVrPMg/rW2Ch1bFLJUp/fqKnJEYvqzMbMe4Wzlx4S64ZWs8yD+tbYKHVg==',

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
"@libp2p/logger": "^2.0.5",
7777
"@libp2p/peer-id": "^2.0.0",
7878
"@stablelib/chacha20poly1305": "^1.0.1",
79-
"@stablelib/hkdf": "^1.0.1",
80-
"@stablelib/sha256": "^1.0.1",
79+
"@noble/hashes": "^1.3.0",
80+
"@noble/curves": "^1.0.0",
8181
"@stablelib/x25519": "^1.0.3",
8282
"it-length-prefixed": "^8.0.2",
8383
"it-pair": "^2.0.2",

src/crypto/stablelib.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { HKDF } from '@stablelib/hkdf'
21
import * as x25519 from '@stablelib/x25519'
3-
import { SHA256, hash } from '@stablelib/sha256'
2+
import { sha256 } from '@noble/hashes/sha256'
3+
import { hkdf } from '@noble/hashes/hkdf'
44
import { ChaCha20Poly1305 } from '@stablelib/chacha20poly1305'
55
import type { bytes32, bytes } from '../@types/basic.js'
66
import type { Hkdf } from '../@types/handshake.js'
@@ -9,13 +9,11 @@ import type { ICryptoInterface } from '../crypto.js'
99

1010
export const stablelib: ICryptoInterface = {
1111
hashSHA256 (data: Uint8Array): Uint8Array {
12-
return hash(data)
12+
return sha256(data)
1313
},
1414

1515
getHKDF (ck: bytes32, ikm: Uint8Array): Hkdf {
16-
const hkdf = new HKDF(SHA256, ikm, ck)
17-
const okmU8Array = hkdf.expand(96)
18-
const okm = okmU8Array
16+
const okm = hkdf(sha256, ikm, ck, undefined, 96)
1917

2018
const k1 = okm.subarray(0, 32)
2119
const k2 = okm.subarray(32, 64)

0 commit comments

Comments
 (0)