Skip to content

feat(zod-solana): add signatureSchema and blockhashSchema - #204

Merged
macalinao merged 3 commits into
masterfrom
macalinao/zod-solana-signature-blockhash
Aug 12, 2026
Merged

macalinao merged 3 commits into
masterfrom
macalinao/zod-solana-signature-blockhash

Conversation

@macalinao

@macalinao macalinao commented Aug 12, 2026 •

Copy link
Copy Markdown
Owner

Adds two new schemas to @macalinao/zod-solana:

  • signatureSchema — parses a string into a Signature (base58, 64 bytes) via signature() from @solana/kit. Invalid input yields "Invalid Solana signature".
  • blockhashSchema — parses a string into a Blockhash (base58, 32 bytes) via blockhash() from @solana/kit. Invalid input yields "Invalid Solana blockhash".

Each schema lives in its own file (signature-schema.ts, blockhash-schema.ts) and is re-exported from index.ts, matching the existing one-schema-per-file layout so bundlers can tree-shake unused schemas.

Also includes tests for both (valid/invalid, length mismatches, base58 charset, safeParse, type inference), README API entries, and a minor changeset.

Test plan

  • bun run build — passes
  • bun run lint:fix — clean
  • bun test in packages/zod-solana — 253 pass, 0 fail

Summary by Sourcery

Add new Zod schemas for validating and transforming Solana transaction signatures and blockhashes, and expose them from the zod-solana package.

New Features:

  • Introduce signatureSchema for validating base58-encoded 64-byte Solana transaction signatures and transforming them into the Signature type from @solana/kit.
  • Introduce blockhashSchema for validating base58-encoded 32-byte Solana blockhashes and transforming them into the Blockhash type from @solana/kit.

Documentation:

  • Document signatureSchema and blockhashSchema in the zod-solana README with usage and error behavior.

Tests:

  • Add unit tests for signatureSchema and blockhashSchema covering valid/invalid inputs, length and character checks, safeParse behavior, and TypeScript type inference.

Chores:

  • Add a minor changeset entry to publish the new signatureSchema and blockhashSchema APIs in @macalinao/zod-solana.

Summary by CodeRabbit

  • New Features

    • Added validation schemas for Solana signatures and blockhashes.
    • Valid values are transformed into strongly typed Solana values.
    • Schemas support both Zod v3 and Zod v4.
  • Documentation

    • Added API documentation and usage details for the new schemas.
  • Bug Fixes

    • Improved consistent validation and error reporting for Solana addresses and branded string values.

Adds Zod schemas for Solana transaction signatures and blockhashes, each in
its own file to keep the package tree-shakeable.
@sourcery-ai

sourcery-ai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR adds two new Zod schemas to @macalinao/zod-solana for validating and transforming Solana signatures and blockhashes into their branded @solana/kit types, along with tests, README documentation, and a minor changeset entry.

File-Level Changes

Change Details Files
Introduce a Zod schema for Solana transaction signatures that transforms validated base58-encoded 64-byte strings into the branded Signature type and surfaces a consistent error message on failure.
  • Define signatureSchema as a ZodType<Signature, string> that starts from z.string() and uses a transform to call signature(val) from @solana/kit.
  • On transform failures, add a custom Zod issue with the message "Invalid Solana signature" and return z.NEVER for compatibility with Zod v3/v4.
  • Add unit tests covering valid signatures (including all-zero), invalid characters, length mismatches, misuse with 32-byte values, safeParse behavior, and TypeScript output type inference via z.output.
  • Re-export signatureSchema from the package index alongside existing schemas.
packages/zod-solana/src/signature-schema.ts
packages/zod-solana/src/signature-schema.test.ts
packages/zod-solana/src/index.ts
Introduce a Zod schema for Solana blockhashes that transforms validated base58-encoded 32-byte strings into the branded Blockhash type and surfaces a consistent error message on failure.
  • Define blockhashSchema as a ZodType<Blockhash, string> that starts from z.string() and uses a transform to call blockhash(val) from @solana/kit.
  • On transform failures, add a custom Zod issue with the message "Invalid Solana blockhash" and return z.NEVER for compatibility with Zod v3/v4.
  • Add unit tests covering valid blockhashes (including all-zero), invalid characters, length mismatches, misuse with 64-byte values, safeParse behavior, and TypeScript output type inference via z.output.
  • Re-export blockhashSchema from the package index alongside existing schemas.
