Esempio n. 1
0
def get_user_address(step, basepub, steppub, magic=None):
    basepub = b58check_to_hex(basepub)
    steppub = b58check_to_hex(steppub)
    pubkey = multiply_pubkeys(basepub, steppub, step)

    address = pubkey_to_address(
        pubkey) if magic is None else pubkey_to_address(pubkey, magic)
    return address
Esempio n. 2
0
def generate_payment_request(crypto_addr, x509_cert, expires, signer=None, amount=0, memo=None, payment_url=None, merchant_data=None):

    # Setup & Populate PaymentDetails
    payment_details = PaymentDetails()

    # Setup Single PaymentDetails Output
    output = payment_details.outputs.add()
    output.amount = amount * 100000000 # BTC to Satoshis

    if crypto_addr[0] == '1':
        output.script = serialize_script([OP_DUP, OP_HASH160, b58check_to_hex(crypto_addr), OP_EQUALVERIFY, OP_CHECKSIG]).decode('hex')
    else:
        try:
            int(crypto_addr, 16)
            output.script = str(crypto_addr).decode('hex')
        except ValueError:
            output.script = str(crypto_addr)

    # Add current and expiration epoch time values
    payment_details.time = int(datetime.utcnow().strftime('%s'))

    payment_details.expires = expires

    # Handle Various Optional Fields in PaymentDetails
    payment_details.memo = memo if memo else ''
    payment_details.payment_url = payment_url if payment_url else ''
    payment_details.merchant_data = str(merchant_data) if merchant_data else ''

    # Setup & Populate PaymentRequest
    payment_request = PaymentRequest()
    payment_request.payment_details_version = 1
    payment_request.serialized_payment_details = payment_details.SerializeToString()

    # Set PKI Type / Data
    if not x509_cert or not signer:
        payment_request.pki_type = 'none'
        payment_request.pki_data = ''
    else:

        payment_request.pki_type = signer.get_pki_type()
        pki_data = X509Certificates()

        for cert in get_certs(x509_cert):
            pki_data.certificate.append(cert)

        payment_request.pki_data = pki_data.SerializeToString()

    # Sign PaymentRequest
    if signer and x509_cert:
        payment_request.signature = ''
        payment_request.signature = signer.sign(payment_request.SerializeToString())

    # Log Payment Request to Logging System
    logger = PluginManager.get_plugin('LOGGER', config.logger_type)
    logger.log_payment_request(crypto_addr, signer.__class__.__name__, amount, expires, memo, payment_url, merchant_data)

    log.debug('Generated Payment Request [Address: %s | Signer: %s | Amount: %s | Expires: %s | Memo: %s | Payment URL: %s | Merchant Data: %s]' %
              (crypto_addr, signer.__class__.__name__, amount, expires, memo, payment_url, merchant_data))

    return payment_request.SerializeToString()
Esempio n. 3
0
    def __init__(self, private, url=NETVEND_URL, seed=False):
        if seed:
            self._private = pybitcointools.sha256(private)
        else:
            try:
                self._private = pybitcointools.b58check_to_hex(private)
            except AssertionError:
                raise RuntimeError("Invalid private key. Did you mean to set seed=True?")

        self.address = pybitcointools.pubkey_to_address(pybitcointools.privtopub(self._private))
        self.url = url
Esempio n. 4
0
    def __init__(self, private, url=NETVEND_URL, seed=False):
        if seed:
            self._private = pybitcointools.sha256(private)
        else:
            try:
                self._private = pybitcointools.b58check_to_hex(private)
            except AssertionError:
                raise RuntimeError(
                    "Invalid private key. Did you mean to set seed=True?")

        self.address = pybitcointools.pubkey_to_address(
            pybitcointools.privtopub(self._private))
        self.url = url
Esempio n. 5
0
    def __init__(self, private, url, privtype):
        if privtype is PRIVTYPE_SEED:
            self.private = pybitcointools.sha256(private)
        elif privtype is PRIVTYPE_B58CHECK:
            try:
                self.private = pybitcointools.b58check_to_hex(private)
            except AssertionError:
                raise ValueError("Invalid private key")
        elif privtype is PRIVTYPE_HEX:
            if len(private) == 64:
                self.private = private
            else:
                raise ValueError("Invalid private key")
        else:
            # Raise a ValueError, otherwise self.private would not be defined
            raise ValueError("Invalid privtype")

        self.address = pybitcointools.pubkey_to_address(pybitcointools.privtopub(self.private))
        self.url = url
Esempio n. 6
0
 def address_distance(addr1, addr2):
     v1 = int(pbt.b58check_to_hex(addr1), 16)
     v2 = int(pbt.b58check_to_hex(addr2), 16)
     return v1 ^ v2
Esempio n. 7
0
def generate_payment_request(crypto_addr, x509_cert, signer=None, amount=0, expires=None, memo=None, payment_url=None, merchant_data=None):

    # Setup & Populate PaymentDetails
    payment_details = PaymentDetails()

    # Setup Single PaymentDetails Output
    output = payment_details.outputs.add()
    output.amount = amount * 100000000 # BTC to Satoshis

    if crypto_addr[0] == '1':
        output.script = serialize_script([OP_DUP, OP_HASH160, b58check_to_hex(crypto_addr), OP_EQUALVERIFY, OP_CHECKSIG]).decode('hex')
    else:
        try:
            int(crypto_addr, 16)
            output.script = str(crypto_addr).decode('hex')
        except ValueError:
            output.script = str(crypto_addr)

    # Add current and expiration epoch time values
    payment_details.time = int(datetime.utcnow().strftime('%s'))

    if expires:
        if isinstance(expires, int) or isinstance(expires, long):
            payment_details.expires = int((datetime.utcnow() + timedelta(seconds=expires)).strftime('%s'))
        elif isinstance(expires, datetime.__class__):
            payment_details.expires = int(expires.strftime('%s'))
    else:
        payment_details.expires = int((datetime.utcnow() + timedelta(seconds=config.bip70_default_expiration)).strftime('%s'))

    # Handle Various Optional Fields in PaymentDetails
    payment_details.memo = memo if memo else ''
    payment_details.payment_url = payment_url if payment_url else ''
    payment_details.merchant_data = str(merchant_data) if merchant_data else ''

    # Setup & Populate PaymentRequest
    payment_request = PaymentRequest()
    payment_request.payment_details_version = 1
    payment_request.serialized_payment_details = payment_details.SerializeToString()

    # Set PKI Type / Data
    if not x509_cert or not signer:
        payment_request.pki_type = 'none'
        payment_request.pki_data = ''
    else:

        payment_request.pki_type = signer.get_pki_type()
        pki_data = X509Certificates()

        for cert in get_certs(x509_cert):
            pki_data.certificate.append(cert)

        payment_request.pki_data = pki_data.SerializeToString()

    # Sign PaymentRequest
    if signer and x509_cert:
        payment_request.signature = ''
        payment_request.signature = signer.sign(payment_request.SerializeToString())

    # Log Payment Request to Logging System
    logger = PluginManager.get_plugin('LOGGER', config.logger_type)
    logger.log_payment_request(crypto_addr, signer.__class__.__name__, amount, expires, memo, payment_url, merchant_data)

    log.debug('Generated Payment Request [Address: %s | Signer: %s | Amount: %s | Expires: %s | Memo: %s | Payment URL: %s | Merchant Data: %s]' %
              (crypto_addr, signer.__class__.__name__, amount, expires, memo, payment_url, merchant_data))

    return payment_request.SerializeToString()
Esempio n. 8
0
 def address_distance(addr1, addr2):
     v1 = int(pbt.b58check_to_hex(addr1), 16)
     v2 = int(pbt.b58check_to_hex(addr2), 16)
     return v1 ^ v2
Esempio n. 9
0
def get_bcap_address(step):
    basepub = b58check_to_hex(settings.BCAP_BASEPUB)
    steppub = b58check_to_hex(settings.BCAP_STEPPUB)
    pubkey = multiply_pubkeys(basepub, steppub, step)
    address = pubkey_to_ethaddress(pubkey)
    return address