Skip to content

Commit

Permalink
fix: write handshake nonce correctly
Browse files Browse the repository at this point in the history
The `value` and `offset` args to `Buffer.writeUInt32LE` vs
`DataView.setUint32` are the other way round.

Fixes a bug introduced in #125 where we were using the nonce value
as an offset and writing `4` rather than writing the nonce value
at offset `4`.
  • Loading branch information
achingbrain committed Jan 14, 2022
1 parent 112e247 commit ecd70af
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/handshakes/abstract-handshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export abstract class AbstractHandshake {
protected nonceToBytes (n: uint64): bytes {
// Even though we're treating the nonce as 8 bytes, RFC7539 specifies 12 bytes for a nonce.
const nonce = new Uint8Array(12)
new DataView(nonce.buffer, nonce.byteOffset, nonce.byteLength).setUint32(n, 4, true)
new DataView(nonce.buffer, nonce.byteOffset, nonce.byteLength).setUint32(4, n, true)

return nonce
}
Expand Down

0 comments on commit ecd70af

Please sign in to comment.