mirror of https://github.com/waku-org/js-waku.git
Move utf-8 utils to `utils`
This commit is contained in:
parent
638b96c17d
commit
bf63e85e9e
|
@ -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
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
query,
|
||||
} from "dns-query";
|
||||
|
||||
import { bytesToUtf8 } from "../utf8";
|
||||
import { bytesToUtf8 } from "../utils";
|
||||
|
||||
import { DnsClient } from "./dns";
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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");
|
|
@ -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");
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
Loading…
Reference in New Issue