Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Conversation

sp00m
Copy link
Contributor

@sp00m sp00m commented May 21, 2024

This would allow us to cache the JWK sets to reduce the IOs and improve performances, for instance with something along those lines:

public class CachedHyperwalletEncryption extends HyperwalletEncryption {

    private final Supplier<JWKSet> clientPrivateKeySetSupplier;
    private final Supplier<JWKSet> hyperwalletKeySetSupplier;

    public CachedHyperwalletEncryption(JWEAlgorithm encryptionAlgorithm, JWSAlgorithm signAlgorithm, EncryptionMethod encryptionMethod, String clientPrivateKeySetLocation, String hyperwalletKeySetLocation, Integer jwsExpirationMinutes) {
        super(encryptionAlgorithm, signAlgorithm, encryptionMethod, clientPrivateKeySetLocation, hyperwalletKeySetLocation, jwsExpirationMinutes);
        this.clientPrivateKeySetSupplier = Suppliers.memoize(() -> super.loadClientPrivateKeySet(), CACHE_DURATION);
        this.hyperwalletKeySetSupplier = Suppliers.memoize(() -> super.loadHyperwalletKeySet(), CACHE_DURATION);
    }

    @Override
    protected JWKSet loadClientPrivateKeySet() throws IOException, ParseException {
        return clientPrivateKeySetSupplier.get();
    }

    @Override
    protected JWKSet loadHyperwalletKeySet() throws IOException, ParseException {
        return hyperwalletKeySetSupplier.get();
    }

}

Let me know if you think of a better approach while ensuring backward compatibility, thanks 🙌

@grmeyer-hw-dev grmeyer-hw-dev merged commit bdda6cb into hyperwallet:master Jul 4, 2024
@grmeyer-hw-dev
Copy link
Collaborator

Hi @sp00m

Thanks for your contribution.
This change will be available on Java V4 SDK v2.4.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants