Skip to content

feat: create shared serialization helpers - #197

Merged
Julink-eth merged 5 commits into
mainfrom
feat/WPN-1630-use-shared-serialization
Aug 28, 2026
Merged

feat: create shared serialization helpers#197
Julink-eth merged 5 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.

@Julink-eth Julink-eth changed the title Feat/wpn 1630 use shared serialization Feat: create shared serialization helpers Aug 27, 2026
@Julink-eth Julink-eth changed the title Feat: create shared serialization helpers feat: create shared serialization helpers Aug 27, 2026

@stanleyyconsensys stanleyyconsensys 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.

leave a small nit comment

Btw do we wanna to re-structure it as what we purpose

IMO, we can just have 1 serialization.ts, and put those type deserialize and serialize into it

but it is optional , not a blocker

@@ -0,0 +1,95 @@
/* eslint-disable jest/prefer-strict-equal */

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.

missing enable after disable

@Julink-eth

Copy link
Copy Markdown
Contributor Author

leave a small nit comment

Btw do we wanna to re-structure it as what we purpose

IMO, we can just have 1 serialization.ts, and put those type deserialize and serialize into it

but it is optional , not a blocker

True better this way, I'll change it.

@Julink-eth
Julink-eth added this pull request to the merge queue Aug 28, 2026
Merged via the queue into main with commit eae5743 Aug 28, 2026
53 checks passed
@Julink-eth
Julink-eth deleted the feat/WPN-1630-use-shared-serialization branch August 28, 2026 07:13
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