-
Notifications
You must be signed in to change notification settings - Fork 262
feat: switch from borsh to zorsh serialization #1719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: pre-release/v7
Are you sure you want to change the base?
feat: switch from borsh to zorsh serialization #1719
Conversation
🦋 Changeset detectedLatest commit: 0946ae7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
💡 Codex ReviewLines 15 to 21 in df68e3b
The package is now marked as ESM ( ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Replace the borsh library with @zorsh/zorsh throughout the codebase: - Update package.json to use @zorsh/zorsh ^0.4.0 instead of borsh 1.0.0 - Convert all schema definitions in src/transactions/schema.ts to use zorsh's builder API (b.struct, b.enum, b.bytes, etc.) - Update serialize/deserialize calls to use schema methods instead of standalone functions - Fix type compatibility issues with type assertions at serialization boundaries where needed - Update test files to use zorsh API The binary serialization format remains identical as both libraries implement the Borsh specification.
- Add ensureBigInt() helper for number-to-BigInt conversion - Update all encoding functions to handle BigInt requirements - Fix test imports for vitest migration - Remove unused Test class and update test expectations
e7c9782 to
abdca41
Compare
- Organize imports in schema.ts and key_pair_signer.test.ts - Fix formatting in schema.ts (constructor parameters, imports) - Apply template literals in serialize.test.ts - Format long lines in test files
- Exclude keyType field from BigInt conversion (it's an enum: 0 or 1) - Convert undefined to null for allowance field (zorsh expects null for optional values) - Prevent mixing BigInt with regular numbers in serialization This fixes the "serialize multi-action tx" test failure.
- Convert all undefined values to null for optional numeric fields (not just allowance, but also maxBlockHeight and other optional fields) - Zorsh's b.option() expects null, not undefined, for "no value" - Add comprehensive unit tests for real-world transaction scenarios including large numbers, mixed numeric types, and JSON-parsed values This ensures compatibility with actual RPC responses where numeric values may be numbers, strings, or BigInt depending on their size.
Changes Made:
{ struct: { field: 'type' } }→ New:b.struct({ field: b.type() })With regards to the
as anycasts, Zorsh generates very strict types from schemas. For enums, zorsh expects discriminated unions like{ ed25519Key: X } | { secp256k1Key: Y }, but the existingPublicKeyclass has a different structure (both properties exist, one is undefined).They only appear at serialization boundaries in:
encodeDelegateAction()(src/transactions/schema.ts:21)encodeSignedDelegate()(src/transactions/schema.ts:30)encodeTransaction()(src/transactions/schema.ts:40)Pre-flight checklist
pnpm changesetto create achangesetJSON document appropriate for this change.Motivation
Test Plan
Related issues/PRs
Closes #1699