Search in sources :

Example 1 with KeySignRequest

use of com.radixdlt.api.core.openapitools.model.KeySignRequest in project radixdlt by radixdlt.

the class KeySignHandlerTest method sign_should_work_on_correct_transaction.

@Test
public void sign_should_work_on_correct_transaction() throws Exception {
    // Arrange
    start();
    // Act
    var from = REAddr.ofPubKeyAccount(selfKey());
    var other = PrivateKeys.ofNumeric(2);
    var to = REAddr.ofPubKeyAccount(other.getPublicKey());
    var unsignedTxn = buildUnsignedTxn(from, to);
    var request = new KeySignRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).publicKey(mapper.publicKey(selfKey())).unsignedTransaction(Bytes.toHexString(unsignedTxn));
    var response = sut.handleRequest(request);
    // Assert
    assertThat(Bytes.fromHexString(response.getSignedTransaction())).isNotNull();
}
Also used : NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) KeySignRequest(com.radixdlt.api.core.openapitools.model.KeySignRequest) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 2 with KeySignRequest

use of com.radixdlt.api.core.openapitools.model.KeySignRequest in project radixdlt by radixdlt.

the class KeySignHandlerTest method sign_should_fail_given_an_invalid_transaction.

@Test
public void sign_should_fail_given_an_invalid_transaction() throws Exception {
    // Arrange
    start();
    // Act
    var request = new KeySignRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).publicKey(mapper.publicKey(selfKey())).unsignedTransaction("badbadbadbad");
    var response = handleRequestWithExpectedResponse(sut, request, UnexpectedError.class);
    // Assert
    assertThat(response.getDetails()).isInstanceOf(InvalidTransactionError.class);
}
Also used : NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) KeySignRequest(com.radixdlt.api.core.openapitools.model.KeySignRequest) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 3 with KeySignRequest

use of com.radixdlt.api.core.openapitools.model.KeySignRequest in project radixdlt by radixdlt.

the class NodeApiClient method submit.

public void submit(NodeTransactionAction action, boolean disableResourceAllocateAndDestroy) throws Exception {
    var networkIdentifier = networkIdentifier();
    var engineConfigurationResponse = engineConfigurationHandler.handleRequest(new EngineConfigurationRequest().networkIdentifier(networkIdentifier));
    var keyListResponse = keyListHandler.handleRequest(new KeyListRequest().networkIdentifier(networkIdentifier));
    var nodePublicKey = keyListResponse.getPublicKeys().get(0).getPublicKey();
    var configuration = engineConfigurationResponse.getForks().get(0).getEngineConfiguration();
    var accountIdentifier = deriveAccount(nodePublicKey);
    var operationGroups = action.toOperationGroups(configuration, this::selfDerive);
    var buildRequest = new ConstructionBuildRequest().networkIdentifier(networkIdentifier).feePayer(accountIdentifier).operationGroups(operationGroups).disableResourceAllocateAndDestroy(disableResourceAllocateAndDestroy);
    var buildResponse = constructionBuildHandler.handleRequest(buildRequest);
    var unsignedTransaction = buildResponse.getUnsignedTransaction();
    var response = keySignHandler.handleRequest(new KeySignRequest().networkIdentifier(networkIdentifier).publicKey(nodePublicKey).unsignedTransaction(unsignedTransaction));
    constructionSubmitHandler.handleRequest(new ConstructionSubmitRequest().networkIdentifier(networkIdentifier).signedTransaction(response.getSignedTransaction()));
}
Also used : EngineConfigurationRequest(com.radixdlt.api.core.openapitools.model.EngineConfigurationRequest) ConstructionBuildRequest(com.radixdlt.api.core.openapitools.model.ConstructionBuildRequest) KeyListRequest(com.radixdlt.api.core.openapitools.model.KeyListRequest) KeySignRequest(com.radixdlt.api.core.openapitools.model.KeySignRequest) ConstructionSubmitRequest(com.radixdlt.api.core.openapitools.model.ConstructionSubmitRequest)

Example 4 with KeySignRequest

use of com.radixdlt.api.core.openapitools.model.KeySignRequest in project radixdlt by radixdlt.

the class KeySignHandlerTest method sign_given_an_unsupported_public_key_should_fail.

@Test
public void sign_given_an_unsupported_public_key_should_fail() throws Exception {
    // Arrange
    start();
    // Act
    var from = REAddr.ofPubKeyAccount(selfKey());
    var other = PrivateKeys.ofNumeric(2);
    var to = REAddr.ofPubKeyAccount(other.getPublicKey());
    var unsignedTxn = buildUnsignedTxn(from, to);
    var request = new KeySignRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).publicKey(mapper.publicKey(other.getPublicKey())).unsignedTransaction(Bytes.toHexString(unsignedTxn));
    var response = handleRequestWithExpectedResponse(sut, request, UnexpectedError.class);
    // Assert
    assertThat(response.getDetails()).isInstanceOf(PublicKeyNotSupportedError.class);
}
Also used : NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) KeySignRequest(com.radixdlt.api.core.openapitools.model.KeySignRequest) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Aggregations

KeySignRequest (com.radixdlt.api.core.openapitools.model.KeySignRequest)4 ApiTest (com.radixdlt.api.ApiTest)3 NetworkIdentifier (com.radixdlt.api.core.openapitools.model.NetworkIdentifier)3 Test (org.junit.Test)3 ConstructionBuildRequest (com.radixdlt.api.core.openapitools.model.ConstructionBuildRequest)1 ConstructionSubmitRequest (com.radixdlt.api.core.openapitools.model.ConstructionSubmitRequest)1 EngineConfigurationRequest (com.radixdlt.api.core.openapitools.model.EngineConfigurationRequest)1 KeyListRequest (com.radixdlt.api.core.openapitools.model.KeyListRequest)1