* Sign scriptPubKey using signature made with creator. * Signatures are returned in scriptSigRet (or returns false if scriptPubKey * can't be signed), unless whichTypeRet is TxoutType::SCRIPTHASH, in which * case scriptSigRet is the redemption script. * Returns false if scriptPubKey could not be completely satisfied. */
| 104 | * Returns false if scriptPubKey could not be completely satisfied. |
| 105 | */ |
| 106 | static bool SignStep(const SigningProvider &provider, |
| 107 | const BaseSignatureCreator &creator, |
| 108 | const CScript &scriptPubKey, std::vector<valtype> &ret, |
| 109 | TxoutType &whichTypeRet, SignatureData &sigdata) { |
| 110 | CScript scriptRet; |
| 111 | uint160 h160; |
| 112 | ret.clear(); |
| 113 | std::vector<uint8_t> sig; |
| 114 | |
| 115 | std::vector<valtype> vSolutions; |
| 116 | whichTypeRet = Solver(scriptPubKey, vSolutions); |
| 117 | |
| 118 | switch (whichTypeRet) { |
| 119 | case TxoutType::NONSTANDARD: |
| 120 | case TxoutType::NULL_DATA: |
| 121 | return false; |
| 122 | case TxoutType::PUBKEY: |
| 123 | if (!CreateSig(creator, sigdata, provider, sig, |
| 124 | CPubKey(vSolutions[0]), scriptPubKey)) { |
| 125 | return false; |
| 126 | } |
| 127 | ret.push_back(std::move(sig)); |
| 128 | return true; |
| 129 | case TxoutType::PUBKEYHASH: { |
| 130 | CKeyID keyID = CKeyID(uint160(vSolutions[0])); |
| 131 | CPubKey pubkey; |
| 132 | if (!GetPubKey(provider, sigdata, keyID, pubkey)) { |
| 133 | // Pubkey could not be found, add to missing |
| 134 | sigdata.missing_pubkeys.push_back(keyID); |
| 135 | return false; |
| 136 | } |
| 137 | if (!CreateSig(creator, sigdata, provider, sig, pubkey, |
| 138 | scriptPubKey)) { |
| 139 | return false; |
| 140 | } |
| 141 | ret.push_back(std::move(sig)); |
| 142 | ret.push_back(ToByteVector(pubkey)); |
| 143 | return true; |
| 144 | } |
| 145 | case TxoutType::SCRIPTHASH: |
| 146 | h160 = uint160(vSolutions[0]); |
| 147 | if (GetCScript(provider, sigdata, CScriptID{h160}, scriptRet)) { |
| 148 | ret.push_back( |
| 149 | std::vector<uint8_t>(scriptRet.begin(), scriptRet.end())); |
| 150 | return true; |
| 151 | } |
| 152 | // Could not find redeemScript, add to missing |
| 153 | sigdata.missing_redeem_script = h160; |
| 154 | return false; |
| 155 | case TxoutType::MULTISIG: { |
| 156 | size_t required = vSolutions.front()[0]; |
| 157 | // workaround CHECKMULTISIG bug |
| 158 | ret.push_back(valtype()); |
| 159 | for (size_t i = 1; i < vSolutions.size() - 1; ++i) { |
| 160 | CPubKey pubkey = CPubKey(vSolutions[i]); |
| 161 | // We need to always call CreateSig in order to fill sigdata |
| 162 | // with all possible signatures that we can create. This will |
| 163 | // allow further PSBT processing to work as it needs all |
no test coverage detected