deterministic_p2p_key.go 436 B

123456789101112131415161718
  1. package devnet
  2. import (
  3. mathrand "math/rand"
  4. "github.com/libp2p/go-libp2p-core/crypto"
  5. )
  6. // DeterministicP2PPrivKeyByIndex generates a deterministic libp2p crypto.PrivateKey from a given index.
  7. func DeterministicP2PPrivKeyByIndex(idx int64) crypto.PrivKey {
  8. r := mathrand.New(mathrand.NewSource(int64(idx)))
  9. priv, _, err := crypto.GenerateKeyPairWithReader(crypto.Ed25519, -1, r)
  10. if err != nil {
  11. panic(err)
  12. }
  13. return priv
  14. }