forked from Qortal/qortal
WIP: trade-bot: add xprv validation method to BTC class and use that for API call /crosschain/tradebot/respond instead of vague byte-length check
This commit is contained in:
parent
e2dc91c1ea
commit
d85b746021
@ -1028,15 +1028,8 @@ public class CrossChainResource {
|
||||
if (atAddress == null || !Crypto.isValidAtAddress(atAddress))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||
|
||||
final byte[] xprv;
|
||||
try {
|
||||
xprv = Base58.decode(tradeBotRespondRequest.xprv58);
|
||||
|
||||
if (xprv.length != 4 + 1 + 4 + 4 + 32 + 33 + 4)
|
||||
if (!BTC.getInstance().isValidXprv(tradeBotRespondRequest.xprv58))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_PRIVATE_KEY);
|
||||
} catch (NumberFormatException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_PRIVATE_KEY);
|
||||
}
|
||||
|
||||
// Extract data from cross-chain trading AT
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
@ -117,6 +117,15 @@ public class BTC {
|
||||
return format(Coin.valueOf(amount));
|
||||
}
|
||||
|
||||
public boolean isValidXprv(String xprv58) {
|
||||
try {
|
||||
DeterministicKey.deserializeB58(null, xprv58, this.params);
|
||||
return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns P2PKH Bitcoin address using passed public key hash. */
|
||||
public String pkhToAddress(byte[] publicKeyHash) {
|
||||
return LegacyAddress.fromPubKeyHash(this.params, publicKeyHash).toString();
|
||||
|
Loading…
Reference in New Issue
Block a user