text
stringlengths
0
828
Details of the steps for creating the address are outlined in this link:
ERROR: type should be string, got " https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses"
The last step is Base58Check encoding, which is similar to Base64 encoding but
slightly different to create a more human-readable string where '1' and 'l' won't
get confused. More on Base64Check encoding here:
ERROR: type should be string, got " https://en.bitcoin.it/wiki/Base58Check_encoding"
""""""
binary_pubkey = binascii.unhexlify(self.public_key)
binary_digest_sha256 = hashlib.sha256(binary_pubkey).digest()
binary_digest_ripemd160 = hashlib.new('ripemd160', binary_digest_sha256).digest()
binary_version_byte = bytes([0])
binary_with_version_key = binary_version_byte + binary_digest_ripemd160
checksum_intermed = hashlib.sha256(binary_with_version_key).digest()
checksum_intermed = hashlib.sha256(checksum_intermed).digest()
checksum = checksum_intermed[:4]
binary_address = binary_digest_ripemd160 + checksum
leading_zero_bytes = 0
for char in binary_address:
if char == 0:
leading_zero_bytes += 1
inp = binary_address + checksum
result = 0
while len(inp) > 0:
result *= 256
result += inp[0]
inp = inp[1:]
result_bytes = bytes()
while result > 0:
curcode = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'[result % 58]
result_bytes = bytes([ord(curcode)]) + result_bytes
result //= 58
pad_size = 0 - len(result_bytes)
padding_element = b'1'
if pad_size > 0:
result_bytes = padding_element * pad_size + result_bytes
result = ''.join([chr(y) for y in result_bytes])
address = '1' * leading_zero_bytes + result
return address"
671,"def double(self):
""""""
Doubles this point.
Returns:
JacobianPoint: The point corresponding to `2 * self`.
""""""
X1, Y1, Z1 = self.X, self.Y, self.Z
if Y1 == 0:
return POINT_AT_INFINITY
S = (4 * X1 * Y1 ** 2) % self.P
M = (3 * X1 ** 2 + self.a * Z1 ** 4) % self.P
X3 = (M ** 2 - 2 * S) % self.P
Y3 = (M * (S - X3) - 8 * Y1 ** 4) % self.P
Z3 = (2 * Y1 * Z1) % self.P
return JacobianPoint(X3, Y3, Z3)"
672,"def to_affine(self):
""""""
Converts this point to an affine representation.
Returns:
AffinePoint: The affine reprsentation.
""""""
X, Y, Z = self.x, self.y, self.inverse(self.z)
return ((X * Z ** 2) % P, (Y * Z ** 3) % P)"
673,"def double(self):
""""""
Doubles this point.
Returns:
AffinePoint: The point corresponding to `2 * self`.
""""""
X1, Y1, a, P = self.X, self.Y, self.a, self.P
if self.infinity:
return self
S = ((3 * X1 ** 2 + a) * self.inverse(2 * Y1)) % P
X2 = (S ** 2 - (2 * X1)) % P
Y2 = (S * (X1 - X2) - Y1) % P
return AffinePoint(X2, Y2)"
674,"def slope(self, other):
""""""
Determines the slope between this point and another point.
Args:
other (AffinePoint): The second point.
Returns: