Ejemplo n.º 1
0
    def _generate(self, privateKey='', seed=''):
        self.seed = seed
        if not privateKey and not seed:
            wordCount = 2048
            words = []
            for i in range(5):
                r = crypto.bytes2str(os.urandom(4))
                x = (ord(r[3])) + (ord(r[2]) << 8) + (ord(r[1]) << 16) + (
                    ord(r[0]) << 24)
                w1 = x % wordCount
                w2 = ((int(x / wordCount) >> 0) + w1) % wordCount
                w3 = ((int((int(x / wordCount) >> 0) / wordCount) >> 0) +
                      w2) % wordCount
                words.append(wordList[w1])
                words.append(wordList[w2])
                words.append(wordList[w3])
            self.seed = ' '.join(words)

        seedHash = crypto.hashChain(('\0\0\0\0' + self.seed).encode('utf-8'))
        accountSeedHash = crypto.sha256(seedHash)
        if not privateKey:
            privKey = curve.generatePrivateKey(accountSeedHash)
        else:
            privKey = base58.b58decode(privateKey)
        pubKey = curve.generatePublicKey(privKey)
        unhashedAddress = chr(1) + str(
            pywaves.CHAIN_ID) + crypto.hashChain(pubKey)[0:20]
        addressHash = crypto.hashChain(crypto.str2bytes(unhashedAddress))[0:4]
        self.address = base58.b58encode(
            crypto.str2bytes(unhashedAddress + addressHash))
        self.publicKey = base58.b58encode(pubKey)
        self.privateKey = base58.b58encode(privKey)
Ejemplo n.º 2
0
def create_waves_privkey(publicKey='', privateKey='', seed='', nonce=0):
    if not publicKey and not privateKey and not seed:
        wordCount = 2048
        words = []
        for i in range(5):
            r = crypto.bytes2str(os.urandom(4))
            x = (ord(r[3])) + (ord(r[2]) << 8) + (ord(r[1]) << 16) + (
                ord(r[0]) << 24)
            w1 = x % wordCount
            w2 = ((int(x / wordCount) >> 0) + w1) % wordCount
            w3 = ((int(
                (int(x / wordCount) >> 0) / wordCount) >> 0) + w2) % wordCount
            words.append(pw.address.wordList[w1])
            words.append(pw.address.wordList[w2])
            words.append(pw.address.wordList[w3])
        seed = ' '.join(words)
    if publicKey:
        pubKey = base58.b58decode(publicKey)
        privKey = ""
    else:
        seedHash = crypto.hashChain(
            struct.pack(">L", nonce) + crypto.str2bytes(seed))
        accountSeedHash = crypto.sha256(seedHash)
        if not privateKey:
            privKey = curve.generatePrivateKey(accountSeedHash)
        else:
            privKey = base58.b58decode(privateKey)
        pubKey = curve.generatePublicKey(privKey)
    unhashedAddress = chr(1) + str(
        pw.CHAIN_ID) + crypto.hashChain(pubKey)[0:20]
    addressHash = crypto.hashChain(crypto.str2bytes(unhashedAddress))[0:4]
    address = base58.b58encode(crypto.str2bytes(unhashedAddress + addressHash))
    publicKey = base58.b58encode(pubKey)
    if privKey != "":
        privateKey = base58.b58encode(privKey)
    return publicKey, privateKey, address
Ejemplo n.º 3
0
# CHECK:print('Expected result:\n3kMEhU5z3v8bmer1ERFUUhW58Dtuhyo9hE5vrhjqAWYT')

#compute Public Key
k_pub = curve.generatePublicKey(k_pr)
#print('Computed Public Key:\n{}'.format(b58encode(k_pub)))
# CHECK:print('Expected result:\nHBqhfdFASRQ5eBBpu2y6c6KKi1az6bMx8v1JxX4iW1Q8')

#compute Address
ver = bytes([1])
scheme = b'\x54'  # \x57 for mainnet, \x54 for testnet
k_pub_hash = SecureHash(k_pub)[:20]
checksum = SecureHash(ver + scheme + k_pub_hash)[0:4]
address = ver + scheme + k_pub_hash + checksum
#print('Computed Address:\n{}\n'.format(b58encode(address)))

unhashedAddress = chr(1) + str('T') + crypto.hashChain(k_pub)[0:20]
addressHash = crypto.hashChain(crypto.str2bytes(unhashedAddress))[0:4]
address2 = crypto.str2bytes(unhashedAddress + addressHash)

pywaves.setNode(node='http://52.30.47.67:6869', chain='testnet')

myAddress = pywaves.Address(seed=seed_str)

#print(myAddress.balance())
#myAddress.sendWaves(recipient = pywaves.Address('3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'), amount = 300000000)

#list of components in bytes to be assembled in transaction or block etc.
comp = {}

#constructing Tx
comp = {
Ejemplo n.º 4
0
def pubkey_to_address(pubkey):
    pubkey_bytes = base58.b58decode(pubkey)
    unhashed_address = chr(1) + str('L') + crypto.hashChain(pubkey_bytes)[0:20]
    address_hash = crypto.hashChain(crypto.str2bytes(unhashed_address))[0:4]
    return base58.b58encode(crypto.str2bytes(unhashed_address + address_hash))