Skip to content

Refactor README and enhance ENS/receipt validation#16

Merged
GsCommand merged 1 commit into
mainfrom
claude/audit-commandlayer-protocol-O05aO
May 14, 2026
Merged

Refactor README and enhance ENS/receipt validation#16
GsCommand merged 1 commit into
mainfrom
claude/audit-commandlayer-protocol-O05aO

Conversation

@GsCommand
Copy link
Copy Markdown
Contributor

Summary

This PR significantly improves the documentation and adds stricter validation to core signing and ENS resolution functions. The README is rewritten to focus on the canonical implementation role of runtime-core, with clearer examples and protocol documentation. Input validation is strengthened across receipt signing, ENS resolution, and legacy compat functions.

Key Changes

Documentation & Examples

  • Completely rewritten README to emphasize runtime-core as the single canonical implementation of signing, verification, and canonicalization
  • Reorganized examples to show common workflows first (canonicalization, signing/verification, ENS resolution)
  • Added protocol constants reference section
  • Added environment variables documentation with .env.example
  • Clarified signing protocol: signatures are over raw UTF-8 bytes of canonical JSON, not hashed
  • Removed outdated contract family (Commons/Commercial) references

ENS Resolution (src/ens.ts)

  • Added support for both positional arguments and options object calling conventions:
    • resolveSignerFromENS('name.eth', provider) (positional)
    • resolveSignerFromENS({ ensName: 'name.eth', provider }) (options)
  • Added ResolveSignerFromENSOptions interface for options object form
  • Enhanced input validation: checks for non-empty ensName string and required provider
  • Improved error messages with clearer guidance
  • Re-exported ENS_KEY_SIGNER constant from crypto module for convenience

Receipt Signing & Verification (src/receipt.ts)

  • Strengthened validation in signReceipt(): now validates all four required fields (verb, version, agent, timestamp) are non-empty strings
  • Added validation for signing options (privateKeyPem, kid, signerEns)
  • Enhanced verifyReceipt() structure checks: validates signature is a non-empty string
  • Improved isSignedLayeredReceipt(): now checks that signature string is non-empty (length > 0)
  • Better type safety with explicit string type checks before use

Legacy Compat (src/compat.ts)

  • Added input validation to signReceiptEd25519Sha256(): validates privateKeyPem, signer_id, kid
  • Added input validation to verifyReceiptEd25519Sha256(): validates publicKeyPemOrDer
  • Improved signature field handling: accepts either signature or signature_b64 field with non-empty string check

Tests (test/ens.test.ts, test/receipt.test.ts)

  • Added comprehensive ENS resolution test suite covering both calling conventions
  • Added tests for input validation edge cases (empty strings, missing fields)
  • Added tests for error conditions (no resolver, network errors, malformed keys)
  • Enhanced receipt tests: added validation for version, agent, timestamp fields
  • Added test for empty signature string detection

Notable Implementation Details

  • ENS resolution now uses a single overloaded function signature that detects calling convention at runtime
  • All validation errors include specific field names and requirements for better debugging
  • Signature validation now explicitly checks for non-empty strings to prevent false positives on empty signatures
  • Error messages use template literals with + concatenation for consistency with existing codebase style

https://claude.ai/code/session_01GQcff5HnFcrTbyuwuvsNEv

- src/ens.ts: fix resolveSignerFromENS signature — positional args (string, provider)
  are the canonical implementation; README was showing the wrong object-destructure
  calling convention. Added resolveSignerFromENSOptions overload for ergonomic usage
  so both calling styles work.
- src/receipt.ts: add missing validation for payload.version in signReceipt;
  add input-length guard on signature base64 before calling verifyCanonical
- src/compat.ts: guard against empty string signature (not just missing field)
  in verifyReceiptEd25519Sha256; add explicit type narrowing
- README.md: remove every fabricated export reference (buildCommonsReceipt,
  buildCommercialReceipt, normalizeCommonsRequest, normalizeCommercialRequest,
  createSchemaClient, buildSchemaPath, createLayeredReceipt, hashReceiptCanonical,
  COMMONS_CONTRACT, COMMERCIAL_CONTRACT, COMMAND_LAYER_CURRENT_LINE,
  signReceiptEd25519, verifyReceiptSignature, toLegacyReceiptEnvelope, receipt-v1
  subpath). Replace with accurate API surface matching src/index.ts exports.
- package.json: remove stale AJV claim from description; confirm no unused deps
- .env.example: add required file documenting RPC_URL and key env vars
- test/receipt.test.ts: remove bare `as any` cast, add assertion on version field
@GsCommand GsCommand merged commit ac9aef9 into main May 14, 2026
1 of 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.

1 participant