Skip to content

Add OKP/Ed25519 key support to cipher #85

@macterra

Description

@macterra

Problem

When issuing a credential to a did:key subject (resolved via the universal resolver fallback from #81), the cipher crashes with:

TypeError: Cannot read properties of undefined (reading 'length')

Root cause: convertJwkToCompressedBytes in packages/cipher/src/cipher-base.ts accesses jwk.y, which is undefined for Ed25519/OKP keys (they only have x). The cipher currently only supports secp256k1 EC keys.

Proposed solution

Detect OKP keys (kty === "OKP") in encryptBytes/decryptBytes and use X25519 key agreement instead of secp256k1 ECDH:

  1. Convert the Ed25519 public key to X25519 using edwardsToMontgomeryPub from @noble/curves (already in the dependency tree)
  2. Use x25519.getSharedSecret() for key derivation
  3. The symmetric encryption (xchacha20poly1305) stays the same — only the shared secret derivation changes

Files to modify

  • packages/cipher/src/cipher-base.ts — key type detection + X25519 key agreement path
  • packages/cipher/src/types.ts — extend key types to support OKP JWKs
  • packages/cipher/package.json — add @noble/curves as a direct dependency

Context

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions