Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow the caller to set the prologue (#181) #182

Merged
merged 4 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
"benchmark": "^2.1.4",
"mkdirp": "^1.0.4",
"protons": "^4.0.0",
"sinon": "^14.0.0"
"sinon": "^14.0.0",
"typescript": "^4.7.4"
John-LittleBearLabs marked this conversation as resolved.
Show resolved Hide resolved
},
"browser": {
"./dist/src/alloc-unsafe.js": "./dist/src/alloc-unsafe-browser.js",
Expand Down
9 changes: 7 additions & 2 deletions src/noise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Noise implements INoiseConnection {
public protocol = '/noise'
public crypto: ICryptoInterface

private readonly prologue = new Uint8Array(0)
private readonly prologue: Uint8Array;
John-LittleBearLabs marked this conversation as resolved.
Show resolved Hide resolved
private readonly staticKeys: KeyPair
private readonly earlyData?: bytes
private readonly useNoisePipes: boolean
Expand All @@ -41,7 +41,7 @@ export class Noise implements INoiseConnection {
* @param {bytes} staticNoiseKey - x25519 private key, reuse for faster handshakes
* @param {bytes} earlyData
*/
constructor (staticNoiseKey?: bytes, earlyData?: bytes, crypto: ICryptoInterface = stablelib) {
constructor (staticNoiseKey?: bytes, earlyData?: bytes, crypto: ICryptoInterface = stablelib, prologueBytes?: Uint8Array) {
this.earlyData = earlyData ?? new Uint8Array(0)
// disabled until properly specked
this.useNoisePipes = false
Expand All @@ -53,6 +53,11 @@ export class Noise implements INoiseConnection {
} else {
this.staticKeys = this.crypto.generateX25519KeyPair()
}
if (prologueBytes) {
John-LittleBearLabs marked this conversation as resolved.
Show resolved Hide resolved
this.prologue = prologueBytes;
} else {
this.prologue = new Uint8Array(0);
}
}

/**
Expand Down