xud
Version:
Exchange Union Daemon
28 lines • 924 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseUri = exports.toUri = void 0;
const assert = require("assert");
/**
* Creates a URI string from the public key, host and port.
*/
exports.toUri = (uriParts) => {
const { nodePubKey, host, port } = uriParts;
return `${nodePubKey}@${host}:${port}`;
};
/**
* Splits a URI in the [pubkey]@[host]:[port] format into the public key, host and port components.
* If port is not present in the URI, it defaults to 8885.
*/
exports.parseUri = (uri) => {
// A regex that splits the string by the symbols "@" and ":"
const split = uri.split(/[@:]+/);
assert(split.length === 3 || split.length === 2);
const port = split[2] !== undefined ? Number(split[2]) : 8885;
assert(!isNaN(port));
return {
port,
nodePubKey: split[0],
host: split[1],
};
};
//# sourceMappingURL=uriUtils.js.map