Hi
My question went like this
I understand asserts in python. but I didn't understand the first '48' part.
my aim is to separate the "signature" and separate it as in the link below, of course together with the PubKey
Can you give me information about conditions (assert) that will help me?
Thanks.
information that helps me https://bitcoin.stackexchange.com/questions/58853/how-do-you-figure-out-the-r-and-s-out-of-a-signature-using-pythontype :pubkeyhash
spending_signature_hex : 483045022100cbee7b355c737bccdaaaf566b52e07c6e560fa33861b3035d37feffad94f66e6022
053114a529ab13eba906f9e08288bcf02dd5142ae0ecb117f10d54f56868443af014104d720973d
f5c090aa1dd17adefd9f575baa2f0547dd2913fb4982bf423f1cf82623b700e0d1b7f2b7b5dcfa9
301f8c197dd0b601204d00e02b544251c5d9ac45a
information I want to parse r = 00cbee7b355c737bccdaaaf566b52e07c6e560fa33861b3035d37feffad94f66e6
s = 53114a529ab13eba906f9e08288bcf02dd5142ae0ecb117f10d54f56868443af
PubKey= 04d720973df5c090aa1dd17adefd9f575baa2f0547dd2913fb4982bf423f1cf82623b700e0d1b7f
2b7b5dcfa9301f8c197dd0b601204d00e02b544251c5d9ac45a
def parse_element(hex_str, offset, element_size):
"""
:param hex_str: string to parse the element from.
:type hex_str: hex str
:param offset: initial position of the object inside the hex_str.
:type offset: int
:param element_size: size of the element to extract.
:type element_size: int
:return: The extracted element from the provided string, and the updated offset after extracting it.
:rtype tuple(str, int)
"""
return hex_str[offset:offset+element_size], offset+element_size
def dissect_signature(hex_sig):
"""
Extracts the r, s and ht components from a Bitcoin ECDSA signature.
:param hex_sig: Signature in hex format.
:type hex_sig: hex str
:return: r, s, t as a tuple.
:rtype: tuple(str, str, str)
"""
offset = 0
# Check the sig contains at least the size and sequence marker
assert len(hex_sig) > 4, "Wrong signature format."
sequence, offset = parse_element(hex_sig, offset, 2)
# Check sequence marker is correct
assert sequence == '30', "Wrong sequence marker."
signature_length, offset = parse_element(hex_sig, offset, 2)
# Check the length of the remaining part matches the length of the signature + the length of the hashflag (1 byte)
assert len(hex_sig[offset:])/2 == int(signature_length, 16) + 1, "Wrong length."
# Get r
marker, offset = parse_element(hex_sig, offset, 2)
assert marker == '02', "Wrong r marker."
len_r, offset = parse_element(hex_sig, offset, 2)
len_r_int = int(len_r, 16) * 2 # Each byte represents 2 characters
r, offset = parse_element(hex_sig, offset, len_r_int)
# Get s
marker, offset = parse_element(hex_sig, offset, 2)
assert marker == '02', "Wrong s marker."
len_s, offset = parse_element(hex_sig, offset, 2)
len_s_int = int(len_s, 16) * 2 # Each byte represents 2 characters
s, offset = parse_element(hex_sig, offset, len_s_int)
# Get ht
ht, offset = parse_element(hex_sig, offset, 2)
assert offset == len(hex_sig), "Wrong parsing."
return r, s, ht
example_sig = None # insert_sig_here
r, s, ht = dissect_signature(example_sig)
print "r: %s\ns: %s\nht: %s\n" % (r, s, ht)