#include "backend/accounts.h" #include "backend/types.h" #include "backend/utils.h" #include #include #include #include #include #include #include "libstatus.h" const int NUMBER_OF_ADDRESSES_TO_GENERATE = 5; const int MNEMONIC_PHRASE_LENGTH = 12; Backend::RpcResponse Backend::Accounts::generateAddresses(QVector paths) { QJsonObject payload{{"n", NUMBER_OF_ADDRESSES_TO_GENERATE}, {"mnemonicPhraseLength", MNEMONIC_PHRASE_LENGTH}, {"bip32Passphrase", ""}, {"paths", Utils::toJsonArray(paths)} }; const char* result = MultiAccountGenerateAndDeriveAddresses(Utils::jsonToStr(payload).toUtf8().data()); return Backend::RpcResponse(result, QJsonDocument::fromJson(result).array()); } Backend::RpcResponse Backend::Accounts::generateIdenticon(QString publicKey) { if(!publicKey.isEmpty()) { auto identicon = QString(Identicon(publicKey.toUtf8().data())); return Backend::RpcResponse(identicon, identicon); } else { throw Backend::RpcException("publicKey can't be empty1"); } } Backend::RpcResponse Backend::Accounts::generateAlias(QString publicKey) { if(!publicKey.isEmpty()) { auto alias = QString(GenerateAlias(publicKey.toUtf8().data())); return Backend::RpcResponse(alias, alias); } else { throw Backend::RpcException("publicKey can't be empty2"); } } Backend::RpcResponse Backend::Accounts::storeDerivedAccounts(QString id, QString hashedPassword, QVector paths) { QJsonObject payload{{"accountID", id}, {"paths", Utils::toJsonArray(paths)}, {"password", hashedPassword}}; auto result = MultiAccountStoreDerivedAccounts(Utils::jsonToStr(payload).toUtf8().data()); auto obj = QJsonDocument::fromJson(result).object(); Backend::Utils::throwOnError(obj); return Backend::RpcResponse(result, obj); } Backend::RpcResponse Backend::Accounts::saveAccountAndLogin( QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject nodeConfig) { auto result = SaveAccountAndLogin(Utils::jsonToStr(account).toUtf8().data(), hashedPassword.toUtf8().data(), Utils::jsonToStr(settings).toUtf8().data(), Utils::jsonToStr(nodeConfig).toUtf8().data(), Utils::jsonToStr(subaccounts).toUtf8().data()); auto obj = QJsonDocument::fromJson(result).object(); Backend::Utils::throwOnError(obj); return Backend::RpcResponse(result, obj); } Backend::RpcResponse Backend::Accounts::openAccounts(QString path) { const char* result = OpenAccounts(path.toUtf8().data()); auto resp = Backend::RpcResponse(result, QJsonDocument::fromJson(result).array()); return resp; } Backend::RpcResponse Backend::Accounts::login( QString name, QString keyUid, QString hashedPassword, QString identicon, QString thumbnail, QString large) { QJsonObject payload{{"name", name}, {"key-uid", keyUid}, {"identityImage", QJsonValue()}, {"identicon", identicon}}; if(!thumbnail.isEmpty() && !large.isEmpty()) { payload["identityImage"] = QJsonObject{{"thumbnail", thumbnail}, {"large", large}}; } auto result = Login(Utils::jsonToStr(payload).toUtf8().data(), hashedPassword.toUtf8().data()); auto obj = QJsonDocument::fromJson(result).object(); Backend::Utils::throwOnError(obj); return Backend::RpcResponse(result, obj); }