Browse Source

nano validates key on load

pull/1782/head
Ethan Frey 7 years ago
parent
commit
2490952515
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      nano/keys.go

+ 18
- 0
nano/keys.go View File

@ -59,6 +59,8 @@ type PrivKeyLedger struct {
CachedPubKey crypto.PubKey
}
// NewPrivKeyLedger will generate a new key and store the
// public key for later use.
func NewPrivKeyLedger() (crypto.PrivKey, error) {
var pk PrivKeyLedger
// getPubKey will cache the pubkey for later use,
@ -68,6 +70,22 @@ func NewPrivKeyLedger() (crypto.PrivKey, error) {
return pk.Wrap(), err
}
// ValidateKey allows us to verify the sanity of a key
// after loading it from disk
func (pk *PrivKeyLedger) ValidateKey() error {
// getPubKey will return an error if the ledger is not
// properly set up...
pub, err := pk.getPubKey()
if err != nil {
return err
}
// verify this matches cached address
if !pub.Equals(pk.CachedPubKey) {
return errors.New("ledger doesn't match cached key")
}
return nil
}
// AssertIsPrivKeyInner fulfils PrivKey Interface
func (pk *PrivKeyLedger) AssertIsPrivKeyInner() {}


Loading…
Cancel
Save