packages/zod-solana/src/blockhash-schema.ts
packages/zod-solana/src/blockhash-schema.test.ts
packages/zod-solana/src/index.ts
Document the new schemas and bump the package version with a minor changeset entry.
  • Update README to add API sections for signatureSchema and blockhashSchema describing inputs, outputs, and error messages in line with existing addressSchema docs.
  • Add a changeset file declaring a minor version bump for @macalinao/zod-solana and summarizing the new schemas and their corresponding branded types.
packages/zod-solana/README.md
.changeset/zod-solana-signature-blockhash.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@macalinao, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 15 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4f8a5565-a34e-4f66-a1c4-964329ca6af1

📥 Commits

Reviewing files that changed from the base of the PR and between bcd2cf7 and f57e783.

📒 Files selected for processing (5)
  • packages/zod-solana/README.md
  • packages/zod-solana/src/address-schema.ts
  • packages/zod-solana/src/blockhash-schema.ts
  • packages/zod-solana/src/create-branded-string-schema.ts
  • packages/zod-solana/src/signature-schema.ts

Walkthrough

Adds branded Zod schemas for Solana signatures and blockhashes. Centralizes branded-string validation, updates address validation, exports the new schemas, and adds tests, documentation, and a release changeset.

Changes

Solana schema validation

Layer / File(s) Summary
Shared branded-string validation
packages/zod-solana/src/create-branded-string-schema.ts, packages/zod-solana/src/address-schema.ts
Adds shared transformation and error handling for branded strings. Updates addressSchema to use the helper.
Signature and blockhash schemas
packages/zod-solana/src/signature-schema.ts, packages/zod-solana/src/blockhash-schema.ts, packages/zod-solana/src/index.ts
Adds schemas that validate base58-encoded Solana signatures and blockhashes, transform them into branded types, and export them from the package.
Validation and release support
packages/zod-solana/src/signature-schema.test.ts, packages/zod-solana/src/blockhash-schema.test.ts, packages/zod-solana/README.md, .changeset/zod-solana-signature-blockhash.md
Adds runtime and TypeScript coverage, documents both schemas, and records a minor release changeset.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • macalinao/grill#203: Both pull requests add public exports through packages/zod-solana/src/index.ts.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the addition of the two main schemas described in the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch macalinao/zod-solana-signature-blockhash

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The signatureSchema and blockhashSchema are typed as z.ZodType<..., string>, but ZodType’s second generic parameter is the definition type, not the input type; consider switching to ZodEffects<z.ZodString, Signature, string> / ZodEffects<z.ZodString, Blockhash, string> or correcting the generics so the input/output typing matches Zod’s signatures.
  • The signature and blockhash schemas share nearly identical transform-and-error-handling logic; consider extracting a small helper for the common pattern to reduce duplication and keep behavior consistent if you adjust validation in the future.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `signatureSchema` and `blockhashSchema` are typed as `z.ZodType<..., string>`, but `ZodType`’s second generic parameter is the definition type, not the input type; consider switching to `ZodEffects<z.ZodString, Signature, string>` / `ZodEffects<z.ZodString, Blockhash, string>` or correcting the generics so the input/output typing matches Zod’s signatures.
- The signature and blockhash schemas share nearly identical transform-and-error-handling logic; consider extracting a small helper for the common pattern to reduce duplication and keep behavior consistent if you adjust validation in the future.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
grill-example-dapp f57e783 Commit Preview URL

Branch Preview URL
Aug 12 2026, 03:13 AM

Addresses review feedback about duplicated transform/error-handling logic
across the address, signature, and blockhash schemas. Each schema keeps its
own module so tree shaking is unaffected.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/zod-solana/src/create-branded-string-schema.ts (1)

1-1: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the required zod namespace import.

The repository rule requires import * as zod from "zod". Rename these imports and their namespace references.

  • packages/zod-solana/src/create-branded-string-schema.ts#L1-L1: rename the runtime namespace import and all z.* references.
  • packages/zod-solana/src/address-schema.ts#L2-L2: rename the type-only namespace import and z.ZodType.
  • packages/zod-solana/src/signature-schema.ts#L2-L2: rename the type-only namespace import and z.ZodType.
  • packages/zod-solana/src/blockhash-schema.ts#L2-L2: rename the type-only namespace import and z.ZodType.

