Skip to content

Commit b1dba4e

Browse files
fix: Allow the caller to set the prologue (#181)
1 parent d6e8745 commit b1dba4e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@
9393
"benchmark": "^2.1.4",
9494
"mkdirp": "^1.0.4",
9595
"protons": "^4.0.0",
96-
"sinon": "^14.0.0"
96+
"sinon": "^14.0.0",
97+
"typescript": "^4.7.4"
9798
},
9899
"browser": {
99100
"./dist/src/alloc-unsafe.js": "./dist/src/alloc-unsafe-browser.js",

src/noise.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class Noise implements INoiseConnection {
3232
public protocol = '/noise'
3333
public crypto: ICryptoInterface
3434

35-
private readonly prologue = new Uint8Array(0)
35+
private readonly prologue: Uint8Array;
3636
private readonly staticKeys: KeyPair
3737
private readonly earlyData?: bytes
3838
private readonly useNoisePipes: boolean
@@ -41,7 +41,7 @@ export class Noise implements INoiseConnection {
4141
* @param {bytes} staticNoiseKey - x25519 private key, reuse for faster handshakes
4242
* @param {bytes} earlyData
4343
*/
44-
constructor (staticNoiseKey?: bytes, earlyData?: bytes, crypto: ICryptoInterface = stablelib) {
44+
constructor (staticNoiseKey?: bytes, earlyData?: bytes, crypto: ICryptoInterface = stablelib, prologueBytes?: Uint8Array) {
4545
this.earlyData = earlyData ?? new Uint8Array(0)
4646
// disabled until properly specked
4747
this.useNoisePipes = false
@@ -53,6 +53,11 @@ export class Noise implements INoiseConnection {
5353
} else {
5454
this.staticKeys = this.crypto.generateX25519KeyPair()
5555
}
56+
if (prologueBytes) {
57+
this.prologue = prologueBytes;
58+
} else {
59+
this.prologue = new Uint8Array(0);
60+
}
5661
}
5762

5863
/**

0 commit comments

Comments
 (0)