Comments (4)
The database we’re using includes bitcoin addresses in P2PKH (address starts with 1), P2SH (address start with 3), and P2WPKH (address start with bc1) formats.
The algorithm we’re using only generates P2PKH addresses and has been really optimized to do it as fast as possible. Since only addresses that start with 1 get generated, all the other bitcoin address types can be ignored when we load the database.
We could make an extension to include the other types. But P2PKH is considered the legacy address format that older forgotten whale bitcoin wallets are in. And doing the other formats would take a bunch of time
from plutus.
Got it. Thanks for the clarification and the program. Running great. I've added a few things to show progress that don't seem to slow anything down. Checked for various ways to speed it up, but it seems you've done a good job already. :-)
I figure I am guaranteed to find a code within the next 1000 million years.
from plutus.
Testing this: (sorry the formatting was lost in this post)
The public_key_to_p2pkh_address function generates a P2PKH address by hashing the public key using RIPEMD-160, prefixing the resulting hash with '00', and then base58 encoding the result.
The public_key_to_p2sh_address function generates a P2SH address by creating a redeem script that pushes the hash of the public key onto the stack, and then base58 encoding the redeem script with a prefix of '05'.
The public_key_to_p2wpkh_address function generates a P2WPKH address by hashing the public key using RIPEMD-160, prefixing the resulting hash with '0014', and then base58 encoding the result with a prefix of 'bc'.
The P2WPKH address format is compatible with the Bech32 address format (starting with 'bc1'), which is the preferred address format for SegWit transactions. However, this implementation uses the base58 encoding format for consistency with the other address formats.
import binascii
import hashlib
import os
import base58
from fastecdsa import keys, curve
from bitcoinlib.encoding import b58encode_check
from bitcoinlib.keys import HDKey, Key
def generate_private_key():
return binascii.hexlify(os.urandom(32)).decode('utf-8').upper()
def private_key_to_public_key(private_key, fastecdsa):
if fastecdsa:
key = keys.get_public_key(int('0x' + private_key, 0), curve.secp256k1)
return '04' + (hex(key.x)[2:] + hex(key.y)[2:]).zfill(128)
else:
pk = Key(privkey=bytes.fromhex(private_key))
return pk.pubkey.serialize(compressed=False).hex()
def public_key_to_p2pkh_address(public_key):
alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
var = hashlib.new('ripemd160')
encoding = binascii.unhexlify(public_key.encode())
var.update(hashlib.sha256(encoding).digest())
var_encoded = ('00' + var.hexdigest()).encode()
digest = hashlib.sha256(binascii.unhexlify(var_encoded)).digest()
var_hex = '00' + var.hexdigest() + hashlib.sha256(digest).hexdigest()[0:8]
count = [char != '0' for char in var_hex].index(True) // 2
n = int(var_hex, 16)
output = []
while n > 0:
n, remainder = divmod(n, 58)
output.append(alphabet[remainder])
for i in range(count): output.append(alphabet[0])
return ''.join(output[::-1])
def public_key_to_p2sh_address(public_key):
redeem_script = '76a914' + hashlib.new('ripemd160', hashlib.sha256(binascii.unhexlify(public_key)).digest()).hexdigest() + '88ac'
return b58encode_check(bytes.fromhex('05' + redeem_script)).decode('utf-8')
def public_key_to_p2wpkh_address(public_key):
witness_program = hashlib.new('ripemd160', hashlib.sha256(binascii.unhexlify(public_key)).digest()).hexdigest()
return b58encode_check(bytes.fromhex('0014' + witness_program)).decode('utf-8')
from plutus.
Y
from plutus.
Related Issues (20)
- ERROR: Could not build wheels for fastecdsa, which is required to install pyproject.toml-based projects HOT 2
- what it is when plutus.py is working
- How to solve Value Problem base 16 (Linux) HOT 3
- r there discord community of this ? HOT 1
- not working HOT 1
- help attribute
- not working
- Substring option HOT 1
- Locating output plutus.txt in ubuntu terminal HOT 1
- Tron brute force
- I got this problem! HOT 1
- UnicodeDecodeError: 'gbk' codec can't decode byte 0xa5 in position 79: illegal multibyte sequence
- Getting killed message
- Fix for ValueError on Windows Machines. HOT 2
- need a perfect function HOT 7
- Plutus for cuda
- why?
- Traceback (most recent call last): HOT 1
- processes spawned: 4 for two days now HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plutus.