pkg/devnet: split up deterministic key generation functions
Only moved code, no functional changes.
This commit is contained in:
parent
da768a09c4
commit
bbf479871f
|
@ -4,8 +4,6 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
mathrand "math/rand"
|
||||
|
||||
"github.com/libp2p/go-libp2p-core/crypto"
|
||||
)
|
||||
|
||||
// DeterministicEcdsaKeyByIndex generates a deterministic ecdsa.PrivateKey from a given index.
|
||||
|
@ -20,14 +18,3 @@ func DeterministicEcdsaKeyByIndex(c elliptic.Curve, idx uint64) *ecdsa.PrivateKe
|
|||
|
||||
return key
|
||||
}
|
||||
|
||||
// DeterministicP2PPrivKeyByIndex generates a deterministic libp2p crypto.PrivateKey from a given index.
|
||||
func DeterministicP2PPrivKeyByIndex(idx int64) crypto.PrivKey {
|
||||
r := mathrand.New(mathrand.NewSource(int64(idx)))
|
||||
priv, _, err := crypto.GenerateKeyPairWithReader(crypto.Ed25519, -1, r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return priv
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package devnet
|
||||
|
||||
import (
|
||||
mathrand "math/rand"
|
||||
|
||||
"github.com/libp2p/go-libp2p-core/crypto"
|
||||
)
|
||||
|
||||
// DeterministicP2PPrivKeyByIndex generates a deterministic libp2p crypto.PrivateKey from a given index.
|
||||
func DeterministicP2PPrivKeyByIndex(idx int64) crypto.PrivKey {
|
||||
r := mathrand.New(mathrand.NewSource(int64(idx)))
|
||||
priv, _, err := crypto.GenerateKeyPairWithReader(crypto.Ed25519, -1, r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return priv
|
||||
}
|
Loading…
Reference in New Issue