Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# -*- coding: utf-8 -*-
from __future__ import print_function
import contextlib
import timeit
import secp256k1
from raiden.utils import sha3, privatekey_to_address
from raiden.messages import decode
from raiden.messages import (
Ack, ConfirmTransfer, DirectTransfer, Lock, MediatedTransfer, Ping,
RefundTransfer, Secret, SecretRequest, TransferTimeout,
)
GLOBAL_CTX = secp256k1.lib.secp256k1_context_create(secp256k1.ALL_FLAGS)
PRIVKEY_BIN = 'x' * 32
PRIVKEY = secp256k1.PrivateKey(PRIVKEY_BIN, ctx=GLOBAL_CTX, raw=True)
ADDRESS = privatekey_to_address(PRIVKEY_BIN)
HASH = sha3(PRIVKEY)
ITERATIONS = 1000000 # timeit default
def run_timeit(message_name, message, iterations=ITERATIONS):
data = message.encode()
def test_encode():
message.encode()
def test_decode():
decode(data)
#!/usr/bin/python
from .py2specials import *
from .py3specials import *
import binascii
import hashlib
import re
import sys
import os
import base64
import time
import random
import hmac
import secp256k1
#Global context for secp256k1 operations (helps with performance)
ctx = secp256k1.lib.secp256k1_context_create(secp256k1.ALL_FLAGS)
#Standard prefix for Bitcoin message signing.
BITCOIN_MESSAGE_MAGIC = '\x18' + 'Bitcoin Signed Message:\n'
"""A custom nonce function acting as a pass-through.
Only used for reusable donation pubkeys (stealth).
"""
from cffi import FFI
ffi = FFI()
ffi.cdef('static int nonce_function_rand(unsigned char *nonce32,'
'const unsigned char *msg32,const unsigned char *key32,'
'const unsigned char *algo16,void *data,unsigned int attempt);')
ffi.set_source("_noncefunc",
"""
#!/usr/bin/python
from .py2specials import *
from .py3specials import *
import binascii
import hashlib
import re
import sys
import os
import base64
import time
import random
import hmac
import secp256k1
ctx = secp256k1.lib.secp256k1_context_create(secp256k1.ALL_FLAGS)
def privkey_to_address(priv, from_hex=True, magicbyte=0):
return pubkey_to_address(privkey_to_pubkey(priv, from_hex), magicbyte)
privtoaddr = privkey_to_address
# Hashes
def bin_hash160(string):
intermed = hashlib.sha256(string).digest()
return hashlib.new('ripemd160', intermed).digest()
def hash160(string):
return safe_hexlify(bin_hash160(string))
def bin_sha256(string):
binary_data = string if isinstance(string, bytes) else bytes(string,