Skip to content

feat(eip712): EIP-712 typed-data signing module (WALLET-1255)#41

Merged
Comp0te merged 11 commits into
masterfrom
WALLET-1255-cw-core-eip-712-signature-requests-parsing-and-validation
Jun 11, 2026
Merged

feat(eip712): EIP-712 typed-data signing module (WALLET-1255)#41
Comp0te merged 11 commits into
masterfrom
WALLET-1255-cw-core-eip-712-signature-requests-parsing-and-validation

Conversation

@ost-ptk

@ost-ptk ost-ptk commented Jun 4, 2026

Copy link
Copy Markdown
Member

Summary

Extracts the reusable, framework-agnostic EIP-712 typed-data signing logic into casper-wallet-core so both consumers — the browser extension and the React-Native mobile app — share one implementation instead of duplicating it. Adds an eip712 repository (wired into setupRepositories()) providing: typed-data validation, EIP-712 digest + hash artifacts, a UI-agnostic display model, a Casper-correct signing helper, and recover/verify.

Hashing/recover/verify are delegated to @casper-ecosystem/casper-eip-712; signing uses casper-js-sdk keys. No UI — each wallet renders its own. casper-click-websdk stays unchanged; this is purely additive.

Closes WALLET-1255.

What's added

  • src/domain/eip712/ — interfaces, EIP712Error (implements IDomainError, also carries the public errorCode), SignTypedDataErrorCodes, IEIP712Repository. Mirrors tx-signature-request.
  • src/utils/eip712/ — pure logic: validation, digest, displayModel, sign, recover (+ barrel).
  • src/data/repositories/eip712/EIP712Repository, a thin synchronous facade delegating to the utils.
  • Wiringdomain/index, utils/index, data/repositories/index, setup.ts (adds eip712Repository), and package.json (@casper-ecosystem/casper-eip-712@1.2.1; transitive deps only @noble/curves + @noble/hashes, RN-safe).

Public API: setupRepositories().eip712Repository, isEIP712Error, SignTypedDataErrorCodes, plus all types/utilities via the root barrel.

Key invariants & decisions

  • No double-hash (load-bearing): for secp256k1, casper-js-sdk PrivateKey.sign() prehashes with SHA-256 internally, so passing the raw EIP-712 digest reproduces the reference 02 + secp256k1.sign(sha256(digest)) wire format byte-for-byte (asserted in tests against an independent @noble reference). No new signing dependency.
  • ed25519 is implemented (prefix 01, signs the digest directly) and covered by a native round-trip test; still unproven by a production consumer (secp256k1 is the proven path).
  • Display model preserves the source's intentional asymmetry: domain rows are addresses when type === 'address' or key contract_package_hash; message rows when type === 'address' or bytes32.
  • recover/verify are a separate, Ethereum-style path: the lib expects a 65-byte recoverable secp256k1 signature over the raw keccak256 digest and returns a 20-byte address. They do not verify the wallet's 02-prefixed signatures (which are over sha256(digest)) and do not apply to ed25519 — documented on the wrappers and the repository.

Test plan

  • yarn code:check — clean (tsc strict + eslint + prettier).
  • yarn test416 passed (42 suites), including:
    • validation — 4-step domain-type priority, array/bytes1..bytes31 rejection (fast-check property), rejectUnknownFields.
    • digest — stable digest + all 6 hash artifacts against real package vectors.
    • displayModel — domain/message address asymmetry, keyToLabel.
    • signsecp256k1 byte-identical gate, ed25519 round-trip, end-to-end (with/without artifacts).
    • recover — recovers the true signer address, verify round-trip, lib re-exports.
    • repository — delegation + error pass-through and non-EIP712 wrapping.
    • setup.integration.test.ts — factory still wires correctly with eip712Repository.

🤖 Generated with Claude Code

ost-ptk added 10 commits June 4, 2026 13:13
- Added EIP-712 entities, errors, and repository interfaces to support typed data handling, signing, and verification
- Integrated `@casper-ecosystem/casper-eip-712` dependency for EIP-712 compatibility
- Included unit tests for EIP-712 error handling
- Added `validatePrimaryType`, `resolveDomainTypes`, `validateTypedDataFieldTypes`, and `validateNoUnknownMessageFields` functions for EIP-712 typed data validation
- Included unit tests to cover validation logic and edge cases
- Implemented `computeTypedDataDigest` to generate EIP-712 digests and optional hash artifacts
- Included comprehensive unit tests for digest stability, artifact generation, and strict field validation
- Implemented `buildTypedDataDisplayModel` to generate structured display models for EIP-712 typed data
- Added `keyToLabel` function to map keys to user-friendly labels
- Included comprehensive unit tests for domain and message row formatting, type handling, and address detection
- Implemented `signTypedData`, `signTypedDataDigestWithKey`, and `signTypedDataWithRawKey` for EIP-712 signing
- Added unit tests to verify signature correctness, digest computation, and hash artifact handling
- Ensured compatibility with `ed25519` and `secp256k1` signing algorithms
…ities with tests

- Implemented `recoverTypedDataSignerAddress` and `verifyTypedDataSignature` for Ethereum-style signature recovery and validation
- Re-exported EIP-712 domain helpers (`CASPER_DOMAIN_TYPES`, `buildDomain`, `PermitTypes`, etc.)
- Added unit tests to validate signature recovery, verification, and helper re-exports
- Added `EIP712Repository` class for typed data handling, digest computation, signing, and verification.
- Implemented methods for building display models, signing typed data, and recovering/verifying signatures.
- Included comprehensive unit tests to validate repository behavior and error handling.
@ost-ptk ost-ptk requested a review from Comp0te June 4, 2026 14:14
Comment thread src/data/repositories/eip712/index.ts Outdated

@Comp0te Comp0te left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setup.integration.test.ts missing new repository

- Adjusted `EIP712Error` instantiation to use `signDigest` as the error context.
- Updated integration test to include the new `eip712Repository` in repository wiring validation.
@Comp0te Comp0te merged commit 4d6f863 into master Jun 11, 2026
4 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