You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(keys): reject Ed25519 public keys that are not 32 bytes in publicKeyBytesToJwk - #263
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.
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.
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.
Invalid Ed25519 key lengths are rejected; no material merge risk was identified.
Pre-merge checks: 5
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly describes the main change: rejecting Ed25519 public keys that are not 32 bytes in publicKeyBytesToJwk.
Docstring Coverage
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
publicKeyBytesToJwkvalidates the key length for secp256k1 and secp256r1 (65 bytes) but not for Ed25519: the Ed25519 branch base64url-encodes whatever bytes it receives.createVerificationMethodindid-pkh.tstakes the Ed25519 path for everysolana:*account whose address is valid base58, so a short address such asabc(whichcaip10AccountAddressRegexaccepts) produces a DID document with a malformedpublicKeyJwk(xdecodes to 2 bytes) instead of failing. Nothing downstream notices, becausepublicKeyJwkToBytesalso returns the Ed25519xas-is.This adds the same length check the other two curves have: an Ed25519 key must be 32 bytes, otherwise
Invalid Ed25519 public key lengthis 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:createDidPkhDocumentwith Solana addressabcthrows.Both fail on
main(no error thrown) and pass with the change. Fullturbo testpasses (26/26 tasks),oxlintandoxfmt --checkare clean. Changeset added (@agentcommercekit/keyspatch).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:pkhdocument creation.Summary by CodeRabbit