mirror of
https://git.wownero.com/lza_menace/wownero-python.git
synced 2024-08-15 03:25:25 +00:00
Add secret key checking methods
This commit is contained in:
parent
741d54c235
commit
e3dcc96a60
4 changed files with 69 additions and 27 deletions
|
@ -4,6 +4,7 @@ import struct
|
|||
from sha3 import keccak_256
|
||||
|
||||
from . import base58
|
||||
from . import ed25519
|
||||
from . import numbers
|
||||
|
||||
_ADDR_REGEX = re.compile(r'^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{95}$')
|
||||
|
@ -75,6 +76,20 @@ class Address(object):
|
|||
"""
|
||||
return hexlify(self._decoded[1:33]).decode()
|
||||
|
||||
def check_private_view_key(self, key):
|
||||
"""Checks if private view key matches this address.
|
||||
|
||||
:rtype: bool
|
||||
"""
|
||||
return ed25519.public_from_secret_hex(key) == self.view_key()
|
||||
|
||||
def check_private_spend_key(self, key):
|
||||
"""Checks if private spend key matches this address.
|
||||
|
||||
:rtype: bool
|
||||
"""
|
||||
return ed25519.public_from_secret_hex(key) == self.spend_key()
|
||||
|
||||
def with_payment_id(self, payment_id=0):
|
||||
"""Integrates payment id into the address.
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#
|
||||
# Parts Copyright (c) 2016 The MoneroPy Developers. Released under the BSD 3-Clause
|
||||
|
||||
from binascii import hexlify, unhexlify
|
||||
import hashlib
|
||||
import operator as _oper
|
||||
import sys as _sys
|
||||
|
@ -133,3 +134,10 @@ def scalarmultbase(e):
|
|||
if e & 1: Q = edwards(Q, B)
|
||||
return Q
|
||||
|
||||
def public_from_secret(k):
|
||||
keyInt = decodeint(k)
|
||||
aG = scalarmultbase(keyInt)
|
||||
return encodepoint(aG)
|
||||
|
||||
def public_from_secret_hex(hk):
|
||||
return hexlify(public_from_secret(unhexlify(hk))).decode()
|
||||
|
|
|
@ -137,14 +137,10 @@ class Seed(object):
|
|||
return self.sc_reduce(h.digest())
|
||||
|
||||
def public_spend_key(self):
|
||||
keyInt = ed25519.decodeint(unhexlify(self.secret_spend_key()))
|
||||
aG = ed25519.scalarmultbase(keyInt)
|
||||
return hexlify(ed25519.encodepoint(aG)).decode()
|
||||
return ed25519.public_from_secret_hex(self.secret_spend_key())
|
||||
|
||||
def public_view_key(self):
|
||||
keyInt = ed25519.decodeint(unhexlify(self.secret_view_key()))
|
||||
aG = ed25519.scalarmultbase(keyInt)
|
||||
return hexlify(ed25519.encodepoint(aG)).decode()
|
||||
return ed25519.public_from_secret_hex(self.secret_view_key())
|
||||
|
||||
def public_address(self, net='mainnet'):
|
||||
"""Returns the master :class:`Address <monero.address.Address>` represented by the seed.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue