Skip to content

fix: use optional instead of exactOptional in KeyringCapabilitiesStruct#481

Open
hmalik88 wants to merge 2 commits intomainfrom
hm/fix-capabilities-struct
Open

fix: use optional instead of exactOptional in KeyringCapabilitiesStruct#481
hmalik88 wants to merge 2 commits intomainfrom
hm/fix-capabilities-struct

Conversation

@hmalik88
Copy link
Copy Markdown
Contributor

@hmalik88 hmalik88 commented Mar 24, 2026

Change KeyringCapabilitiesStruct to use optional instead of exactOptional for nested fields

exactOptional rejects explicit undefined values while optional accepts them. The distinction is meaningless for this struct because capabilities data is always JSON-sourced (from Snap manifests and JSON-RPC messages), and undefined cannot exist in JSON. JSON.parse never produces it, and JSON.stringify silently drops keys with undefined values.

The practical motivation: @metamask/snaps-utils mirrors this struct for manifest validation, where PermissionsStruct is annotated as Describe<InitialPermissions>. Superstruct's Describe<T> maps TypeScript's prop?: T to a struct whose refiner accepts T | undefined, but exactOptional(T) produces a refiner that only accepts T. These are incompatible at the type level, forcing consumers to maintain a duplicate struct with optional just to satisfy Describe. Switching the canonical struct to optional eliminates this duplication with no change in runtime behavior for JSON data.


Note

Low Risk
Low risk: schema validation is loosened only to accept explicit undefined for nested capability fields; behavior for JSON-derived data should be unchanged.

Overview
Updates KeyringCapabilitiesStruct to use superstruct optional() (instead of exactOptional()) for nested capability objects and their fields (bip44, privateKey, custom).

Adds a changelog entry documenting this as a fix, primarily improving TypeScript Describe<> compatibility while keeping effective JSON validation the same.

Written by Cursor Bugbot for commit ba24cd8. This will update automatically on new commits. Configure here.

@hmalik88 hmalik88 requested a review from a team as a code owner March 24, 2026 17:12
@hmalik88 hmalik88 changed the title refactor: use optional instead of exactOptional in KeyringCapabilitiesStruct fix: use optional instead of exactOptional in KeyringCapabilitiesStruct Mar 24, 2026
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.

1 participant