Skip to content

Feat/wpn 1630 use shared serialization - #197

Open
Julink-eth wants to merge 3 commits into
mainfrom
feat/WPN-1630-use-shared-serialization
Open

Feat/wpn 1630 use shared serialization#197
Julink-eth wants to merge 3 commits into
mainfrom
feat/WPN-1630-use-shared-serialization

Conversation

@Julink-eth

Copy link
Copy Markdown
Contributor

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-utils so the snaps can share one implementation.

  • serialize / deserialize / Serializable are exported from the package.
  • Wire format is unchanged: { __type: 'undefined' | 'BigNumber' | 'bigint' | 'Uint8Array', value? }.
  • Uint8Array uses portable btoa/atob (same as Tron/Stellar), not Solana’s @solana/kit codec. 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

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@Julink-eth
Julink-eth requested review from a team as code owners August 26, 2026 13:14
@Julink-eth
Julink-eth deployed to default-branch August 26, 2026 13:14 — with GitHub Actions Active

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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, and Serializable supporting undefined, BigNumber, bigint, and Uint8Array via { __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.

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