从Scriptsig中提取R&S值的Python脚本

2024-09-30 06:17:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我读过一些文章,我熟悉scriptsig是如何格式化的,以及如何从中提取相关信息。我遇到的问题是把它放入代码中。我读过这些帖子: https://bitcoin.stackexchange.com/questions/58853/how-do-you-figure-out-the-r-and-s-out-of-a-signature-using-pythonhttps://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}

这是最好的路线吗?如果是这样的话,最好的方法是什么?在


Tags: oftohttpscomoutecdsabitcoinquestions
1条回答
网友
1楼 · 发布于 2024-09-30 06:17:56

弄明白了:

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

相关问题 更多 >

    热门问题