@swype-org/react-sdk 0.1.20 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -583,6 +583,41 @@ function resolveRootDomainFromHostname(hostname) {
583
583
  }
584
584
  return parts.slice(-2).join(".");
585
585
  }
586
+ var ERC_6492_MAGIC_SUFFIX = "6492649264926492649264926492649264926492649264926492649264926492";
587
+ function normalizeSignature(sig) {
588
+ const hex = sig.startsWith("0x") ? sig.slice(2) : sig;
589
+ if (hex.length === 130) {
590
+ return `0x${hex}`;
591
+ }
592
+ if (hex.length === 128) {
593
+ const r = hex.slice(0, 64);
594
+ const yParityAndS = hex.slice(64, 128);
595
+ const highByte = parseInt(yParityAndS.slice(0, 2), 16);
596
+ const v = (highByte & 128) !== 0 ? 28 : 27;
597
+ const sFirstByte = (highByte & 127).toString(16).padStart(2, "0");
598
+ const s = sFirstByte + yParityAndS.slice(2);
599
+ return `0x${r}${s}${v.toString(16)}`;
600
+ }
601
+ if (hex.length > 64 && hex.endsWith(ERC_6492_MAGIC_SUFFIX)) {
602
+ const { signature: inner } = utils.parseErc6492Signature(
603
+ `0x${hex}`
604
+ );
605
+ return normalizeSignature(inner);
606
+ }
607
+ if (hex.length > 130) {
608
+ try {
609
+ const [, innerBytes] = viem.decodeAbiParameters(
610
+ [{ type: "uint256" }, { type: "bytes" }],
611
+ `0x${hex}`
612
+ );
613
+ return normalizeSignature(innerBytes);
614
+ } catch {
615
+ }
616
+ }
617
+ throw new Error(
618
+ `Invalid signature: unable to normalize. Length=${hex.length / 2} bytes. Expected 65, 64, ERC-6492 wrapped, or ABI-encoded SignatureWrapper.`
619
+ );
620
+ }
586
621
 
587
622
  // src/hooks.ts
588
623
  var WALLET_CLIENT_MAX_ATTEMPTS = 15;
@@ -1006,13 +1041,14 @@ async function executeSignPermit2(action, wagmiConfig2, apiBaseUrl, sessionId) {
1006
1041
  console.info(
1007
1042
  `[swype-sdk][sign-permit2] Signing typed data. expectedOwner=${expectedWallet ?? "N/A"}, senderParam=${sender}, connectedAddress=${connectedAddress ?? "N/A"}, primaryType=${parsed.primaryType}, domainChainId=${String(parsed.domain.chainId ?? "N/A")}, verifyingContract=${String(parsed.domain.verifyingContract ?? "N/A")}`
1008
1043
  );
1009
- const signature = await walletClient.signTypedData({
1044
+ const rawSignature = await walletClient.signTypedData({
1010
1045
  account: sender,
1011
1046
  domain: parsed.domain,
1012
1047
  types: parsed.types,
1013
1048
  primaryType: parsed.primaryType,
1014
1049
  message: parsed.message
1015
1050
  });
1051
+ const signature = normalizeSignature(rawSignature);
1016
1052
  const recoverInput = {
1017
1053
  domain: parsed.domain,
1018
1054
  types: parsed.types,