/** * Send a microtransaction signing it locally (without sending the private key to the server) * * @param string $hexPrivateKey * @param string $toAddress * @param int $valueSatoshis * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls * @return MicroTX */ public function sendSigned($hexPrivateKey, $toAddress, $valueSatoshis, $apiContext = null, $restCall = null) { $compressed = true; $pubkey = PrivateKeyManipulator::generateHexPubKeyFromHexPrivKey($hexPrivateKey, $compressed); $microTX = MicroTXBuilder::newMicroTX()->fromPubkey($pubkey)->toAddress($toAddress)->withValueInSatoshis($valueSatoshis)->build(); $microTX = $this->create($microTX, $apiContext, $restCall); $microTX->sign($hexPrivateKey); $microTX = $this->send($microTX, $apiContext, $restCall); return $microTX; }
/** * Sign hex data deterministically using deterministic k. * * @param string $hexDataToSign * @param PrivateKeyInterface|string $privateKey * @return string */ public static function sign($hexDataToSign, $privateKey) { if (is_string($privateKey)) { $privateKey = PrivateKeyManipulator::importPrivateKey($privateKey); } // Convert hex data to buffer $data = Buffer::hex($hexDataToSign); /** @var EcAdapterInterface $ecAdapter */ $ecAdapter = Bitcoin::getEcAdapter(); // Deterministic digital signature generation $k = new Rfc6979($ecAdapter, $privateKey, $data, 'sha256'); $sig = $ecAdapter->sign($data, $privateKey, $k); // DEBUG //echo "hexDataToSign: <br/>"; //var_dump($hexDataToSign); //echo "sig: <br/>"; //var_dump($sig->getHex()); return $sig->getHex(); }
/** * @param string $coinSymbol * @return \string[] */ public function getAddresses($coinSymbol) { $addresses = array(); foreach ($this->privateKeys as $privateKey) { $address = PrivateKeyManipulator::getAddressFromPrivateKey($privateKey, $coinSymbol); $addresses[] = $address; } return $addresses; }
/** * @dataProvider dataProvider * @param $address * @throws \BlockCypher\Exception\BlockCypherInvalidPrivateKeyException */ public function testLength($address) { $privateKeyList = $this->anEmptyPrivateKeyList(); $this->assertEquals(0, $privateKeyList->length()); $privateKey = PrivateKeyManipulator::importPrivateKeyFromHex($address['private'], $address['compressed']); $privateKeyList = $this->aPrivateKeyListWithOne($privateKey); $this->assertEquals(1, $privateKeyList->length()); }
/** * @test */ public function should_allow_sign_data_with_private_key() { $privateKey = PrivateKeyManipulator::importPrivateKey(self::PRIVATE_KEY); $signature = Signer::sign(self::TO_SIGN, $privateKey); $this->assertEquals(self::SIGNATURE, $signature); }
protected function setUp() { $this->privateKey = PrivateKeyManipulator::importPrivateKeyFromHex(self::ADDRESS_PRIVATE_KEY, true); }