*Update dist
This commit is contained in:
parent
f2e6e36783
commit
b2f2c7e9f0
|
@ -5,7 +5,6 @@ export default class DHT {
|
||||||
private _relays;
|
private _relays;
|
||||||
constructor(opts?: {});
|
constructor(opts?: {});
|
||||||
ready(): Promise<void>;
|
ready(): Promise<void>;
|
||||||
static get IS_WEB(): boolean;
|
|
||||||
get relays(): string[];
|
get relays(): string[];
|
||||||
addRelay(pubkey: string): Promise<boolean>;
|
addRelay(pubkey: string): Promise<boolean>;
|
||||||
removeRelay(pubkey: string): boolean;
|
removeRelay(pubkey: string): boolean;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAkB5C,MAAM,CAAC,OAAO,OAAO,GAAG;IACpB,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,OAAO,CAAoC;gBAEvC,IAAI,KAAK;IAOrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAEY,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAgChD,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAWpC,WAAW,IAAI,IAAI;YAKZ,iBAAiB;IAazB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC;IAavD,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC;CAUvD;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAEvD"}
|
|
@ -1,17 +1,23 @@
|
||||||
// src/index.ts
|
// @ts-ignore
|
||||||
import DhtNode from "@hyperswarm/dht-relay";
|
import DhtNode from "@hyperswarm/dht-relay";
|
||||||
|
// @ts-ignore
|
||||||
import Stream from "@hyperswarm/dht-relay/ws";
|
import Stream from "@hyperswarm/dht-relay/ws";
|
||||||
|
// @ts-ignore
|
||||||
import createRoundRobin from "@derhuerst/round-robin-scheduler";
|
import createRoundRobin from "@derhuerst/round-robin-scheduler";
|
||||||
|
// @ts-ignore
|
||||||
import { Buffer } from "buffer";
|
import { Buffer } from "buffer";
|
||||||
|
// @ts-ignore
|
||||||
import { blake2b } from "libskynet";
|
import { blake2b } from "libskynet";
|
||||||
|
// @ts-ignore
|
||||||
import { registryRead } from "libkmodule";
|
import { registryRead } from "libkmodule";
|
||||||
import { unpack } from "msgpackr";
|
import { unpack } from "msgpackr";
|
||||||
var REGISTRY_DHT_KEY = "lumeweb-dht-node";
|
const REGISTRY_DHT_KEY = "lumeweb-dht-node";
|
||||||
var DHT = class {
|
export default class DHT {
|
||||||
_wsPool;
|
_wsPool;
|
||||||
_options;
|
_options;
|
||||||
_relays = {};
|
_relays = {};
|
||||||
constructor(opts = {}) {
|
constructor(opts = {}) {
|
||||||
|
// @ts-ignore
|
||||||
opts.custodial = true;
|
opts.custodial = true;
|
||||||
this._options = opts;
|
this._options = opts;
|
||||||
this._wsPool = createRoundRobin();
|
this._wsPool = createRoundRobin();
|
||||||
|
@ -23,15 +29,15 @@ var DHT = class {
|
||||||
return Object.keys(this._relays);
|
return Object.keys(this._relays);
|
||||||
}
|
}
|
||||||
async addRelay(pubkey) {
|
async addRelay(pubkey) {
|
||||||
var _a;
|
|
||||||
let entry = await registryRead(Uint8Array.from(Buffer.from(pubkey, "hex")), hashDataKey(REGISTRY_DHT_KEY));
|
let entry = await registryRead(Uint8Array.from(Buffer.from(pubkey, "hex")), hashDataKey(REGISTRY_DHT_KEY));
|
||||||
if (entry[1] || !((_a = entry[0]) == null ? void 0 : _a.exists)) {
|
if (entry[1] || !entry[0]?.exists) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let host;
|
let host;
|
||||||
try {
|
try {
|
||||||
host = unpack(entry[0].entryData);
|
host = unpack(entry[0].entryData);
|
||||||
} catch (e) {
|
}
|
||||||
|
catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const [domain, port] = host.split(":");
|
const [domain, port] = host.split(":");
|
||||||
|
@ -85,8 +91,8 @@ var DHT = class {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
function hashDataKey(dataKey) {
|
export function hashDataKey(dataKey) {
|
||||||
return blake2b(encodeUtf8String(dataKey));
|
return blake2b(encodeUtf8String(dataKey));
|
||||||
}
|
}
|
||||||
function encodeUtf8String(str) {
|
function encodeUtf8String(str) {
|
||||||
|
@ -102,13 +108,8 @@ function stringToUint8ArrayUtf8(str) {
|
||||||
function encodeNumber(num) {
|
function encodeNumber(num) {
|
||||||
const encoded = new Uint8Array(8);
|
const encoded = new Uint8Array(8);
|
||||||
for (let index = 0; index < encoded.length; index++) {
|
for (let index = 0; index < encoded.length; index++) {
|
||||||
encoded[index] = num & 255;
|
encoded[index] = num & 0xff;
|
||||||
num = num >> 8;
|
num = num >> 8;
|
||||||
}
|
}
|
||||||
return encoded;
|
return encoded;
|
||||||
}
|
}
|
||||||
export {
|
|
||||||
DHT as default,
|
|
||||||
hashDataKey
|
|
||||||
};
|
|
||||||
//# sourceMappingURL=index.js.map
|
|
Loading…
Reference in New Issue