secp: convenience api (#897)
This commit is contained in:
parent
6975869ad6
commit
8b6c51e78d
|
@ -7,7 +7,7 @@ import
|
|||
chronicles, stew/[results, objects], eth/keys, eth/trie/db, eth/p2p/enode,
|
||||
eth/p2p/discoveryv5/[enr, protocol, discovery_db, types],
|
||||
libp2p/[multiaddress, peer],
|
||||
libp2p/crypto/crypto as libp2pCrypto,
|
||||
libp2p/crypto/crypto as libp2pCrypto, libp2p/crypto/secp,
|
||||
conf
|
||||
|
||||
type
|
||||
|
@ -67,7 +67,7 @@ proc toENode*(a: MultiAddress): Result[ENode, cstring] {.raises: [Defect].} =
|
|||
|
||||
proc toMultiAddressStr*(enode: ENode): string =
|
||||
var peerId = PeerID.init(libp2pCrypto.PublicKey(
|
||||
scheme: Secp256k1, skkey: SkPublicKey(enode.pubkey)))
|
||||
scheme: Secp256k1, skkey: secp.SkPublicKey(enode.pubkey)))
|
||||
&"/ip4/{enode.address.ip}/tcp/{enode.address.tcpPort}/p2p/{peerId.pretty}"
|
||||
|
||||
proc toENode*(enrRec: enr.Record): Result[ENode, cstring] {.raises: [Defect].} =
|
||||
|
|
|
@ -10,7 +10,7 @@ import
|
|||
chronos, chronicles, metrics,
|
||||
# TODO: create simpler to use libp2p modules that use re-exports
|
||||
libp2p/[switch, standard_setup, peerinfo, peer, connection,
|
||||
multiaddress, multicodec, crypto/crypto,
|
||||
multiaddress, multicodec, crypto/crypto, crypto/secp,
|
||||
protocols/identify, protocols/protocol],
|
||||
libp2p/protocols/secure/[secure, secio],
|
||||
libp2p/protocols/pubsub/[pubsub, floodsub, rpc/messages],
|
||||
|
@ -18,7 +18,6 @@ import
|
|||
libp2p/stream/lpstream,
|
||||
eth/[keys, async_utils], eth/p2p/[enode, p2p_protocol_dsl],
|
||||
eth/net/nat, eth/p2p/discoveryv5/[enr, node],
|
||||
|
||||
# Beacon node modules
|
||||
version, conf, eth2_discovery, libp2p_json_serialization, conf, ssz,
|
||||
peer_pool, spec/[datatypes, network]
|
||||
|
@ -633,7 +632,7 @@ proc toPeerInfo*(r: enr.TypedRecord): PeerInfo =
|
|||
return # TODO
|
||||
|
||||
let peerId = PeerID.init crypto.PublicKey(
|
||||
scheme: Secp256k1, skkey: SkPublicKey(pubKey[]))
|
||||
scheme: Secp256k1, skkey: secp.SkPublicKey(pubKey[]))
|
||||
var addresses = newSeq[MultiAddress]()
|
||||
|
||||
if r.ip.isSome and r.tcp.isSome:
|
||||
|
@ -913,10 +912,10 @@ proc setupNat(conf: BeaconNodeConf): tuple[ip: Option[IpAddress],
|
|||
(result.tcpPort, result.udpPort) = extPorts.get()
|
||||
|
||||
func asLibp2pKey*(key: keys.PublicKey): PublicKey =
|
||||
PublicKey(scheme: Secp256k1, skkey: SkPublicKey(key))
|
||||
PublicKey(scheme: Secp256k1, skkey: secp.SkPublicKey(key))
|
||||
|
||||
func asEthKey*(key: PrivateKey): keys.PrivateKey =
|
||||
keys.PrivateKey(SkSecretKey(data: key.skkey.data))
|
||||
keys.PrivateKey(key.skkey)
|
||||
|
||||
proc initAddress*(T: type MultiAddress, str: string): T =
|
||||
let address = MultiAddress.init(str)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit ee5c9619e0ae7e847e205f3a9dcc1c95a2e10f90
|
||||
Subproject commit 7c709551a5ad2a42f66ca004cdc064bb70b60bd1
|
|
@ -1 +1 @@
|
|||
Subproject commit 4d1fc9dacd932fbb61abe54d4a792e0178807e2d
|
||||
Subproject commit e8b33c64fac2e69e82fab7d7b8fadb2e2262a49a
|
|
@ -1 +1 @@
|
|||
Subproject commit 5af866754b5f17c49e1a1f7f90f2fd0c235eee99
|
||||
Subproject commit e8fa92a0c6217103eecce2a9e6f274c7eedac13b
|
Loading…
Reference in New Issue