@zombienet/orchestrator
Version:
ZombieNet aim to be a testing framework for substrate based blockchains, providing a simple cli tool that allow users to spawn and test ephemeral Substrate based networks
39 lines (38 loc) • 2.14 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateNodeMultiAddress = generateNodeMultiAddress;
const util_1 = require("@polkadot/util");
const libp2p_crypto_1 = require("libp2p-crypto");
const peer_id_1 = __importDefault(require("peer-id"));
function generateNodeMultiAddress(key_1, args_1, ip_1, port_1) {
return __awaiter(this, arguments, void 0, function* (key, args, ip, port, useWs = true, certhash) {
let multiaddress;
const pair = yield libp2p_crypto_1.keys.generateKeyPairFromSeed("Ed25519", (0, util_1.hexToU8a)((0, util_1.hexAddPrefix)(key)), 1024);
const peerId = yield peer_id_1.default.createFromPrivKey(pair.bytes);
const listenIndex = args.findIndex((arg) => arg === "--listen-addr");
if (listenIndex >= 0) {
const listenAddrParts = args[listenIndex + 1].split("/");
listenAddrParts[2] = ip;
listenAddrParts[4] = port.toString();
if (certhash)
listenAddrParts.push("certhash", certhash);
multiaddress = `${listenAddrParts.join("/")}/p2p/${peerId.toB58String()}`;
}
else {
multiaddress = `/ip4/${ip}/tcp/${port}/${useWs ? "ws/" : "/"}p2p/${peerId.toB58String()}`;
}
return multiaddress;
});
}