Skip to content

fix(sdk): canonicalize Permit2 signature v-byte in MocIntegration route - #1150

Open
tjcloa wants to merge 1 commit into
developfrom
fix/sdk-permit2-signature-normalization
Open

fix(sdk): canonicalize Permit2 signature v-byte in MocIntegration route#1150
tjcloa wants to merge 1 commit into
developfrom
fix/sdk-permit2-signature-normalization

Conversation

@tjcloa

@tjcloa tjcloa commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What

SDK-side counterpart of #1147, so the Permit2 signature fix ships inside @sovryn/sdk 2.0.11 rather than only in the frontend.

The MocIntegration route ABI-encodes options.typedDataSignature verbatim into the getDocFromDllrAndRedeemRbtcWithPermit2 call. Wallets that expose raw signer output (Frame, onboard-ledger, some WalletConnect/MPC wallets) return the ECDSA v byte as the recovery id (0/1), and EIP-2098 signers return a 64-byte compact form — both produce calldata that Permit2's SignatureVerification (raw ecrecover) rejects on-chain. #1147 normalizes at the frontend boundary; this PR applies the same canonicalization where the SDK itself consumes the signature, covering direct SDK integrators.

  • New normalizeSignature helper in internal/utils (joinSignature(splitSignature(x)) — same idiom as fix: canonicalize typed-data signature v-byte before forwarding on-chain (Permit2 flows failing for Frame/Ledger wallets) #1147): canonical signatures pass through byte-for-byte, raw/compact forms are normalized to 65-byte r||s||v with v ∈ {27, 28}, malformed signatures throw at build time instead of reverting on-chain.
  • Applied at the MocIntegration encoding site — the only raw-signature sink in the SDK. The ZeroRedemption path already canonicalizes via its existing splitSignature call and is unchanged.
  • Changeset: @sovryn/sdk patch (joins the pending 2.0.11 release train).

Tests (TDD, red→green watched)

  • raw v=1 signature in → canonical v=28 encoded in calldata
  • already-canonical signature passes through unchanged
  • slippage-invariant moc fixture switched from the 0xab…ab placeholder to the shared valid FAKE_SIGNATURE (the placeholder's s has its top bit set, which ethers rejects as inconsistent in the 65-byte form — the route now correctly refuses it at build time)

Verification

Full sdk jest suite 88/88 green (fresh worktree, deps built from source); eslint clean.

Release note

Intended to merge before the Version Packages PR #1149 so it rides the 2.0.11 release together with #1147's frontend half.

SDK counterpart of the frontend fix in PR #1147. The MocIntegration
route ABI-encoded options.typedDataSignature verbatim into the
getDocFromDllrAndRedeemRbtcWithPermit2 call; wallets that return v as
a raw recovery id (0/1 — Frame, onboard-ledger, some MPC wallets) or
an EIP-2098 compact form produced calldata Permit2's ecrecover
rejects on-chain. Add normalizeSignature (joinSignature∘splitSignature)
to internal/utils and apply it at the encoding site; canonical
signatures pass through byte-identical, malformed ones throw at build
time. The ZeroRedemption path already canonicalizes via its existing
splitSignature call and needs no change.

Tests: raw v=1 in -> canonical v=28 encoded; canonical passthrough
pinned. The slippage-invariant moc fixture switched to the shared
valid FAKE_SIGNATURE (its 0xab..ab placeholder has s's top bit set,
which ethers rejects as inconsistent in the 65-byte form). Full sdk
suite 88/88 green, eslint clean.
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cb8b432

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sovryn/sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Aug 7, 2026

Copy link
Copy Markdown

Deploy Preview for sovryn-dapp ready!

Name Link
🔨 Latest commit cb8b432
🔍 Latest deploy log https://app.netlify.com/projects/sovryn-dapp/deploys/6a75dc6169b6220008b9044f
😎 Deploy Preview https://deploy-preview-1150.preview.sovryns.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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