@@ -15,6 +15,7 @@ import { decryptStream, encryptStream } from './crypto/streaming.js'
1515import { uint16BEDecode , uint16BEEncode } from './encoder.js'
1616import { XXHandshake } from './handshake-xx.js'
1717import { getPayload } from './utils.js'
18+ import type { NoiseExtensions } from './proto/payload.js'
1819
1920interface HandshakeParams {
2021 connection : ProtobufStream
@@ -29,15 +30,15 @@ export class Noise implements INoiseConnection {
2930
3031 private readonly prologue : Uint8Array
3132 private readonly staticKeys : KeyPair
32- private readonly earlyData ?: bytes
33+ private readonly extensions ?: NoiseExtensions
3334
3435 /**
3536 * @param {bytes } staticNoiseKey - x25519 private key, reuse for faster handshakes
36- * @param {bytes } earlyData
37+ * @param {NoiseExtensions } extensions
3738 */
38- constructor ( staticNoiseKey ?: bytes , earlyData ?: bytes , crypto : ICryptoInterface = stablelib , prologueBytes ?: Uint8Array ) {
39- this . earlyData = earlyData ?? new Uint8Array ( 0 )
39+ constructor ( staticNoiseKey ?: bytes , extensions ?: NoiseExtensions , crypto : ICryptoInterface = stablelib , prologueBytes ?: Uint8Array ) {
4040 this . crypto = crypto
41+ this . extensions = extensions
4142
4243 if ( staticNoiseKey ) {
4344 // accepts x25519 private key of length 32
@@ -56,7 +57,7 @@ export class Noise implements INoiseConnection {
5657 * @param {PeerId } remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer.
5758 * @returns {Promise<SecuredConnection> }
5859 */
59- public async secureOutbound ( localPeer : PeerId , connection : Duplex < Uint8Array > , remotePeer ?: PeerId ) : Promise < SecuredConnection > {
60+ public async secureOutbound ( localPeer : PeerId , connection : Duplex < Uint8Array > , remotePeer ?: PeerId ) : Promise < SecuredConnection < NoiseExtensions > > {
6061 const wrappedConnection = pbStream (
6162 connection ,
6263 {
@@ -75,7 +76,7 @@ export class Noise implements INoiseConnection {
7576
7677 return {
7778 conn,
78- remoteEarlyData : handshake . remoteEarlyData ,
79+ remoteExtensions : handshake . remoteExtensions ,
7980 remotePeer : handshake . remotePeer
8081 }
8182 }
@@ -88,7 +89,7 @@ export class Noise implements INoiseConnection {
8889 * @param {PeerId } remotePeer - optional PeerId of the initiating peer, if known. This may only exist during transport upgrades.
8990 * @returns {Promise<SecuredConnection> }
9091 */
91- public async secureInbound ( localPeer : PeerId , connection : Duplex < Uint8Array > , remotePeer ?: PeerId ) : Promise < SecuredConnection > {
92+ public async secureInbound ( localPeer : PeerId , connection : Duplex < Uint8Array > , remotePeer ?: PeerId ) : Promise < SecuredConnection < NoiseExtensions > > {
9293 const wrappedConnection = pbStream (
9394 connection ,
9495 {
@@ -107,8 +108,8 @@ export class Noise implements INoiseConnection {
107108
108109 return {
109110 conn,
110- remoteEarlyData : handshake . remoteEarlyData ,
111- remotePeer : handshake . remotePeer
111+ remotePeer : handshake . remotePeer ,
112+ remoteExtensions : handshake . remoteExtensions
112113 }
113114 }
114115
@@ -119,7 +120,7 @@ export class Noise implements INoiseConnection {
119120 * @param {HandshakeParams } params
120121 */
121122 private async performHandshake ( params : HandshakeParams ) : Promise < IHandshake > {
122- const payload = await getPayload ( params . localPeer , this . staticKeys . publicKey , this . earlyData )
123+ const payload = await getPayload ( params . localPeer , this . staticKeys . publicKey , this . extensions )
123124
124125 // run XX handshake
125126 return await this . performXXHandshake ( params , payload )
0 commit comments