Skip to content

Commit 62b2c91

Browse files
authored
fix: upgrade aegir to 38.1.7 (#292)
chore: upgrade aegir to 38.1.7 + linting
1 parent 61a53e4 commit 62b2c91

File tree

9 files changed

+34
-24
lines changed

9 files changed

+34
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"@libp2p/peer-id-factory": "^2.0.0",
9797
"@libp2p/tcp": "^6.0.2",
9898
"@multiformats/multiaddr": "^11.0.3",
99-
"aegir": "^37.3.0",
99+
"aegir": "^38.1.7",
100100
"benchmark": "^2.1.4",
101101
"execa": "^7.0.0",
102102
"go-libp2p": "^0.0.6",

src/handshakes/abstract-handshake.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import type { ICryptoInterface } from '../crypto.js'
77
import { logger } from '../logger.js'
88
import { Nonce } from '../nonce.js'
99

10+
export interface DecryptedResult {
11+
plaintext: bytes
12+
valid: boolean
13+
}
14+
15+
export interface SplitState {
16+
cs1: CipherState
17+
cs2: CipherState
18+
}
19+
1020
export abstract class AbstractHandshake {
1121
public crypto: ICryptoInterface
1222

@@ -21,7 +31,7 @@ export abstract class AbstractHandshake {
2131
return e
2232
}
2333

24-
public decryptWithAd (cs: CipherState, ad: Uint8Array, ciphertext: Uint8Array, dst?: Uint8Array): {plaintext: bytes, valid: boolean} {
34+
public decryptWithAd (cs: CipherState, ad: Uint8Array, ciphertext: Uint8Array, dst?: Uint8Array): DecryptedResult {
2535
const { plaintext, valid } = this.decrypt(cs.k, cs.n, ad, ciphertext, dst)
2636
if (valid) cs.n.increment()
2737

@@ -60,7 +70,7 @@ export abstract class AbstractHandshake {
6070
return ciphertext
6171
}
6272

63-
protected decrypt (k: bytes32, n: Nonce, ad: bytes, ciphertext: bytes, dst?: Uint8Array): {plaintext: bytes, valid: boolean} {
73+
protected decrypt (k: bytes32, n: Nonce, ad: bytes, ciphertext: bytes, dst?: Uint8Array): DecryptedResult {
6474
n.assertValue()
6575

6676
const encryptedMessage = this.crypto.chaCha20Poly1305Decrypt(ciphertext, n.getBytes(), ad, k, dst)
@@ -78,7 +88,7 @@ export abstract class AbstractHandshake {
7888
}
7989
}
8090

81-
protected decryptAndHash (ss: SymmetricState, ciphertext: bytes): {plaintext: bytes, valid: boolean} {
91+
protected decryptAndHash (ss: SymmetricState, ciphertext: bytes): DecryptedResult {
8292
let plaintext: bytes; let valid = true
8393
if (this.hasKey(ss.cs)) {
8494
({ plaintext, valid } = this.decryptWithAd(ss.cs, ss.h, ciphertext))
@@ -148,7 +158,7 @@ export abstract class AbstractHandshake {
148158
}
149159
}
150160

151-
protected split (ss: SymmetricState): {cs1: CipherState, cs2: CipherState} {
161+
protected split (ss: SymmetricState): SplitState {
152162
const [tempk1, tempk2] = this.crypto.getHKDF(ss.ck, new Uint8Array(0))
153163
const cs1 = this.initializeKey(tempk1)
154164
const cs2 = this.initializeKey(tempk2)
@@ -164,7 +174,7 @@ export abstract class AbstractHandshake {
164174
return { ne, ns, ciphertext }
165175
}
166176

167-
protected readMessageRegular (cs: CipherState, message: MessageBuffer): {plaintext: bytes, valid: boolean} {
177+
protected readMessageRegular (cs: CipherState, message: MessageBuffer): DecryptedResult {
168178
return this.decryptWithAd(cs, new Uint8Array(0), message.ciphertext)
169179
}
170180
}

src/handshakes/xx.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { bytes32, bytes } from '../@types/basic.js'
22
import type { KeyPair } from '../@types/libp2p.js'
33
import { isValidPublicKey } from '../utils.js'
44
import type { CipherState, HandshakeState, MessageBuffer, NoiseSession } from '../@types/handshake.js'
5-
import { AbstractHandshake } from './abstract-handshake.js'
5+
import { AbstractHandshake, DecryptedResult } from './abstract-handshake.js'
66

77
export class XX extends AbstractHandshake {
88
private initializeInitiator (prologue: bytes32, s: KeyPair, rs: bytes32, psk: bytes32): HandshakeState {
@@ -67,7 +67,7 @@ export class XX extends AbstractHandshake {
6767
return { h: hs.ss.h, messageBuffer, cs1, cs2 }
6868
}
6969

70-
private readMessageA (hs: HandshakeState, message: MessageBuffer): {plaintext: bytes, valid: boolean} {
70+
private readMessageA (hs: HandshakeState, message: MessageBuffer): DecryptedResult {
7171
if (isValidPublicKey(message.ne)) {
7272
hs.re = message.ne
7373
}
@@ -76,7 +76,7 @@ export class XX extends AbstractHandshake {
7676
return this.decryptAndHash(hs.ss, message.ciphertext)
7777
}
7878

79-
private readMessageB (hs: HandshakeState, message: MessageBuffer): {plaintext: bytes, valid: boolean} {
79+
private readMessageB (hs: HandshakeState, message: MessageBuffer): DecryptedResult {
8080
if (isValidPublicKey(message.ne)) {
8181
hs.re = message.ne
8282
}
@@ -95,7 +95,7 @@ export class XX extends AbstractHandshake {
9595
return { plaintext, valid: (valid1 && valid2) }
9696
}
9797

98-
private readMessageC (hs: HandshakeState, message: MessageBuffer): {h: bytes, plaintext: bytes, valid: boolean, cs1: CipherState, cs2: CipherState} {
98+
private readMessageC (hs: HandshakeState, message: MessageBuffer): { h: bytes, plaintext: bytes, valid: boolean, cs1: CipherState, cs2: CipherState } {
9999
const { plaintext: ns, valid: valid1 } = this.decryptAndHash(hs.ss, message.ns)
100100
if (valid1 && isValidPublicKey(ns)) {
101101
hs.rs = ns
@@ -163,7 +163,7 @@ export class XX extends AbstractHandshake {
163163
return messageBuffer
164164
}
165165

166-
public recvMessage (session: NoiseSession, message: MessageBuffer): {plaintext: bytes, valid: boolean} {
166+
public recvMessage (session: NoiseSession, message: MessageBuffer): DecryptedResult {
167167
let plaintext: bytes = new Uint8Array(0)
168168
let valid = false
169169
if (session.mc === 0) {

src/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function logLocalStaticKeys (s: KeyPair): void {
2424
keyLogger(`LOCAL_STATIC_PRIVATE_KEY ${uint8ArrayToString(s.privateKey, 'hex')}`)
2525
}
2626

27-
export function logLocalEphemeralKeys (e: KeyPair|undefined): void {
27+
export function logLocalEphemeralKeys (e: KeyPair | undefined): void {
2828
if (e) {
2929
keyLogger(`LOCAL_PUBLIC_EPHEMERAL_KEY ${uint8ArrayToString(e.publicKey, 'hex')}`)
3030
keyLogger(`LOCAL_PRIVATE_EPHEMERAL_KEY ${uint8ArrayToString(e.privateKey, 'hex')}`)

src/metrics.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { Metrics } from '@libp2p/interface-metrics'
1+
import type { Counter, Metrics } from '@libp2p/interface-metrics'
22

3-
export type MetricsRegistry = ReturnType<typeof registerMetrics>
3+
export type MetricsRegistry = Record<string, Counter>
44

5-
export function registerMetrics (metrics: Metrics) {
5+
export function registerMetrics (metrics: Metrics): MetricsRegistry {
66
return {
77
xxHandshakeSuccesses: metrics.registerCounter(
88
'libp2p_noise_xxhandshake_successes_total', {

test/handshakes/xx.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('XX Handshake', () => {
1818

1919
const kpInitiator: KeyPair = stablelib.generateX25519KeyPair()
2020

21-
await xx.initSession(true, prologue, kpInitiator)
21+
xx.initSession(true, prologue, kpInitiator)
2222
} catch (e) {
2323
const err = e as Error
2424
assert(false, err.message)
@@ -60,7 +60,7 @@ describe('XX Handshake', () => {
6060
libp2pInitKeys.marshal().slice(0, 32)
6161
const libp2pInitPubKey = libp2pInitKeys.marshal().slice(32, 64)
6262

63-
const payloadInitEnc = await createHandshakePayload(libp2pInitPubKey, initSignedPayload)
63+
const payloadInitEnc = createHandshakePayload(libp2pInitPubKey, initSignedPayload)
6464

6565
// initiator sends message
6666
const message = Buffer.concat([Buffer.alloc(0), payloadInitEnc])
@@ -76,7 +76,7 @@ describe('XX Handshake', () => {
7676
// responder creates payload
7777
libp2pRespKeys.marshal().slice(0, 32)
7878
const libp2pRespPubKey = libp2pRespKeys.marshal().slice(32, 64)
79-
const payloadRespEnc = await createHandshakePayload(libp2pRespPubKey, respSignedPayload)
79+
const payloadRespEnc = createHandshakePayload(libp2pRespPubKey, respSignedPayload)
8080

8181
const message1 = Buffer.concat([message, payloadRespEnc])
8282
const messageBuffer2 = xx.sendMessage(nsResp, message1)

test/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Noise } from '../src/noise.js'
88
import { createPeerIdsFromFixtures } from './fixtures/peer.js'
99
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
1010

11-
function createCounterSpy () {
11+
function createCounterSpy (): ReturnType<typeof sinon.spy> {
1212
return sinon.spy({
1313
increment: () => {},
1414
reset: () => {}

test/interop.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function createGoPeer (options: SpawnOptions): Promise<Daemon> {
5757
return {
5858
client: createClient(apiAddr),
5959
stop: async () => {
60-
await proc.kill()
60+
proc.kill()
6161
}
6262
}
6363
}
@@ -82,7 +82,7 @@ async function createJsPeer (options: SpawnOptions): Promise<Daemon> {
8282
}
8383

8484
const node = await createLibp2p(opts)
85-
const server = await createServer(multiaddr('/ip4/0.0.0.0/tcp/0'), node as any)
85+
const server = createServer(multiaddr('/ip4/0.0.0.0/tcp/0'), node as any)
8686
await server.start()
8787

8888
return {
@@ -105,7 +105,7 @@ async function main (): Promise<void> {
105105
}
106106
}
107107

108-
await connectInteropTests(factory)
108+
connectInteropTests(factory)
109109
}
110110

111111
main().catch(err => {

test/noise.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('Noise', () => {
8282
// Stage 1
8383
const { publicKey: libp2pPubKey } = getKeyPairFromPeerId(remotePeer)
8484
const signedPayload = await signPayload(remotePeer, getHandshakePayload(staticKeys.publicKey))
85-
const handshakePayload = await createHandshakePayload(libp2pPubKey, signedPayload)
85+
const handshakePayload = createHandshakePayload(libp2pPubKey, signedPayload)
8686

8787
const messageBuffer = xx.sendMessage(handshake.session, handshakePayload)
8888
wrapped.writeLP(encode1(messageBuffer))
@@ -98,7 +98,7 @@ describe('Noise', () => {
9898
wrappedOutbound.write(uint8ArrayFromString('test'))
9999

100100
// Check that noise message is prefixed with 16-bit big-endian unsigned integer
101-
const data = await (await wrapped.readLP()).slice()
101+
const data = (await wrapped.readLP()).slice()
102102
const { plaintext: decrypted, valid } = handshake.decrypt(data, handshake.session)
103103
// Decrypted data should match
104104
expect(uint8ArrayEquals(decrypted, uint8ArrayFromString('test'))).to.be.true()

0 commit comments

Comments
 (0)