Skip to content

fix(keys): reject Ed25519 public keys that are not 32 bytes in publicKeyBytesToJwk - #263

Open
0xcfloki wants to merge 1 commit into
agentcommercekit:mainfrom
0xcfloki:fix/ed25519-jwk-key-length
Open

0xcfloki wants to merge 1 commit into
agentcommercekit:mainfrom
0xcfloki:fix/ed25519-jwk-key-length

Conversation

@0xcfloki

@0xcfloki 0xcfloki commented Nov 6, 2026 •

Copy link
Copy Markdown

Summary

publicKeyBytesToJwk validates the key length for secp256k1 and secp256r1 (65 bytes) but not for Ed25519: the Ed25519 branch base64url-encodes whatever bytes it receives.

createVerificationMethod in did-pkh.ts takes the Ed25519 path for every solana:* account whose address is valid base58, so a short address such as abc (which caip10AccountAddressRegex accepts) produces a DID document with a malformed publicKeyJwk (x decodes to 2 bytes) instead of failing. Nothing downstream notices, because publicKeyJwkToBytes also returns the Ed25519 x as-is.

This adds the same length check the other two curves have: an Ed25519 key must be 32 bytes, otherwise Invalid Ed25519 public key length is thrown. Valid Solana addresses are unaffected (they decode to 32 bytes).

Tests

  • jwk.test.ts: 2-byte and 33-byte Ed25519 inputs throw.
  • did-pkh.test.ts: createDidPkhDocument with Solana address abc throws.

Both fail on main (no error thrown) and pass with the change. Full turbo test passes (26/26 tasks), oxlint and oxfmt --check are clean. Changeset added (@agentcommercekit/keys patch).

AI disclosure

Written with Claude Code (Claude Sonnet 5.5). I reviewed the change and the tests, ran the full suite locally, and can explain how the key-length check interacts with did:pkh document creation.

Summary by CodeRabbit

  • Bug Fixes
    • Invalid Ed25519 public keys with incorrect lengths are now rejected with a clear error, including malformed Solana addresses.

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

publicKeyBytesToJwk now rejects Ed25519 public keys that are not 32 bytes. Tests cover short and long keys and a malformed Solana address in DID-document creation.

Changes

Ed25519 key validation

Layer / File(s) Summary
Validate Ed25519 public-key length
packages/keys/src/encoding/jwk.ts, packages/keys/src/encoding/jwk.test.ts, packages/did/src/methods/did-pkh.test.ts, .changeset/ed25519-jwk-key-length.md
publicKeyBytesToJwk throws Invalid Ed25519 public key length when an Ed25519 public key is not 32 bytes. Tests cover inputs of 2 and 33 bytes and a Solana address of "abc". The changeset describes the validation and malformed-key case.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: Minimal · up to a8d99

Invalid Ed25519 key lengths are rejected; no material merge risk was identified.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: rejecting Ed25519 public keys that are not 32 bytes in publicKeyBytesToJwk.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files. (1 skipped: 1 unsupported.)

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8117fc45-c5a6-4674-8c4d-292f43a6a9e7
Commits

Reviewing files that changed from the base of the PR and between 3db94d6 and a8d9970.

Files selected for processing: 4

  • .changeset/ed25519-jwk-key-length.md
  • packages/did/src/methods/did-pkh.test.ts
  • packages/keys/src/encoding/jwk.test.ts
  • packages/keys/src/encoding/jwk.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

This branch has not been deployed

No deployments
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