use of com.radixdlt.api.core.openapitools.model.Signature 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();
}
use of com.radixdlt.api.core.openapitools.model.Signature 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);
}
Aggregations