API tidy up

GET /addresses/proxykey/{privkey}/{pubkey} now POST /addresses/proxykey

GET /utils/fromBase58 now GET /utils/frombase58
GET /utils/fromBase64 now GET /utils/frombase64

GET /utils/toBase58/{hex} now GET /utils/tobase58/{hex}
GET /utils/toBase64/{hex} now GET /utils/tobase64/{hex}

GET /utils/privateKey/{entropy} now POST /utils/privatekey
GET /utils/publicKey/{privateKey} now POST /utils/publickey
This commit is contained in:
catbref 2019-05-23 09:46:32 +01:00
parent a3d4cf2900
commit 40d6190265
8 changed files with 95 additions and 30 deletions

View File

@ -0,0 +1,20 @@
package org.qora.api.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import io.swagger.v3.oas.annotations.media.Schema;
@XmlAccessorType(XmlAccessType.FIELD)
public class ProxyKeyRequest {
@Schema(example = "private_key")
public byte[] generatorPrivateKey;
@Schema(example = "public_key")
public byte[] recipientPublicKey;
public ProxyKeyRequest() {
}
}

View File

@ -27,6 +27,7 @@ import org.qora.api.ApiError;
import org.qora.api.ApiErrors; import org.qora.api.ApiErrors;
import org.qora.api.ApiException; import org.qora.api.ApiException;
import org.qora.api.ApiExceptionFactory; import org.qora.api.ApiExceptionFactory;
import org.qora.api.model.ProxyKeyRequest;
import org.qora.api.resource.TransactionsResource; import org.qora.api.resource.TransactionsResource;
import org.qora.asset.Asset; import org.qora.asset.Asset;
import org.qora.crypto.Crypto; import org.qora.crypto.Crypto;
@ -301,7 +302,7 @@ public class AddressesResource {
) )
} }
) )
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.REPOSITORY_ISSUE}) @ApiErrors({ApiError.INVALID_ADDRESS, ApiError.INVALID_CRITERIA, ApiError.REPOSITORY_ISSUE})
public List<ProxyForgerData> getProxying(@QueryParam("proxiedFor") List<String> recipients, public List<ProxyForgerData> getProxying(@QueryParam("proxiedFor") List<String> recipients,
@QueryParam("proxiedBy") List<String> forgers, @QueryParam("proxiedBy") List<String> forgers,
@Parameter( @Parameter(
@ -321,30 +322,42 @@ public class AddressesResource {
} }
} }
@GET @POST
@Path("/proxykey/{generatorprivatekey}/{recipientpublickey}") @Path("/proxykey")
@Operation( @Operation(
summary = "Calculate proxy private key", summary = "Calculate proxy private key",
description = "Calculates proxy private key using passed generator's private key and recipient's public key",
requestBody = @RequestBody(
required = true,
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(
implementation = ProxyKeyRequest.class
)
)
),
responses = { responses = {
@ApiResponse( @ApiResponse(
content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(type = "string")) content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(type = "string"))
) )
} }
) )
public String calculateProxyKey(@PathParam("generatorprivatekey") String generatorKey58, @PathParam("recipientpublickey") String recipientKey58) { @ApiErrors({ApiError.INVALID_PRIVATE_KEY, ApiError.INVALID_PUBLIC_KEY, ApiError.REPOSITORY_ISSUE})
try { public String calculateProxyKey(ProxyKeyRequest proxyKeyRequest) {
byte[] generatorKey = Base58.decode(generatorKey58); byte[] generatorKey = proxyKeyRequest.generatorPrivateKey;
byte[] recipientKey = Base58.decode(recipientKey58); byte[] recipientKey = proxyKeyRequest.recipientPublicKey;
if (generatorKey.length != Transformer.PRIVATE_KEY_LENGTH || recipientKey.length != Transformer.PRIVATE_KEY_LENGTH)
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_PRIVATE_KEY);
PrivateKeyAccount generator = new PrivateKeyAccount(null, generatorKey);
byte[] proxyPrivateKey = generator.getProxyPrivateKey(recipientKey); if (generatorKey == null || generatorKey.length != Transformer.PRIVATE_KEY_LENGTH)
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_PRIVATE_KEY);
return Base58.encode(proxyPrivateKey); if (recipientKey == null || recipientKey.length != Transformer.PUBLIC_KEY_LENGTH)
} catch (NumberFormatException e) { throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_PUBLIC_KEY);
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_PRIVATE_KEY, e);
} PrivateKeyAccount generator = new PrivateKeyAccount(null, generatorKey);
byte[] proxyPrivateKey = generator.getProxyPrivateKey(recipientKey);
return Base58.encode(proxyPrivateKey);
} }
@POST @POST

View File

