def make_and_add_seed(self, lang="en"): try: self.decoded_seed = ' '.join(self.make_seed(lang).split()) self.seed = pw_encode(self.decoded_seed, self._password) return self.decoded_seed except DuplicateKeyError: # seed 重复 self.add_seed(self.make_seed(lang))
def add_xprv_from_seed(self): # we don't store the seed, only the master xpriv xprv, xpub = bip32_root(self.mnemonic_to_seed()) self.decoded_xprv, xpub = bip32_private_derivation( xprv, "m/", self.root_derivation) self.master_public_keys = {self.root_name: xpub} self.master_private_keys = { self.root_name: pw_encode(self.decoded_xprv, self._password) }
def update_password(self, new_password): if not new_password: raise ParamsError('51002') try: str(new_password) except: raise ParamsError('51001', "the password can't conversion into str") self.get_decode_seed() seed = pw_encode(self.decoded_seed, new_password) master_private_keys = {} for k, v in self.master_private_keys.items(): b = pw_decode(v, self._password) c = pw_encode(b, new_password) master_private_keys[k] = c # save to mongodb self.seed = seed self.master_private_keys = master_private_keys self._password = new_password
def update_password(self, old_password, new_password): for k, v in self.keypairs.items(): pubkey, a = v b = pw_decode(a, old_password) c = pw_encode(b, new_password) self.keypairs[k] = (pubkey, c)
def add(self, address, pubkey, privkey, password): self.keypairs[address] = (pubkey, pw_encode(privkey, password))