示例#1
0
文件: dashutil.py 项目: Oxodus/Oxodus
def sign_vote(votestr, mnprivkey):
    privatekey = utils.wifToPrivateKey(mnprivkey)
    signingkey = Bip62SigningKey.from_string(privatekey.decode('hex'),
                                             curve=ecdsa.SECP256k1)
    public_key = signingkey.get_verifying_key()
    key = Key.from_text(mnprivkey)
    address = key.address(use_uncompressed=True)
    msghash = utils.double_sha256(utils.msg_magic(votestr))
    signature = signingkey.sign_digest_deterministic(
        msghash,
        hashfunc=hashlib.sha256,
        sigencode=ecdsa.util.sigencode_string)
    assert public_key.verify_digest(signature,
                                    msghash,
                                    sigdecode=ecdsa.util.sigdecode_string)
    for i in range(4):
        sig = base64.b64encode(chr(27 + i) + signature)
        if verify_dash_signature(generator_secp256k1, address, msghash, sig):
            return sig
示例#2
0
def main():
    counter = 0
    try:
        if args.n:
            fp = open("ga1", "a+")
            for i in xrange(args.n):
                print counter
                private_key = "".join(["%x" % randrange(16) for x in range(0, 64)])
                wif = utils.base58CheckEncode(0x80, private_key.decode("hex"))
                address = utils.pubKeyToAddr(utils.privateKeyToPublicKey(utils.wifToPrivateKey(wif)))
                fp.write("PK: " + private_key + "\n" + "WIF: " + wif + "\n" + "ADDR: " + address + "\n")
                counter = counter + 1
            fp.close()
            print "File successfully closed."
    except KeyboardInterrupt:
        print "[!] User Keyboard Interrupt"
        fp.close()
        print "File successfully closed."

    print "Exiting."
    exit()
示例#3
0
def main():
    counter = 0
    try:
        if args.n:
            fp = open("ga1", 'a+')
            for i in xrange(args.n):
                print counter
                private_key = ''.join(
                    ['%x' % randrange(16) for x in range(0, 64)])
                wif = utils.base58CheckEncode(0x80, private_key.decode('hex'))
                address = utils.pubKeyToAddr(
                    utils.privateKeyToPublicKey(utils.wifToPrivateKey(wif)))
                fp.write("PK: " + private_key + '\n' + "WIF: " + wif + '\n' +
                         "ADDR: " + address + '\n')
                counter = counter + 1
            fp.close()
            print "File successfully closed."
    except KeyboardInterrupt:
        print "[!] User Keyboard Interrupt"
        fp.close()
        print "File successfully closed."

    print "Exiting."
    exit()
示例#4
0
def index():
    form = TransactionForm(fee=utils.convertSatoshistoBCH(DEFAULT_FEE))
    if request.method == 'POST' and form.validate_on_submit():
        # Get Sender Legacy Details
        senderResp = requests.get(API_ADDR_URL + form.senderAddr.data)
        senderDetails = senderResp.json()['data'][form.senderAddr.data]
        if senderDetails['address']['formats'] is None:
            return render_template(
                'index.html',
                form=form,
                error='Sender address \'{}\' is invalid'.format(
                    form.senderAddr.data))
        senderLegacyAddress = str(
            senderDetails['address']['formats']['legacy'])
        senderCashAddress = str(
            senderDetails['address']['formats']['cashaddr'])
        transactions = senderDetails['transactions']
        # Check if WIF compatible with sender Address
        if not utils.checkWifAddressCompatibility(str(form.wif.data),
                                                  senderLegacyAddress):
            return render_template(
                'index.html',
                form=form,
                error='WIF is not compatible with address : {}.'.format(
                    senderLegacyAddress))
        # Check if balance is sufficient
        initialBalance = float(senderDetails['address']['balance'])
        logging.debug('Is {} > {} + {} ?'.format(
            initialBalance, utils.convertBCHtoSatoshis(form.amount.data),
            utils.convertBCHtoSatoshis(form.fee.data)))
        if utils.convertSatoshistoBCH(
                initialBalance) < form.amount.data + form.fee.data:
            return render_template(
                'index.html',
                form=form,
                error=
                'Insufficient balance. You only have {} BCH (< {} BCH + fee)  on this address.'
                .format(utils.convertSatoshistoBCH(initialBalance),
                        form.amount.data))
        # Get Receiver Details
        receiverResp = requests.get(API_ADDR_URL + form.receiverAddr.data)
        receiverDetails = receiverResp.json()['data'][form.receiverAddr.data]
        if receiverDetails['address']['formats'] is None:
            return render_template(
                'index.html',
                form=form,
                error='Receiver address \'{}\' is invalid'.format(
                    form.receiverAddr.data))
        receiverLegacyAddress = str(
            receiverDetails['address']['formats']['legacy'])
        # Get Transaction Inputs
        inputs = buildTxIns(senderCashAddress, transactions)
        # Get Transaction Outputs
        outputs = buildTxOuts(senderLegacyAddress, receiverLegacyAddress,
                              initialBalance,
                              utils.convertBCHtoSatoshis(form.amount.data),
                              utils.convertBCHtoSatoshis(form.fee.data))

        # Create Transaction
        transaction = Transaction(utils.wifToPrivateKey(str(form.wif.data)),
                                  senderLegacyAddress, inputs, outputs)
        signedTrx = transaction.buildSignedTransaction()
        logging.info('Raw Transaction {}'.format(binascii.hexlify(signedTrx)))

        # Broadcast Transaction
        response = requests.post(API_SEND_TRX,
                                 json={'rawtx': binascii.hexlify(signedTrx)})
        if response.status_code >= 400:
            return render_template('index.html',
                                   form=form,
                                   error=response.text)
        return render_template('result.html',
                               details=binascii.hexlify(
                                   utils.doubleSHA256(signedTrx)[::-1]))

    return render_template('index.html', form=form, error='')
