Transactions

使用未/壓縮密鑰簽署交易

  • June 13, 2018

再會。

我從同一個私鑰創建了 2 個地址。一個地址當然是壓縮的,而另一個則不是。

compressed_public_key = "025d9a1a0a5dab7e3e4a84c30a42ddc0d71b2da0fa1f3b99fbda9fc03eb8c75cd5" 
corresponding_address = "mfjRUvWr9QZadpiRnbRfHS4UDSxdR9FE75"

uncompressed_public_key =  "045d9a1a0a5dab7e3e4a84c30a42ddc0d71b2da0fa1f3b99fbda9fc03eb8c75cd535a0b893f20338d37d20eebe2941859dfe53b175f0bb24a27bc77741f0bb8cac"
uncompressed_address = "mi4kMd3HcLUGJSouNdJZ87eUBbi7cNE6C3"

我還向每個地址發送了一些硬幣。

utxo_to_compressed = "963baf6eb615a09afcb05ebcdbd3db05a163994dd2035002477c753ba3281eff"
utxo_to_uncompressed = "08a1286bb379f6eb5151828505b934c1b917201592bb76bd252a53b7a3009b17"

使用 bitcore 我創建了 private_key 來簽署交易和 utxos,如下所示:

privateKey = new bitcore.PrivateKey(BN, "testnet")

scriptSig =  "76a914" + hashedPubKey + "88ac";

And the hashed public keys are:
1bf398bb044e55f1971e384cc1e6d861dca3adb9 for the uncompressed 
025bafbac8a8a1fcbae04f9a6aa8b6f968c9d145 for the compressed

utxo_compressed = new bitcore.Transaction.UnspentOutput({
   "txId": "08a1286bb379f6eb5151828505b934c1b917201592bb76bd252a53b7a3009b17",
   "outputIndex": 0,
 "address": "mi4kMd3HcLUGJSouNdJZ87eUBbi7cNE6C3",
   "script": scriptSig,
   "satoshis": 5000000000
});

utxo_uncompressed = new bitcore.Transaction.UnspentOutput({
   "txId": "963baf6eb615a09afcb05ebcdbd3db05a163994dd2035002477c753ba3281eff",
   "outputIndex": 0,
 "address": "mfjRUvWr9QZadpiRnbRfHS4UDSxdR9FE75",
   "script": scriptSig,
   "satoshis": 5000000000
});

簽署壓縮的 utxo 不是問題。但是,一旦我嘗試簽署未壓縮的交易,我就會收到一條錯誤消息。

compressedTx = new bitcore.Transaction();
uncompressedTx = new bitcore.Transaction();
compressedTx.from(utxo).to(some output).sign(privateKey); <-This one works fine
uncompressedTx.from(utxo).to(some output).sign(privateKey); <-This one fails
//Some inputs have not been fully signed Use//

過去,我從未壓縮的公鑰發送和贖回交易(我是手動完成的,使用簡單的 python 程式碼)。我似乎找不到輸入未簽名的任何原因。

我將非常感謝您提供的任何幫助

壓縮的公鑰和未壓縮的公鑰具有不同的雜湊值。所以,你的程式碼應該是這樣的:

scriptSig1 = "76a914" + hashedPubKey_1 + "88ac"; 
scriptSig2 = "76a914" + hashedPubKey_2 + "88ac"; 

sign.cpp現在大約 line25的以下程式碼。似乎在較新的核心程式碼中有意禁用未壓縮密鑰的簽名。

我沒有理解為什麼禁用它,也許只是為了避免potential hash collision將來並保留更多數據standardized

// Signing with uncompressed keys is disabled in witness scripts
if (sigversion == SigVersion::WITNESS_V0 && !key.IsCompressed())
   return false;

引用自:https://bitcoin.stackexchange.com/questions/50025