prysm-pulse/validator/keymanager/direct_interop.go
Jim McDonald 5ff9ae2108 Validator keymanager refactor (#4340)
* Move to keymanager
* Move to keymanager
* Merge branch 'keymanager' of github.com:mcdee/prysm into keymanager
* Lint
* Fix visibility
* Bazel fix
* Merge remote-tracking branch 'upstream/master' into keymanager
* logrus->log
* Merge branch 'master' into keymanager
* Merge remote-tracking branch 'upstream/master' into keymanager
* Merge branch 'master' into keymanager
* Merge branch 'master' into keymanager
* Merge branch 'master' into keymanager
* Merge branch 'master' into keymanager
* Fix test after merge
* Merge branch 'master' into keymanager
* And again
2020-01-04 03:51:53 +00:00

34 lines
865 B
Go

package keymanager
import (
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/interop"
)
// Interop is a key manager that deterministically generates keys.
type Interop struct {
*Direct
}
// NewInterop creates a key manager using the given number of interop keys at the given offset.
func NewInterop(keys uint64, offset uint64) (*Interop, error) {
sks, pks, err := interop.DeterministicallyGenerateKeys(offset, keys)
if err != nil {
return nil, err
}
km := &Interop{
Direct: &Direct{
publicKeys: make(map[[48]byte]*bls.PublicKey),
secretKeys: make(map[[48]byte]*bls.SecretKey),
},
}
for i := 0; uint64(i) < keys; i++ {
pubKey := bytesutil.ToBytes48(pks[i].Marshal())
km.publicKeys[pubKey] = pks[i]
km.secretKeys[pubKey] = sks[i]
}
return km, nil
}