As per coding guidelines, use namespace imports for Zod: import * as zod from "zod".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/zod-solana/src/create-branded-string-schema.ts` at line 1, Replace
the Zod namespace imports with import * as zod from "zod" and rename every
corresponding namespace reference. In
packages/zod-solana/src/create-branded-string-schema.ts lines 1-1, update the
runtime import and all z.* usages; in packages/zod-solana/src/address-schema.ts
lines 2-2, packages/zod-solana/src/signature-schema.ts lines 2-2, and
packages/zod-solana/src/blockhash-schema.ts lines 2-2, update the type-only
imports and z.ZodType references.

Source: Coding guidelines

packages/zod-solana/src/signature-schema.test.ts (1)

1-1: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use zod as the Zod namespace import.

Rename the namespace import and its type references in both test files.

  • packages/zod-solana/src/signature-schema.test.ts#L1-L1: Change the import to import type * as zod from "zod" and update z.output on Line 67.
  • packages/zod-solana/src/blockhash-schema.test.ts#L1-L1: Change the import to import type * as zod from "zod" and update z.output on Line 64.

As per coding guidelines, use namespace imports for Zod: import * as zod from "zod".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/zod-solana/src/signature-schema.test.ts` at line 1, Rename the Zod
namespace import to zod and update all corresponding type references in
packages/zod-solana/src/signature-schema.test.ts (including z.output) and
packages/zod-solana/src/blockhash-schema.test.ts (including z.output); use the
prescribed namespace import form consistently in both files.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/zod-solana/src/create-branded-string-schema.ts`:
- Around line 14-18: Align the Zod compatibility contract across
createBrandedStringSchema in
packages/zod-solana/src/create-branded-string-schema.ts (lines 14-18),
address-schema.ts (lines 11-12), signature-schema.ts (lines 12-13), and
blockhash-schema.ts (lines 12-13): either widen the peer dependency to support
Zod v3 and use the shared z.ZodType<T> annotation, or remove the Zod v3
compatibility claims from all four schema comments.

---

Nitpick comments:
In `@packages/zod-solana/src/create-branded-string-schema.ts`:
- Line 1: Replace the Zod namespace imports with import * as zod from "zod" and
rename every corresponding namespace reference. In
packages/zod-solana/src/create-branded-string-schema.ts lines 1-1, update the
runtime import and all z.* usages; in packages/zod-solana/src/address-schema.ts
lines 2-2, packages/zod-solana/src/signature-schema.ts lines 2-2, and
packages/zod-solana/src/blockhash-schema.ts lines 2-2, update the type-only
imports and z.ZodType references.

In `@packages/zod-solana/src/signature-schema.test.ts`:
- Line 1: Rename the Zod namespace import to zod and update all corresponding
type references in packages/zod-solana/src/signature-schema.test.ts (including
z.output) and packages/zod-solana/src/blockhash-schema.test.ts (including
z.output); use the prescribed namespace import form consistently in both files.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 639918c2-a214-4909-bf61-8b32c30b1688

📥 Commits

Reviewing files that changed from the base of the PR and between 7f1777a and bcd2cf7.

📒 Files selected for processing (9)
  • .changeset/zod-solana-signature-blockhash.md
  • packages/zod-solana/README.md
  • packages/zod-solana/src/address-schema.ts
  • packages/zod-solana/src/blockhash-schema.test.ts
  • packages/zod-solana/src/blockhash-schema.ts
  • packages/zod-solana/src/create-branded-string-schema.ts
  • packages/zod-solana/src/index.ts
  • packages/zod-solana/src/signature-schema.test.ts
  • packages/zod-solana/src/signature-schema.ts

The package's peer dependency is zod ^4 and the schemas use the v4
ZodType<Output, Input> typing, which does not compile against v3.
@macalinao
macalinao merged commit bb2fd2c into master Aug 12, 2026
10 checks passed
@macalinao
macalinao deleted the macalinao/zod-solana-signature-blockhash branch August 12, 2026 12:21
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