Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/DerivationPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ DerivationPath::DerivationPath(const std::string& string) {
if (hardened) {
++it;
}
if (!hardened && value >= 0x80000000) {
throw std::invalid_argument("Non-hardened index must be less than 2^31");
}
indices.emplace_back(value, hardened);

if (it == end) {
Expand Down
11 changes: 10 additions & 1 deletion src/Stellar/Signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../Hash.h"
#include "../HexCoding.h"
#include "../proto/Stellar.pb.h"
#include <stdexcept>

#include <TrustWalletCore/TWStellarMemoType.h>

Expand All @@ -17,7 +18,12 @@ namespace TW::Stellar {
Proto::SigningOutput Signer::sign(const Proto::SigningInput& input) {
auto signer = Signer(input);
auto output = Proto::SigningOutput();
output.set_signature(signer.sign());
try {
output.set_signature(signer.sign());
} catch (const std::invalid_argument& ex) {
output.set_error(Common::Proto::Error_invalid_params);
output.set_error_message(ex.what());
}
Comment thread
nikhil-gupta-tw marked this conversation as resolved.
return output;
}

Expand Down Expand Up @@ -201,6 +207,9 @@ void Signer::encodeAsset(const Proto::Asset& asset, Data& data) {
uint32_t assetType = 0; // native
std::string alphaUse;
if (asset.issuer().length() > 0 && Address::isValid(asset.issuer()) && asset.alphanum4().length() > 0) {
if (asset.alphanum4().length() > 4) {
throw std::invalid_argument("alphanum4 asset code must be 4 characters or fewer");
}
assetType = 1; // alphanum4
alphaUse = asset.alphanum4();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Zilliqa/Signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Data Signer::getPreImage(const Proto::SigningInput& input, Address& address) {
return Data(0);
}
const auto pubKey = key.getPublicKey(TWPublicKeyTypeSECP256k1);
auto gasPrice = Data(input.gas_price().begin(), input.gas_price().end());
auto gasPrice = store(load(input.gas_price()));

internal.set_version(input.version());
internal.set_nonce(input.nonce());
Expand All @@ -63,12 +63,12 @@ Data Signer::getPreImage(const Proto::SigningInput& input, Address& address) {
switch (input.transaction().message_oneof_case()) {
case Proto::Transaction::kTransfer: {
const auto transfer = input.transaction().transfer();
amount = Data(transfer.amount().begin(), transfer.amount().end());
amount = store(load(transfer.amount()));
break;
}
case Proto::Transaction::kRawTransaction: {
const auto raw = input.transaction().raw_transaction();
amount = Data(raw.amount().begin(), raw.amount().end());
amount = store(load(raw.amount()));
if (!raw.code().empty()) {
internal.set_code(raw.code());
}
Expand Down
Loading