예제 #1
0
 /**
  * @param int $tweak
  * @return PublicKey
  * @throws \Exception
  */
 public function tweakAdd($tweak)
 {
     $context = $this->ecAdapter->getContext();
     $math = $this->ecAdapter->getMath();
     $bin = pack('H*', str_pad($math->decHex($tweak), 64, '0', STR_PAD_LEFT));
     $clone = $this->clonePubkey();
     if (1 !== secp256k1_ec_pubkey_tweak_add($context, $clone, $bin)) {
         throw new \RuntimeException('Secp256k1: tweak add failed.');
     }
     return new PublicKey($this->ecAdapter, $clone, $this->compressed);
 }
 /**
  * @dataProvider getErroneousTypeVectors
  * @expectedException \PHPUnit_Framework_Error_Warning
  */
 public function testErroneousTypes($context, $pubkey, $tweak)
 {
     \secp256k1_ec_pubkey_tweak_add($context, $pubkey, $tweak);
 }
예제 #3
0
 /**
  * @param PublicKeyInterface $publicKey
  * @param int|string $integer
  * @return \BitWasp\Bitcoin\Key\PublicKey
  * @throws \Exception
  */
 public function publicKeyAdd(PublicKeyInterface $publicKey, $integer)
 {
     $pubKey = $publicKey->getBuffer()->getBinary();
     $ret = (bool) \secp256k1_ec_pubkey_tweak_add($pubKey, $this->getBinaryScalar($integer));
     if ($ret === false) {
         throw new \Exception('Secp256k1 pubkey tweak add: failed');
     }
     return $this->getRelatedPublicKey($publicKey, $pubKey);
 }
 /**
  * @expectedException \PHPUnit_Framework_Error_Warning
  */
 public function testEnforceZvalString()
 {
     $tweak = $this->pack('0af79b2b747548d59a4a765fb73a72bc4208d00b43d0606c13d332d5c284b0ef');
     $pubkey = array();
     \secp256k1_ec_pubkey_tweak_add(TestCase::getContext(), $pubkey, $tweak);
 }