Skip to content

Commit 2e90d72

Browse files
committed
[Ed25519] Leverage new Ed25519 keypool when creating BDAP objects. Restore BDAP when importing mnemonic. WIP
1 parent 3a78d69 commit 2e90d72

File tree

8 files changed

+235
-79
lines changed

8 files changed

+235
-79
lines changed

src/bdap/rpcdomainentry.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ static UniValue AddDomainEntry(const JSONRPCRequest& request, BDAP::ObjectType b
4848
if (GetDomainEntry(txDomainEntry.vchFullObjectPath(), txDomainEntry))
4949
throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3500 - " + txDomainEntry.GetFullObjectPath() + _(" entry already exists. Can not add duplicate."));
5050

51-
//now using GetKeyFromPool instead of MakeNewKey
51+
LogPrintf("DEBUGGER ED %s - made it here! BEFORE\n", __func__);
52+
53+
//now using GetKeyFromPool instead of MakeNewKey
5254
CPubKey pubWalletKey;
53-
if (!pwalletMain->GetKeyFromPool(pubWalletKey, true))
55+
CharString vchDHTPubKey;
56+
if (!pwalletMain->GetEdKeyFromPool(pubWalletKey, vchDHTPubKey, true))
5457
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
5558
CKeyID keyWalletID = pubWalletKey.GetID();
5659
CDynamicAddress walletAddress = CDynamicAddress(keyWalletID);
@@ -62,14 +65,20 @@ static UniValue AddDomainEntry(const JSONRPCRequest& request, BDAP::ObjectType b
6265
txDomainEntry.WalletAddress = vchWalletAddress;
6366

6467
// TODO: Add ability to pass in the DHT public key
65-
CKeyEd25519 privDHTKey;
66-
CharString vchDHTPubKey = privDHTKey.GetPubKey();
68+
//CKeyEd25519 privDHTKey;
69+
//CharString vchDHTPubKey = privDHTKey.GetPubKey();
6770

68-
if (pwalletMain && !pwalletMain->AddDHTKey(privDHTKey, vchDHTPubKey))
69-
throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3503 - " + _("Error adding ed25519 key to wallet for BDAP"));
71+
//if (pwalletMain && !pwalletMain->AddDHTKey(privDHTKey, vchDHTPubKey))
72+
// throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3503 - " + _("Error adding ed25519 key to wallet for BDAP"));
7073

7174
txDomainEntry.DHTPublicKey = vchDHTPubKey;
72-
pwalletMain->SetAddressBook(privDHTKey.GetID(), strObjectID, "bdap-dht-key");
75+
CKeyID vchDHTPubKeyID = GetIdFromCharVector(vchDHTPubKey); // CKeyID(Hash160(vchDHTPubKey.begin(), vchDHTPubKey.end()));
76+
//pwalletMain->SetAddressBook(privDHTKey.GetID(), strObjectID, "bdap-dht-key"); //need private key for this?
77+
pwalletMain->SetAddressBook(vchDHTPubKeyID, strObjectID, "bdap-dht-key");
78+
79+
LogPrintf("DEBUGGER ED %s - made it here! AFTER\n", __func__);
80+
81+
7382

7483
// TODO: Add ability to pass in the link address
7584
// TODO: Use stealth address for the link address so linking will be private
@@ -147,8 +156,13 @@ static UniValue AddDomainEntry(const JSONRPCRequest& request, BDAP::ObjectType b
147156
testDomainEntry.nVersion, testDomainEntry.GetFullObjectPath(), stringFromVch(testDomainEntry.CommonName),
148157
stringFromVch(testDomainEntry.OrganizationalUnit), stringFromVch(testDomainEntry.DHTPublicKey));
149158
}
150-
std::string strPubKeyHash = privDHTKey.GetHash().ToString();
151-
std::string strPubKeyID = privDHTKey.GetID().ToString();
159+
std::string strPubKeyHash = GetHashFromCharVector(vchDHTPubKey).ToString();
160+
std::string strPubKeyID = GetIdFromCharVector(vchDHTPubKey).ToString();
161+
162+
LogPrintf("DEBUGGER ED %s - GetHashFromCharVector [%s]\n", __func__,strPubKeyHash);
163+
LogPrintf("DEBUGGER ED %s - GetIdFromCharVector [%s]\n", __func__,strPubKeyID);
164+
165+
152166
oName.push_back(Pair("dht_pubkey_hash", strPubKeyHash));
153167
oName.push_back(Pair("dht_pubkey_id", strPubKeyID));
154168
return oName;
@@ -858,10 +872,14 @@ UniValue mybdapaccounts(const JSONRPCRequest& request)
858872
if (!pwalletMain->GetDHTPubKeys(vvchDHTPubKeys))
859873
return NullUniValue;
860874

875+
LogPrintf("DEBUGGER ED %s - size [%d]\n",__func__,vvchDHTPubKeys.size());
876+
877+
861878
UniValue result(UniValue::VOBJ);
862879
uint32_t nCount = 1;
863880
for (const std::vector<unsigned char>& vchPubKey : vvchDHTPubKeys) {
864881
CDomainEntry entry;
882+
LogPrintf("DEBUGGER ED %s - PubKey [%s]\n",__func__,stringFromVch(vchPubKey));
865883
if (pDomainEntryDB->ReadDomainEntryPubKey(vchPubKey, entry)) {
866884
UniValue oAccount(UniValue::VOBJ);
867885
if (BuildBDAPJson(entry, oAccount, false)) {

src/bdap/rpclinking.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,22 @@ static UniValue SendLinkRequest(const JSONRPCRequest& request)
154154
txLink.RequestorFullObjectPath = vchRequestorFQDN;
155155
txLink.RecipientFullObjectPath = vchRecipientFQDN;
156156
txLink.LinkMessage = vchFromString(strLinkMessage);
157+
158+
CPubKey pubWalletKey; //won't be needing this
159+
CharString vchDHTPubKey;
157160
CKeyEd25519 privReqDHTKey;
158-
CharString vchDHTPubKey = privReqDHTKey.GetPubKey();
159-
if (pwalletMain && !pwalletMain->AddDHTKey(privReqDHTKey, vchDHTPubKey))
160-
throw std::runtime_error("BDAP_SEND_LINK_RPC_ERROR: ERRCODE: 4002 - " + _("Error adding ed25519 key to wallet for BDAP link"));
161+
if (!pwalletMain->GetEdKeyFromPool(pubWalletKey, vchDHTPubKey, true))
162+
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
163+
164+
CKeyID vchDHTPubKeyID = GetIdFromCharVector(vchDHTPubKey);
165+
if (!pwalletMain->GetDHTKey(vchDHTPubKeyID, privReqDHTKey))
166+
throw std::runtime_error("BDAP_SEND_LINK_RPC_ERROR: Unable to retrieve DHT Key");
167+
else LogPrintf("DEBUGGER ED %s - got request privatekey [%s]\n",__func__,privReqDHTKey.GetPrivKeyString());
168+
169+
//CKeyEd25519 privReqDHTKey;
170+
//CharString vchDHTPubKey = privReqDHTKey.GetPubKey();
171+
//if (pwalletMain && !pwalletMain->AddDHTKey(privReqDHTKey, vchDHTPubKey))
172+
// throw std::runtime_error("BDAP_SEND_LINK_RPC_ERROR: ERRCODE: 4002 - " + _("Error adding ed25519 key to wallet for BDAP link"));
161173

162174
txLink.RequestorPubKey = vchDHTPubKey;
163175

@@ -306,10 +318,22 @@ static UniValue SendLinkAccept(const JSONRPCRequest& request)
306318
txLinkAccept.RequestorFullObjectPath = vchRequestorFQDN;
307319
txLinkAccept.RecipientFullObjectPath = vchAcceptorFQDN;
308320

321+
322+
CPubKey pubWalletKey; //won't be needing this
323+
CharString vchDHTPubKey;
309324
CKeyEd25519 privAcceptDHTKey;
310-
CharString vchDHTPubKey = privAcceptDHTKey.GetPubKey();
311-
if (pwalletMain && !pwalletMain->AddDHTKey(privAcceptDHTKey, vchDHTPubKey))
312-
throw std::runtime_error("BDAP_ACCEPT_LINK_RPC_ERROR: ERRCODE: 4104 - " + _("Error adding ed25519 key to wallet for BDAP link"));
325+
if (!pwalletMain->GetEdKeyFromPool(pubWalletKey, vchDHTPubKey, true))
326+
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
327+
328+
CKeyID vchDHTPubKeyID = GetIdFromCharVector(vchDHTPubKey);
329+
if (!pwalletMain->GetDHTKey(vchDHTPubKeyID, privAcceptDHTKey))
330+
throw std::runtime_error("BDAP_SEND_LINK_RPC_ERROR: Unable to retrieve DHT Key");
331+
else LogPrintf("DEBUGGER ED %s - got accept privatekey [%s]\n",__func__,privAcceptDHTKey.GetPrivKeyString());
332+
333+
//CKeyEd25519 privAcceptDHTKey;
334+
//CharString vchDHTPubKey = privAcceptDHTKey.GetPubKey();
335+
//if (pwalletMain && !pwalletMain->AddDHTKey(privAcceptDHTKey, vchDHTPubKey))
336+
// throw std::runtime_error("BDAP_ACCEPT_LINK_RPC_ERROR: ERRCODE: 4104 - " + _("Error adding ed25519 key to wallet for BDAP link"));
313337

314338
txLinkAccept.RecipientPubKey = vchDHTPubKey;
315339

src/dht/ed25519.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,14 @@ std::string CharVectorToByteArrayString(const std::vector<unsigned char>& vchDat
244244
ss << "\n";
245245
}
246246
return ss.str();
247+
}
248+
249+
CKeyID GetIdFromCharVector(const std::vector<unsigned char>& vchIn)
250+
{
251+
return CKeyID(Hash160(vchIn.begin(), vchIn.end()));
252+
}
253+
254+
uint256 GetHashFromCharVector(const std::vector<unsigned char>& vchIn)
255+
{
256+
return Hash(vchIn.begin(), vchIn.end());
247257
}

src/dht/ed25519.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,7 @@ bool ECC_Ed25519_InitSanityCheck();
142142
void ECC_Ed25519_Start();
143143
void ECC_Ed25519_Stop();
144144

145+
CKeyID GetIdFromCharVector(const std::vector<unsigned char>& vchIn);
146+
uint256 GetHashFromCharVector(const std::vector<unsigned char>& vchIn);
147+
145148
#endif // DYNAMIC_DHT_ED25519_H

src/key.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ class CKey
9292

9393
const std::vector<unsigned char, secure_allocator<unsigned char> > getKeyData() const { return keydata; }
9494

95-
96-
9795
//! Check whether this private key is valid.
9896
bool IsValid() const { return fValid; }
9997

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ UniValue getnewed25519address(const JSONRPCRequest& request)
170170
strAccount = AccountFromValue(request.params[0]);
171171

172172
if (!pwalletMain->IsLocked(true))
173-
pwalletMain->TopUpEdKeyPool();
173+
pwalletMain->TopUpKeyPoolCombo(); //TopUpEdKeyPool();
174174

175175
// Generate a new key that is added to wallet
176176
CPubKey newKey;
@@ -190,7 +190,6 @@ UniValue getnewed25519address(const JSONRPCRequest& request)
190190

191191
return returnvalue;
192192

193-
194193
} //getnewed25519address
195194

196195

@@ -2183,7 +2182,7 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
21832182
if (!pwalletMain->Unlock(strWalletPass, fForMixingOnly))
21842183
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
21852184

2186-
pwalletMain->TopUpKeyPool();
2185+
pwalletMain->TopUpKeyPoolCombo(); //TopUpKeyPool();
21872186

21882187
LOCK(cs_nWalletUnlockTime);
21892188
nWalletUnlockTime = GetTime() + nSleepTime;

0 commit comments

Comments
 (0)