Skip to content

Add signTypedData address recovery test (#2019)#2260

Open
Sukuna0007Abhi wants to merge 1 commit intoLFDT-web3j:mainfrom
Sukuna0007Abhi:test/2019-sign-typed-data-recovery
Open

Add signTypedData address recovery test (#2019)#2260
Sukuna0007Abhi wants to merge 1 commit intoLFDT-web3j:mainfrom
Sukuna0007Abhi:test/2019-sign-typed-data-recovery

Conversation

@Sukuna0007Abhi
Copy link
Copy Markdown

@Sukuna0007Abhi Sukuna0007Abhi commented Apr 6, 2026

What does this PR do?

Adds a focused unit test to demonstrate and verify how to recover the signer address from a signTypedData signature.

Specifically:

  1. Reuses the existing typed-data JSON fixture in SignTest.
  2. Signs the typed data with Sign.signTypedData(...).
  3. Recomputes the structured-data hash via StructuredDataEncoder.hashStructuredData().
  4. Recovers the public key using Sign.signedMessageHashToKey(...).
  5. Derives and asserts the recovered address matches SampleKeys.ADDRESS

Where should the reviewer start?

Start in crypto/src/test/java/org/web3j/crypto/SignTest.java, especially:

The new typed-data fixture constant near the top of the class.
testRecoverAddressFromSignTypedData() for the recovery flow.
testSignTypedData() which now reuses the shared fixture.

Why is it needed?

Issue #2019 identifies a real gap: while signTypedData signing is tested, recovery/verification flow is not clearly demonstrated in tests.

This PR closes that gap by adding an executable example that:

  • Serves as documentation for users verifying typed-data signatures.
  • Improves confidence in end-to-end signing + recovery behavior.
  • Increases robustness of the crypto test suite without changing production behavior.

Checklist

  • I've read the contribution guidelines.
  • I've added tests (if applicable).
  • I've added a changelog entry if necessary.

Signed-off-by: Sukuna0007Abhi <appsonly310@gmail.com>
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