public function associate_sigs_with_keys($raw_tx, $json_string, $address_version = '00') { $raw_tx = trim($raw_tx); $json_string = str_replace("'", '', $json_string); $decode = \BitWasp\BitcoinLib\RawTransaction::decode($raw_tx, $address_version); if ($decode == FALSE) { return FALSE; } $json_arr = (array) json_decode($json_string); $message_hash = \BitWasp\BitcoinLib\RawTransaction::_create_txin_signature_hash($raw_tx, $json_string); $results = array(); foreach ($decode['vin'] as $i => $vin) { // Decode previous scriptPubKey to learn tramsaction type. $type_info = \BitWasp\BitcoinLib\RawTransaction::_get_transaction_type(\BitWasp\BitcoinLib\RawTransaction::_decode_scriptPubKey($json_arr[$i]->scriptPubKey)); if ($type_info['type'] == 'scripthash') { // Pay-to-script-hash. Check OP_FALSE <sig> ... <redeemScript> // Store the redeemScript, then remove OP_FALSE + the redeemScript from the array. $scripts = explode(" ", $vin['scriptSig']['asm']); $redeemScript = \BitWasp\BitcoinLib\RawTransaction::decode_redeem_script(end($scripts)); unset($scripts[count($scripts) - 1]); // Unset redeemScript unset($scripts[0]); // Unset '0'; // Extract signatures, remove the "0" byte, and redeemScript. // Loop through the remaining values - the signatures foreach ($scripts as $signature) { // Test each signature with the public keys in the redeemScript. foreach ($redeemScript['keys'] as $public_key) { if (\BitWasp\BitcoinLib\RawTransaction::_check_sig($signature, $message_hash[$i], $public_key) == TRUE) { $results[$i][$public_key] = $signature; } } } } } return $results; }
} $inputs[] = $input; } unset($input); unset($tx_info); unset($dec); unset($get); $json_str = json_encode($inputs); } else { $try = @json_decode($line); if (is_object($try) and count($try) == count($decoded_transaction['vin'])) { $to_check = count($try); $i = 0; foreach ($try as &$input) { if (isset($input->txid) and $decoded_transaction['vin'][$i]['txid'] == $input->txid and isset($input->vout) and $decoded_transaction['vin'][$i]['vout'] == $input->vout and isset($input->scriptPubKey)) { $tx_info = RawTransaction::_get_transaction_type(RawTransaction::_decode_scriptPubKey($input->scriptPubKey)); if ($tx_info['hash160'] == $script_hash) { $input->redeemScript = $redeem_script; } $to_check--; } $i++; } if ($to_check == 0) { $json_str = json_encode($try); } } } } while (!isset($seed)) { echo "\nEnter electrum seed or mnemonic: ";