@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.js CHANGED
@@ -4,8 +4,8 @@ import { createConfig, http, WagmiProvider, useConfig, useConnect, useSwitchChai
4
4
  import { mainnet, arbitrum, base } from 'wagmi/chains';
5
5
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
6
6
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
- import { recoverTypedDataAddress, walletActions, createClient, custom } from 'viem';
8
- import { parseAccount, getAddress } from 'viem/utils';
7
+ import { recoverTypedDataAddress, decodeAbiParameters, walletActions, createClient, custom } from 'viem';
8
+ import { parseErc6492Signature, parseAccount, getAddress } from 'viem/utils';
9
9
 
10
10
  var __defProp = Object.defineProperty;
11
11
  var __export = (target, all) => {
@@ -580,6 +580,41 @@ function resolveRootDomainFromHostname(hostname) {
580
580
  }
581
581
  return parts.slice(-2).join(".");
582
582
  }
583
+ var ERC_6492_MAGIC_SUFFIX = "6492649264926492649264926492649264926492649264926492649264926492";
584
+ function normalizeSignature(sig) {
585
+ const hex = sig.startsWith("0x") ? sig.slice(2) : sig;
586
+ if (hex.length === 130) {
587
+ return `0x${hex}`;
588
+ }
589
+ if (hex.length === 128) {
590
+ const r = hex.slice(0, 64);
591
+ const yParityAndS = hex.slice(64, 128);
592
+ const highByte = parseInt(yParityAndS.slice(0, 2), 16);
593
+ const v = (highByte & 128) !== 0 ? 28 : 27;
594
+ const sFirstByte = (highByte & 127).toString(16).padStart(2, "0");
595
+ const s = sFirstByte + yParityAndS.slice(2);
596
+ return `0x${r}${s}${v.toString(16)}`;
597
+ }
598
+ if (hex.length > 64 && hex.endsWith(ERC_6492_MAGIC_SUFFIX)) {
599
+ const { signature: inner } = parseErc6492Signature(
600
+ `0x${hex}`
601
+ );
602
+ return normalizeSignature(inner);
603
+ }
604
+ if (hex.length > 130) {
605
+ try {
606
+ const [, innerBytes] = decodeAbiParameters(
607
+ [{ type: "uint256" }, { type: "bytes" }],
608
+ `0x${hex}`
609
+ );
610
+ return normalizeSignature(innerBytes);
611
+ } catch {
612
+ }
613
+ }
614
+ throw new Error(
615
+ `Invalid signature: unable to normalize. Length=${hex.length / 2} bytes. Expected 65, 64, ERC-6492 wrapped, or ABI-encoded SignatureWrapper.`
616
+ );
617
+ }
583
618
 
584
619
  // src/hooks.ts
585
620
  var WALLET_CLIENT_MAX_ATTEMPTS = 15;
@@ -1003,13 +1038,14 @@ async function executeSignPermit2(action, wagmiConfig2, apiBaseUrl, sessionId) {
1003
1038
  console.info(
1004
1039
  `[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")}`
1005
1040
  );
1006
- const signature = await walletClient.signTypedData({
1041
+ const rawSignature = await walletClient.signTypedData({
1007
1042
  account: sender,
1008
1043
  domain: parsed.domain,
1009
1044
  types: parsed.types,
1010
1045
  primaryType: parsed.primaryType,
1011
1046
  message: parsed.message
1012
1047
  });
1048
+ const signature = normalizeSignature(rawSignature);
1013
1049
  const recoverInput = {
1014
1050
  domain: parsed.domain,
1015
1051
  types: parsed.types,