def generate_signature(cls, message, private_key): x = ffi.new('long long *') x[0] = random.SystemRandom().randint(0, sys.maxsize) key = PrivateKey.from_hex(private_key) signature = key.sign(message.encode('utf-8'), custom_nonce=(ffi.NULL, x)) return base64.b64encode(signature).decode('utf-8')
def generate_deterministic_signature(cls, config, message: str, private_key=None): if not private_key: private_key = config.private_key key = PrivateKey.from_hex(private_key) signature = key.sign(message.encode('utf-8')) return base64.b64encode(signature).decode('utf-8')
def generate(cls, username): num = os.urandom(32).hex() wif = cls.to_wif(num) inst = cls(wif, username) inst.key = PrivateKey.from_hex(num) inst.public_key = inst.key.public_key inst.username = username inst.username_signature = base64.b64encode( inst.key.sign(inst.username.encode("utf-8")) ).decode("utf-8") return inst
def __init__(self, wif, username): self.wif = wif self.key = PrivateKey.from_hex(binascii.hexlify( base58.b58decode(wif) )[2:-10].decode()) self.public_key = self.key.public_key self.username = username self.username_signature = self.generate_service_username_signature() self.cipher_key = PBKDF2(hashlib.sha256( self.wif.encode('utf-8') ).hexdigest(), 'salt', 400).read(32)
def test_from_hex(self): assert PrivateKey.from_hex(PRIVATE_KEY_HEX).secret == PRIVATE_KEY_BYTES
def generate_signature_with_private_key(cls, private_key, message): x = ffi.new('long *') x[0] = random.SystemRandom().randint(0, sys.maxint) key = PrivateKey.from_hex(private_key) signature = key.sign(message, custom_nonce=(ffi.NULL, x)) return base64.b64encode(signature)
def generate_deterministic_signature(cls, message): key = PrivateKey.from_hex(Config.private_key) signature = key.sign(message) return base64.b64encode(signature)