From a30b2bd747dedeef69b46cfafb88898ba35d8f67 Mon Sep 17 00:00:00 2001 From: Danish Arora <35004822+danisharora099@users.noreply.github.com> Date: Tue, 14 Mar 2023 10:10:38 +0530 Subject: [PATCH] chore!: add exports map to @waku/utils (#1201) * add exports map * merge: master * export subdir with default export path * import according to the export path --- packages/core/src/lib/base_protocol.ts | 2 +- packages/core/src/lib/store/index.ts | 2 +- packages/dns-discovery/src/dns_over_https.ts | 2 +- packages/dns-discovery/src/enrtree.ts | 2 +- packages/enr/src/creator.ts | 2 +- packages/enr/src/crypto.ts | 2 +- packages/enr/src/decoder.ts | 2 +- packages/enr/src/encoder.ts | 2 +- packages/enr/src/enr.spec.ts | 2 +- packages/enr/src/raw_enr.ts | 2 +- packages/enr/src/v4.ts | 2 +- packages/message-encryption/src/crypto/ecies.ts | 2 +- packages/message-encryption/src/crypto/index.ts | 2 +- packages/message-encryption/src/waku_payload.ts | 2 +- packages/tests/src/nwaku.ts | 2 +- packages/tests/tests/ephemeral.node.spec.ts | 2 +- packages/tests/tests/filter.node.spec.ts | 2 +- packages/tests/tests/light_push.node.spec.ts | 2 +- packages/tests/tests/relay.node.spec.ts | 2 +- packages/tests/tests/store.node.spec.ts | 2 +- packages/tests/tests/waku.node.spec.ts | 2 +- packages/utils/package.json | 8 ++++++++ packages/utils/src/index.ts | 2 -- 23 files changed, 29 insertions(+), 23 deletions(-) diff --git a/packages/core/src/lib/base_protocol.ts b/packages/core/src/lib/base_protocol.ts index df18e9fb29..8f3a27b921 100644 --- a/packages/core/src/lib/base_protocol.ts +++ b/packages/core/src/lib/base_protocol.ts @@ -5,7 +5,7 @@ import { getPeersForProtocol, selectConnection, selectPeerForProtocol, -} from "@waku/utils"; +} from "@waku/utils/libp2p"; /** * A class with predefined helpers, to be used as a base to implement Waku diff --git a/packages/core/src/lib/store/index.ts b/packages/core/src/lib/store/index.ts index e50190d1ef..c5f87a06e3 100644 --- a/packages/core/src/lib/store/index.ts +++ b/packages/core/src/lib/store/index.ts @@ -10,7 +10,7 @@ import { ProtocolCreateOptions, } from "@waku/interfaces"; import { proto_store as proto } from "@waku/proto"; -import { concat, utf8ToBytes } from "@waku/utils"; +import { concat, utf8ToBytes } from "@waku/utils/bytes"; import debug from "debug"; import all from "it-all"; import * as lp from "it-length-prefixed"; diff --git a/packages/dns-discovery/src/dns_over_https.ts b/packages/dns-discovery/src/dns_over_https.ts index ae49aa87f5..1e0403ec9c 100644 --- a/packages/dns-discovery/src/dns_over_https.ts +++ b/packages/dns-discovery/src/dns_over_https.ts @@ -1,4 +1,4 @@ -import { bytesToUtf8 } from "@waku/utils"; +import { bytesToUtf8 } from "@waku/utils/bytes"; import debug from "debug"; import { Endpoint, query, toEndpoint } from "dns-query"; diff --git a/packages/dns-discovery/src/enrtree.ts b/packages/dns-discovery/src/enrtree.ts index 30b54847b9..7a1412c29b 100644 --- a/packages/dns-discovery/src/enrtree.ts +++ b/packages/dns-discovery/src/enrtree.ts @@ -1,6 +1,6 @@ import { ENR } from "@waku/enr"; import { keccak256, verifySignature } from "@waku/enr"; -import { utf8ToBytes } from "@waku/utils"; +import { utf8ToBytes } from "@waku/utils/bytes"; import base32 from "hi-base32"; import { fromString } from "uint8arrays/from-string"; diff --git a/packages/enr/src/creator.ts b/packages/enr/src/creator.ts index b310789184..d9d4b02f0a 100644 --- a/packages/enr/src/creator.ts +++ b/packages/enr/src/creator.ts @@ -1,6 +1,6 @@ import { PeerId } from "@libp2p/interface-peer-id"; import type { ENRKey, ENRValue } from "@waku/interfaces"; -import { utf8ToBytes } from "@waku/utils"; +import { utf8ToBytes } from "@waku/utils/bytes"; import { compressPublicKey } from "./crypto.js"; import { ENR } from "./enr.js"; diff --git a/packages/enr/src/crypto.ts b/packages/enr/src/crypto.ts index 4d9f8729b9..47b5676d08 100644 --- a/packages/enr/src/crypto.ts +++ b/packages/enr/src/crypto.ts @@ -1,5 +1,5 @@ import * as secp from "@noble/secp256k1"; -import { concat } from "@waku/utils"; +import { concat } from "@waku/utils/bytes"; import sha3 from "js-sha3"; /** diff --git a/packages/enr/src/decoder.ts b/packages/enr/src/decoder.ts index 12f1dfc241..67a1ee57ef 100644 --- a/packages/enr/src/decoder.ts +++ b/packages/enr/src/decoder.ts @@ -1,6 +1,6 @@ import * as RLP from "@ethersproject/rlp"; import type { ENRKey, ENRValue } from "@waku/interfaces"; -import { bytesToHex, bytesToUtf8, hexToBytes } from "@waku/utils"; +import { bytesToHex, bytesToUtf8, hexToBytes } from "@waku/utils/bytes"; import { log } from "debug"; import { fromString } from "uint8arrays/from-string"; diff --git a/packages/enr/src/encoder.ts b/packages/enr/src/encoder.ts index 9076ab8fdf..00a1e98553 100644 --- a/packages/enr/src/encoder.ts +++ b/packages/enr/src/encoder.ts @@ -1,6 +1,6 @@ import * as RLP from "@ethersproject/rlp"; import type { ENRKey, ENRValue } from "@waku/interfaces"; -import { hexToBytes, utf8ToBytes } from "@waku/utils"; +import { hexToBytes, utf8ToBytes } from "@waku/utils/bytes"; import { toString } from "uint8arrays/to-string"; import { ERR_NO_SIGNATURE, MAX_RECORD_SIZE } from "./constants.js"; diff --git a/packages/enr/src/enr.spec.ts b/packages/enr/src/enr.spec.ts index f498089f4d..4ca19fc92e 100644 --- a/packages/enr/src/enr.spec.ts +++ b/packages/enr/src/enr.spec.ts @@ -3,7 +3,7 @@ import { createSecp256k1PeerId } from "@libp2p/peer-id-factory"; import { multiaddr } from "@multiformats/multiaddr"; import * as secp from "@noble/secp256k1"; import type { Waku2 } from "@waku/interfaces"; -import { bytesToHex, hexToBytes, utf8ToBytes } from "@waku/utils"; +import { bytesToHex, hexToBytes, utf8ToBytes } from "@waku/utils/bytes"; import { assert, expect } from "chai"; import { equals } from "uint8arrays/equals"; diff --git a/packages/enr/src/raw_enr.ts b/packages/enr/src/raw_enr.ts index 848eceb5da..4dcd4879d2 100644 --- a/packages/enr/src/raw_enr.ts +++ b/packages/enr/src/raw_enr.ts @@ -4,7 +4,7 @@ import { convertToString, } from "@multiformats/multiaddr/convert"; import type { ENRKey, ENRValue, SequenceNumber, Waku2 } from "@waku/interfaces"; -import { bytesToUtf8 } from "@waku/utils"; +import { bytesToUtf8 } from "@waku/utils/bytes"; import { ERR_INVALID_ID } from "./constants.js"; import { decodeMultiaddrs, encodeMultiaddrs } from "./multiaddrs_codec.js"; diff --git a/packages/enr/src/v4.ts b/packages/enr/src/v4.ts index e1d3b1666f..e880deb106 100644 --- a/packages/enr/src/v4.ts +++ b/packages/enr/src/v4.ts @@ -1,6 +1,6 @@ import * as secp from "@noble/secp256k1"; import type { NodeId } from "@waku/interfaces"; -import { bytesToHex } from "@waku/utils"; +import { bytesToHex } from "@waku/utils/bytes"; import { keccak256 } from "./crypto.js"; export async function sign( diff --git a/packages/message-encryption/src/crypto/ecies.ts b/packages/message-encryption/src/crypto/ecies.ts index 3f6279cb95..a2ed83fd60 100644 --- a/packages/message-encryption/src/crypto/ecies.ts +++ b/packages/message-encryption/src/crypto/ecies.ts @@ -1,5 +1,5 @@ import * as secp from "@noble/secp256k1"; -import { concat, hexToBytes } from "@waku/utils"; +import { concat, hexToBytes } from "@waku/utils/bytes"; import { getSubtle, randomBytes, sha256 } from "./index.js"; /** diff --git a/packages/message-encryption/src/crypto/index.ts b/packages/message-encryption/src/crypto/index.ts index 991d442bf7..ec6cc06747 100644 --- a/packages/message-encryption/src/crypto/index.ts +++ b/packages/message-encryption/src/crypto/index.ts @@ -1,7 +1,7 @@ import nodeCrypto from "crypto"; import * as secp from "@noble/secp256k1"; -import { concat } from "@waku/utils"; +import { concat } from "@waku/utils/bytes"; import sha3 from "js-sha3"; import { Asymmetric, Symmetric } from "../constants.js"; diff --git a/packages/message-encryption/src/waku_payload.ts b/packages/message-encryption/src/waku_payload.ts index dffc95070d..8da80da4be 100644 --- a/packages/message-encryption/src/waku_payload.ts +++ b/packages/message-encryption/src/waku_payload.ts @@ -1,5 +1,5 @@ import * as secp from "@noble/secp256k1"; -import { concat, hexToBytes } from "@waku/utils"; +import { concat, hexToBytes } from "@waku/utils/bytes"; import { Symmetric } from "./constants.js"; import * as ecies from "./crypto/ecies.js"; diff --git a/packages/tests/src/nwaku.ts b/packages/tests/src/nwaku.ts index 8fee5a02c6..54ea8b3ffa 100644 --- a/packages/tests/src/nwaku.ts +++ b/packages/tests/src/nwaku.ts @@ -4,7 +4,7 @@ import type { PeerId } from "@libp2p/interface-peer-id"; import { peerIdFromString } from "@libp2p/peer-id"; import { Multiaddr, multiaddr } from "@multiformats/multiaddr"; import { DefaultPubSubTopic } from "@waku/core"; -import { bytesToHex, hexToBytes } from "@waku/utils"; +import { bytesToHex, hexToBytes } from "@waku/utils/bytes"; import appRoot from "app-root-path"; import debug from "debug"; import portfinder from "portfinder"; diff --git a/packages/tests/tests/ephemeral.node.spec.ts b/packages/tests/tests/ephemeral.node.spec.ts index 2b87dcc5a2..2821458cf8 100644 --- a/packages/tests/tests/ephemeral.node.spec.ts +++ b/packages/tests/tests/ephemeral.node.spec.ts @@ -18,7 +18,7 @@ import { createDecoder as symDecoder, createEncoder as symEncoder, } from "@waku/message-encryption/symmetric"; -import { bytesToUtf8, utf8ToBytes } from "@waku/utils"; +import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes"; import { expect } from "chai"; import debug from "debug"; diff --git a/packages/tests/tests/filter.node.spec.ts b/packages/tests/tests/filter.node.spec.ts index dde262ac0c..b5471056c3 100644 --- a/packages/tests/tests/filter.node.spec.ts +++ b/packages/tests/tests/filter.node.spec.ts @@ -8,7 +8,7 @@ import { import { createLightNode } from "@waku/create"; import type { LightNode } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces"; -import { bytesToUtf8, utf8ToBytes } from "@waku/utils"; +import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes"; import { expect } from "chai"; import debug from "debug"; diff --git a/packages/tests/tests/light_push.node.spec.ts b/packages/tests/tests/light_push.node.spec.ts index cb7b4b2a07..789255e89a 100644 --- a/packages/tests/tests/light_push.node.spec.ts +++ b/packages/tests/tests/light_push.node.spec.ts @@ -2,7 +2,7 @@ import { createEncoder, waitForRemotePeer } from "@waku/core"; import { createLightNode } from "@waku/create"; import type { LightNode } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces"; -import { utf8ToBytes } from "@waku/utils"; +import { utf8ToBytes } from "@waku/utils/bytes"; import { expect } from "chai"; import debug from "debug"; diff --git a/packages/tests/tests/relay.node.spec.ts b/packages/tests/tests/relay.node.spec.ts index 5b8e86f99f..1438bd29cb 100644 --- a/packages/tests/tests/relay.node.spec.ts +++ b/packages/tests/tests/relay.node.spec.ts @@ -20,7 +20,7 @@ import { createEncoder as createSymEncoder, generateSymmetricKey, } from "@waku/message-encryption/symmetric"; -import { bytesToUtf8, utf8ToBytes } from "@waku/utils"; +import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes"; import { expect } from "chai"; import debug from "debug"; diff --git a/packages/tests/tests/store.node.spec.ts b/packages/tests/tests/store.node.spec.ts index 444e81ec2e..0c04876acc 100644 --- a/packages/tests/tests/store.node.spec.ts +++ b/packages/tests/tests/store.node.spec.ts @@ -20,7 +20,7 @@ import { createEncoder as createSymEncoder, generateSymmetricKey, } from "@waku/message-encryption/symmetric"; -import { bytesToUtf8, utf8ToBytes } from "@waku/utils"; +import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes"; import { expect } from "chai"; import debug from "debug"; diff --git a/packages/tests/tests/waku.node.spec.ts b/packages/tests/tests/waku.node.spec.ts index 29103f4c4a..d65077d077 100644 --- a/packages/tests/tests/waku.node.spec.ts +++ b/packages/tests/tests/waku.node.spec.ts @@ -13,7 +13,7 @@ import { createEncoder, generateSymmetricKey, } from "@waku/message-encryption/symmetric"; -import { bytesToUtf8, utf8ToBytes } from "@waku/utils"; +import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes"; import { expect } from "chai"; import { diff --git a/packages/utils/package.json b/packages/utils/package.json index b50133b30c..0d6c264e2c 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -8,6 +8,14 @@ ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" + }, + "./libp2p": { + "types": "./dist/libp2p/index.d.ts", + "import": "./dist/libp2p/index.js" + }, + "./bytes": { + "types": "./dist/bytes/index.d.ts", + "import": "./dist/bytes/index.js" } }, "type": "module", diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 33c0548d02..027f648c0c 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -1,3 +1 @@ -export * from "./bytes/index.js"; -export * from "./libp2p/index.js"; export * from "./common/index.js";