Skip to content

Implement Flattened JWS serialization for Veramo compatibility#35

Merged
pelle merged 3 commits intomainfrom
claude/fix-veramo-test-failures-tkSsV
Feb 22, 2026
Merged

Implement Flattened JWS serialization for Veramo compatibility#35
pelle merged 3 commits intomainfrom
claude/fix-veramo-test-failures-tkSsV

Conversation

@pelle
Copy link
Copy Markdown
Contributor

@pelle pelle commented Feb 22, 2026

Summary

This PR updates the TAP agent to use Flattened JWS (JSON Web Signature) serialization format instead of General JWS format, enabling proper interoperability with Veramo's DIDComm implementation. The changes include custom serialization logic, flexible base64 decoding, and improved DID resolution for verification.

Key Changes

Message Format (Flattened JWS)

  • Custom JWS serialization: Implemented Serialize and Deserialize traits for the Jws struct to support both formats:
    • Single signature: Flattened format with payload, protected, and signature at top level
    • Multiple signatures: General format with payload and signatures array
  • Flexible base64 decoding: Added base64_decode_flexible() function that accepts standard base64, base64url with/without padding to handle different encoding schemes from Veramo
  • Updated all JWS encoding to use URL_SAFE_NO_PAD (base64url without padding) per RFC 7515

DID Resolution Improvements

  • Enhanced resolve_verification_key() in both DefaultKeyManager and AgentKeyManager to directly resolve did:key DIDs without requiring external resolver setup
  • Added caching of resolved verification keys for performance
  • Improved error handling for key resolution failures

Test Updates

  • Updated integration tests to expect Flattened JWS structure (protected/signature fields instead of signatures array)
  • Removed try-catch error handling from interoperability tests - they now expect successful message exchange
  • Simplified test assertions to work with the new format
  • Marked JWE (encrypted) tests as skipped since TAP WASM currently only supports JWS
  • Updated Veramo integration tests to use built-in memory stores (MemoryDIDStore, MemoryKeyStore, MemoryPrivateKeyStore) imported from @veramo/did-manager and @veramo/key-manager

Build Configuration

  • Added wasm-opt = false to wasm-pack release profile in Cargo.toml to prevent optimization issues

Implementation Details

  • The custom JWS deserializer intelligently detects format (General vs Flattened) and normalizes to internal representation
  • All base64 decoding now uses the flexible function to handle both standard and URL-safe variants
  • DID resolution for did:key is now self-contained, reducing external dependencies during message verification
  • Message packing/unpacking logic updated to handle both JWS formats transparently

https://claude.ai/code/session_01WWHiooMRiBBdSiQQwWqQGt

claude and others added 3 commits February 22, 2026 15:54
- Switch JWS encoding from standard Base64 to Base64URL (no padding) per RFC 7515
- Default to Flattened JWS serialization for single signatures (Veramo compat)
- Accept both General and Flattened JWS formats on deserialization
- Add base64_decode_flexible() helper that accepts all Base64 variants
- Implement did:key resolution in resolve_verification_key for cross-agent verification
- Fix Veramo integration tests: use built-in memory stores, fix message passing,
  remove error-swallowing try/catch patterns
- Update Flattened JWS detection in agent.rs, tap-node, and mock-server
- Update all TypeScript tests to expect Flattened JWS format

https://claude.ai/code/session_01WWHiooMRiBBdSiQQwWqQGt
- Add x25519-dalek for proper X25519 ECDH key agreement
- Make apv/apu optional in JweProtected (Veramo omits them)
- Support X25519 EPK in unwrap_jwe alongside existing P-256
- Use base64_decode_flexible for all JWE fields (base64url compat)
- Match JWE recipients by DID prefix (X25519 key agreement kids)
- Improve JWE unpack error messages with last failure details
- Enable Veramo JWE anoncrypt test (was skipped)

https://claude.ai/code/session_01WWHiooMRiBBdSiQQwWqQGt
@pelle pelle merged commit a3d9306 into main Feb 22, 2026
3 checks passed
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.

2 participants