forked from Qortal/qortal
Added 2 PirateChain api endpoints
This commit is contained in:
parent
61d6bd9bca
commit
6c4ed2496d
4
pom.xml
4
pom.xml
@ -13,7 +13,7 @@
|
|||||||
<build-helper-maven-plugin.version>3.4.0</build-helper-maven-plugin.version>
|
<build-helper-maven-plugin.version>3.4.0</build-helper-maven-plugin.version>
|
||||||
<build.timestamp>${maven.build.timestamp}</build.timestamp>
|
<build.timestamp>${maven.build.timestamp}</build.timestamp>
|
||||||
<ciyam-at.version>1.4.1</ciyam-at.version>
|
<ciyam-at.version>1.4.1</ciyam-at.version>
|
||||||
<commons-net.version>3.10.0</commons-net.version>
|
<commons-net.version>3.8.0</commons-net.version>
|
||||||
<commons-text.version>1.11.0</commons-text.version>
|
<commons-text.version>1.11.0</commons-text.version>
|
||||||
<commons-io.version>2.11.0</commons-io.version>
|
<commons-io.version>2.11.0</commons-io.version>
|
||||||
<commons-compress.version>1.24.0</commons-compress.version>
|
<commons-compress.version>1.24.0</commons-compress.version>
|
||||||
@ -43,7 +43,7 @@
|
|||||||
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
|
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
|
||||||
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
|
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
|
||||||
<maven-shade-plugin.version>3.5.1</maven-shade-plugin.version>
|
<maven-shade-plugin.version>3.5.1</maven-shade-plugin.version>
|
||||||
<maven-surefire-plugin.version>3.2.1</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>3.2.2</maven-surefire-plugin.version>
|
||||||
<package-info-maven-plugin.version>1.1.0</package-info-maven-plugin.version>
|
<package-info-maven-plugin.version>1.1.0</package-info-maven-plugin.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<protobuf.version>3.24.4</protobuf.version>
|
<protobuf.version>3.24.4</protobuf.version>
|
||||||
|
@ -222,6 +222,77 @@ public class CrossChainPirateChainResource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/walletprivatekey")
|
||||||
|
@Operation(
|
||||||
|
summary = "Returns main wallet private key",
|
||||||
|
description = "Supply 32 bytes of entropy, Base58 encoded",
|
||||||
|
requestBody = @RequestBody(
|
||||||
|
required = true,
|
||||||
|
content = @Content(
|
||||||
|
mediaType = MediaType.TEXT_PLAIN,
|
||||||
|
schema = @Schema(
|
||||||
|
type = "string",
|
||||||
|
description = "32 bytes of entropy, Base58 encoded",
|
||||||
|
example = "5oSXF53qENtdUyKhqSxYzP57m6RhVFP9BJKRr9E5kRGV"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(type = "string", description = "Private Key String"))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiErrors({ApiError.INVALID_PRIVATE_KEY, ApiError.FOREIGN_BLOCKCHAIN_NETWORK_ISSUE})
|
||||||
|
@SecurityRequirement(name = "apiKey")
|
||||||
|
public String getPirateChainPrivateKey(@HeaderParam(Security.API_KEY_HEADER) String apiKey, String entropy58) {
|
||||||
|
Security.checkApiCallAllowed(request);
|
||||||
|
|
||||||
|
PirateChain pirateChain = PirateChain.getInstance();
|
||||||
|
|
||||||
|
try {
|
||||||
|
return pirateChain.getPrivateKey(entropy58);
|
||||||
|
} catch (ForeignBlockchainException e) {
|
||||||
|
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.FOREIGN_BLOCKCHAIN_NETWORK_ISSUE, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/walletseedphrase")
|
||||||
|
@Operation(
|
||||||
|
summary = "Returns main wallet seedphrase",
|
||||||
|
description = "Supply 32 bytes of entropy, Base58 encoded",
|
||||||
|
requestBody = @RequestBody(
|
||||||
|
required = true,
|
||||||
|
content = @Content(
|
||||||
|
mediaType = MediaType.TEXT_PLAIN,
|
||||||
|
schema = @Schema(
|
||||||
|
type = "string",
|
||||||
|
description = "32 bytes of entropy, Base58 encoded",
|
||||||
|
example = "5oSXF53qENtdUyKhqSxYzP57m6RhVFP9BJKRr9E5kRGV"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(type = "string", description = "Wallet Seedphrase String"))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiErrors({ApiError.INVALID_PRIVATE_KEY, ApiError.FOREIGN_BLOCKCHAIN_NETWORK_ISSUE})
|
||||||
|
@SecurityRequirement(name = "apiKey")
|
||||||
|
public String getPirateChainWalletSeed(@HeaderParam(Security.API_KEY_HEADER) String apiKey, String entropy58) {
|
||||||
|
Security.checkApiCallAllowed(request);
|
||||||
|
|
||||||
|
PirateChain pirateChain = PirateChain.getInstance();
|
||||||
|
|
||||||
|
try {
|
||||||
|
return pirateChain.getWalletSeed(entropy58);
|
||||||
|
} catch (ForeignBlockchainException e) {
|
||||||
|
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.FOREIGN_BLOCKCHAIN_NETWORK_ISSUE, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/syncstatus")
|
@Path("/syncstatus")
|
||||||
|
@ -356,6 +356,30 @@ public class PirateChain extends Bitcoiny {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPrivateKey(String entropy58) throws ForeignBlockchainException {
|
||||||
|
synchronized (this) {
|
||||||
|
PirateChainWalletController walletController = PirateChainWalletController.getInstance();
|
||||||
|
walletController.initWithEntropy58(entropy58);
|
||||||
|
walletController.ensureInitialized();
|
||||||
|
walletController.ensureNotNullSeed();
|
||||||
|
walletController.getCurrentWallet().unlock();
|
||||||
|
|
||||||
|
return walletController.getCurrentWallet().getPrivateKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWalletSeed(String entropy58) throws ForeignBlockchainException {
|
||||||
|
synchronized (this) {
|
||||||
|
PirateChainWalletController walletController = PirateChainWalletController.getInstance();
|
||||||
|
walletController.initWithEntropy58(entropy58);
|
||||||
|
walletController.ensureInitialized();
|
||||||
|
walletController.ensureNotNullSeed();
|
||||||
|
walletController.getCurrentWallet().unlock();
|
||||||
|
|
||||||
|
return walletController.getCurrentWallet().getWalletSeed(entropy58);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getUnusedReceiveAddress(String key58) throws ForeignBlockchainException {
|
public String getUnusedReceiveAddress(String key58) throws ForeignBlockchainException {
|
||||||
// For now, return the main wallet address
|
// For now, return the main wallet address
|
||||||
// FUTURE: generate an unused one
|
// FUTURE: generate an unused one
|
||||||
|
@ -398,6 +398,25 @@ public class PirateWallet {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getWalletSeed(String entropy58) {
|
||||||
|
// Decode entropy to bytes
|
||||||
|
byte[] myEntropyBytes = Base58.decode(entropy58);
|
||||||
|
|
||||||
|
// Pirate library uses base64 encoding
|
||||||
|
String myEntropy64 = Base64.toBase64String(myEntropyBytes);
|
||||||
|
|
||||||
|
// Derive seed phrase from entropy bytes
|
||||||
|
String mySeedResponse = LiteWalletJni.getseedphrasefromentropyb64(myEntropy64);
|
||||||
|
JSONObject mySeedJson = new JSONObject(mySeedResponse);
|
||||||
|
String mySeedPhrase = null;
|
||||||
|
if (mySeedJson.has("seedPhrase")) {
|
||||||
|
mySeedPhrase = mySeedJson.getString("seedPhrase");
|
||||||
|
|
||||||
|
return mySeedPhrase;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public PirateLightClient.Server getRandomServer() {
|
public PirateLightClient.Server getRandomServer() {
|
||||||
PirateChain.PirateChainNet pirateChainNet = Settings.getInstance().getPirateChainNet();
|
PirateChain.PirateChainNet pirateChainNet = Settings.getInstance().getPirateChainNet();
|
||||||
Collection<PirateLightClient.Server> servers = pirateChainNet.getServers();
|
Collection<PirateLightClient.Server> servers = pirateChainNet.getServers();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user