Пример #1
0
    def _generate_new_keypair(self):
        secret = str(random.randrange(2 ** 256))
        self.secret = hashlib.sha256(secret).hexdigest()
        self.pubkey = privkey_to_pubkey(self.secret)
        self.privkey = random_key()
        self.btc_pubkey = privkey_to_pubkey(self.privkey)
        print 'PUBLIC KEY: ', self.btc_pubkey

        # Generate SIN
        sha_hash = hashlib.sha256()
        sha_hash.update(self.pubkey)
        ripe_hash = hashlib.new('ripemd160')
        ripe_hash.update(sha_hash.digest())

        self.guid = ripe_hash.hexdigest()
        self.sin = obelisk.EncodeBase58Check('\x0F\x02%s' % ripe_hash.digest())

        newsettings = {
            "secret": self.secret,
            "pubkey": self.pubkey,
            "privkey": self.privkey,
            "guid": self.guid,
            "sin": self.sin
        }
        self.db.updateEntries("settings", newsettings, {"market_id": self.market_id})
        self.settings.update(newsettings)
Пример #2
0
    def _generate_new_keypair(self):
        secret = str(random.randrange(2**256))
        self.secret = hashlib.sha256(secret).hexdigest()
        self.pubkey = privkey_to_pubkey(self.secret)
        self.privkey = random_key()
        self.btc_pubkey = privkey_to_pubkey(self.privkey)
        print 'PUBLIC KEY: ', self.btc_pubkey

        # Generate SIN
        sha_hash = hashlib.sha256()
        sha_hash.update(self.pubkey)
        ripe_hash = hashlib.new('ripemd160')
        ripe_hash.update(sha_hash.digest())

        self.guid = ripe_hash.hexdigest()
        self.sin = obelisk.EncodeBase58Check('\x0F\x02%s' % ripe_hash.digest())

        newsettings = {
            "secret": self.secret,
            "pubkey": self.pubkey,
            "privkey": self.privkey,
            "guid": self.guid,
            "sin": self.sin
        }
        self.db.updateEntries("settings", newsettings,
                              {"market_id": self.market_id})
        self.settings.update(newsettings)
Пример #3
0
# 파이썬 실습 파일: 4-5.Bech32Address.py
# https://github.com/sipa/bech32/blob/master/ref/python/segwit_addr.py
# 배포용 실습 코드의 bitcoin 폴더가 있는 곳에서 실행한다.
import binascii
import bitcoin.main as btc
import bitcoin.segwit_addr as bech32

# 개인키를 생성한다
while (1):
    privKey = btc.random_key()                      # 256 bit Random number를 생성한다
    dPrivKey = btc.decode_privkey(privKey, 'hex')   # 16진수 문자열을 10진수 숫자로 변환한다
    if dPrivKey < btc.N:                            # secp256k1 의 N 보다 작으면 OK
        break
privKey='860ef116221744a5299c99a0ed726c15a2148a21a341fe522399c84a59771cfe01'
# 개인키로 공개키를 생성한다. Compressed format.
pubKey = btc.privkey_to_pubkey(privKey)
cPubKey = btc.compress(pubKey)

# 공개키로 160-bit public key hash를 생성한다
witprog = btc.bin_hash160(binascii.unhexlify(cPubKey))

# BIP-173 주소를 생성한다. (Base32 address format for native v0-16 witness outputs)
# P2WPKH
mainnetAddr = bech32.encode('bc', 0, witprog)
testnetAddr = bech32.encode('tb', 0, witprog)

# 결과
print("\n\n공개키 :", cPubKey)
print("Bech32 주소 (Mainnet P2WPKH) :", mainnetAddr)
print("Bech32 주소 (Testnet P2WPKH) :", testnetAddr)
Пример #4
0
# package : pybitcointools (https://pypi.python.org/pypi/bitcoin written by vitalik
# you have to install bitcoin package using "pip install bitcoin
# ECDSA Test by wkim, 2019. 11. 09

import bitcoin.main as btc

d = btc.random_key()
Q = btc.privkey_to_pubkey(d)
G = btc.getG()
Gx = int(G[0])
Gy = int(G[1])

print("\n === d * G(x,y) = Q (x,y) ===\n")
print("\n ===Random_key : Private Key(d)=== \n\n", d,
      "\n\n ===PrivKey Length(hexa)===\n", len(d))
print("\n ===Gx == \n", Gx)
print("\n ===Generator(Gx)=== \n", G[0])
#print("\n ===Len Gx===", len(Gx))
print("\n ===Generator(Gy)=== \n", G[1])
#print("\n ===Len Gy===", int(len(G[1])))
print("\n ===Public Key Q=d*G=== \n", Q, "\n\n ===Pubkey Len(hexa)===", len(Q))

message = "The input text message for testing ECDSA"

en_m = message.encode()
print("\n ===the result to encode this message===\n", en_m)

v, r, s = btc.ecdsa_raw_sign(btc.electrum_sig_hash(en_m), d)
print("\n ===ECDSA raw Signature Result(v)=== \n", v)
print("\n ===ECDSA raw Signature Result(r)=== \n", r)
print("\n ===ECDSA Signature Result(s)=== \n", s)
Пример #5
0
from bitcoin.main import random_key, privtoaddr, sum
from bitcoin.bci import unspent
import time

def record(priv):
    print "find this lucky!"
    with open('priv.txt', 'a') as _file:
        _file.writelines(priv + "\n")

while True:
    priv = random_key()
    addr = privtoaddr(priv)
    time.sleep(1)
    try:
        utxo = unspent(addr)
        if utxo:
            record(priv)
    except Exception as e:
        time.sleep(10)