From 7327419954cda699cf60ec117bdd4376352f88e4 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 4 Jul 2023 07:20:06 -0400 Subject: [PATCH] refactor: replace b4a with uint8ArrayToHexString --- src/network.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/network.ts b/src/network.ts index 6d24c4a..3ceff0f 100644 --- a/src/network.ts +++ b/src/network.ts @@ -3,6 +3,7 @@ import Hyperswarm from "hyperswarm"; import RpcNetworkQueryFactory from "./query/index.js"; import b4a from "b4a"; import { createHash, maybeGetAsyncProperty } from "./util.js"; +import { uint8ArrayToHexString } from "binconv"; export default class RpcNetwork { private _relaysAvailablePromise?: Promise; @@ -71,7 +72,7 @@ export default class RpcNetwork { get ready(): Promise { if (!this._ready) { this._ready = maybeGetAsyncProperty(this._swarm.dht).then((dht: any) => - dht.ready() + dht.ready(), ) as Promise; } @@ -102,7 +103,7 @@ export default class RpcNetwork { } return this._relays.get( - Array.from(relays)[Math.floor(Math.random() * relays.size)] + Array.from(relays)[Math.floor(Math.random() * relays.size)], ); } @@ -119,9 +120,9 @@ export default class RpcNetwork { this.setupRelayPromise(); this._swarm.on("connection", async (relay: any) => { - const pubkey = b4a - .from(await maybeGetAsyncProperty(relay.remotePublicKey)) - .toString("hex"); + const pubkey = uint8ArrayToHexString( + await maybeGetAsyncProperty(relay.remotePublicKey), + ); relay.once("close", () => { this._methods.forEach((item) => { if (item.has(pubkey)) {