mirror of
https://github.com/lubosz/overte.git
synced 2025-04-27 01:35:36 +02:00
initial prototype
This commit is contained in:
parent
04d72ea39d
commit
73cca42940
3 changed files with 51 additions and 2 deletions
interface/src/commerce
|
@ -125,8 +125,19 @@ bool Ledger::receiveAt(const QString& hfc_key, const QString& signing_key) {
|
|||
emit receiveAtResult(result);
|
||||
return false; // We know right away that we will fail, so tell the caller.
|
||||
}
|
||||
|
||||
signedSend("public_key", hfc_key.toUtf8(), signing_key, "receive_at", "receiveAtSuccess", "receiveAtFailure");
|
||||
auto wallet = DependencyManager::get<Wallet>();
|
||||
QByteArray locker = wallet->getWallet();
|
||||
if (locker.isEmpty()) {
|
||||
signedSend("public_key", hfc_key.toUtf8(), signing_key, "receive_at", "receiveAtSuccess", "receiveAtFailure");
|
||||
} else {
|
||||
QJsonObject transaction;
|
||||
transaction["public_key"] = hfc_key;
|
||||
transaction["locker"] = QString::fromUtf8(locker);
|
||||
QJsonDocument transactionDoc{ transaction };
|
||||
auto transactionString = transactionDoc.toJson(QJsonDocument::Compact);
|
||||
qCDebug(commerce) << "FIXME transactionString" << transactionString;
|
||||
signedSend("text", transactionString, signing_key, "receive_at", "receiveAtSuccess", "receiveAtFailure");
|
||||
}
|
||||
return true; // Note that there may still be an asynchronous signal of failure that callers might be interested in.
|
||||
}
|
||||
|
||||
|
@ -277,17 +288,22 @@ void Ledger::accountSuccess(QNetworkReply* reply) {
|
|||
// lets set the appropriate stuff in the wallet now
|
||||
auto wallet = DependencyManager::get<Wallet>();
|
||||
QByteArray response = reply->readAll();
|
||||
qCDebug(commerce) << "FIXME accountSuccess got" << response;
|
||||
QJsonObject data = QJsonDocument::fromJson(response).object()["data"].toObject();
|
||||
|
||||
auto salt = QByteArray::fromBase64(data["salt"].toString().toUtf8());
|
||||
auto iv = QByteArray::fromBase64(data["iv"].toString().toUtf8());
|
||||
auto ckey = QByteArray::fromBase64(data["ckey"].toString().toUtf8());
|
||||
QString remotePublicKey = data["public_key"].toString();
|
||||
const QByteArray locker = data["locker"].toString().toUtf8();
|
||||
bool isOverride = wallet->wasSoftReset();
|
||||
|
||||
wallet->setSalt(salt);
|
||||
wallet->setIv(iv);
|
||||
wallet->setCKey(ckey);
|
||||
if (!locker.isEmpty()) {
|
||||
wallet->setWallet(locker);
|
||||
}
|
||||
|
||||
QString keyStatus = "ok";
|
||||
QStringList localPublicKeys = wallet->listPublicKeys();
|
||||
|
@ -301,6 +317,9 @@ void Ledger::accountSuccess(QNetworkReply* reply) {
|
|||
keyStatus = "preexisting";
|
||||
} else if (localPublicKeys.first() != remotePublicKey) {
|
||||
keyStatus = "conflicting";
|
||||
} else if (locker.isEmpty()) {
|
||||
QString key = localPublicKeys.first();
|
||||
receiveAt(key, key);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -190,6 +190,32 @@ bool writeKeys(const char* filename, EC_KEY* keys) {
|
|||
return retval;
|
||||
}
|
||||
|
||||
bool Wallet::setWallet(const QByteArray& wallet) {
|
||||
QFile file(keyFilePath());
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
qCCritical(commerce) << "Unable to open wallet for write in" << keyFilePath();
|
||||
return false;
|
||||
}
|
||||
if (file.write(wallet) != wallet.count()) {
|
||||
qCCritical(commerce) << "Unable to write wallet in" << keyFilePath();
|
||||
return false;
|
||||
}
|
||||
file.close();
|
||||
qCDebug(commerce) << "FIXME wrote" << wallet.count() << "to" << keyFilePath();
|
||||
return true;
|
||||
}
|
||||
QByteArray Wallet::getWallet() {
|
||||
QFile file(keyFilePath());
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qCInfo(commerce) << "No existing wallet in" << keyFilePath();
|
||||
return QByteArray();
|
||||
}
|
||||
QByteArray wallet = file.readAll();
|
||||
file.close();
|
||||
qCDebug(commerce) << "FIXME read" << wallet.count() << "from" << keyFilePath();
|
||||
return wallet;
|
||||
}
|
||||
|
||||
QPair<QByteArray*, QByteArray*> generateECKeypair() {
|
||||
|
||||
EC_KEY* keyPair = EC_KEY_new_by_curve_name(NID_secp256k1);
|
||||
|
|
|
@ -44,6 +44,10 @@ public:
|
|||
void setCKey(const QByteArray& ckey) { _ckey = ckey; }
|
||||
QByteArray getCKey() { return _ckey; }
|
||||
|
||||
// FIXME protect more
|
||||
bool setWallet(const QByteArray& wallet);
|
||||
QByteArray getWallet();
|
||||
|
||||
bool setPassphrase(const QString& passphrase);
|
||||
QString* getPassphrase() { return _passphrase; }
|
||||
bool getPassphraseIsCached() { return !(_passphrase->isEmpty()); }
|
||||
|
|
Loading…
Reference in a new issue