mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-06 16:17:11 +00:00
Allow Signer to be generated with priv key
Prior to this change, a custom Signer would have no knowledge of the private key stored in the configuration file. This changes introduces a generator function, which creates a Signer based on the private key. This provides an opportunity for customer Signers to adjust behaviour based on the key contents. (E.g. imagine key contents are a key label, rather than the key itself).
This commit is contained in:
committed by
Ethan Buchman
parent
7e4a704bd1
commit
0d392a0442
+10
-7
@@ -55,6 +55,10 @@ type PrivValidator struct {
|
||||
mtx sync.Mutex
|
||||
}
|
||||
|
||||
|
||||
type SignerGenerator func(pk crypto.PrivKey) (Signer)
|
||||
|
||||
|
||||
// This is used to sign votes.
|
||||
// It is the caller's duty to verify the msg before calling Sign,
|
||||
// eg. to avoid double signing.
|
||||
@@ -112,10 +116,12 @@ func GenPrivValidator() *PrivValidator {
|
||||
}
|
||||
|
||||
func LoadPrivValidator(filePath string) *PrivValidator {
|
||||
return LoadPrivValidatorWithSigner(filePath, nil)
|
||||
return LoadPrivValidatorWithSigner(filePath, func(pk crypto.PrivKey) Signer {
|
||||
return NewDefaultSigner(pk)
|
||||
})
|
||||
}
|
||||
|
||||
func LoadPrivValidatorWithSigner(filePath string, signer Signer) *PrivValidator {
|
||||
func LoadPrivValidatorWithSigner(filePath string, generator SignerGenerator) *PrivValidator {
|
||||
privValJSONBytes, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
@@ -127,11 +133,8 @@ func LoadPrivValidatorWithSigner(filePath string, signer Signer) *PrivValidator
|
||||
}
|
||||
|
||||
privVal.filePath = filePath
|
||||
if signer == nil {
|
||||
privVal.Signer = NewDefaultSigner(privVal.PrivKey)
|
||||
} else {
|
||||
privVal.Signer = signer
|
||||
}
|
||||
privVal.Signer = generator(privVal.PrivKey)
|
||||
|
||||
privVal.setPubKeyAndAddress()
|
||||
return &privVal
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user