Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/privy/authorization/jwt_exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

module Privy
class JwtExchangeService
def initialize(wallets_resource:, cache_max_capacity: 1000)
DEFAULT_CACHE_MAX_CAPACITY = 1000

attr_reader :cache_max_capacity

def initialize(wallets_resource:, cache_max_capacity: DEFAULT_CACHE_MAX_CAPACITY)
@wallets = wallets_resource
@hpke_recipient = Privy::Cryptography::HpkeRecipient.new
@cache = {}
Expand Down
8 changes: 6 additions & 2 deletions lib/privy/public_api/privy_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def initialize(
timeout: Privy::Client::DEFAULT_TIMEOUT_IN_SECONDS,
initial_retry_delay: Privy::Client::DEFAULT_INITIAL_RETRY_DELAY,
max_retry_delay: Privy::Client::DEFAULT_MAX_RETRY_DELAY,
request_expiry: Privy::PrivyRequestExpiryOptions.build
request_expiry: Privy::PrivyRequestExpiryOptions.build,
authorization_key_cache_max_capacity: Privy::JwtExchangeService::DEFAULT_CACHE_MAX_CAPACITY
)
@app_id = app_id
@app_secret = app_secret
Expand All @@ -47,7 +48,10 @@ def initialize(
@users = Privy::Services::Users.new(client: @api, privy_client: self)
@policies = Privy::Services::Policies.new(client: @api, privy_client: self)
@key_quorums = Privy::Services::KeyQuorums.new(client: @api, privy_client: self)
@jwt_exchange = Privy::JwtExchangeService.new(wallets_resource: @api.wallets)
@jwt_exchange = Privy::JwtExchangeService.new(
wallets_resource: @api.wallets,
cache_max_capacity: authorization_key_cache_max_capacity
)
end

# Resolves the absolute Unix-ms timestamp to send as `privy-request-expiry`.
Expand Down
17 changes: 17 additions & 0 deletions test/privy/public_api/privy_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,21 @@ def test_compute_request_expiry_callable_without_arguments
client = build_client
refute_nil(client.compute_request_expiry)
end

def test_default_authorization_key_cache_max_capacity_uses_service_default
client = Privy::PrivyClient.new(app_id: "app-123", app_secret: "secret", environment: :staging)
configured = client.jwt_exchange.cache_max_capacity
assert_equal(Privy::JwtExchangeService::DEFAULT_CACHE_MAX_CAPACITY, configured)
end

def test_authorization_key_cache_max_capacity_is_forwarded_to_jwt_exchange
client = Privy::PrivyClient.new(
app_id: "app-123",
app_secret: "secret",
environment: :staging,
authorization_key_cache_max_capacity: 7
)
configured = client.jwt_exchange.cache_max_capacity
assert_equal(7, configured)
end
end
Loading