Skip to content

Commit 49b3379

Browse files
committed
chore: ensuring that all composite responses have 0x prefix
1 parent 3b6ec38 commit 49b3379

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

src/rpc/rpc_composite_handlers.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ QJsonObject RpcService::handleExportExtendedPublicKey(quint64 id, const QJsonObj
114114
}
115115

116116
QJsonObject keyObj;
117-
keyObj["address"] = key.address;
118-
keyObj["publicKey"] = key.publicKey;
119-
keyObj["chainCode"] = key.chainCode;
117+
keyObj["address"] = ensure0xPrefix(key.address);
118+
keyObj["publicKey"] = ensure0xPrefix(key.publicKey);
119+
keyObj["chainCode"] = ensure0xPrefix(key.chainCode);
120120
keyObj["xpub"] = key.xpub;
121121

122122
return createSuccessResponse(id, keyObj);
@@ -178,19 +178,19 @@ QJsonObject RpcService::handleExportPublicKey(quint64 id, const QJsonObject& par
178178

179179
QJsonObject response;
180180
if (!result.masterKeyAddress.isEmpty()) {
181-
response["masterKeyAddress"] = result.masterKeyAddress;
181+
response["masterKeyAddress"] = ensure0xPrefix(result.masterKeyAddress);
182182
}
183183
if (inputWasArray) {
184184
QJsonArray exportedArray;
185185
for (const auto& kp : result.exportedKeys) {
186186
QJsonObject keyObj;
187-
keyObj["address"] = kp.address;
188-
keyObj["publicKey"] = kp.publicKey;
187+
keyObj["address"] = ensure0xPrefix(kp.address);
188+
keyObj["publicKey"] = ensure0xPrefix(kp.publicKey);
189189
if (!kp.privateKey.isEmpty()) {
190-
keyObj["privateKey"] = kp.privateKey;
190+
keyObj["privateKey"] = ensure0xPrefix(kp.privateKey);
191191
}
192192
if (!kp.chainCode.isEmpty()) {
193-
keyObj["chainCode"] = kp.chainCode;
193+
keyObj["chainCode"] = ensure0xPrefix(kp.chainCode);
194194
}
195195
exportedArray.append(keyObj);
196196
}
@@ -201,13 +201,13 @@ QJsonObject RpcService::handleExportPublicKey(quint64 id, const QJsonObject& par
201201
} else {
202202
const auto& kp = result.exportedKeys.first();
203203
QJsonObject keyObj;
204-
keyObj["address"] = kp.address;
205-
keyObj["publicKey"] = kp.publicKey;
204+
keyObj["address"] = ensure0xPrefix(kp.address);
205+
keyObj["publicKey"] = ensure0xPrefix(kp.publicKey);
206206
if (!kp.privateKey.isEmpty()) {
207-
keyObj["privateKey"] = kp.privateKey;
207+
keyObj["privateKey"] = ensure0xPrefix(kp.privateKey);
208208
}
209209
if (!kp.chainCode.isEmpty()) {
210-
keyObj["chainCode"] = kp.chainCode;
210+
keyObj["chainCode"] = ensure0xPrefix(kp.chainCode);
211211
}
212212
response["exportedKey"] = keyObj;
213213
}

src/rpc/rpc_service.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "rpc_service.h"
22
#include "../utils/constants.h"
3+
#include "../utils/common.h"
34
#include "../session/session_manager.h"
45
#include "../storage/file_pairing_storage.h"
56
#include "keycard-qt/communication_manager.h"
@@ -237,14 +238,14 @@ QJsonObject RpcService::validateAndConfigureStorage(quint64 id, const QString& s
237238

238239
QJsonObject RpcService::loginKeysToJson(const SessionManager::LoginKeys& keys) {
239240
QJsonObject whisperKey;
240-
whisperKey["address"] = keys.whisperPrivateKey.address;
241-
whisperKey["publicKey"] = keys.whisperPrivateKey.publicKey;
242-
whisperKey["privateKey"] = keys.whisperPrivateKey.privateKey;
241+
whisperKey["address"] = ensure0xPrefix(keys.whisperPrivateKey.address);
242+
whisperKey["publicKey"] = ensure0xPrefix(keys.whisperPrivateKey.publicKey);
243+
whisperKey["privateKey"] = ensure0xPrefix(keys.whisperPrivateKey.privateKey);
243244

244245
QJsonObject encryptionKey;
245-
encryptionKey["address"] = keys.encryptionPrivateKey.address;
246-
encryptionKey["publicKey"] = keys.encryptionPrivateKey.publicKey;
247-
encryptionKey["privateKey"] = keys.encryptionPrivateKey.privateKey;
246+
encryptionKey["address"] = ensure0xPrefix(keys.encryptionPrivateKey.address);
247+
encryptionKey["publicKey"] = ensure0xPrefix(keys.encryptionPrivateKey.publicKey);
248+
encryptionKey["privateKey"] = ensure0xPrefix(keys.encryptionPrivateKey.privateKey);
248249

249250
QJsonObject keysObject;
250251
keysObject["whisperPrivateKey"] = whisperKey;
@@ -257,16 +258,16 @@ QJsonObject RpcService::loginKeysToJson(const SessionManager::LoginKeys& keys) {
257258
}
258259

259260
QJsonObject RpcService::recoverKeysToJson(const SessionManager::RecoverKeys& keys) {
260-
// Helper to convert KeyPair to JSON
261+
// Helper to convert KeyPair to JSON (hex values with 0x prefix)
261262
auto keyPairToJson = [](const SessionManager::KeyPair& kp) {
262263
QJsonObject obj;
263-
obj["address"] = kp.address;
264-
obj["publicKey"] = kp.publicKey;
264+
obj["address"] = ensure0xPrefix(kp.address);
265+
obj["publicKey"] = ensure0xPrefix(kp.publicKey);
265266
if (!kp.privateKey.isEmpty()) {
266-
obj["privateKey"] = kp.privateKey;
267+
obj["privateKey"] = ensure0xPrefix(kp.privateKey);
267268
}
268269
if (!kp.chainCode.isEmpty()) {
269-
obj["chainCode"] = kp.chainCode;
270+
obj["chainCode"] = ensure0xPrefix(kp.chainCode);
270271
}
271272
return obj;
272273
};

src/utils/common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@ namespace StatusKeycard {
88
return str.startsWith("0x") ? str.mid(2) : str;
99
}
1010

11+
inline QString ensure0xPrefix(const QString& hex) {
12+
if (hex.isEmpty()) return hex;
13+
if (hex.length() >= 2 && hex[0] == '0' && (hex[1] == 'x' || hex[1] == 'X'))
14+
return hex;
15+
return QString("0x") + hex;
16+
}
17+
1118
} // namespace StatusKeycard

0 commit comments

Comments
 (0)