Skip to content

@rainbow-me/[email protected]

Compare
Choose a tag to compare
@DanielSinclair DanielSinclair released this 15 Oct 09:06
· 23 commits to main since this release
d1c0e9b

Minor Changes

  • f02bced: The Authentication API now supports ERC-1271 and ERC-6492 for smart contract signature verification to enable Sign-in with Ethereum for Smart Contract Wallets.

    We have also deprecated the siwe and ethers peer dependencies in favor of viem/siwe.

    Follow the appropriate steps below to migrate.

    1. Remove siwe and ethers
    npm uninstall siwe ethers
    1. Upgrade RainbowKit, rainbowkit-siwe-next-auth, and viem
    npm i @rainbow-me/rainbowkit@^2.2.0 rainbow-me/rainbowkit-siwe-next-auth@^0.5.0 viem@^2.12.0
    1. Create a Public Client

    This allows viem to verify smart contract signatures.

    const config = getDefaultConfig({
      /* your config */
    });
    + const publicClient = config.getClient().extend(publicActions);
    1. Adjust your authorize implementation in /api/auth/[...nextauth].ts
    - import { SiweMessage } from 'siwe';
    + import {
    +   type SiweMessage,
    +   parseSiweMessage,
    +   validateSiweMessage,
    + } from 'viem/siwe';
    
    export function getAuthOptions(req: IncomingMessage): NextAuthOptions {
      const providers = [
        CredentialsProvider({
          async authorize(credentials: any) {
    
    -       const siwe = new SiweMessage(
    -         JSON.parse(credentials?.message || '{}'),
    -       );
    +       const siweMessage = parseSiweMessage(
    +         credentials?.message,
    +       ) as SiweMessage;
    
    +       if (!validateSiweMessage({
    +         address: siweMessage?.address,
    +         message: siweMessage,
    +       })) {
    +         return null;
    +       }
    
            /* ... */
    
    -       await siwe.verify({ signature: credentials?.signature || '' });
    +       const valid = await publicClient.verifyMessage({
    +         address: siweMessage?.address,
    +         message: credentials?.message,
    +         signature: credentials?.signature,
    +       });
    
    +       if (!valid) {
    +         return null;
    +       }
          },
          /* ... */
        })
      ]
    }

    Reference the with-next-siwe-next-auth example for more guidance.