Python 用于从 Scriptsig 中提取 R & S 值的脚本
Python Script for Extracting R & S Values from Scriptsig
我已经阅读了一些帖子,我熟悉 scriptsig 的格式以及如何从中提取相关信息。我遇到的问题是将其放入代码中。我读过这些帖子:
https://bitcoin.stackexchange.com/questions/58853/how-do-you-figure-out-the-r-and-s-out-of-a-signature-using-python
https://bitcoin.stackexchange.com/questions/2376/ecdsa-r-s-encoding-as-a-signature
我有一个 scriptsig 列表,我有一个函数(到目前为止)在 scriptsig 字符串上使用切片:
def scriptsig_to_ecdsa_sig(asn_sig):
strip1 = asn_sig[6:] #Remove first 6 characters
if strip1[:2] == "20" #Read next two characters to determine length of r
return {
'r': some list,
's': some list}
这是最好的路线吗?如果是这样,最好的完成方式是什么?
想通了:
from pyasn1.codec.der import decoder as asn1der
int_value = asn1der.decode(asn_sig.decode('hex')[1:]) #asn_sig is the scriptsig hex
long(int_value[0][0]) #R Value in int form
long(int_value[0][1]) #S Value in int form
我已经阅读了一些帖子,我熟悉 scriptsig 的格式以及如何从中提取相关信息。我遇到的问题是将其放入代码中。我读过这些帖子: https://bitcoin.stackexchange.com/questions/58853/how-do-you-figure-out-the-r-and-s-out-of-a-signature-using-python https://bitcoin.stackexchange.com/questions/2376/ecdsa-r-s-encoding-as-a-signature
我有一个 scriptsig 列表,我有一个函数(到目前为止)在 scriptsig 字符串上使用切片:
def scriptsig_to_ecdsa_sig(asn_sig):
strip1 = asn_sig[6:] #Remove first 6 characters
if strip1[:2] == "20" #Read next two characters to determine length of r
return {
'r': some list,
's': some list}
这是最好的路线吗?如果是这样,最好的完成方式是什么?
想通了:
from pyasn1.codec.der import decoder as asn1der
int_value = asn1der.decode(asn_sig.decode('hex')[1:]) #asn_sig is the scriptsig hex
long(int_value[0][0]) #R Value in int form
long(int_value[0][1]) #S Value in int form