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