diff --git a/CHANGELOG.md b/CHANGELOG.md index 1883dc6514..16f8d6fa59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Examples: Add Relay JavaScript example. +- **Breaking**: Moved utf-8 conversion functions to `utils`. ### Fixed diff --git a/src/index.ts b/src/index.ts index 5d8e9de24a..85052167d2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,8 +3,6 @@ export * as discovery from "./lib/discovery"; export * as enr from "./lib/enr"; -export * as utf8 from "./lib/utf8"; - export * as utils from "./lib/utils"; export * as waku from "./lib/waku"; diff --git a/src/lib/discovery/dns_over_https.ts b/src/lib/discovery/dns_over_https.ts index 97f57b2cba..cbeabb3f65 100644 --- a/src/lib/discovery/dns_over_https.ts +++ b/src/lib/discovery/dns_over_https.ts @@ -6,7 +6,7 @@ import { query, } from "dns-query"; -import { bytesToUtf8 } from "../utf8"; +import { bytesToUtf8 } from "../utils"; import { DnsClient } from "./dns"; diff --git a/src/lib/discovery/enrtree.ts b/src/lib/discovery/enrtree.ts index 0626ca339a..6abddae350 100644 --- a/src/lib/discovery/enrtree.ts +++ b/src/lib/discovery/enrtree.ts @@ -5,8 +5,7 @@ import { ecdsaVerify } from "secp256k1"; import { fromString } from "uint8arrays/from-string"; import { ENR } from "../enr"; -import { utf8ToBytes } from "../utf8"; -import { keccak256Buf } from "../utils"; +import { keccak256Buf, utf8ToBytes } from "../utils"; export type ENRRootValues = { eRoot: string; diff --git a/src/lib/enr/enr.spec.ts b/src/lib/enr/enr.spec.ts index d18bb0be8f..ee38c2cca1 100644 --- a/src/lib/enr/enr.spec.ts +++ b/src/lib/enr/enr.spec.ts @@ -2,8 +2,7 @@ import { assert, expect } from "chai"; import { Multiaddr } from "multiaddr"; import PeerId from "peer-id"; -import { utf8ToBytes } from "../utf8"; -import { bytesToHex, hexToBytes } from "../utils"; +import { bytesToHex, hexToBytes, utf8ToBytes } from "../utils"; import { ERR_INVALID_ID } from "./constants"; import { ENR } from "./enr"; diff --git a/src/lib/enr/enr.ts b/src/lib/enr/enr.ts index 561457cc98..17787e6491 100644 --- a/src/lib/enr/enr.ts +++ b/src/lib/enr/enr.ts @@ -9,8 +9,7 @@ import { fromString } from "uint8arrays/from-string"; import { toString } from "uint8arrays/to-string"; import { encode as varintEncode } from "varint"; -import { bytesToUtf8, utf8ToBytes } from "../utf8"; -import { bytesToHex, hexToBytes } from "../utils"; +import { bytesToHex, bytesToUtf8, hexToBytes, utf8ToBytes } from "../utils"; import { ERR_INVALID_ID, ERR_NO_SIGNATURE, MAX_RECORD_SIZE } from "./constants"; import { diff --git a/src/lib/utf8.ts b/src/lib/utf8.ts deleted file mode 100644 index f627566fed..0000000000 --- a/src/lib/utf8.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Decode bytes to utf-8 string. - */ -import { fromString } from "uint8arrays/from-string"; -import { toString } from "uint8arrays/to-string"; - -export const bytesToUtf8 = (b: Uint8Array): string => toString(b, "utf8"); - -/** - * Encode utf-8 string to byte array - */ -export const utf8ToBytes = (s: string): Uint8Array => fromString(s, "utf8"); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 217de7626b..7e64388a4c 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -27,3 +27,13 @@ export const bytesToHex = (bytes: Uint8Array): string => export function keccak256Buf(message: Message): Uint8Array { return new Uint8Array(keccak256.arrayBuffer(message)); } + +/** + * Decode byte array to utf-8 string. + */ +export const bytesToUtf8 = (b: Uint8Array): string => toString(b, "utf8"); + +/** + * Encode utf-8 string to byte array. + */ +export const utf8ToBytes = (s: string): Uint8Array => fromString(s, "utf8"); diff --git a/src/lib/waku_message/index.node.spec.ts b/src/lib/waku_message/index.node.spec.ts index 3d14ecf178..cfc5e14ffc 100644 --- a/src/lib/waku_message/index.node.spec.ts +++ b/src/lib/waku_message/index.node.spec.ts @@ -8,8 +8,7 @@ import { WakuRelayMessage, } from "../../test_utils"; import { delay } from "../../test_utils/delay"; -import { bytesToUtf8, utf8ToBytes } from "../utf8"; -import { bytesToHex, hexToBytes } from "../utils"; +import { bytesToHex, bytesToUtf8, hexToBytes, utf8ToBytes } from "../utils"; import { Protocols, Waku } from "../waku"; import { diff --git a/src/lib/waku_message/index.ts b/src/lib/waku_message/index.ts index 1f7fcdbebc..602d3b9d20 100644 --- a/src/lib/waku_message/index.ts +++ b/src/lib/waku_message/index.ts @@ -3,7 +3,7 @@ import Long from "long"; import { Reader } from "protobufjs/minimal"; import * as proto from "../../proto/waku/v2/message"; -import { bytesToUtf8, utf8ToBytes } from "../utf8"; +import { bytesToUtf8, utf8ToBytes } from "../utils"; import * as version_1 from "./version_1";