Skip to content

Commit

Permalink
#624 used keykeeper for utxo check
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolse committed Jun 7, 2019
1 parent 2f83b65 commit 983b951
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
23 changes: 20 additions & 3 deletions wallet/base_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ namespace beam::wallet
LoadNonceSeeds();
}

void LocalPrivateKeyKeeper::GenerateKey(const vector<Key::IDV>& ids, bool createCoinKey, Callback<PublicKeys>&& resultCallback, ExceptionCallback&& exceptionCallback)
void LocalPrivateKeyKeeper::GeneratePublicKeys(const vector<Key::IDV>& ids, bool createCoinKey, Callback<PublicKeys>&& resultCallback, ExceptionCallback&& exceptionCallback)
{
try
{
resultCallback(GenerateKeySync(ids, createCoinKey));
resultCallback(GeneratePublicKeysSync(ids, createCoinKey));
}
catch (const exception & ex)
{
Expand Down Expand Up @@ -164,7 +164,7 @@ namespace beam::wallet

////

IPrivateKeyKeeper::PublicKeys LocalPrivateKeyKeeper::GenerateKeySync(const std::vector<Key::IDV>& ids, bool createCoinKey)
IPrivateKeyKeeper::PublicKeys LocalPrivateKeyKeeper::GeneratePublicKeysSync(const std::vector<Key::IDV>& ids, bool createCoinKey)
{
PublicKeys result;
Scalar::Native secretKey;
Expand All @@ -189,6 +189,23 @@ namespace beam::wallet
return result;
}

ECC::Point LocalPrivateKeyKeeper::GeneratePublicKeySync(const Key::IDV& id, bool createCoinKey)
{
Scalar::Native secretKey;
Point publicKey = Zero;

if (createCoinKey)
{
SwitchCommitment().Create(secretKey, publicKey, *GetChildKdf(id.m_SubIdx), id);
}
else
{
m_MasterKdf->DeriveKey(secretKey, id);
publicKey = Context::get().G * secretKey;
}
return publicKey;
}

IPrivateKeyKeeper::Outputs LocalPrivateKeyKeeper::GenerateOutputsSync(Height schemeHeigh, const std::vector<Key::IDV>& ids)
{
Outputs result;
Expand Down
19 changes: 13 additions & 6 deletions wallet/base_transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ namespace beam::wallet
ECC::Point m_PublicValue;
};

virtual void GenerateKey(const std::vector<Key::IDV>& ids, bool createCoinKey, Callback<PublicKeys>&&, ExceptionCallback&&) = 0;
virtual void GeneratePublicKeys(const std::vector<Key::IDV>& ids, bool createCoinKey, Callback<PublicKeys>&&, ExceptionCallback&&) = 0;
virtual void GenerateOutputs(Height schemeHeigh, const std::vector<Key::IDV>& ids, Callback<Outputs>&&, ExceptionCallback&&) = 0;

virtual size_t AllocateNonceSlot() = 0;

// sync part for integration test
virtual PublicKeys GenerateKeySync(const std::vector<Key::IDV>& ids, bool createCoinKey) = 0;
virtual PublicKeys GeneratePublicKeysSync(const std::vector<Key::IDV>& ids, bool createCoinKey) = 0;
virtual ECC::Point GeneratePublicKeySync(const Key::IDV& id, bool createCoinKey) = 0;
virtual Outputs GenerateOutputsSync(Height schemeHeigh, const std::vector<Key::IDV>& ids) = 0;
//virtual RangeProofs GenerateRangeProofSync(Height schemeHeigh, const std::vector<Key::IDV>& ids) = 0;
virtual ECC::Point GenerateNonceSync(size_t slot) = 0;
Expand All @@ -86,7 +87,7 @@ namespace beam::wallet
class HWWalletKeyKeeper : public IPrivateKeyKeeper
{
public:
void GenerateKey(const std::vector<Key::IDV>& ids, bool createCoinKey, Callback<PublicKeys>&&, ExceptionCallback&&) override
void GeneratePublicKeys(const std::vector<Key::IDV>& ids, bool createCoinKey, Callback<PublicKeys>&&, ExceptionCallback&&) override
{

}
Expand All @@ -96,7 +97,12 @@ namespace beam::wallet
return 0;
}

PublicKeys GenerateKeySync(const std::vector<Key::IDV>& ids, bool createCoinKey) override
PublicKeys GeneratePublicKeysSync(const std::vector<Key::IDV>& ids, bool createCoinKey) override
{
return {};
}

ECC::Point GeneratePublicKeySync(const Key::IDV& id, bool createCoinKey) override
{
return {};
}
Expand Down Expand Up @@ -130,12 +136,13 @@ namespace beam::wallet
public:
LocalPrivateKeyKeeper(IWalletDB::Ptr walletDB);
private:
void GenerateKey(const std::vector<Key::IDV>& ids, bool createCoinKey, Callback<PublicKeys>&& resultCallback, ExceptionCallback&& exceptionCallback) override;
void GeneratePublicKeys(const std::vector<Key::IDV>& ids, bool createCoinKey, Callback<PublicKeys>&& resultCallback, ExceptionCallback&& exceptionCallback) override;
void GenerateOutputs(Height schemeHeight, const std::vector<Key::IDV>& ids, Callback<Outputs>&&, ExceptionCallback&&) override;

size_t AllocateNonceSlot() override;

PublicKeys GenerateKeySync(const std::vector<Key::IDV>& ids, bool createCoinKey) override;
PublicKeys GeneratePublicKeysSync(const std::vector<Key::IDV>& ids, bool createCoinKey) override;
ECC::Point GeneratePublicKeySync(const Key::IDV& id, bool createCoinKey) override;
Outputs GenerateOutputsSync(Height schemeHeigh, const std::vector<Key::IDV>& ids) override;
//RangeProofs GenerateRangeProofSync(Height schemeHeight, const std::vector<Key::IDV>& ids) override;
ECC::Point GenerateNonceSync(size_t slot) override;
Expand Down
2 changes: 1 addition & 1 deletion wallet/base_tx_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ namespace beam::wallet
// {
// //m_Tx.Update();
// });
auto commitments = m_Tx.GetKeyKeeper()->GenerateKeySync(m_InputCoins, true);
auto commitments = m_Tx.GetKeyKeeper()->GeneratePublicKeysSync(m_InputCoins, true);
m_Inputs.reserve(commitments.size());
for (const auto& commitment : commitments)
{
Expand Down
14 changes: 7 additions & 7 deletions wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,15 +785,15 @@ namespace beam::wallet
const std::vector<proto::UtxoEvent>& v = r.m_Res.m_Events;
for (size_t i = 0; i < v.size(); i++)
{
const proto::UtxoEvent& evt = v[i];
const auto& event = v[i];

// filter-out false positives
Scalar::Native sk;
Point comm;
m_WalletDB->calcCommitment(sk, comm, evt.m_Kidv);

if (comm == evt.m_Commitment)
ProcessUtxoEvent(evt);
if (m_KeyKeeper)
{
Point commitment = m_KeyKeeper->GeneratePublicKeySync(event.m_Kidv, true);
if (commitment == event.m_Commitment)
ProcessUtxoEvent(event);
}
}

if (r.m_Res.m_Events.size() < proto::UtxoEvent::s_Max)
Expand Down

0 comments on commit 983b951

Please sign in to comment.