コード例 #1
0
ファイル: MicroTXClient.php プロジェクト: toneloc/php-client
 /**
  * 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;
 }
コード例 #2
0
ファイル: Signer.php プロジェクト: toneloc/php-client
 /**
  * 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();
 }
コード例 #3
0
ファイル: PrivateKeyList.php プロジェクト: toneloc/php-client
 /**
  * @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;
 }
コード例 #4
0
 /**
  * @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());
 }
コード例 #5
0
ファイル: SignerTest.php プロジェクト: toneloc/php-client
 /**
  * @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);
 }
コード例 #6
0
 protected function setUp()
 {
     $this->privateKey = PrivateKeyManipulator::importPrivateKeyFromHex(self::ADDRESS_PRIVATE_KEY, true);
 }