It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.
The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.
We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.
import hmac
from hashlib import sha256
def bits_to_int(b: bytes, qlen: int):
# https://www.rfc-editor.org/rfc/rfc6979 section 2.3.2.
blen = len(b) * 8
b_int = int.from_bytes(b, 'big')
if blen > qlen:
b_int = b_int >> blen - qlen
return b_int
def int_to_oct(x: int, rolen: int) -> bytes:
# https://www.rfc-editor.org/rfc/rfc6979 section 2.3.3.
xolen = x.bit_length() >> 3
x_hex = f'{x:x}'
if xolen < rolen:
x_hex = f'{x:0>{rolen*2}x}'
elif xolen > rolen:
x_hex = x_hex[(xolen - rolen)*2:]
return bytes.fromhex(x_hex)
def bits_to_oct(b: bytes, q: int, qlen: int, rolen: int) -> bytes:
# https://www.rfc-editor.org/rfc/rfc6979 section 2.3.4.
z1 = bits_to_int(b, qlen)
z2 = z1 - q
if z2 < 0:
z2 = z1
return int_to_oct(z2, rolen)
# H(m) - hash of the message
def rfc_sign(x: int, m: int, q: int):
qlen = q.bit_length()
qolen = qlen >> 3
rolen = qlen + 7 >> 3
h1 = m.to_bytes(32, 'big')
V = b'\x01' * 32
K = b'\x00' * 32
m1 = b'\x00' + int_to_oct(x, rolen) + bits_to_oct(h1, q, qlen, rolen)
m2 = b'\x01' + int_to_oct(x, rolen) + bits_to_oct(h1, q, qlen, rolen)
K = hmac.new(K, digestmod=sha256)
K.update(V + m1)
K = K.digest()
V = hmac.new(K, V, digestmod=sha256).digest()
K = hmac.new(K, digestmod=sha256)
K.update(V + m2)
K = K.digest()
V = hmac.new(K, V, digestmod=sha256).digest()
while True:
T = b''
while len(T) < qolen:
V = hmac.new(K, V, digestmod=sha256).digest()
T = T + V
k = bits_to_int(T, qlen)
if 0 < k < q:
return k
K = hmac.new(K, digestmod=sha256)
K.update(V + b'\x00')
K = K.digest()
V = hmac.new(K, V, digestmod=sha256).digest()
if __name__ == '__main__':
h1 = int(sha256(b'sample').hexdigest(), 16)
q = 0x4000000000000000000020108A2E0CC0D99F8A5EF
x = 0x09A4D6792295A7F730FC3F2B49CBC0F62E862272F
qlen = q.bit_length()
rolen = (qlen + 7) >> 3
rlen = rolen * 8
print(hex(rfc_sign(x, h1, q)))
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from piewallet import PieWallet
>>> my_wallet = PieWallet()
>>> address = my_wallet.address
>>> message = 'hello'
>>> privkey = my_wallet.private_key
>>> # non-deterministic signing
>>> my_wallet.sign_message(address, message)
'H7eHPZ0VELgy0uDdpT+QO5KZdGWmXskaQ5imO4Ur6oUoAyQYADCIEet59UoNUVnkBploYtBYoCzZiIeW2qf6zzk='
>>> # one more time to show it produces a different signature
>>> my_wallet.sign_message(address, message)
'H6bcqqu2NV4IYfazxFs9MGRLu0NZZ0SKwTQrgxFFgknVIs0fTXiVJptnAndR5YNgaasO9Dt/jBCcduvv24dhCPU='
>>> # deterministic signing
>>> my_wallet.sign_message(address, message, deterministic=True)
'IFAlCd4P86pKHtKdhyWGyOAi9oGx2fi4FEUK3IwgvtEgElZbE7IvdnpnrDRQ7tMAHzKCw2Lr24QflcUOYGA4dn0='
>>> # one more time to show it produces the same signature
>>> my_wallet.sign_message(address, message, deterministic=True)
'IFAlCd4P86pKHtKdhyWGyOAi9oGx2fi4FEUK3IwgvtEgElZbE7IvdnpnrDRQ7tMAHzKCw2Lr24QflcUOYGA4dn0='
\x18Bitcoin Signed Message:\n
def varint(length: int):
# https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer
if length < 0xFD:
return length.to_bytes(1, 'little')
elif length <= 0xFFFF:
return b'\0xFD' + length.to_bytes(2, 'little')
elif length <= 0xFFFFFFFF:
return b'\0xFE' + length.to_bytes(4, 'little')
elif length <= 0xFFFFFFFFFFFFFFFF:
return b'\0xFF' + length.to_bytes(8, 'little')
else:
raise MessageError(f'Message is too lengthy: {length}')
def msg_magic(message: str) -> bytes:
return b'\x18Bitcoin Signed Message:\n' + varint(len(message)) + message.encode('utf-8')
\x18Bitcoin Signed Message:\n
>>> message = 'Hello World'
>>> address = my_wallet.native_segwit_address
>>> my_wallet.bitcoin_message(address, message)
-----BEGIN BITCOIN SIGNED MESSAGE-----
Hello World
-----BEGIN BITCOIN SIGNATURE-----
bc1q0xgv8nk93rxvkwttx5c69k3fyf9w48pckac5ld
J2P0cOVIEn+5tPIU8RC9vMXLTW2dLD1fW7ZK6egzhLwjBUIm1vIxBw0Hs4ezONbnUKliun5Ye2wFtLhTHOQg7bA=
-----END BITCOIN SIGNATURE-----
>>> sig = 'J2P0cOVIEn+5tPIU8RC9vMXLTW2dLD1fW7ZK6egzhLwjBUIm1vIxBw0Hs4ezONbnUKliun5Ye2wFtLhTHOQg7bA='
>>> my_wallet.verify_message(address, message, sig)
True
>>>
-----BEGIN BITCOIN SIGNED MESSAGE-----
Messages
-----BEGIN BITCOIN SIGNATURE-----
Version: Bitcoin-qt (1.0)
Address: 1CwyZx1qsVmyCMZuJ8dsauJ2jGzQuioSCq
HzltDw7ksvwyDeInbgT8/sqUO8JYO+8jobvonXCIHUBOYtMxkyLaQrTTIOJbOoidoquVD6+21NQwA0MZiqvuw5U=
-----END BITCOIN SIGNATURE-----