deterministic_bridge_key.go 522 B

1234567891011121314151617181920
  1. package devnet
  2. import (
  3. "crypto/ecdsa"
  4. "crypto/elliptic"
  5. mathrand "math/rand"
  6. )
  7. // DeterministicEcdsaKeyByIndex generates a deterministic ecdsa.PrivateKey from a given index.
  8. func DeterministicEcdsaKeyByIndex(c elliptic.Curve, idx uint64) *ecdsa.PrivateKey {
  9. // use 555 as offset to deterministically generate key 0 to match vaa-test such that
  10. // we generate the same key.
  11. r := mathrand.New(mathrand.NewSource(int64(555 + idx)))
  12. key, err := ecdsa.GenerateKey(c, r)
  13. if err != nil {
  14. panic(err)
  15. }
  16. return key
  17. }