return h.keyStore.StoreKey(xpb.File, xkey, newAuth)
}
+func (h *HSM) HasAlias(alias string) bool {
+ return h.cache.hasAlias(alias)
+}
+
+func (h *HSM) HasKey(xprv chainkd.XPrv) bool {
+ return h.cache.hasKey(xprv.XPub())
+}
+
//ImportXPrvKey import XPrv to chainkd
func (h *HSM) ImportXPrvKey(auth string, alias string, xprv chainkd.XPrv) (*XPub, bool, error) {
if ok := h.cache.hasAlias(alias); ok {
// ImportAccountPrivKey imports the account key in the Wallet Import Formt.
func (w *Wallet) ImportAccountPrivKey(hsm *pseudohsm.HSM, xprv chainkd.XPrv, keyAlias, auth string, index uint64, accountAlias string) (*pseudohsm.XPub, error) {
+ if hsm.HasAlias(keyAlias) {
+ return nil, pseudohsm.ErrDuplicateKeyAlias
+ }
+ if hsm.HasKey(xprv) {
+ return nil, pseudohsm.ErrDuplicateKey
+ }
+
+ if acc, _ := w.AccountMgr.FindByAlias(nil, accountAlias); acc != nil {
+ return nil, account.ErrDuplicateAlias
+ }
+
xpub, _, err := hsm.ImportXPrvKey(auth, keyAlias, xprv)
if err != nil {
return nil, err