Beispiel #1
0
 /**
  * @param int $tweak
  * @var string $tweak
  * @return PrivateKey
  */
 public function tweakAdd($tweak)
 {
     $adapter = $this->ecAdapter;
     $math = $adapter->getMath();
     $context = $adapter->getContext();
     $privKey = $this->getBinary();
     // mod by reference
     $tweak = Buffer::int($tweak, 32, $math)->getBinary();
     $ret = \secp256k1_ec_privkey_tweak_add($context, $privKey, $tweak);
     if ($ret !== 1) {
         throw new \RuntimeException('Secp256k1 privkey tweak add: failed');
     }
     $secret = $math->hexDec(bin2hex($privKey));
     return $adapter->getPrivateKey($secret, $this->compressed);
 }
 /**
  * @expectedException \Exception
  */
 public function testEnforceZvalString()
 {
     $tweak = $this->pack('0af79b2b747548d59a4a765fb73a72bc4208d00b43d0606c13d332d5c284b0ef');
     $privateKey = array();
     \secp256k1_ec_privkey_tweak_add(TestCase::getContext(), $privateKey, $tweak);
 }
Beispiel #3
0
 /**
  * @param PrivateKeyInterface $privateKey
  * @param int|string $integer
  * @return \BitWasp\Bitcoin\Key\PrivateKey
  * @throws \Exception
  */
 public function privateKeyAdd(PrivateKeyInterface $privateKey, $integer)
 {
     $privKey = $privateKey->getBuffer()->getBinary();
     // mod by reference
     $ret = (bool) \secp256k1_ec_privkey_tweak_add($privKey, $this->getBinaryScalar($integer));
     if ($ret === false) {
         throw new \Exception('Secp256k1 privkey tweak add: failed');
     }
     return $this->getRelatedPrivateKey($privateKey, $privKey);
 }