|
@ -59,6 +59,8 @@ type PrivKeyLedger struct { |
|
|
CachedPubKey crypto.PubKey |
|
|
CachedPubKey crypto.PubKey |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// NewPrivKeyLedger will generate a new key and store the
|
|
|
|
|
|
// public key for later use.
|
|
|
func NewPrivKeyLedger() (crypto.PrivKey, error) { |
|
|
func NewPrivKeyLedger() (crypto.PrivKey, error) { |
|
|
var pk PrivKeyLedger |
|
|
var pk PrivKeyLedger |
|
|
// getPubKey will cache the pubkey for later use,
|
|
|
// getPubKey will cache the pubkey for later use,
|
|
@ -68,6 +70,22 @@ func NewPrivKeyLedger() (crypto.PrivKey, error) { |
|
|
return pk.Wrap(), err |
|
|
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
|
|
|
// AssertIsPrivKeyInner fulfils PrivKey Interface
|
|
|
func (pk *PrivKeyLedger) AssertIsPrivKeyInner() {} |
|
|
func (pk *PrivKeyLedger) AssertIsPrivKeyInner() {} |
|
|
|
|
|
|
|
|