Feat/wpn 1630 use shared serialization - #197
Open
Julink-eth wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds shared serialization utilities to @metamask/snap-networks-utils so network snaps can round-trip non-JSON-native values through snap state / interface context using a consistent wire format.
Changes:
- Introduces
serialize,deserialize, andSerializablesupportingundefined,BigNumber,bigint, andUint8Arrayvia{ __type, value? }. - Exposes the new helpers from the package root export surface.
- Adds Jest coverage and a changelog entry; introduces needed dependencies (
bignumber.js,lodash,@types/lodash).
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Adds lockfile entries for newly introduced dependencies. |
| packages/snap-networks-utils/src/serialization/types.ts | Defines the Serializable type used by the helpers. |
| packages/snap-networks-utils/src/serialization/serialize.ts | Implements JSON-safe serialization with a stable { __type, value? } wire format. |
| packages/snap-networks-utils/src/serialization/serialize.test.ts | Adds unit tests covering primitives, nested structures, and Uint8Array encoding. |
| packages/snap-networks-utils/src/serialization/deserialize.ts | Implements deserialization back to original runtime types. |
| packages/snap-networks-utils/src/serialization/deserialize.test.ts | Adds unit tests for deserialization, including falsy-value handling and Uint8Array. |
| packages/snap-networks-utils/src/index.ts | Exports serialize, deserialize, and Serializable from the package entrypoint. |
| packages/snap-networks-utils/package.json | Adds runtime/dev dependencies required by the new helpers. |
| packages/snap-networks-utils/CHANGELOG.md | Documents the addition of the new serialization helpers. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Solana, Tron, and Stellar each keep a local
{ __type, value }serialize/deserialize pair so snap state can round-trip values JSON cannot represent (undefined,BigNumber,bigint,Uint8Array). This PR adds that helper to@metamask/snap-networks-utilsso the snaps can share one implementation.serialize/deserialize/Serializableare exported from the package.{ __type: 'undefined' | 'BigNumber' | 'bigint' | 'Uint8Array', value? }.Uint8Arrayuses portablebtoa/atob(same as Tron/Stellar), not Solana’s@solana/kitcodec. Encoded bytes still match ([1, 2, 3]→AQID).This PR is utils-only. Follow-up PRs will switch Solana, Tron, and Stellar to the shared helpers.
References
Checklist