From 4c219c031a18e93cb5d6897b27a3dc7466c2a14b Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 6 Dec 2022 22:36:03 -0400 Subject: [PATCH] fix: add missing .js suffix in imports --- package.json | 1 + src/codec.ts | 4 ++-- src/handshake.ts | 12 ++++++------ src/handshake_state.ts | 28 ++++++++++++++-------------- src/noise.ts | 6 +++--- src/nonce.ts | 2 +- src/payload.ts | 10 +++++----- src/publickey.ts | 6 +++--- src/qr.ts | 2 +- 9 files changed, 36 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index fc1cf00..18e874f 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "engines": { "node": ">=16" }, + "moduleResolution": "node16", "license": "Apache-2.0 OR MIT", "publishConfig": { "access": "public", diff --git a/src/codec.ts b/src/codec.ts index 64dac76..aa0482f 100644 --- a/src/codec.ts +++ b/src/codec.ts @@ -3,8 +3,8 @@ import { proto_message } from "js-waku"; import { Decoder, Encoder, Message, ProtoMessage } from "js-waku/lib/interfaces"; import { MessageV0 } from "js-waku/lib/waku_message/version_0"; -import { HandshakeResult, HandshakeStepResult } from "./handshake"; -import { PayloadV2 } from "./payload"; +import { HandshakeResult, HandshakeStepResult } from "./handshake.js"; +import { PayloadV2 } from "./payload.js"; const log = debug("waku:message:noise-encoder"); diff --git a/src/handshake.ts b/src/handshake.ts index bae70b5..6d16142 100644 --- a/src/handshake.ts +++ b/src/handshake.ts @@ -4,12 +4,12 @@ import { equals as uint8ArrayEquals } from "uint8arrays/equals"; import { bytes32 } from "./@types/basic"; import { KeyPair } from "./@types/keypair"; -import { getHKDFRaw } from "./crypto"; -import { HandshakeState, NoisePaddingBlockSize } from "./handshake_state"; -import { CipherState } from "./noise"; -import { HandshakePattern, PayloadV2ProtocolIDs } from "./patterns"; -import { MessageNametagBuffer, PayloadV2, toMessageNametag } from "./payload"; -import { NoisePublicKey } from "./publickey"; +import { getHKDFRaw } from "./crypto.js"; +import { HandshakeState, NoisePaddingBlockSize } from "./handshake_state.js"; +import { CipherState } from "./noise.js"; +import { HandshakePattern, PayloadV2ProtocolIDs } from "./patterns.js"; +import { MessageNametagBuffer, PayloadV2, toMessageNametag } from "./payload.js"; +import { NoisePublicKey } from "./publickey.js"; // Noise state machine diff --git a/src/handshake_state.ts b/src/handshake_state.ts index 1f6d0a7..f6fdaeb 100644 --- a/src/handshake_state.ts +++ b/src/handshake_state.ts @@ -6,7 +6,7 @@ import { MessageNametag } from "./@types/handshake.js"; import type { KeyPair } from "./@types/keypair.js"; import { Curve25519KeySize, dh, generateX25519KeyPair, getHKDF, intoCurve25519Key } from "./crypto.js"; import { SymmetricState } from "./noise.js"; -import { EmptyPreMessage, HandshakePattern, MessageDirection, NoiseTokens, PreMessagePattern } from "./patterns"; +import { EmptyPreMessage, HandshakePattern, MessageDirection, NoiseTokens, PreMessagePattern } from "./patterns.js"; import { NoisePublicKey } from "./publickey.js"; // The padding blocksize of a transport message @@ -208,7 +208,7 @@ export class HandshakeState { // If user is reading the "e" token if (reading) { - console.trace("noise pre-message read e"); + console.debug("noise pre-message read e"); // We check if current key is encrypted or not. We assume pre-message public keys are all unencrypted on users' end if (currPK.flag == 0) { @@ -220,7 +220,7 @@ export class HandshakeState { } // If user is writing the "e" token } else if (writing) { - console.trace("noise pre-message write e"); + console.debug("noise pre-message write e"); // When writing, the user is sending a public key, // We check that the public part corresponds to the set local key and we call MixHash(e.public_key). @@ -252,7 +252,7 @@ export class HandshakeState { // If user is reading the "s" token if (reading) { - console.trace("noise pre-message read s"); + console.debug("noise pre-message read s"); // We check if current key is encrypted or not. We assume pre-message public keys are all unencrypted on users' end if (currPK.flag == 0) { @@ -265,7 +265,7 @@ export class HandshakeState { // If user is writing the "s" token } else if (writing) { - console.trace("noise pre-message write s"); + console.debug("noise pre-message write s"); // If writing, it means that the user is sending a public key, // We check that the public part corresponds to the set local key and we call MixHash(s.public_key). @@ -345,7 +345,7 @@ export class HandshakeState { case NoiseTokens.e: // If user is reading the "s" token if (reading) { - console.trace("noise read e"); + console.debug("noise read e"); // We expect an ephemeral key, so we attempt to read it (next PK to process will always be at index 0 of preMessagePKs) if (inHandshakeMessage.length > 0) { @@ -384,7 +384,7 @@ export class HandshakeState { // If user is writing the "e" token } else if (writing) { - console.trace("noise write e"); + console.debug("noise write e"); // We generate a new ephemeral keypair this.e = generateX25519KeyPair(); @@ -408,7 +408,7 @@ export class HandshakeState { case NoiseTokens.s: // If user is reading the "s" token if (reading) { - console.trace("noise read s"); + console.debug("noise read s"); // We expect a static key, so we attempt to read it (next PK to process will always be at index 0 of preMessagePKs) if (inHandshakeMessage.length > 0) { @@ -436,7 +436,7 @@ export class HandshakeState { // If user is writing the "s" token } else if (writing) { - console.trace("noise write s"); + console.debug("noise write s"); // If the local static key is not set (the handshake state was not properly initialized), we raise an error if (!this.s) { @@ -462,7 +462,7 @@ export class HandshakeState { case NoiseTokens.psk: // If user is reading the "psk" token - console.trace("noise psk"); + console.debug("noise psk"); // Calls MixKeyAndHash(psk) this.ss.mixKeyAndHash(this.psk); @@ -471,7 +471,7 @@ export class HandshakeState { case NoiseTokens.ee: // If user is reading the "ee" token - console.trace("noise dh ee"); + console.debug("noise dh ee"); // If local and/or remote ephemeral keys are not set, we raise an error if (!this.e || !this.re) { @@ -485,7 +485,7 @@ export class HandshakeState { case NoiseTokens.es: // If user is reading the "es" token - console.trace("noise dh es"); + console.debug("noise dh es"); // We check if keys are correctly set. // If both present, we call MixKey(DH(e, rs)) if initiator, MixKey(DH(s, re)) if responder. @@ -507,7 +507,7 @@ export class HandshakeState { case NoiseTokens.se: // If user is reading the "se" token - console.trace("noise dh se"); + console.debug("noise dh se"); // We check if keys are correctly set. // If both present, call MixKey(DH(s, re)) if initiator, MixKey(DH(e, rs)) if responder. @@ -529,7 +529,7 @@ export class HandshakeState { case NoiseTokens.ss: // If user is reading the "ss" token - console.trace("noise dh ss"); + console.debug("noise dh ss"); // If local and/or remote static keys are not set, we raise an error if (!this.s || !this.rs) { diff --git a/src/noise.ts b/src/noise.ts index d1dc7c0..b5c7e35 100644 --- a/src/noise.ts +++ b/src/noise.ts @@ -83,7 +83,7 @@ export class CipherState { this.n.increment(); this.n.assertValue(); - console.trace("encryptWithAd", ciphertext, this.n.getUint64() - 1); + console.debug("encryptWithAd", ciphertext, this.n.getUint64() - 1); } else { // Otherwise we return the input plaintext according to specification http://www.noiseprotocol.org/noise.html#the-cipherstate-object ciphertext = plaintext; @@ -191,7 +191,7 @@ export class SymmetricState { // We update ck and the Cipher state's key k using the output of HDKF this.cs = new CipherState(tempK); this.ck = ck; - console.trace("mixKey", this.ck, this.cs.k); + console.debug("mixKey", this.ck, this.cs.k); } // MixHash as per Noise specification http://www.noiseprotocol.org/noise.html#the-symmetricstate-object @@ -199,7 +199,7 @@ export class SymmetricState { mixHash(data: Uint8Array): void { // We hash the previous handshake hash and input data and store the result in the Symmetric State's handshake hash value this.h = hashSHA256(uint8ArrayConcat([this.h, data])); - console.trace("mixHash", this.h); + console.debug("mixHash", this.h); } // mixKeyAndHash as per Noise specification http://www.noiseprotocol.org/noise.html#the-symmetricstate-object diff --git a/src/nonce.ts b/src/nonce.ts index 71a13ec..1b266fa 100644 --- a/src/nonce.ts +++ b/src/nonce.ts @@ -1,4 +1,4 @@ -import type { bytes, uint64 } from "./@types/basic"; +import type { bytes, uint64 } from "./@types/basic.js"; export const MIN_NONCE = 0; // For performance reasons, the nonce is represented as a JS `number` diff --git a/src/payload.ts b/src/payload.ts index 979a803..924cf84 100644 --- a/src/payload.ts +++ b/src/payload.ts @@ -5,11 +5,11 @@ import { concat as uint8ArrayConcat } from "uint8arrays/concat"; import { equals as uint8ArrayEquals } from "uint8arrays/equals"; -import { MessageNametag } from "./@types/handshake"; -import { ChachaPolyTagLen, Curve25519KeySize, hashSHA256 } from "./crypto"; -import { PayloadV2ProtocolIDs } from "./patterns"; -import { NoisePublicKey } from "./publickey"; -import { readUIntLE, writeUIntLE } from "./utils"; +import { MessageNametag } from "./@types/handshake.js"; +import { ChachaPolyTagLen, Curve25519KeySize, hashSHA256 } from "./crypto.js"; +import { PayloadV2ProtocolIDs } from "./patterns.js"; +import { NoisePublicKey } from "./publickey.js"; +import { readUIntLE, writeUIntLE } from "./utils.js"; export const MessageNametagLength = 16; export const MessageNametagBufferSize = 50; diff --git a/src/publickey.ts b/src/publickey.ts index cb72bc7..86e29b5 100644 --- a/src/publickey.ts +++ b/src/publickey.ts @@ -1,9 +1,9 @@ import { concat as uint8ArrayConcat } from "uint8arrays/concat"; import { equals as uint8ArrayEquals } from "uint8arrays/equals"; -import { bytes32 } from "./@types/basic"; -import { chaCha20Poly1305Decrypt, chaCha20Poly1305Encrypt } from "./crypto"; -import { isEmptyKey } from "./noise"; +import { bytes32 } from "./@types/basic.js"; +import { chaCha20Poly1305Decrypt, chaCha20Poly1305Encrypt } from "./crypto.js"; +import { isEmptyKey } from "./noise.js"; // A ChaChaPoly Cipher State containing key (k), nonce (nonce) and associated data (ad) export class ChaChaPolyCipherState { diff --git a/src/qr.ts b/src/qr.ts index bbf5a8e..45b8340 100644 --- a/src/qr.ts +++ b/src/qr.ts @@ -1,6 +1,6 @@ import { decode, encode, fromUint8Array, toUint8Array } from "js-base64"; -import { bytes32 } from "./@types/basic"; +import { bytes32 } from "./@types/basic.js"; export class QR { constructor(