*Add dist

This commit is contained in:
Derrick Hammer 2022-12-20 07:28:01 -05:00
parent e340a79d5c
commit 0a780414e2
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 50 additions and 0 deletions

12
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,12 @@
/// <reference types="node" />
export interface Peer {
host: string;
port: number;
}
export type PeerSource = (pubkey: Buffer) => Promise<boolean | Peer>;
export declare class PeerDiscovery {
private _sources;
registerSource(name: string, source: PeerSource): boolean;
removeSource(name: string): boolean;
discover(pubkey: string | Buffer): Promise<Peer | boolean>;
}

38
dist/index.js vendored Normal file
View File

@ -0,0 +1,38 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PeerDiscovery = void 0;
const b4a_1 = __importDefault(require("b4a"));
class PeerDiscovery {
_sources = new Map();
registerSource(name, source) {
if (this._sources.has(name)) {
return false;
}
this._sources.set(name, source);
return true;
}
removeSource(name) {
if (!this._sources.has(name)) {
return false;
}
this._sources.delete(name);
return true;
}
async discover(pubkey) {
if (!b4a_1.default.isBuffer(pubkey)) {
pubkey = b4a_1.default.from(pubkey, "hex");
}
for (const source of this._sources.values()) {
const result = await source(pubkey);
if (result) {
return result;
}
}
return false;
}
}
exports.PeerDiscovery = PeerDiscovery;
//# sourceMappingURL=index.js.map