feat: add received outputs to /get_address_txs (#304)
What changed, and why it matters
This commit adds an optional feature to the Monero Light Wallet Server's /get_address_txs endpoint. When a wallet explicitly asks for it by setting 'receives': true, the server will include details about incoming (received) transaction outputs in the response. The feature is off by default and requires the same view-key authentication already used by the endpoint. The change refactors existing code to reuse the RingCT decoding logic rather than duplicating it.
No immediate security action required. Treat as a normal feature review: verify that the view-key gating is correct in production builds and that the new receives flag cannot be used to bypass authentication or leak another user's outputs.
Security signals we found
New optional RPC field exposes additional wallet data (received outputs) only when explicitly requested and authenticated
Refactoring reuses existing RingCT decryption logic; no new cryptographic primitives introduced
Default behavior unchanged: 'receives' defaults to false, preserving prior response shape
Endpoint still requires account_credentials (address + view_key) before returning any data
Evidence from the diff
The patch extends the /get_address_txs RPC: it introduces get_address_txs_request (replacing bare account_credentials) with a defaulted-false ‘receives’ boolean, and adds an optional user_key to get_address_txs_response so that serialized transactions can include received output expansion. A new expand_rct helper is extracted from the existing spent-output path and reused for received outputs. Received outputs are only serialized when the request set receives=true and the response carries the user’s secret view key; otherwise an empty/no-receives path is taken. The API schema and unit tests are updated accordingly.
Changed components
docs/api/wallet.yamlsrc/rest_server.cppsrc/rpc/light_wallet.cppsrc/rpc/light_wallet.htests/unit/rest.test.cppInspect captured patch +365 / −29
### docs/api/wallet.yaml
@@ -142,6 +142,10 @@ paths:
description: Block hash of most recent tx
allOf:
- $ref: '#/components/schemas/binary32'
+ receives:
+ description: Return the received outputs of each transaction in `receives`
+ type: boolean
+ default: false
required: true
responses:
'200':
@@ -1042,6 +1046,40 @@ components:
- spend_key_images
- timestamp
- height
+ received_output:
+ description: |
+ A received output in a transaction. The fields have the same format as in `output`.
+
+ `global_index` does not have a valid value when the transaction is in the mempool.
+ type: object
+ properties:
+ amount:
+ $ref: '#/components/schemas/uint64-string'
+ public_key:
+ $ref: '#/components/schemas/binary32'
+ index:
+ description: Index within vout vector
+ allOf:
+ - $ref: '#/components/schemas/uint16'
+ global_index:
+ description: Index within amount (determined by blockchain order)
+ allOf:
+ - $ref: '#/components/schemas/uint64'
+ tx_pub_key:
+ description: Bytes of the ephermal tx public key
+ allOf:
+ - $ref: '#/components/schemas/binary32'
+ rct:
+ $ref: '#/components/schemas/ringct-packed'
+ recipient:
+ $ref: '#/components/schemas/address_meta'
+ required:
+ - amount
+ - public_key
+ - index
+ - global_index
+ - tx_pub_key
+ - recipient
rates:
description: "Conversion rates into common/popular currencies"
type: object
@@ -1188,6 +1226,11 @@ components:
type: array
items:
$ref: '#/components/schemas/spend'
+ receives:
+ description: Received outputs. Sent only when the request has `receives` set to true. Omitted when the transaction has no received outputs.
+ type: array
+ items:
+ $ref: '#/components/schemas/received_output'
payment_id:
$ref: '#/components/schemas/payment-id'
coinbase:
### src/rest_server.cpp
@@ -553,17 +553,20 @@ namespace lws
struct get_address_txs
{
- using request = rpc::account_credentials;
+ using request = rpc::get_address_txs_request;
using response = rpc::get_address_txs_response;
static expect<response> handle(const request& req, connection_data& data, std::function<async_complete>&&)
{
- auto user = lws::rpc::open_account(req, data.global->disk);
+ auto user = lws::rpc::open_account(req.creds, data.global->disk);
if (!user)
return user.error();
data.passed_login = true;
- return response::load(user->second, user->first, data.global->mempool.get(), false);
+ auto resp = response::load(user->second, user->first, data.global->mempool.get(), req.receives);
+ if (resp && req.receives)
+ resp->user_key = req.creds.key;
+ return resp;
}
};
### src/rpc/light_wallet.cpp
@@ -77,6 +77,12 @@ namespace
const std::pair<lws::db::output, std::vector<crypto::key_image>>& data;
const crypto::secret_key& user_key;
};
+
+ struct expand_receive
+ {
+ const lws::db::output& data;
+ const crypto::secret_key& user_key;
+ };
} // anonymous
namespace wire
@@ -106,6 +112,35 @@ namespace
dest.string({buf, sizeof(buf) - 1});
}
+ //! \return False if `src` is not a ringct output.
+ bool expand_rct(rct_bytes& rct, const lws::db::output& src, const crypto::secret_key& user_key)
+ {
+ const auto flags = unpack(src.extra).first;
+ if (!(flags & lws::db::ringct_output))
+ return false;
+
+ if (!(flags & lws::db::coinbase_output))
+ {
+ crypto::key_derivation derived;
+ if (!crypto::generate_key_derivation(src.spend_meta.tx_public, user_key, derived))
+ MONERO_THROW(lws::error::crypto_failure, "generate_key_derivation failed");
+
+ crypto::secret_key scalar;
+ rct::ecdhTuple encrypted{src.ringct_mask, rct::d2h(src.spend_meta.amount)};
+
+ crypto::derivation_to_scalar(derived, src.spend_meta.index, scalar);
+ rct::ecdhEncode(encrypted, rct::sk2rct(scalar), false);
+
+ rct.commitment = rct::commit(src.spend_meta.amount, src.ringct_mask);
+ rct.mask = encrypted.mask;
+ rct.amount = encrypted.amount;
+ }
+ else
+ rct.mask = rct::identity();
+
+ return true;
+ }
+
void write_bytes(wire::json_writer& dest, const expand_outputs self)
{
/*! \TODO Sending the public key for the output isn't necessary, as it can be
@@ -115,30 +150,8 @@ namespace
rct_bytes rct{};
rct_bytes const* optional_rct = nullptr;
- const auto flags = unpack(self.data.first.extra).first;
- if (flags & lws::db::ringct_output)
- {
- if (!(flags & lws::db::coinbase_output))
- {
- crypto::key_derivation derived;
- if (!crypto::generate_key_derivation(self.data.first.spend_meta.tx_public, self.user_key, derived))
- MONERO_THROW(lws::error::crypto_failure, "generate_key_derivation failed");
-
- crypto::secret_key scalar;
- rct::ecdhTuple encrypted{self.data.first.ringct_mask, rct::d2h(self.data.first.spend_meta.amount)};
-
- crypto::derivation_to_scalar(derived, self.data.first.spend_meta.index, scalar);
- rct::ecdhEncode(encrypted, rct::sk2rct(scalar), false);
-
- rct.commitment = rct::commit(self.data.first.spend_meta.amount, self.data.first.ringct_mask);
- rct.mask = encrypted.mask;
- rct.amount = encrypted.amount;
- }
- else
- rct.mask = rct::identity();
-
+ if (expand_rct(rct, self.data.first, self.user_key))
optional_rct = std::addressof(rct);
- }
wire::object(dest,
wire::field("amount", lws::rpc::safe_uint64(self.data.first.spend_meta.amount)),
@@ -157,6 +170,24 @@ namespace
);
}
+ void write_bytes(wire::json_writer& dest, const expand_receive self)
+ {
+ rct_bytes rct{};
+ rct_bytes const* optional_rct = nullptr;
+ if (expand_rct(rct, self.data, self.user_key))
+ optional_rct = std::addressof(rct);
+
+ wire::object(dest,
+ wire::field("amount", lws::rpc::safe_uint64(self.data.spend_meta.amount)),
+ wire::field("public_key", self.data.pub),
+ wire::field("index", self.data.spend_meta.index),
+ wire::field("global_index", self.data.spend_meta.id.low),
+ wire::field("tx_pub_key", self.data.spend_meta.tx_public),
+ wire::optional_field("rct", optional_rct),
+ wire::field("recipient", std::cref(self.data.recipient))
+ );
+ }
+
void convert_address(const boost::string_ref source, lws::db::account_address& dest)
{
expect<lws::db::account_address> bytes = lws::db::address_string(source);
@@ -491,7 +522,12 @@ namespace lws
namespace rpc
{
- static void write_bytes(wire::json_writer& dest, boost::range::index_value<const get_transaction&> self)
+ struct indexed_transaction : boost::range::index_value<const get_transaction&>
+ {
+ crypto::secret_key const* user_key;
+ };
+
+ static void write_bytes(wire::json_writer& dest, const indexed_transaction& self)
{
epee::span<const std::uint8_t> const* payment_id = nullptr;
epee::span<const std::uint8_t> payment_id_bytes;
@@ -512,6 +548,14 @@ namespace lws
const bool mempool = height == db::block_id::txpool;
const iso_timestamp timestamp{self.value().info.timestamp};
+ // Mempool outputs are always in `receives`, so only the key enables this field
+ static const std::vector<db::output> no_receives{};
+ const auto& receives = self.user_key ? self.value().receives : no_receives;
+ const auto expand = [&self] (const db::output& src)
+ {
+ return expand_receive{src, *self.user_key};
+ };
+
wire::object(dest,
wire::field("id", std::uint64_t(self.index())),
wire::field("hash", std::cref(self.value().info.link.tx_hash)),
@@ -526,7 +570,8 @@ namespace lws
wire::field("mempool", mempool),
wire::field("mixin", self.value().info.spend_meta.mixin_count),
wire::field("recipient", self.value().info.recipient),
- wire::field("spent_outputs", std::cref(self.value().spends))
+ wire::field("spent_outputs", std::cref(self.value().spends)),
+ wire::optional_field("receives", wire::array(boost::adaptors::transform(receives, expand)))
);
}
} // rpc
@@ -805,6 +850,10 @@ namespace lws
void rpc::write_bytes(wire::json_writer& dest, const get_address_txs_response& self)
{
+ const auto with_key = [&self] (boost::range::index_value<const get_transaction&> tx)
+ {
+ return indexed_transaction{tx, self.user_key.get_ptr()};
+ };
wire::object(dest,
wire::field("total_received", safe_uint64(self.total_received)),
WIRE_FIELD_COPY(scanned_height),
@@ -814,8 +863,19 @@ namespace lws
WIRE_FIELD_COPY(blockchain_height),
WIRE_FIELD_DEFAULTED(lookahead_fail, unsigned(0)),
WIRE_FIELD_DEFAULTED(lookahead, db::address_index{}),
- wire::optional_field("transactions", wire::array(boost::adaptors::index(self.transactions)))
+ wire::optional_field("transactions", wire::array(boost::adaptors::transform(boost::adaptors::index(self.transactions), with_key)))
+ );
+ }
+
+ void rpc::read_bytes(wire::json_reader& source, get_address_txs_request& self)
+ {
+ std::string address;
+ wire::object(source,
+ wire::field("address", std::ref(address)),
+ wire::field("view_key", std::ref(unwrap(unwrap(self.creds.key)))),
+ WIRE_FIELD_DEFAULTED(receives, false)
);
+ convert_address(address, self.creds.address);
}
void rpc::read_bytes(wire::json_reader& source, get_random_outs_request& self)
### src/rpc/light_wallet.h
@@ -154,6 +154,7 @@ namespace rpc
std::uint64_t lookahead_fail;
std::vector<get_transaction> transactions;
db::address_index lookahead;
+ boost::optional<crypto::secret_key> user_key;
};
void write_bytes(wire::json_writer&, const get_address_txs_response&);
@@ -268,6 +269,15 @@ namespace rpc
void write_bytes(wire::json_writer&, const get_address_info_response&);
+ struct get_address_txs_request
+ {
+ get_address_txs_request() = delete;
+ account_credentials creds;
+ bool receives;
+ };
+ void read_bytes(wire::json_reader&, get_address_txs_request&);
+
+
struct get_random_outs_request
{
get_random_outs_request() = delete;
### tests/unit/rest.test.cpp
@@ -793,6 +793,85 @@ LWS_CASE("rest_server")
})";
verify_json(lest_env, "/get_address_txs", response, expected);
+ const auto block_rct = get_rct_bytes(view, tx_public, ringct, 40000, 2, true);
+ const auto pool_rct = get_rct_bytes(view, tx.pub_keys.at(0), tx.ringct.at(0), 8000, 0, false);
+ const std::string receives_message =
+ "{\"address\":\"" + address + "\",\"view_key\":\"" + viewkey + "\",\"receives\":true}";
+ response = invoke(client, "/get_address_txs", receives_message);
+ const std::string expected_receives =
+ R"({
+ "total_received":"48000",
+ "scanned_height":)" + scan_height + R"(,
+ "scanned_block_height":)" + scan_height + R"(,
+ "start_height":)" + start_height + R"(,
+ "transaction_height":)" + scan_height + R"(,
+ "blockchain_height":)" + scan_height + R"(,
+ "transactions":[
+ {
+ "id":0,
+ "hash":")" + epee::to_hex::string(epee::as_byte_span(link.tx_hash)) + R"(",
+ "timestamp":"1970-01-01T01:56:40Z",
+ "total_received":"40000",
+ "total_sent":"40000",
+ "fee":"100",
+ "unlock_time":4670,
+ "height":4000,
+ "payment_id":")" + epee::to_hex::string(epee::as_byte_span(payment_id_.long_)) + R"(",
+ "coinbase":true,
+ "mempool":false,
+ "mixin":16,
+ "recipient":{"maj_i":2,"min_i":66},
+ "spent_outputs":[{
+ "amount":"40000",
+ "key_image":")" + epee::to_hex::string(epee::as_byte_span(image)) + R"(",
+ "tx_pub_key":")" + epee::to_hex::string(epee::as_byte_span(tx_public)) + R"(",
+ "out_index":2,
+ "mixin":16,
+ "sender":{"maj_i":4,"min_i":55}
+ }],
+ "receives":[{
+ "amount":"40000",
+ "public_key":")" + epee::to_hex::string(epee::as_byte_span(pub)) + R"(",
+ "index":2,
+ "global_index":35,
+ "tx_pub_key":")" + epee::to_hex::string(epee::as_byte_span(tx_public)) + R"(",
+ "rct":")" + epee::to_hex::string(epee::as_byte_span(block_rct)) + R"(",
+ "recipient":{"maj_i":2,"min_i":66}
+ }]
+ },{
+ "id":1,
+ "hash":")" + epee::to_hex::string(epee::as_byte_span(get_transaction_hash(tx.tx))) + R"(",
+ "total_received":"8000",
+ "total_sent":"40000",
+ "fee":"12000",
+ "unlock_time":0,
+ "payment_id":"0000000000000000",
+ "coinbase":false,
+ "mempool":true,
+ "mixin":15,
+ "recipient":{"maj_i":0,"min_i":0},
+ "spent_outputs":[{
+ "amount":"40000",
+ "key_image":")" + epee::to_hex::string(epee::as_byte_span(tx.images.at(0))) + R"(",
+ "tx_pub_key":")" + epee::to_hex::string(epee::as_byte_span(tx_public)) + R"(",
+ "out_index":2,
+ "mixin":15,
+ "sender":{"maj_i":2, "min_i": 66}
+ }],
+ "receives":[{
+ "amount":"8000",
+ "public_key":")" + epee::to_hex::string(epee::as_byte_span(tx.spend_publics.at(0))) + R"(",
+ "index":0,
+ "global_index":18446744073709551615,
+ "tx_pub_key":")" + epee::to_hex::string(epee::as_byte_span(tx.pub_keys.at(0))) + R"(",
+ "rct":")" + epee::to_hex::string(epee::as_byte_span(pool_rct)) + R"(",
+ "recipient":{"maj_i":0,"min_i":0}
+ }]
+ }
+ ]
+ })";
+ verify_json(lest_env, "/get_address_txs receives", response, expected_receives);
+
std::vector<epee::byte_slice> messages;
messages.emplace_back(get_fee_response());
std::atomic<bool> ready{false};
@@ -826,6 +905,147 @@ LWS_CASE("rest_server")
);
}
+ SECTION("get_address_txs receives")
+ {
+ const std::string scan_height = std::to_string(std::uint64_t(account.scan_height) + 5);
+ const std::string start_height = std::to_string(std::uint64_t(account.start_height));
+
+ const lws::db::transaction_link link_a{
+ lws::db::block_id(4000), crypto::rand<crypto::hash>()
+ };
+ const lws::db::transaction_link link_b{
+ lws::db::block_id(4001), crypto::rand<crypto::hash>()
+ };
+ const crypto::public_key tx_public = []() {
+ crypto::secret_key secret;
+ crypto::public_key out;
+ crypto::generate_keys(out, secret);
+ return out;
+ }();
+ const crypto::public_key pub_a0 = crypto::rand<crypto::public_key>();
+ const crypto::public_key pub_a1 = crypto::rand<crypto::public_key>();
+ const crypto::public_key pub_b = crypto::rand<crypto::public_key>();
+ const rct::key mask_a0 = crypto::rand<rct::key>();
+ const rct::key mask_a1 = crypto::rand<rct::key>();
+ const auto ringct = lws::db::pack(lws::db::extra::ringct_output, 0);
+ const auto legacy = lws::db::pack(lws::db::extra(0), 0);
+
+ const auto make_output = [&] (const lws::db::transaction_link& link, const lws::db::output_id id, const std::uint64_t amount, const std::uint32_t index, const crypto::public_key& pub, const rct::key& mask, const lws::db::extra_and_length extra, const lws::db::address_index recipient)
+ {
+ return lws::db::output{
+ link,
+ lws::db::output::spend_meta_{id, amount, std::uint32_t(15), index, tx_public},
+ std::uint64_t(7000),
+ std::uint64_t(0),
+ crypto::rand<crypto::hash>(),
+ pub,
+ mask,
+ {0, 0, 0, 0, 0, 0, 0},
+ extra,
+ {},
+ std::uint64_t(100),
+ recipient
+ };
+ };
+
+ lws::account real_account{account, {}, {}};
+ real_account.add_out(make_output(link_a, {0, 40}, 10000, 0, pub_a0, mask_a0, ringct, {}));
+ real_account.add_out(
+ make_output(link_a, {0, 41}, 20000, 1, pub_a1, mask_a1, ringct, {lws::db::major_index(1), lws::db::minor_index(3)})
+ );
+ real_account.add_out(make_output(link_b, {5000, 7}, 5000, 0, pub_b, rct::key{}, legacy, {}));
+
+ {
+ std::vector<crypto::hash> hashes{
+ last_block.hash,
+ crypto::rand<crypto::hash>(),
+ crypto::rand<crypto::hash>(),
+ crypto::rand<crypto::hash>(),
+ crypto::rand<crypto::hash>(),
+ crypto::rand<crypto::hash>()
+ };
+
+ EXPECT(db.update(last_block.id, epee::to_span(hashes), {std::addressof(real_account), 1}, {}));
+ }
+
+ const std::string credentials = "\"address\":\"" + address + "\",\"view_key\":\"" + viewkey + "\"";
+ const std::string response_default = invoke(client, "/get_address_txs", "{" + credentials + "}");
+ EXPECT(response_default.find("\"receives\"") == std::string::npos);
+
+ response = invoke(client, "/get_address_txs", "{" + credentials + ",\"receives\":false}");
+ EXPECT(response == response_default);
+
+ const auto rct_a0 = get_rct_bytes(view, tx_public, mask_a0, 10000, 0, false);
+ const auto rct_a1 = get_rct_bytes(view, tx_public, mask_a1, 20000, 1, false);
+ response = invoke(client, "/get_address_txs", "{" + credentials + ",\"receives\":true}");
+ const std::string expected =
+ R"({
+ "total_received":"35000",
+ "scanned_height":)" + scan_height + R"(,
+ "scanned_block_height":)" + scan_height + R"(,
+ "start_height":)" + start_height + R"(,
+ "transaction_height":)" + scan_height + R"(,
+ "blockchain_height":)" + scan_height + R"(,
+ "transactions":[
+ {
+ "id":0,
+ "hash":")" + epee::to_hex::string(epee::as_byte_span(link_a.tx_hash)) + R"(",
+ "timestamp":"1970-01-01T01:56:40Z",
+ "total_received":"30000",
+ "total_sent":"0",
+ "fee":"100",
+ "unlock_time":0,
+ "height":4000,
+ "coinbase":false,
+ "mempool":false,
+ "mixin":15,
+ "recipient":{"maj_i":0,"min_i":0},
+ "receives":[
+ {
+ "amount":"10000",
+ "public_key":")" + epee::to_hex::string(epee::as_byte_span(pub_a0)) + R"(",
+ "index":0,
+ "global_index":40,
+ "tx_pub_key":")" + epee::to_hex::string(epee::as_byte_span(tx_public)) + R"(",
+ "rct":")" + epee::to_hex::string(epee::as_byte_span(rct_a0)) + R"(",
+ "recipient":{"maj_i":0,"min_i":0}
+ },{
+ "amount":"20000",
+ "public_key":")" + epee::to_hex::string(epee::as_byte_span(pub_a1)) + R"(",
+ "index":1,
+ "global_index":41,
+ "tx_pub_key":")" + epee::to_hex::string(epee::as_byte_span(tx_public)) + R"(",
+ "rct":")" + epee::to_hex::string(epee::as_byte_span(rct_a1)) + R"(",
+ "recipient":{"maj_i":1,"min_i":3}
+ }
+ ]
+ },{
+ "id":1,
+ "hash":")" + epee::to_hex::string(epee::as_byte_span(link_b.tx_hash)) + R"(",
+ "timestamp":"1970-01-01T01:56:40Z",
+ "total_received":"5000",
+ "total_sent":"0",
+ "fee":"100",
+ "unlock_time":0,
+ "height":4001,
+ "coinbase":false,
+ "mempool":false,
+ "mixin":15,
+ "recipient":{"maj_i":0,"min_i":0},
+ "receives":[{
+ "amount":"5000",
+ "public_key":")" + epee::to_hex::string(epee::as_byte_span(pub_b)) + R"(",
+ "index":0,
+ "global_index":7,
+ "tx_pub_key":")" + epee::to_hex::string(epee::as_byte_span(tx_public)) + R"(",
+ "recipient":{"maj_i":0,"min_i":0}
+ }]
+ }
+ ]
+ })";
+ verify_json(lest_env, "/get_address_txs receives", response, expected);
+ }
+
SECTION("provision_subaddrs")
{
const std::string scan_height = std::to_string(std::uint64_t(account.scan_height) + 5);Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.