Skip to content

feat(encryption): allow custom loading of JWK sets #214

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jul 4, 2024
Merged

feat(encryption): allow custom loading of JWK sets #214

merged 2 commits into from
Jul 4, 2024

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
1 check passed
@grmeyer-hw-dev
Copy link
Collaborator

Hi @sp00m

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

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

Successfully merging this pull request may close these issues.

2 participants