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; }