Search in sources :

Example 1 with ConstructionFinalizeRequest

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

the class ConstructionFinalizeTest method finalizing_a_transaction_with_signature_should_return_back_signed_tranaction.

@Test
public void finalizing_a_transaction_with_signature_should_return_back_signed_tranaction() throws Exception {
    // Arrange
    start();
    // Act
    var accountAddress = REAddr.ofPubKeyAccount(self);
    var otherAddress = REAddr.ofPubKeyAccount(PrivateKeys.ofNumeric(2).getPublicKey());
    var unsignedTxn = buildUnsignedTransferTxn(accountAddress, otherAddress);
    var sig = hashSigner.sign(unsignedTxn.hashToSign());
    var os = new ByteArrayOutputStream();
    var asn1OutputStream = ASN1OutputStream.create(os);
    asn1OutputStream.writeObject(new DLSequence(new ASN1Encodable[] { new ASN1Integer(sig.getR()), new ASN1Integer(sig.getS()) }));
    var derSignature = os.toByteArray();
    var request = new ConstructionFinalizeRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).unsignedTransaction(Bytes.toHexString(unsignedTxn.blob())).signature(new Signature().bytes(Bytes.toHexString(derSignature)).publicKey(coreModelMapper.publicKey(self)));
    var response = handleRequestWithExpectedResponse(sut, request, ConstructionFinalizeResponse.class);
    // Assert
    var bytes = Bytes.fromHexString(response.getSignedTransaction());
    assertThat(bytes).isNotNull();
}
Also used : ConstructionFinalizeRequest(com.radixdlt.api.core.openapitools.model.ConstructionFinalizeRequest) DLSequence(org.bouncycastle.asn1.DLSequence) Signature(com.radixdlt.api.core.openapitools.model.Signature) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 2 with ConstructionFinalizeRequest

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

the class ConstructionFinalizeTest method finalizing_a_transaction_with_invalid_signature_should_throw.

@Test
public void finalizing_a_transaction_with_invalid_signature_should_throw() throws Exception {
    // Arrange
    start();
    // Act
    var accountAddress = REAddr.ofPubKeyAccount(self);
    var otherAddress = REAddr.ofPubKeyAccount(PrivateKeys.ofNumeric(2).getPublicKey());
    var unsignedTxn = buildUnsignedTransferTxn(accountAddress, otherAddress);
    var sig = hashSigner.sign(unsignedTxn.hashToSign());
    var invalidSignature = // This is an invalid signature since it must be DER encoded
    sig.toHexString();
    var request = new ConstructionFinalizeRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).unsignedTransaction(Bytes.toHexString(unsignedTxn.blob())).signature(new Signature().bytes(invalidSignature).publicKey(coreModelMapper.publicKey(self)));
    var response = handleRequestWithExpectedResponse(sut, request, UnexpectedError.class);
    // Assert
    assertThat(response.getDetails()).isInstanceOf(InvalidSignatureError.class);
}
Also used : ConstructionFinalizeRequest(com.radixdlt.api.core.openapitools.model.ConstructionFinalizeRequest) Signature(com.radixdlt.api.core.openapitools.model.Signature) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Aggregations

ApiTest (com.radixdlt.api.ApiTest)2 ConstructionFinalizeRequest (com.radixdlt.api.core.openapitools.model.ConstructionFinalizeRequest)2 NetworkIdentifier (com.radixdlt.api.core.openapitools.model.NetworkIdentifier)2 Signature (com.radixdlt.api.core.openapitools.model.Signature)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)1 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)1 DLSequence (org.bouncycastle.asn1.DLSequence)1