use of io.libp2p.core.crypto.PrivKey in project xdagj by XDagger.
the class DiscoveryPeerTest method startup.
@Before
public void startup() throws UnknownHostException {
String priString = "0x0802122074ca7d1380b2c407be6878669ebb5c7a2ee751bb18198f1a0f214bcb93b894b5";
Bytes privkeybytes = Bytes.fromHexString(priString);
PrivKey privKey = KeyKt.unmarshalPrivateKey(privkeybytes.toArrayUnsafe());
// PrivKey privKey1 = KeyKt.generateKeyPair(KEY_TYPE.SECP256K1).component1();
// String s = Hex.toHexString(privKey1.bytes());
// System.out.println(Arrays.toString(Hex.decode(s)));
discoveryPeer = new DiscoveryPeer(Bytes.wrap(privKey.publicKey().raw()), new InetSocketAddress(InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 10001));
// System.out.println(discoveryPeer.getNodeAddress().toString());
List<String> boot = new ArrayList<>();
Bytes bytes = Bytes.wrap(privKey.raw());
discV5Service1 = DiscV5Service.create((bytes), "127.0.0.1", 10001, Collections.emptyList());
if (discV5Service1.getEnr().isPresent()) {
boot.add(discV5Service1.getEnr().get());
}
discV5Service2 = DiscV5Service.create(Bytes.wrap(KeyKt.generateKeyPair(KEY_TYPE.SECP256K1).component1().raw()), "127.0.0.1", 11111, boot);
discV5Service1.start();
discV5Service1.searchForPeers();
discV5Service2.start();
discV5Service2.searchForPeers();
}
use of io.libp2p.core.crypto.PrivKey in project teku by ConsenSys.
the class LibP2PPrivateKeyLoaderTest method assertRoundTrip.
private void assertRoundTrip(final PrivKey generatedPK) {
final PrivKey reparsed = KeyKt.unmarshalPrivateKey(generatedPK.bytes());
assertThat(reparsed).isEqualTo(generatedPK);
}
use of io.libp2p.core.crypto.PrivKey in project teku by ConsenSys.
the class LibP2PPrivateKeyLoader method generateNewPrivateKey.
private Bytes generateNewPrivateKey() {
final Bytes privateKey;
final Optional<Bytes> generatedKeyBytes = keyValueStore.get(GENERATED_NODE_KEY_KEY);
if (generatedKeyBytes.isEmpty()) {
final PrivKey privKey = KeyKt.generateKeyPair(KEY_TYPE.SECP256K1).component1();
privateKey = Bytes.wrap(KeyKt.marshalPrivateKey(privKey));
keyValueStore.put(GENERATED_NODE_KEY_KEY, privateKey);
STATUS_LOG.usingGeneratedP2pPrivateKey(GENERATED_NODE_KEY_KEY, true);
} else {
privateKey = generatedKeyBytes.get();
STATUS_LOG.usingGeneratedP2pPrivateKey(GENERATED_NODE_KEY_KEY, false);
}
return privateKey;
}
use of io.libp2p.core.crypto.PrivKey in project teku by ConsenSys.
the class PeerCommand method validateParamsAndGenerate.
void validateParamsAndGenerate(String outputFile, int number) throws IOException {
try {
File f = new File(outputFile);
if (f.exists()) {
throw new InvalidConfigurationException(String.format("Not overwriting existing file %s \nDelete file or use --output-file to point to a file that does not currently exist.", outputFile));
}
FileWriter fileWriter = new FileWriter(outputFile, Charset.defaultCharset());
PrintWriter printWriter = new PrintWriter(fileWriter);
printWriter.println("Private Key(Hex)\tPublic Key(Hex)\tPeerId(Base58)");
for (int i = 0; i < number; i++) {
PrivKey privKey = KeyKt.generateKeyPair(KEY_TYPE.SECP256K1).component1();
PubKey pubKey = privKey.publicKey();
PeerId peerId = PeerId.fromPubKey(pubKey);
printWriter.println(Bytes.wrap(privKey.bytes()).toHexString() + "\t" + Bytes.wrap(pubKey.bytes()).toHexString() + "\t" + peerId.toBase58());
}
printWriter.close();
} catch (final FileNotFoundException ex) {
throw new InvalidConfigurationException("use --output-file to point to a file in an existing directory " + ex.getMessage());
}
}
use of io.libp2p.core.crypto.PrivKey in project xdagj by XDagger.
the class DiscoveryPeerTest method start.
@Before
public void start() throws UnknownHostException {
PrivKey privKey = KeyKt.generateKeyPair(KEY_TYPE.SECP256K1).component1();
peer = new DiscoveryPeer(Bytes.wrap(privKey.publicKey().raw()), new InetSocketAddress(InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 10000));
expectStirng = "/ip4/127.0.0.1/tcp/10000/ipfs/" + new LibP2PNodeId(PeerId.fromPubKey(privKey.publicKey())).toString();
}
Aggregations