Skip to content

feat: allow for multiple keys in snap_getState - #4125

Merged
hmalik88 merged 11 commits into
mainfrom
hm/update-get-state
Sep 21, 2026
Merged

hmalik88 merged 11 commits into
mainfrom
hm/update-get-state

Conversation

@hmalik88

@hmalik88 hmalik88 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Description

Updates snap_getState to accept an array of keys in the key parameter, allowing a Snap to fetch multiple state values in a single call.

Before

// Only one key at a time
const value = await snap.request({
  method: 'snap_getState',
  params: { key: 'user.name' },
});
// → "Alice"

After

// Multiple keys in one call
const values = await snap.request({
  method: 'snap_getState',
  params: { key: ['user.name', 'user.age', 'settings.theme'] },
});
// → { 'user.name': 'Alice', 'user.age': 42, 'settings.theme': 'dark' }

Behavior

  • When key is a string[], the result is a Record<string, Json> mapping each key to its resolved value. Keys not found in state map to null.
  • All existing validation rules apply to each element in the array (dot-path syntax, forbidden keys).

Note

Medium Risk
Changes permitted state-read RPC validation and response shape for a new parameter form; backward compatible for string keys but affects Snap storage access semantics.

Overview
snap_getState now accepts key as either a dot-path string or a string array, so Snaps can read several state paths in one RPC call. With an array, the result is a Record<string, Json> keyed by the requested paths; paths that are missing resolve to null. Single-key and whole-state behavior is unchanged.

The RPC layer validates array vs string key via selectiveUnion and StateKeysStruct, and the internal get helper builds the record while still enforcing forbidden-key checks on every path segment. GetStateParams in the SDK is updated accordingly; the manage-state example and test-snaps UI (comma-separated keys) exercise the new shape, with unit and integration tests added.

Reviewed by Cursor Bugbot for commit f9ec0f6. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.60%. Comparing base (7e3d201) to head (91be136).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4125   +/-   ##
=======================================
  Coverage   98.59%   98.60%           
=======================================
  Files         429      429           
  Lines       12497    12509   +12     
  Branches     1976     1978    +2     
=======================================
+ Hits        12322    12334   +12     
  Misses        175      175           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hmalik88
hmalik88 marked this pull request as ready for review September 17, 2026 16:58
@hmalik88
hmalik88 requested a review from a team as a code owner September 17, 2026 16:58
Comment thread packages/snaps-rpc-methods/src/permitted/getState.ts Outdated
Comment thread packages/snaps-rpc-methods/src/permitted/getState.ts Outdated
@hmalik88
hmalik88 added this pull request to the merge queue Sep 21, 2026
Merged via the queue into main with commit 9127573 Sep 21, 2026
129 checks passed
@hmalik88
hmalik88 deleted the hm/update-get-state branch September 21, 2026 09:32
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