refactor: replace b4a with uint8ArrayToHexString
This commit is contained in:
parent
7826b8d2d6
commit
7327419954
|
@ -3,6 +3,7 @@ import Hyperswarm from "hyperswarm";
|
||||||
import RpcNetworkQueryFactory from "./query/index.js";
|
import RpcNetworkQueryFactory from "./query/index.js";
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
import { createHash, maybeGetAsyncProperty } from "./util.js";
|
import { createHash, maybeGetAsyncProperty } from "./util.js";
|
||||||
|
import { uint8ArrayToHexString } from "binconv";
|
||||||
|
|
||||||
export default class RpcNetwork {
|
export default class RpcNetwork {
|
||||||
private _relaysAvailablePromise?: Promise<void>;
|
private _relaysAvailablePromise?: Promise<void>;
|
||||||
|
@ -71,7 +72,7 @@ export default class RpcNetwork {
|
||||||
get ready(): Promise<void> {
|
get ready(): Promise<void> {
|
||||||
if (!this._ready) {
|
if (!this._ready) {
|
||||||
this._ready = maybeGetAsyncProperty(this._swarm.dht).then((dht: any) =>
|
this._ready = maybeGetAsyncProperty(this._swarm.dht).then((dht: any) =>
|
||||||
dht.ready()
|
dht.ready(),
|
||||||
) as Promise<void>;
|
) as Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +103,7 @@ export default class RpcNetwork {
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._relays.get(
|
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.setupRelayPromise();
|
||||||
|
|
||||||
this._swarm.on("connection", async (relay: any) => {
|
this._swarm.on("connection", async (relay: any) => {
|
||||||
const pubkey = b4a
|
const pubkey = uint8ArrayToHexString(
|
||||||
.from(await maybeGetAsyncProperty(relay.remotePublicKey))
|
await maybeGetAsyncProperty(relay.remotePublicKey),
|
||||||
.toString("hex");
|
);
|
||||||
relay.once("close", () => {
|
relay.once("close", () => {
|
||||||
this._methods.forEach((item) => {
|
this._methods.forEach((item) => {
|
||||||
if (item.has(pubkey)) {
|
if (item.has(pubkey)) {
|
||||||
|
|
Loading…
Reference in New Issue