def test_derive_key_data(self, sk, pk, hash): public_key = Key(pk) self.assertFalse(public_key.is_secret) self.assertEqual(pk, public_key.public_key()) self.assertEqual(hash, public_key.public_key_hash()) secret_key = Key(sk) self.assertTrue(secret_key.is_secret) self.assertEqual(pk, secret_key.public_key()) self.assertEqual(sk, secret_key.secret_key())
def get_key(self, name) -> Key: self.reload() value = next(item['value'] for item in self._secret_keys if item['name'] == name) prefix, key = value.split(':', maxsplit=1) if prefix == 'encrypted': password = getpass(f'Please, enter passphrase for `{name}`:\n') key = Key(key, passphrase=password) else: key = Key(key) return key
def sign(self, key): if isinstance(key, str): key = Key(key) if not isinstance(key, Key): raise ValueError('Base58 encoded secret key or Key instance required.') self._data['signature'] = key.sign(self.unsigned_bytes(), generic=True) return self._data['signature']
def test_deterministic_signatures(self, sk, msg, sig): """ See RFC6979 for explanation https://tools.ietf.org/html/rfc6979#section-3.2 """ key = Key(sk) signature = key.sign(msg) self.assertEqual(sig, signature)
def __init__(self, key, interval=5, shell=mainnet): """ :param key: secret key (encrypted/unencrypted), public key or public key hash, all base58 encoded :param interval: number of blocks to check (tolerance) :param shell: Shell instance """ if not isinstance(key, Key): if is_pkh(key): key = shell.get_public_key(key) key = Key(key) self._key = key self._interval = interval self._shell = shell
def verify_signature(self): pk = self.get_public_key(self.metadata.get('baker')) Key(pk).verify(self.header.get('signature'), self.header.unsigned_bytes())
def verify_signature(self): pk = self.get_public_key(self.source()) Key(pk).verify(self.get('signature'), self.unsigned_bytes())
def test_sign_and_verify(self, sk, msg): key = Key(sk) sig = key.sign(msg) key.verify(sig, msg) self.assertRaises(ValueError, key.verify, sig, b'fake')
def test_verify_ext_signatures(self, pk, msg, sig): key = Key(pk) key.verify(sig, msg) self.assertRaises(ValueError, key.verify, sig, b'fake')
def test_encrypted_keys(self, sk, passphrase, salt, pk): key = Key(sk, passphrase=passphrase) self.assertEqual(pk, key.public_key()) with patch('pytezos.crypto.pysodium.randombytes', return_value=salt): self.assertEqual(sk, key.secret_key(passphrase))