/** * Signs MicroTX. * * @param string[]|string $hexPrivateKey * @return $this * @throws \Exception */ public function sign($hexPrivateKey) { $this->setSignatures(Signer::signMultiple($this->tosign, $hexPrivateKey)); return $this; }
/** * @dataProvider invalidSignMultipleParameters * @test * @expectedException \InvalidArgumentException * @param $toSign */ public function should_only_allow_sign_multiple_data_from_an_array($toSign) { Signer::signMultiple($toSign, self::PRIVATE_KEY); }
/** * @param PrivateKeyList $privateKeyCompressedList * @param PrivateKeyList $privateKeyUncompressedList * @param string $coinSymbol * @throws BlockCypherSignatureException * @throws BlockCypherUncompressedKeyException */ private function generateSignatures($privateKeyCompressedList, $privateKeyUncompressedList, $coinSymbol) { $signatures = array(); $pubkeys = array(); $tosignIndex = 0; $privateKeysUsed = array(); foreach ($this->getTxInputs() as $txInput) { // Addresses can be network addresses or pubkeys (multisig txs) $txInputAddresses = $txInput->getAddresses(); foreach ($txInputAddresses as $inputAddress) { if ($privateKeyCompressedList->containsPrivateKeyFor($inputAddress, $coinSymbol)) { // Get private key to sign $privateKey = $privateKeyCompressedList->getPrivateKey($inputAddress, $coinSymbol); // Signature $signatures[] = Signer::sign($this->tosign[$tosignIndex], $privateKey); // Pubkey $pubkeys[] = $privateKey->getPublicKey()->getHex(); // Mark private key as used $privateKeysUsed[] = $inputAddress; } else { if ($privateKeyUncompressedList->containsPrivateKeyFor($inputAddress, $coinSymbol)) { throw new BlockCypherUncompressedKeyException(sprintf("Invalid private key for address %s. Address correspond to uncompressed public key. Uncompressed public keys are not supported.", $inputAddress)); } else { // User has not provide a private key for this address // API allows to send partially signed tx // TODO: add log? } } } $tosignIndex++; } $numPrivateKeysNotUsed = $privateKeyCompressedList->length() - count($privateKeysUsed); if ($numPrivateKeysNotUsed > 0) { throw new BlockCypherSignatureException(sprintf("%s private keys do not correspond to any input. Please check private keys provided.", $numPrivateKeysNotUsed)); } $this->signatures = $signatures; $this->pubkeys = $pubkeys; }