flow-emulator
flow-emulator copied to clipboard
Service private key is not correctly set when public key is present
Problem
Using flags to set private and public key is causing private key to be ignored and not set on the configuration object.
Steps to Reproduce
Pass both values --service-priv-key and --service-pub-key and check what was the private key that was actually set.
Acceptance Criteria
The private key should be set when passed using a flag.
Context
The code processing configuration private and public key is faulty as seen here: https://github.com/onflow/flow-emulator/blob/master/cmd/emulator/start/start.go#L95-L118
if len(conf.ServicePublicKey) > 0 {
checkKeyAlgorithms(serviceKeySigAlgo, serviceKeyHashAlgo)
servicePublicKey, err = crypto.DecodePublicKeyHex(serviceKeySigAlgo, conf.ServicePublicKey)
if err != nil {
Exit(1, err.Error())
}
} else if len(conf.ServicePrivateKey) > 0 {
checkKeyAlgorithms(serviceKeySigAlgo, serviceKeyHashAlgo)
servicePrivateKey, err = crypto.DecodePrivateKeyHex(serviceKeySigAlgo, conf.ServicePrivateKey)
if err != nil {
Exit(1, err.Error())
}
servicePublicKey = servicePrivateKey.PublicKey()
} else {
servicePrivateKey, serviceKeySigAlgo, serviceKeyHashAlgo = getServiceKey(
conf.Init,
serviceKeySigAlgo,
serviceKeyHashAlgo,
)
servicePublicKey = servicePrivateKey.PublicKey()
}