Search in sources :

Example 1 with PublicKeyNotSupportedError

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

the class KeySignHandler method handleRequest.

@Override
public KeySignResponse handleRequest(KeySignRequest request) throws CoreApiException {
    coreModelMapper.verifyNetwork(request.getNetworkIdentifier());
    var pubKey = coreModelMapper.ecPublicKey(request.getPublicKey());
    if (!self.equals(pubKey)) {
        throw CoreApiException.notSupported(new PublicKeyNotSupportedError().unsupportedPublicKey(request.getPublicKey()).type(PublicKeyNotSupportedError.class.getSimpleName()));
    }
    // Verify this is a valid transaction and not anything more malicious
    var bytes = coreModelMapper.bytes(request.getUnsignedTransaction());
    var txn = Txn.create(bytes);
    try {
        radixEngineProvider.get().getParser().parse(txn);
    } catch (TxnParseException e) {
        throw coreModelMapper.parseException(e);
    }
    var builder = TxLowLevelBuilder.newBuilder(bytes);
    var hash = builder.hashToSign();
    var signature = this.hashSigner.sign(hash);
    var signedTransaction = builder.sig(signature).blob();
    return new KeySignResponse().signedTransaction(Bytes.toHexString(signedTransaction));
}
Also used : TxnParseException(com.radixdlt.engine.parser.exceptions.TxnParseException) PublicKeyNotSupportedError(com.radixdlt.api.core.openapitools.model.PublicKeyNotSupportedError) KeySignResponse(com.radixdlt.api.core.openapitools.model.KeySignResponse)

Aggregations

KeySignResponse (com.radixdlt.api.core.openapitools.model.KeySignResponse)1 PublicKeyNotSupportedError (com.radixdlt.api.core.openapitools.model.PublicKeyNotSupportedError)1 TxnParseException (com.radixdlt.engine.parser.exceptions.TxnParseException)1