我正在尝试使用here中描述的比特币引擎在比特币测试网上签署一项BlockCypher交易,但我一直收到错误:
{"error": "Couldn't deserialize request: invalid character 'x' in literal true (expecting 'r')"}
我已经到处搜索了,但找不到关于问题所在的文档。下面是我用来尝试和签署事务的代码。
var bitcoin = require("bitcoinjs-lib");
var buffer = require('buffer');
var keys = new bitcoin.ECPair.fromWIF('cMvPQZiG5mLARSjxbBwMxKwzhTHaxgpTsXB6ymx7SGAeYUqF8HAT', bitcoin.networks.testnet);
const publicKey = keys.publicKey;
console.log(keys.publicKey.toString("hex"));
var newtx = {
inputs: [{addresses: ['ms9ySK54aEC2ykDviet9jo4GZE6GxEZMzf']}],
outputs: [{addresses: ['msWccFYm5PPCn6TNPbNEnprA4hydPGadBN'], value: 1000}]
};
// calling the new endpoint, same as above
$.post('https://api.blockcypher.com/v1/btc/test3/txs/new', JSON.stringify(newtx))
.then(function(tmptx) {
// signing each of the hex-encoded string required to finalize the transaction
tmptx.pubkeys = [];
tmptx.signatures = tmptx.tosign.map(function(tosign, n) {
tmptx.pubkeys.push(keys.publicKey.toString("hex"));
return keys.sign(new buffer.Buffer(tosign, "hex")).toString("hex");
});
// sending back the transaction with all the signatures to broadcast
$.post('https://api.blockcypher.com/v1/btc/test3/txs/send', tmptx).then(function(finaltx) {
console.log(finaltx);
}).catch(function (response) {
console.log(response.responseText);
});
}).catch(function (response) {
console.log(response.responseText);
});似乎return keys.sign(new buffer.Buffer(tosign, "hex")).toString("hex");这一行是问题所在,但我不确定哪里出了问题。
发布于 2020-09-11 17:50:31
讨论了这个问题,并回答了here。This post和this one将特别受到关注。
据我所知,根据这个问题,respective one是在BlockCypher repo上打开的。尽管到目前为止它的状态仍然是opened,但是当前的BlockCypher JS docs respective API description包含该行的更改版本
return keys.sign(new buffer.Buffer(tosign, "hex")).toString("hex"); 在toString()之前使用toDER()转换,因此它现在看起来像这样
return keys.sign(new buffer.Buffer(tosign, "hex")).toDER().toString("hex"); https://stackoverflow.com/questions/56235135
复制相似问题