示例#5
0
文件: key.py 项目: fpitlok/getbtc
if q == 1:
    priv_key = raw_input("[ ] Enter Private Key: ")
    address = utils.pubKeyToAddr(utils.privateKeyToPublicKey(priv_key))
    print
    print "Address: " + address
    print "Private Key: " + priv_key
    print "Wallet Import Format Private Key: " + utils.privateKeyToWif(
        priv_key)
    print "Public Key: " + utils.privateKeyToPublicKey(priv_key)
    info = utils.getInfo(address)
    if info.balance() > 0:
        info.display()

elif q == 2:
    wif_priv_key = raw_input("[ ] Enter Wallet Import Format Private Key: ")
    address = utils.pubKeyToAddr(
        utils.privateKeyToPublicKey(utils.wifToPrivateKey(wif_priv_key)))
    print
    print "Address: " + address
    print "Private key: " + utils.wifToPrivateKey(wif_priv_key)
    print "Wallet Import Format Private Key: " + wif_priv_key
    print "Public Key: " + utils.privateKeyToPublicKey(
        utils.wifToPrivateKey(wif_priv_key))
    info = utils.getInfo(address)
    if info.balance() > 0:
        info.display()

elif q == 3:
    pub_key = raw_input("[ ] Enter Public Key: ")
示例#6
0
文件: key.py 项目: imstumbles/getbtc
q = int(raw_input("1:\tPrivate Key\n2:\tWallet Import Format Private Key\n3:\tPublic Key\n\n[ ] Enter selection: "))

print 

if q == 1:
    priv_key = raw_input("[ ] Enter Private Key: ")
    address = utils.pubKeyToAddr(utils.privateKeyToPublicKey(priv_key))
    print
    print "Address: " + address
    print "Private Key: " + priv_key
    print "Wallet Import Format Private Key: " + utils.privateKeyToWif(priv_key)
    print "Public Key: " + utils.privateKeyToPublicKey(priv_key)
    info = utils.getInfo(address)
    if info.balance() > 0:
        info.display()

elif q == 2:
    wif_priv_key = raw_input("[ ] Enter Wallet Import Format Private Key: ")
    address = utils.pubKeyToAddr(utils.privateKeyToPublicKey(utils.wifToPrivateKey(wif_priv_key)))
    print
    print "Address: " + address
    print "Private key: " + utils.wifToPrivateKey(wif_priv_key)
    print "Wallet Import Format Private Key: " + wif_priv_key
    print "Public Key: " + utils.privateKeyToPublicKey(utils.wifToPrivateKey(wif_priv_key))
    info = utils.getInfo(address)
    if info.balance() > 0:
        info.display()

elif q == 3:	
    pub_key = raw_input("[ ] Enter Public Key: ")