mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
update rpc auth + verify
This commit is contained in:
committed by
Richard Holland
parent
2c2b70f05e
commit
720930a8f6
@@ -149,6 +149,37 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build an object or string
|
||||||
|
// { "currency" : "XYZ", "issuer" : "rXYX", "value": 1000 }
|
||||||
|
// "1000"
|
||||||
|
static Json::Value
|
||||||
|
jvParseAmount(std::string const& strAmount)
|
||||||
|
{
|
||||||
|
Json::Reader reader;
|
||||||
|
Json::Value jv;
|
||||||
|
Json::Value jv1{Json::objectValue};
|
||||||
|
if (to_uint64(strAmount))
|
||||||
|
return strAmount;
|
||||||
|
|
||||||
|
bool valid_parse = reader.parse(strAmount, jv);
|
||||||
|
if (valid_parse)
|
||||||
|
{
|
||||||
|
if (jv.isObject())
|
||||||
|
{
|
||||||
|
if (jv.isMember(jss::params))
|
||||||
|
{
|
||||||
|
auto const& params = jv[jss::params];
|
||||||
|
for (auto i = params.begin(); i != params.end(); ++i)
|
||||||
|
jv1[i.key().asString()] = *i;
|
||||||
|
}
|
||||||
|
jv1[jss::issuer] = jv[jss::issuer];
|
||||||
|
jv1[jss::currency] = jv[jss::currency];
|
||||||
|
jv1[jss::value] = jv[jss::value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return jv1;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
validPublicKey(
|
validPublicKey(
|
||||||
std::string const& strPk,
|
std::string const& strPk,
|
||||||
@@ -851,14 +882,24 @@ private:
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!jvParams[index].isString() ||
|
{
|
||||||
!to_uint64(jvParams[index].asString()))
|
// validate amount string | json
|
||||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
if (!jvParams[index].isString())
|
||||||
jvRequest[jss::amount] = jvParams[index];
|
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||||
|
|
||||||
|
Json::Value amountJson = jvParseAmount(jvParams[index].asString());
|
||||||
|
if (!amountJson)
|
||||||
|
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||||
|
|
||||||
|
STAmount amount;
|
||||||
|
if (!amountFromJsonNoThrow(amount, amountJson))
|
||||||
|
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||||
|
|
||||||
|
jvRequest[jss::amount] = amountJson;
|
||||||
|
}
|
||||||
|
|
||||||
// If additional parameters are appended, be sure to increment index
|
// If additional parameters are appended, be sure to increment index
|
||||||
// here
|
// here
|
||||||
|
|
||||||
return jvRequest;
|
return jvRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -882,9 +923,21 @@ private:
|
|||||||
}
|
}
|
||||||
jvRequest[jss::channel_id] = jvParams[1u].asString();
|
jvRequest[jss::channel_id] = jvParams[1u].asString();
|
||||||
|
|
||||||
if (!jvParams[2u].isString() || !to_uint64(jvParams[2u].asString()))
|
{
|
||||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
// validate amount string | json
|
||||||
jvRequest[jss::amount] = jvParams[2u];
|
if (!jvParams[2u].isString())
|
||||||
|
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||||
|
|
||||||
|
Json::Value amountJson = jvParseAmount(jvParams[2u].asString());
|
||||||
|
if (!amountJson)
|
||||||
|
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||||
|
|
||||||
|
STAmount amount;
|
||||||
|
if (!amountFromJsonNoThrow(amount, amountJson))
|
||||||
|
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||||
|
|
||||||
|
jvRequest[jss::amount] = amountJson;
|
||||||
|
}
|
||||||
|
|
||||||
jvRequest[jss::signature] = jvParams[3u].asString();
|
jvRequest[jss::signature] = jvParams[3u].asString();
|
||||||
|
|
||||||
|
|||||||
@@ -63,17 +63,26 @@ doChannelAuthorize(RPC::JsonContext& context)
|
|||||||
if (!channelId.parseHex(params[jss::channel_id].asString()))
|
if (!channelId.parseHex(params[jss::channel_id].asString()))
|
||||||
return rpcError(rpcCHANNEL_MALFORMED);
|
return rpcError(rpcCHANNEL_MALFORMED);
|
||||||
|
|
||||||
std::optional<std::uint64_t> const optDrops = params[jss::amount].isString()
|
STAmount amount;
|
||||||
? to_uint64(params[jss::amount].asString())
|
bool isAmount = amountFromJsonNoThrow(amount, params[jss::amount]);
|
||||||
: std::nullopt;
|
if (!isAmount)
|
||||||
|
|
||||||
if (!optDrops)
|
|
||||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||||
|
|
||||||
std::uint64_t const drops = *optDrops;
|
|
||||||
|
|
||||||
Serializer msg;
|
Serializer msg;
|
||||||
serializePayChanAuthorization(msg, channelId, XRPAmount(drops));
|
if (isXRP(amount))
|
||||||
|
{
|
||||||
|
serializePayChanAuthorization(msg, channelId, amount.xrp());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serializePayChanAuthorization(
|
||||||
|
msg,
|
||||||
|
channelId,
|
||||||
|
amount.iou(),
|
||||||
|
amount.getCurrency(),
|
||||||
|
amount.getIssuer()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -124,22 +133,31 @@ doChannelVerify(RPC::JsonContext& context)
|
|||||||
if (!channelId.parseHex(params[jss::channel_id].asString()))
|
if (!channelId.parseHex(params[jss::channel_id].asString()))
|
||||||
return rpcError(rpcCHANNEL_MALFORMED);
|
return rpcError(rpcCHANNEL_MALFORMED);
|
||||||
|
|
||||||
std::optional<std::uint64_t> const optDrops = params[jss::amount].isString()
|
STAmount amount;
|
||||||
? to_uint64(params[jss::amount].asString())
|
bool isAmount = amountFromJsonNoThrow(amount, params[jss::amount]);
|
||||||
: std::nullopt;
|
if (!isAmount)
|
||||||
|
|
||||||
if (!optDrops)
|
|
||||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||||
|
|
||||||
std::uint64_t const drops = *optDrops;
|
Serializer msg;
|
||||||
|
if (isXRP(amount))
|
||||||
|
{
|
||||||
|
serializePayChanAuthorization(msg, channelId, amount.xrp());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serializePayChanAuthorization(
|
||||||
|
msg,
|
||||||
|
channelId,
|
||||||
|
amount.iou(),
|
||||||
|
amount.getCurrency(),
|
||||||
|
amount.getIssuer()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
auto sig = strUnHex(params[jss::signature].asString());
|
auto sig = strUnHex(params[jss::signature].asString());
|
||||||
if (!sig || !sig->size())
|
if (!sig || !sig->size())
|
||||||
return rpcError(rpcINVALID_PARAMS);
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
Serializer msg;
|
|
||||||
serializePayChanAuthorization(msg, channelId, XRPAmount(drops));
|
|
||||||
|
|
||||||
Json::Value result;
|
Json::Value result;
|
||||||
result[jss::signature_verified] =
|
result[jss::signature_verified] =
|
||||||
verify(*pk, msg.slice(), makeSlice(*sig), /*canonical*/ true);
|
verify(*pk, msg.slice(), makeSlice(*sig), /*canonical*/ true);
|
||||||
|
|||||||
Reference in New Issue
Block a user