Skip to content

feat(midnight-sdk): ratify Ecrecover trees with client signing#809

Open
Rubilmax wants to merge 3 commits into
tib-midnight-instance-actionsfrom
ecrecover-ratify-wallet-client
Open

feat(midnight-sdk): ratify Ecrecover trees with client signing#809
Rubilmax wants to merge 3 commits into
tib-midnight-instance-actionsfrom
ecrecover-ratify-wallet-client

Conversation

@Rubilmax

@Rubilmax Rubilmax commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Update EcrecoverRatifierUtils.ratify/sign to accept a viem Client plus explicit account for local Ecrecover signing.
  • Derive the EIP-712 domain chain id from client.chain.id; callers no longer pass chainId to ratify.
  • Support delegated signer accounts and mixed-maker trees, while still rejecting mixed-ratifier trees.
  • Verify the returned signature via viem verifyTypedData without wrapping viem/noble errors in an SDK-specific error.
  • Update README/TIB docs, tests, errors, and changeset language.

Protocol Check

  • Confirmed morpho-org/midnight EcrecoverRatifier accepts _signer == offer.maker || IMidnight(MIDNIGHT).isAuthorized(offer.maker, _signer).
  • Checked local viem source: utility verifyTypedData returns isAddressEqual(getAddress(address), await recoverTypedDataAddress(...)); malformed signatures throw from the underlying recovery path.

Validation

  • pnpm --filter @morpho-org/midnight-sdk build
  • pnpm --filter @morpho-org/midnight-sdk test
  • pnpm exec biome check packages/midnight-sdk/src/signatures/EcrecoverRatifierUtils.ts packages/midnight-sdk/src/signatures/EcrecoverRatifierUtils.test.ts packages/midnight-sdk/src/errors.ts .changeset/add-midnight-sdk.md

@Rubilmax Rubilmax self-assigned this Jun 22, 2026
@Rubilmax Rubilmax marked this pull request as ready for review June 22, 2026 10:48
@Rubilmax Rubilmax requested a review from a team as a code owner June 22, 2026 10:48

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@Rubilmax Rubilmax changed the title [codex] Ratify Ecrecover trees with wallet client feat(midnight-sdk) Ratify Ecrecover trees with wallet client Jun 22, 2026
@Rubilmax Rubilmax changed the title feat(midnight-sdk) Ratify Ecrecover trees with wallet client feat(midnight-sdk): ratify Ecrecover trees with wallet client Jun 22, 2026
@yum0e

yum0e commented Jun 22, 2026

Copy link
Copy Markdown
Member

One compatibility caveat with router/onchain behavior: the new walletClient convenience path only supports direct maker signing, while router/onchain Ecrecover also supports delegated signers authorized by the maker.

In this PR, sign({ tree, walletClient }) rejects walletClient.account !== tree.offers[0].maker and verifies the returned signature against maker, so an authorized delegate wallet cannot use:

await EcrecoverRatifierUtils.ratify({ tree, walletClient: delegateWallet });

Delegated signing is still possible through the precomputed-signature path:

const typedData = EcrecoverRatifierUtils.typedData({ tree, chainId });
const signature = await delegateWallet.signTypedData({
  account: delegateAccount,
  ...typedData,
});
const items = await EcrecoverRatifierUtils.ratify({ tree, signature });

Could we document that distinction explicitly (or rename the error/docs to say this wallet-client overload is maker-only)? Otherwise SDK users may think delegated signing is unsupported, even though it remains compatible with router/onchain when using the manual signature path.

@Rubilmax Rubilmax changed the title feat(midnight-sdk): ratify Ecrecover trees with wallet client feat(midnight-sdk): ratify Ecrecover trees with client signing Jun 22, 2026
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.

3 participants