为什么 Blockcypher signer tool return 比 bip32 dart 包多了一些字符?

Why does Blockcypher signer tool return some extra characters than bip32 dart package?

我正在尝试签署交易框架 Blockcypher returns,以便在 https://www.blockcypher.com/dev/bitcoin/#creating-transactions.

之后发送它

对于这个例子,我将使用完全不安全的 'raw raw raw raw raw raw raw raw raw raw raw raw' 助记符,它使用 dart bip32 包创建带有私钥 0x05a2716a8eb37eb2aaa72594573165349498aa6ca20c71346fb15d82c0cbbf7c 和地址 mpQfiFFq7SHvzS9ebxMRGVohwHTRJJf9ra1=15[].[46] 的 BIP32

Blockcypher Tx 骨架 tosign1cbbb4d229dcafe6dc3363daab8de99d6d38b043ce62b7129a8236e40053383e.

使用Blockcypher signer tool

$ ./signer 1cbbb4d229dcafe6dc3363daab8de99d6d38b043ce62b7129a8236e40053383e 05a2716a8eb37eb2aaa72594573165349498aa6ca20c71346fb15d82c0cbbf7c

304402202711792b72547d2a1730a319bd219854f0892451b8bc2ab8c17ec0c6cba4ecc4022058f675ca0af3db455913e59dadc7c5e0bd0bf1b8ef8c13e830a627a18ac375ab

另一方面,使用 bip32 我得到:

String toSign = txSkel['tosign'][0];
var uToSign = crypto.hexToBytes(toSign);
var signed = fromNode.sign(uToSign);
var signedHex = bufferToHex(signed);
var signedHexNo0x = signedHex.substring(2);

其中 fromNodebip32.BIP32 节点。输出为 signedHexNo0x = 2711792b72547d2a1730a319bd219854f0892451b8bc2ab8c17ec0c6cba4ecc458f675ca0af3db455913e59dadc7c5e0bd0bf1b8ef8c13e830a627a18ac375ab.

乍一看,它们似乎是完全不同的缓冲区,但仔细观察后,Blockcypher signer输出仅比bip32[=多了一些字符52=]:

Blockcypher signer output (I split it into several lines for you to see it clearly):
30440220
2711792b72547d2a1730a319bd219854f0892451b8bc2ab8c17ec0c6cba4ecc4
0220
58f675ca0af3db455913e59dadc7c5e0bd0bf1b8ef8c13e830a627a18ac375ab
bip32 output (also intentionally split):
2711792b72547d2a1730a319bd219854f0892451b8bc2ab8c17ec0c6cba4ecc4
58f675ca0af3db455913e59dadc7c5e0bd0bf1b8ef8c13e830a627a18ac375ab

我期望两个 64 个字符的数字给出一个 128 个字符的签名,bip32 输出完成。因此,Blockcypher signer 输出有 140 个字符,即比前者多 12 个字符,当如上拆分成行时,这一点很清楚。

我真的很感谢任何人对这个问题有所了解,我需要理解和纠正。我需要在 dart 中实现解决方案,除了测试之外我不能使用签名者脚本。

dart bip32 包似乎没有以 DER 格式对签名进行编码,而是以简单的 (r, s) 编码。但是比特币需要 DER。有关更多信息,请参阅:

https://bitcoin.stackexchange.com/questions/92680/what-are-the-der-signature-and-sec-format

你可以根据你的r和s自己添加DER额外字节,或者检查dart bip32库中是否有DER编码。