本文整理汇总了C++中CKey::GetPrivKey方法的典型用法代码示例。如果您正苦于以下问题:C++ CKey::GetPrivKey方法的具体用法?C++ CKey::GetPrivKey怎么用?C++ CKey::GetPrivKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CKey
的用法示例。
在下文中一共展示了CKey::GetPrivKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddKey
bool CWallet::AddKey(const CKey& key)
{
this->CKeyStore::AddKey(key);
if (!fFileBacked)
return true;
return CWalletDB(strWalletFile).WriteKey(key.GetPubKey(), key.GetPrivKey());
}
示例2: AddKey
bool CWallet::AddKey(const CKey& key)
{
if (!CCryptoKeyStore::AddKey(key))
return false;
if (!fFileBacked)
return true;
if (!IsCrypted())
return CWalletDB(strWalletFile).WriteKey(key.GetPubKey(), key.GetPrivKey());
}
示例3: mintCoinFast
void PrivateCoin::mintCoinFast(const CoinDenomination denomination) {
// Generate a random serial number in the range 0...{q-1} where
// "q" is the order of the commitment group.
// And where the serial also doubles as a public key
CKey key;
CBigNum s;
bool isValid = false;
while (!isValid) {
isValid = GenerateKeyPair(this->params->coinCommitmentGroup.groupOrder, uint256(0), key, s);
}
// Generate a random number "r" in the range 0...{q-1}
CBigNum r = CBigNum::randBignum(this->params->coinCommitmentGroup.groupOrder);
// Manually compute a Pedersen commitment to the serial number "s" under randomness "r"
// C = g^s * h^r mod p
CBigNum commitmentValue = this->params->coinCommitmentGroup.g.pow_mod(s, this->params->coinCommitmentGroup.modulus).mul_mod(this->params->coinCommitmentGroup.h.pow_mod(r, this->params->coinCommitmentGroup.modulus), this->params->coinCommitmentGroup.modulus);
// Repeat this process up to MAX_COINMINT_ATTEMPTS times until
// we obtain a prime number
for (uint32_t attempt = 0; attempt < MAX_COINMINT_ATTEMPTS; attempt++) {
// First verify that the commitment is a prime number
// in the appropriate range. If not, we'll throw this coin
// away and generate a new one.
if (commitmentValue.isPrime(ZEROCOIN_MINT_PRIME_PARAM) &&
commitmentValue >= params->accumulatorParams.minCoinValue &&
commitmentValue <= params->accumulatorParams.maxCoinValue) {
// Found a valid coin. Store it.
this->serialNumber = s;
this->randomness = r;
this->publicCoin = PublicCoin(params, commitmentValue, denomination);
this->privkey = key.GetPrivKey();
this->version = 2;
// Success! We're done.
return;
}
// Generate a new random "r_delta" in 0...{q-1}
CBigNum r_delta = CBigNum::randBignum(this->params->coinCommitmentGroup.groupOrder);
// The commitment was not prime. Increment "r" and recalculate "C":
// r = r + r_delta mod q
// C = C * h mod p
r = (r + r_delta) % this->params->coinCommitmentGroup.groupOrder;
commitmentValue = commitmentValue.mul_mod(this->params->coinCommitmentGroup.h.pow_mod(r_delta, this->params->coinCommitmentGroup.modulus), this->params->coinCommitmentGroup.modulus);
}
// We only get here if we did not find a coin within
// MAX_COINMINT_ATTEMPTS. Throw an exception.
throw std::runtime_error("Unable to mint a new Zerocoin (too many attempts)");
}
示例4: GenerateBeaconKeys
bool GenerateBeaconKeys(const std::string &cpid, std::string &sOutPubKey, std::string &sOutPrivKey)
{
// First Check the Index - if it already exists, use it
sOutPrivKey = GetArgument("privatekey" + cpid + GetNetSuffix(), "");
sOutPubKey = GetArgument("publickey" + cpid + GetNetSuffix(), "");
// If current keypair is not empty, but is invalid, allow the new keys to be stored, otherwise return 1: (10-25-2016)
if (!sOutPrivKey.empty() && !sOutPubKey.empty())
{
uint256 hashBlock = GetRandHash();
std::string sSignature;
std::string sError;
bool fResult;
fResult = SignBlockWithCPID(cpid, hashBlock.GetHex(), sSignature, sError, true);
if (!fResult)
LogPrintf("GenerateBeaconKeys::Failed to sign block with cpid with existing keys; generating new key pair -> %s", sError);
else
{
fResult = VerifyCPIDSignature(cpid, hashBlock.GetHex(), sSignature);
if (fResult)
{
LogPrintf("GenerateBeaconKeys::Current keypair is valid.");
return true;
}
else
LogPrintf("GenerateBeaconKeys::Signing block with CPID was successful; However Verifying CPID Sign was not; Key pair is not valid, generating new key pair");
}
}
// Generate the Keypair
CKey key;
key.MakeNewKey(false);
CPrivKey vchPrivKey = key.GetPrivKey();
sOutPrivKey = HexStr<CPrivKey::iterator>(vchPrivKey.begin(), vchPrivKey.end());
sOutPubKey = HexStr(key.GetPubKey().Raw());
return true;
}
示例5: GenerateMint
void CzPIVWallet::GenerateMint(const uint32_t& nCount, const CoinDenomination denom, PrivateCoin& coin, CDeterministicMint& dMint)
{
uint512 seedZerocoin = GetZerocoinSeed(nCount);
CBigNum bnValue;
CBigNum bnSerial;
CBigNum bnRandomness;
CKey key;
SeedToZPIV(seedZerocoin, bnValue, bnSerial, bnRandomness, key);
coin = PrivateCoin(Params().Zerocoin_Params(false), denom, bnSerial, bnRandomness);
coin.setPrivKey(key.GetPrivKey());
coin.setVersion(PrivateCoin::CURRENT_VERSION);
uint256 hashSeed = Hash(seedMaster.begin(), seedMaster.end());
uint256 hashSerial = GetSerialHash(bnSerial);
uint256 nSerial = bnSerial.getuint256();
uint256 hashStake = Hash(nSerial.begin(), nSerial.end());
uint256 hashPubcoin = GetPubCoinHash(bnValue);
dMint = CDeterministicMint(coin.getVersion(), nCount, hashSeed, hashSerial, hashPubcoin, hashStake);
dMint.SetDenomination(denom);
}
示例6: mintCoin
void PrivateCoin::mintCoin(const CoinDenomination denomination) {
// Repeat this process up to MAX_COINMINT_ATTEMPTS times until
// we obtain a prime number
for(uint32_t attempt = 0; attempt < MAX_COINMINT_ATTEMPTS; attempt++) {
// Generate a random serial number in the range 0...{q-1} where
// "q" is the order of the commitment group.
// And where the serial also doubles as a public key
CKey key;
CBigNum s;
bool isValid = false;
while (!isValid) {
isValid = GenerateKeyPair(this->params->coinCommitmentGroup.groupOrder, uint256(0), key, s);
}
// Generate a Pedersen commitment to the serial number "s"
Commitment coin(¶ms->coinCommitmentGroup, s);
// Now verify that the commitment is a prime number
// in the appropriate range. If not, we'll throw this coin
// away and generate a new one.
if (coin.getCommitmentValue().isPrime(ZEROCOIN_MINT_PRIME_PARAM) &&
coin.getCommitmentValue() >= params->accumulatorParams.minCoinValue &&
coin.getCommitmentValue() <= params->accumulatorParams.maxCoinValue) {
// Found a valid coin. Store it.
this->serialNumber = s;
this->randomness = coin.getRandomness();
this->publicCoin = PublicCoin(params,coin.getCommitmentValue(), denomination);
this->privkey = key.GetPrivKey();
this->version = 2;
// Success! We're done.
return;
}
}
// We only get here if we did not find a coin within
// MAX_COINMINT_ATTEMPTS. Throw an exception.
throw std::runtime_error("Unable to mint a new Zerocoin (too many attempts)");
}