コード例 #1
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();
 }
コード例 #2
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);
 }
コード例 #3
0
 /**
  * @test
  * @expectedException \InvalidArgumentException
  */
 public function should_throw_an_exception_importing_a_private_key_with_invalid_format()
 {
     PrivateKeyManipulator::importPrivateKey('INVALID PRIVATE KEY');
 }