Skip to content

Conversation

@spencerstock
Copy link
Collaborator

@spencerstock spencerstock commented Oct 13, 2025

Summary

Keys now supports this - ready to merge into SDk

Added requireBalance capability support for spend permissions in both subscribe() and requestSpendPermission() functions. This capability enables wallets to verify that users have sufficient balance before creating a spend permission, preventing failed transactions due to insufficient funds.

Changes:

  • Added requireBalance optional parameter to SubscriptionOptions type (defaults to true)
  • Added WalletSignCapabilities type with requireBalance option for requestSpendPermission()
  • Updated subscribe() to include capabilities in wallet_sign call when requireBalance is set
  • Updated requestSpendPermission() to use wallet_sign (instead of eth_signTypedData_v4) when capabilities are provided
  • Added validation and error handling for wallet_sign responses

How did you test your changes?

Added test coverage for:

  • subscribe() with requireBalance: true - verifies capabilities are included in wallet_sign call
  • subscribe() with requireBalance: false - verifies capabilities are excluded
  • subscribe() with requireBalance: undefined - verifies default behavior (capabilities included)
  • requestSpendPermission() with capabilities - verifies wallet_sign is used with proper parameters
  • requestSpendPermission() without capabilities - verifies fallback to eth_signTypedData_v4
  • Error handling for invalid wallet_sign responses

All tests pass. CI checks (lint, format, test, typecheck) pass.

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Oct 13, 2025

✅ Heimdall Review Status

Requirement Status More Info
Reviews 2/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@spencerstock spencerstock force-pushed the spencer/require-balance-capability branch from ede9bed to 8c645cd Compare October 13, 2025 20:03
@spencerstock spencerstock marked this pull request as ready for review October 21, 2025 15:06
try {
// Build capabilities if requireBalance is set
const capabilities = requireBalance
? { spendPermission: { requireBalance: true } }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wallet_sendCalls' spend permission capability is called spendPermissions, would be nice to maintain consistency across them...

@spencerstock spencerstock force-pushed the spencer/require-balance-capability branch from ffd360f to 0360ad4 Compare October 24, 2025 16:07
@spencerstock spencerstock merged commit b46d0b3 into master Oct 24, 2025
9 checks passed
@spencerstock spencerstock deleted the spencer/require-balance-capability branch October 24, 2025 17:23
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.

4 participants