@ -391,7 +391,7 @@ public class TransactionsResource {
schema = @Schema( schema = @Schema(
type = "string", type = "string",
description = "raw, signed transaction in base58 encoding", description = "raw, signed transaction in base58 encoding",
example = "base58" example = "raw transaction base58"
) )
) )
), ),
@ -447,7 +447,7 @@ public class TransactionsResource {
@POST @POST
@Path("/decode") @Path("/decode")
@Operation( @Operation(
summary = "Decode a raw, signed transaction", summary = "Decode a raw, signed/unsigned transaction",
requestBody = @RequestBody( requestBody = @RequestBody(
required = true, required = true,
content = @Content( content = @Content(
@ -455,7 +455,7 @@ public class TransactionsResource {
schema = @Schema( schema = @Schema(
type = "string", type = "string",
description = "raw, unsigned/signed transaction in base58 encoding", description = "raw, unsigned/signed transaction in base58 encoding",
example = "base58" example = "raw transaction base58"
) )
) )
), ),

View File

@ -49,7 +49,7 @@ public class UtilsResource {
HttpServletRequest request; HttpServletRequest request;
@POST @POST
@Path("/fromBase64") @Path("/frombase64")
@Operation( @Operation(
summary = "Convert base64 data to hex", summary = "Convert base64 data to hex",
requestBody = @RequestBody( requestBody = @RequestBody(
@ -85,7 +85,7 @@ public class UtilsResource {
} }
@POST @POST
@Path("/fromBase58") @Path("/frombase58")
@Operation( @Operation(
summary = "Convert base58 data to hex", summary = "Convert base58 data to hex",
requestBody = @RequestBody( requestBody = @RequestBody(
@ -121,7 +121,7 @@ public class UtilsResource {
} }
@GET @GET
@Path("/toBase64/{hex}") @Path("/tobase64/{hex}")
@Operation( @Operation(
summary = "Convert hex to base64", summary = "Convert hex to base64",
responses = { responses = {
@ -144,7 +144,7 @@ public class UtilsResource {
} }
@GET @GET
@Path("/toBase58/{hex}") @Path("/tobase58/{hex}")
@Operation( @Operation(
summary = "Convert hex to base58", summary = "Convert hex to base58",
responses = { responses = {
@ -313,10 +313,19 @@ public class UtilsResource {
return Base58.encode(entropy); return Base58.encode(entropy);
} }
@GET @POST
@Path("/privateKey/{entropy}") @Path("/privatekey")
@Operation( @Operation(
summary = "Calculate private key from supplied 16-byte entropy", summary = "Calculate private key from supplied 16-byte entropy",
requestBody = @RequestBody(
required = true,
content = @Content(
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(
type = "string"
)
)
),
responses = { responses = {
@ApiResponse( @ApiResponse(
description = "private key in base58", description = "private key in base58",
@ -330,7 +339,7 @@ public class UtilsResource {
} }
) )
@ApiErrors({ApiError.NON_PRODUCTION, ApiError.INVALID_DATA}) @ApiErrors({ApiError.NON_PRODUCTION, ApiError.INVALID_DATA})
public String privateKey(@PathParam("entropy") String entropy58) { public String privateKey(String entropy58) {
if (Settings.getInstance().isApiRestricted()) if (Settings.getInstance().isApiRestricted())
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.NON_PRODUCTION); throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.NON_PRODUCTION);
@ -349,10 +358,19 @@ public class UtilsResource {
return Base58.encode(privateKey); return Base58.encode(privateKey);
} }
@GET @POST
@Path("/publicKey/{privateKey}") @Path("/publickey")
@Operation( @Operation(
summary = "Calculate public key from supplied 32-byte private key", summary = "Calculate public key from supplied 32-byte private key",
requestBody = @RequestBody(
required = true,
content = @Content(
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(
type = "string"
)
)
),
responses = { responses = {
@ApiResponse( @ApiResponse(
description = "public key in base58", description = "public key in base58",
@ -365,8 +383,8 @@ public class UtilsResource {
) )
} }
) )
@ApiErrors({ApiError.NON_PRODUCTION, ApiError.INVALID_DATA}) @ApiErrors({ApiError.NON_PRODUCTION, ApiError.INVALID_DATA, ApiError.INVALID_PRIVATE_KEY})
public String publicKey(@PathParam("privateKey") String privateKey58) { public String publicKey(String privateKey58) {
if (Settings.getInstance().isApiRestricted()) if (Settings.getInstance().isApiRestricted())
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.NON_PRODUCTION); throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.NON_PRODUCTION);

View File

@ -30,8 +30,13 @@ public class ArbitraryTransactionData extends TransactionData {
// Properties // Properties
private int version; private int version;
@Schema(example = "sender_public_key")
private byte[] senderPublicKey; private byte[] senderPublicKey;
private int service; private int service;
@Schema(example = "raw_data_in_base58")
private byte[] data; private byte[] data;
private DataType dataType; private DataType dataType;
private List<PaymentData> payments; private List<PaymentData> payments;

View File

@ -27,7 +27,8 @@ public class GroupApprovalTransactionData extends TransactionData {
) )
private byte[] adminPublicKey; private byte[] adminPublicKey;
@Schema( @Schema(
description = "transaction pending approval" description = "transaction pending approval",
example = "transaction_signature"
) )
private byte[] pendingSignature; private byte[] pendingSignature;
@Schema( @Schema(

View File

@ -16,10 +16,16 @@ import io.swagger.v3.oas.annotations.media.Schema;
@Schema(allOf = {TransactionData.class}) @Schema(allOf = {TransactionData.class})
public class ProxyForgingTransactionData extends TransactionData { public class ProxyForgingTransactionData extends TransactionData {
@Schema(example = "forger_public_key")
private byte[] forgerPublicKey; private byte[] forgerPublicKey;
private String recipient; private String recipient;
@Schema(example = "proxy_public_key")
private byte[] proxyPublicKey; private byte[] proxyPublicKey;
private BigDecimal share; private BigDecimal share;
// No need to ever expose this via API // No need to ever expose this via API
@XmlTransient @XmlTransient
@Schema(hidden = true) @Schema(hidden = true)

View File

@ -17,7 +17,9 @@ import io.swagger.v3.oas.annotations.media.Schema.AccessMode;
public class TransferAssetTransactionData extends TransactionData { public class TransferAssetTransactionData extends TransactionData {
// Properties // Properties
@Schema(example = "sender_public_key")
private byte[] senderPublicKey; private byte[] senderPublicKey;
private String recipient; private String recipient;
private BigDecimal amount; private BigDecimal amount;
private long assetId; private long assetId;