// { // passphrase: <string> // } Json::Value doWalletPropose (RPC::Context& context) { context.lock_.unlock (); RippleAddress naSeed; RippleAddress naAccount; if (!context.params_.isMember ("passphrase")) naSeed.setSeedRandom (); else if (!naSeed.setSeedGeneric (context.params_["passphrase"].asString ())) return rpcError(rpcBAD_SEED); RippleAddress naGenerator = RippleAddress::createGeneratorPublic (naSeed); naAccount.setAccountPublic (naGenerator, 0); Json::Value obj (Json::objectValue); obj["master_seed"] = naSeed.humanSeed (); obj["master_seed_hex"] = to_string (naSeed.getSeed ()); obj["master_key"] = naSeed.humanSeed1751(); obj["account_id"] = naAccount.humanAccountID (); obj["public_key"] = naAccount.humanAccountPublic(); auto acct = naAccount.getAccountPublic(); obj["public_key_hex"] = strHex(acct.begin(), acct.size()); return obj; }
std::vector<unsigned char> RippleAddress::accountPrivateDecrypt(const RippleAddress& naPublicFrom, const std::vector<unsigned char>& vucCipherText) const { CKey ckPrivate; CKey ckPublic; std::vector<unsigned char> vucPlainText; if (!ckPublic.SetPubKey(naPublicFrom.getAccountPublic())) { // Bad public key. cLog(lsWARNING) << "accountPrivateDecrypt: Bad public key."; } else if (!ckPrivate.SetPrivateKeyU(getAccountPrivate())) { // Bad private key. cLog(lsWARNING) << "accountPrivateDecrypt: Bad private key."; } else { try { vucPlainText = ckPrivate.decryptECIES(ckPublic, vucCipherText); } catch (...) { nothing(); } } return vucPlainText; }
Blob RippleAddress::accountPrivateDecrypt (const RippleAddress& naPublicFrom, Blob const& vucCipherText) const { CKey ckPrivate; CKey ckPublic; Blob vucPlainText; if (!ckPublic.SetPubKey (naPublicFrom.getAccountPublic ())) { // Bad public key. WriteLog (lsWARNING, RippleAddress) << "accountPrivateDecrypt: Bad public key."; } else if (!ckPrivate.SetPrivateKeyU (getAccountPrivate ())) { // Bad private key. WriteLog (lsWARNING, RippleAddress) << "accountPrivateDecrypt: Bad private key."; } else { try { vucPlainText = ckPrivate.decryptECIES (ckPublic, vucCipherText); } catch (...) { nothing (); } } return vucPlainText; }
std::string rippleGetAddressFromSecret(const std::string& secretkey) { RippleAddress secret; if (!secret.SetString(secretkey, VER_FAMILY_SEED)) return ""; RippleAddress masterGenerator = createGeneratorPublic(secret); RippleAddress masterAccountPublic; masterAccountPublic.setAccountPublic(masterGenerator.getAccountPublic(), 0); return masterAccountPublic.humanAccountID(); }
// DEPRECATED AccountID calcAccountID (RippleAddress const& publicKey) { auto const& pk = publicKey.getAccountPublic(); ripesha_hasher rsh; rsh(pk.data(), pk.size()); auto const d = static_cast< ripesha_hasher::result_type>(rsh); AccountID id; static_assert(sizeof(d) == sizeof(id), ""); std::memcpy(id.data(), d.data(), d.size()); return id; }
void rippleGenerateAddress(std::string& address, std::string& secret) { RippleAddress naSeed; RippleAddress naAccount; uint128 key; getRand(key.begin(), key.size()); naSeed.setSeed(key); RippleAddress naGenerator = createGeneratorPublic(naSeed); naAccount.setAccountPublic(naGenerator.getAccountPublic(), 0); secret = naSeed.humanSeed(); address = naAccount.humanAccountID(); }
void run() { RippleAddress seed; seed.setSeedRandom (); RippleAddress generator = RippleAddress::createGeneratorPublic (seed); RippleAddress publicAcct = RippleAddress::createAccountPublic (generator, 1); RippleAddress privateAcct = RippleAddress::createAccountPrivate (generator, seed, 1); STTx j (ttACCOUNT_SET); j.setSourceAccount (publicAcct); j.setSigningPubKey (publicAcct); j.setFieldVL (sfMessageKey, publicAcct.getAccountPublic ()); j.sign (privateAcct); unexpected (!j.checkSign (), "Transaction fails signature test"); Serializer rawTxn; j.add (rawTxn); SerialIter sit (rawTxn); STTx copy (sit); if (copy != j) { log << j.getJson (0); log << copy.getJson (0); fail ("Transaction fails serialize/deserialize test"); } else { pass (); } STParsedJSONObject parsed ("test", j.getJson (0)); if (!parsed.object) fail ("Unable to build object from json"); if (STObject (j) != parsed.object) { log << "ORIG: " << j.getJson (0); log << "BUILT " << parsed.object->getJson (0); fail ("Built a different transaction"); } else { pass (); } }
Blob RippleAddress::accountPrivateDecrypt ( RippleAddress const& naPublicFrom, Blob const& vucCipherText) const { uint256 secretKey = getAccountPrivate(); Blob publicKey = naPublicFrom.getAccountPublic(); Blob vucPlainText; { try { vucPlainText = decryptECIES (secretKey, publicKey, vucCipherText); } catch (std::exception const&) { // TODO: log this or explain why this is unimportant! } } return vucPlainText; }
void STTx::setSigningPubKey (RippleAddress const& naSignPubKey) { setFieldVL (sfSigningPubKey, naSignPubKey.getAccountPublic ()); }
// VFALCO TODO This function should take a reference to the params, modify it // as needed, and then there should be a separate function to // submit the transaction. // Json::Value transactionSign ( Json::Value params, bool bSubmit, bool bFailHard, RPCDetail::LedgerFacade& ledgerFacade, Role role) { Json::Value jvResult; WriteLog (lsDEBUG, RPCHandler) << "transactionSign: " << params; if (! params.isMember ("secret")) return RPC::missing_field_error ("secret"); if (! params.isMember ("tx_json")) return RPC::missing_field_error ("tx_json"); RippleAddress naSeed; if (! naSeed.setSeedGeneric (params["secret"].asString ())) return RPC::make_error (rpcBAD_SEED, RPC::invalid_field_message ("secret")); Json::Value& tx_json (params ["tx_json"]); if (! tx_json.isObject ()) return RPC::object_field_error ("tx_json"); if (! tx_json.isMember ("TransactionType")) return RPC::missing_field_error ("tx_json.TransactionType"); std::string const sType = tx_json ["TransactionType"].asString (); if (! tx_json.isMember ("Account")) return RPC::make_error (rpcSRC_ACT_MISSING, RPC::missing_field_message ("tx_json.Account")); RippleAddress raSrcAddressID; if (! raSrcAddressID.setAccountID (tx_json["Account"].asString ())) return RPC::make_error (rpcSRC_ACT_MALFORMED, RPC::invalid_field_message ("tx_json.Account")); bool const verify = !(params.isMember ("offline") && params["offline"].asBool ()); if (!tx_json.isMember ("Sequence") && !verify) return RPC::missing_field_error ("tx_json.Sequence"); // Check for current ledger. if (verify && !getConfig ().RUN_STANDALONE && (ledgerFacade.getValidatedLedgerAge () > 120)) return rpcError (rpcNO_CURRENT); // Check for load. if (ledgerFacade.isLoadedCluster () && (role != Role::ADMIN)) return rpcError (rpcTOO_BUSY); ledgerFacade.snapshotAccountState (raSrcAddressID); if (verify) { if (!ledgerFacade.isValidAccount ()) { // If not offline and did not find account, error. WriteLog (lsDEBUG, RPCHandler) << "transactionSign: Failed to find source account " << "in current ledger: " << raSrcAddressID.humanAccountID (); return rpcError (rpcSRC_ACT_NOT_FOUND); } } autofill_fee (params, ledgerFacade, jvResult, role == Role::ADMIN); if (RPC::contains_error (jvResult)) return jvResult; if ("Payment" == sType) { auto e = signPayment( params, tx_json, raSrcAddressID, ledgerFacade, role); if (contains_error(e)) return e; } if (!tx_json.isMember ("Sequence")) tx_json["Sequence"] = ledgerFacade.getSeq (); if (!tx_json.isMember ("Flags")) tx_json["Flags"] = tfFullyCanonicalSig; if (verify) { if (!ledgerFacade.hasAccountRoot ()) // XXX Ignore transactions for accounts not created. return rpcError (rpcSRC_ACT_NOT_FOUND); } RippleAddress secret = RippleAddress::createSeedGeneric ( params["secret"].asString ()); RippleAddress masterGenerator = RippleAddress::createGeneratorPublic ( secret); RippleAddress masterAccountPublic = RippleAddress::createAccountPublic ( masterGenerator, 0); if (verify) { WriteLog (lsTRACE, RPCHandler) << "verify: " << masterAccountPublic.humanAccountID () << " : " << raSrcAddressID.humanAccountID (); auto const secretAccountID = masterAccountPublic.getAccountID(); if (raSrcAddressID.getAccountID () == secretAccountID) { if (ledgerFacade.accountMasterDisabled ()) return rpcError (rpcMASTER_DISABLED); } else if (!ledgerFacade.accountMatchesRegularKey (secretAccountID)) { return rpcError (rpcBAD_SECRET); } } STParsedJSONObject parsed ("tx_json", tx_json); if (!parsed.object.get()) { jvResult ["error"] = parsed.error ["error"]; jvResult ["error_code"] = parsed.error ["error_code"]; jvResult ["error_message"] = parsed.error ["error_message"]; return jvResult; } std::unique_ptr<STObject> sopTrans = std::move(parsed.object); sopTrans->setFieldVL ( sfSigningPubKey, masterAccountPublic.getAccountPublic ()); STTx::pointer stpTrans; try { stpTrans = std::make_shared<STTx> (*sopTrans); //WriteLog(lsINFO, RPCHandler) << "radar: before sign " << stpTrans->getFieldAmount(sfAmount); } catch (std::exception&) { return RPC::make_error (rpcINTERNAL, "Exception occurred during transaction"); } std::string reason; if (!passesLocalChecks (*stpTrans, reason)) return RPC::make_error (rpcINVALID_PARAMS, reason); if (params.isMember ("debug_signing")) { jvResult["tx_unsigned"] = strHex ( stpTrans->getSerializer ().peekData ()); jvResult["tx_signing_hash"] = to_string (stpTrans->getSigningHash ()); } // FIXME: For performance, transactions should not be signed in this code // path. RippleAddress naAccountPrivate = RippleAddress::createAccountPrivate ( masterGenerator, secret, 0); stpTrans->sign (naAccountPrivate); Transaction::pointer tpTrans; try { //WriteLog(lsINFO, RPCHandler) << "radar: after sign " << stpTrans->getFieldAmount(sfAmount); tpTrans = std::make_shared<Transaction>(stpTrans, Validate::NO); //WriteLog(lsINFO, RPCHandler) << "radar: after copy" << tpTrans->getSTransaction()->getFieldAmount(sfAmount); } catch (std::exception&) { return RPC::make_error (rpcINTERNAL, "Exception occurred during transaction"); } try { // FIXME: For performance, should use asynch interface. tpTrans = ledgerFacade.submitTransactionSync (tpTrans, role == Role::ADMIN, true, bFailHard, bSubmit); if (!tpTrans) { return RPC::make_error (rpcINTERNAL, "Unable to sterilize transaction."); } } catch (std::exception&) { return RPC::make_error (rpcINTERNAL, "Exception occurred during transaction submission."); } try { jvResult["tx_json"] = tpTrans->getJson (0); jvResult["tx_blob"] = strHex ( tpTrans->getSTransaction ()->getSerializer ().peekData ()); if (temUNCERTAIN != tpTrans->getResult ()) { std::string sToken; std::string sHuman; transResultInfo (tpTrans->getResult (), sToken, sHuman); jvResult["engine_result"] = sToken; jvResult["engine_result_code"] = tpTrans->getResult (); jvResult["engine_result_message"] = sHuman; } return jvResult; } catch (std::exception&) { return RPC::make_error (rpcINTERNAL, "Exception occurred during JSON handling."); } }
void LoopThread(unsigned int n, uint64_t eta50, string* ppattern, string* pmaster_seed, string* pmaster_seed_hex, string* paccount_id) { RippleAddress naSeed; RippleAddress naAccount; string pattern = *ppattern; string account_id; uint128 key; getRand(key.begin(), key.size()); uint64_t count = 0; uint64_t last_count = 0; do { naSeed.setSeed(key); RippleAddress naGenerator = createGeneratorPublic(naSeed); naAccount.setAccountPublic(naGenerator.getAccountPublic(), 0); account_id = naAccount.humanAccountID(); count++; if (count % UPDATE_ITERATIONS == 0) { boost::unique_lock<boost::mutex> lock(mutex); total_searched += count - last_count; last_count = count; uint64_t nSecs = time(NULL) - start_time; double speed = (1.0 * total_searched)/nSecs; const char* unit = "seconds"; double eta50f = eta50/speed; if (eta50f > 100) { unit = "minutes"; eta50f /= 60; if (eta50f > 100) { unit = "hours"; eta50f /= 60; if (eta50f > 48) { unit = "days"; eta50f /= 24; } } } cout << "# Thread " << n << ": " << count << " seeds." << endl << "#" << endl << "# Total Speed: " << speed << " seeds/second" << endl << "# Total Searched: " << total_searched << endl << "# Total Time: " << nSecs << " seconds" << endl << "# ETA 50%: " << eta50f << " " << unit << endl << "# Last: " << account_id << endl << "# Pattern: " << pattern << endl << "#" << endl; } key++; boost::this_thread::yield(); } while ((account_id.substr(0, pattern.size()) != pattern) && !fDone); boost::unique_lock<boost::mutex> lock(mutex); if (fDone) return; fDone = true; cout << "# *** Found by thread " << n << ". ***" << endl << "#" << endl; *pmaster_seed = naSeed.humanSeed(); *pmaster_seed_hex = naSeed.getSeed().ToString(); *paccount_id = account_id; }
// VFALCO TODO This function should take a reference to the params, modify it // as needed, and then there should be a separate function to // submit the transaction // Json::Value transactionSign ( Json::Value params, bool bSubmit, bool bFailHard, Application::ScopedLockType& mlh, NetworkOPs& netOps, int role) { Json::Value jvResult; WriteLog (lsDEBUG, RPCHandler) << "transactionSign: " << params; if (! params.isMember ("secret")) return RPC::missing_field_error ("secret"); if (! params.isMember ("tx_json")) return RPC::missing_field_error ("tx_json"); RippleAddress naSeed; if (! naSeed.setSeedGeneric (params["secret"].asString ())) return RPC::make_error (rpcBAD_SEED, RPC::invalid_field_message ("secret")); Json::Value& tx_json (params ["tx_json"]); if (! tx_json.isObject ()) return RPC::object_field_error ("tx_json"); if (! tx_json.isMember ("TransactionType")) return RPC::missing_field_error ("tx_json.TransactionType"); std::string const sType = tx_json ["TransactionType"].asString (); if (! tx_json.isMember ("Account")) return RPC::make_error (rpcSRC_ACT_MISSING, RPC::missing_field_message ("tx_json.Account")); RippleAddress raSrcAddressID; if (! raSrcAddressID.setAccountID (tx_json["Account"].asString ())) return RPC::make_error (rpcSRC_ACT_MALFORMED, RPC::invalid_field_message ("tx_json.Account")); bool const verify = !(params.isMember ("offline") && params["offline"].asBool ()); if (!tx_json.isMember ("Sequence") && !verify) return RPC::missing_field_error ("tx_json.Sequence"); // Check for current ledger if (verify && !getConfig ().RUN_STANDALONE && (getApp().getLedgerMaster().getValidatedLedgerAge() > 120)) return rpcError (rpcNO_CURRENT); // Check for load if (getApp().getFeeTrack().isLoadedCluster() && (role != Config::ADMIN)) return rpcError(rpcTOO_BUSY); Ledger::pointer lSnapshot = netOps.getCurrentLedger (); AccountState::pointer asSrc; if (verify) { asSrc = netOps.getAccountState (lSnapshot, raSrcAddressID); if (!asSrc) { // If not offline and did not find account, error. WriteLog (lsDEBUG, RPCHandler) << "transactionSign: Failed to find source account in current ledger: " << raSrcAddressID.humanAccountID (); return rpcError (rpcSRC_ACT_NOT_FOUND); } } autofill_fee (params, lSnapshot, jvResult, role == Config::ADMIN); if (RPC::contains_error (jvResult)) return jvResult; if ("Payment" == sType) { auto e = signPayment(params, tx_json, raSrcAddressID, lSnapshot, role); if (contains_error(e)) return e; } if ("Genesis" == sType) { auto e = signGenesis(params, tx_json, raSrcAddressID, lSnapshot, role); if (contains_error(e)) return e; } if ("Transfer" == sType) { auto e = signTransfer(params, tx_json, raSrcAddressID, lSnapshot, role); if (contains_error(e)) return e; } if ("AccountCreate" == sType) { auto e = signAccountCreate(params, tx_json, raSrcAddressID, lSnapshot, role); if (contains_error(e)) return e; } if (!tx_json.isMember ("Fee")) { auto const& transactionType = tx_json["TransactionType"].asString (); if ("AccountSet" == transactionType || "OfferCreate" == transactionType || "OfferCancel" == transactionType || "TrustSet" == transactionType) { tx_json["Fee"] = (int) getConfig ().FEE_DEFAULT; } } if (!tx_json.isMember ("Sequence")) tx_json["Sequence"] = asSrc->getSeq (); if (!tx_json.isMember ("Flags")) tx_json["Flags"] = tfFullyCanonicalSig; if (verify) { SLE::pointer sleAccountRoot = netOps.getSLEi (lSnapshot, Ledger::getAccountRootIndex (raSrcAddressID.getAccountID ())); if (!sleAccountRoot) // XXX Ignore transactions for accounts not created. return rpcError (rpcSRC_ACT_NOT_FOUND); } RippleAddress naSecret = RippleAddress::createSeedGeneric (params["secret"].asString ()); RippleAddress masterAccountPublic = RippleAddress::createAccountPublic(naSecret); if (verify) { auto account = masterAccountPublic.getAccountID(); auto const& sle = asSrc->peekSLE(); WriteLog (lsWARNING, RPCHandler) << "verify: " << masterAccountPublic.humanAccountID () << " : " << raSrcAddressID.humanAccountID (); if (raSrcAddressID.getAccountID () == account) { if (sle.isFlag(lsfDisableMaster) && "Inflation" != sType) return rpcError (rpcMASTER_DISABLED); } else if (!sle.isFieldPresent(sfRegularKey) || account != sle.getFieldAccount160 (sfRegularKey)) { return rpcError (rpcBAD_SECRET); } } STParsedJSON parsed ("tx_json", tx_json); if (!parsed.object.get()) { jvResult ["error"] = parsed.error ["error"]; jvResult ["error_code"] = parsed.error ["error_code"]; jvResult ["error_message"] = parsed.error ["error_message"]; return jvResult; } std::unique_ptr<STObject> sopTrans = std::move(parsed.object); sopTrans->setFieldVL (sfSigningPubKey, masterAccountPublic.getAccountPublic ()); SerializedTransaction::pointer stpTrans; try { stpTrans = boost::make_shared<SerializedTransaction> (*sopTrans); } catch (std::exception&) { return RPC::make_error (rpcINTERNAL, "Exception occurred during transaction"); } std::string reason; if (!passesLocalChecks (*stpTrans, reason)) return RPC::make_error (rpcINVALID_PARAMS, reason); if (params.isMember ("debug_signing")) { jvResult["tx_unsigned"] = strHex ( stpTrans->getSerializer ().peekData ()); jvResult["tx_signing_hash"] = to_string (stpTrans->getSigningHash ()); } // FIXME: For performance, transactions should not be signed in this code path. RippleAddress naAccountPrivate = RippleAddress::createAccountPrivate (naSecret); stpTrans->sign (naAccountPrivate); Transaction::pointer tpTrans; tpTrans = getApp().getMasterTransaction().fetch(stpTrans->getTransactionID(), false); if (tpTrans) { TER res = tpTrans->getResult(); if (!(isTelLocal(res) || isTemMalformed(res) || isTefFailure(res))) { tpTrans = Transaction::pointer(); } } if (!tpTrans) { try { tpTrans = boost::make_shared<Transaction> (stpTrans, false); } catch (std::exception&) { return RPC::make_error (rpcINTERNAL, "Exception occurred during transaction"); } try { // FIXME: For performance, should use asynch interface tpTrans = netOps.submitTransactionSync (tpTrans, role == Config::ADMIN, true, bFailHard, bSubmit); if (!tpTrans) { return RPC::make_error (rpcINTERNAL, "Unable to sterilize transaction."); } } catch (std::exception&) { return RPC::make_error (rpcINTERNAL, "Exception occurred during transaction submission."); } } try { jvResult["tx_json"] = tpTrans->getJson (0); jvResult["tx_blob"] = strHex ( tpTrans->getSTransaction ()->getSerializer ().peekData ()); if (temUNCERTAIN != tpTrans->getResult ()) { std::string sToken; std::string sHuman; transResultInfo (tpTrans->getResult (), sToken, sHuman); jvResult["engine_result"] = sToken; jvResult["engine_result_code"] = tpTrans->getResult (); jvResult["engine_result_message"] = sHuman; } return jvResult; } catch (std::exception&) { return RPC::make_error (rpcINTERNAL, "Exception occurred during JSON handling."); } }
Json::Value walletPropose (Json::Value const& params) { RippleAddress naSeed; RippleAddress naAccount; KeyType type = KeyType::secp256k1; bool const has_key_type = params.isMember (jss::key_type); bool const has_passphrase = params.isMember (jss::passphrase); if (has_key_type) { // `key_type` must be valid if present. type = keyTypeFromString (params[jss::key_type].asString()); if (type == KeyType::invalid) { return rpcError (rpcBAD_SEED); } naSeed = getSeedFromRPC (params); } else if (has_passphrase) { naSeed.setSeedGeneric (params[jss::passphrase].asString()); } else { naSeed.setSeedRandom(); } if (!naSeed.isSet()) { return rpcError(rpcBAD_SEED); } if (type == KeyType::secp256k1) { RippleAddress naGenerator = RippleAddress::createGeneratorPublic (naSeed); naAccount.setAccountPublic (naGenerator, 0); } else if (type == KeyType::ed25519) { uint256 secretkey = keyFromSeed (naSeed.getSeed()); Blob publickey (33); publickey[0] = 0xED; ed25519_publickey (secretkey.data(), &publickey[1]); secretkey.zero(); // security erase naAccount.setAccountPublic (publickey); } else { assert (false); // not reached } Json::Value obj (Json::objectValue); obj[jss::master_seed] = naSeed.humanSeed (); obj[jss::master_seed_hex] = to_string (naSeed.getSeed ()); obj[jss::master_key] = naSeed.humanSeed1751(); obj[jss::account_id] = naAccount.humanAccountID (); obj[jss::public_key] = naAccount.humanAccountPublic(); obj[jss::key_type] = to_string (type); auto acct = naAccount.getAccountPublic(); obj[jss::public_key_hex] = strHex(acct.begin(), acct.size()); return obj; }