DEV Community

Embed.WS
Embed.WS

Posted on

Implementing Wallet Connect Verification with Siwe-java

To implement Wallet Connect verification using the Siwe-java library, follow these steps:

1. Add the Siwe-java dependency:

In your pom.xml file, add the following dependency:

<dependency>
    <groupId>com.moonstoneid</groupId>
    <artifactId>siwe-java</artifactId>
    <version>1.0.6</version>
</dependency>
Enter fullscreen mode Exit fullscreen mode

2.Parse the Siwe message provided by the frontend:

String message = "example.com wants you to sign in with your Ethereum account:\n" +
    "0xAd472fbB6781BbBDfC4Efea378ed428083541748\n\n" +
    "Sign in to use the app.\n\n" +
    "URI: https://example.com\n" +
    "Version: 1\n" +
    "Chain ID: 1\n" +
    "Nonce: EnZ3CLrm6ap78uiNE0MU\n" +
    "Issued At: 2022-06-17T22:29:40.065529400+02:00";

String signature = "0x2ce1f57908b3d1cfece352a90cec9beab0452829a0bf741d26016d60676d63" +
        "807b5080b4cc387edbe741203387ef0b8a6e79743f636512cc48c80cbb12ffa8261b";

try {
    // Parse the Siwe message
    SiweMessage siwe = new SiweMessage.Parser().parse(message);

    // Verify the Siwe message signature
    siwe.verify("example.com", "EnZ3CLrm6ap78uiNE0MU", signature);
} catch (SiweException e) {
    // Handle the exception
}
Enter fullscreen mode Exit fullscreen mode

3. After the signature verification is successful, you can confirm the user's identity and proceed with the login flow.

Using the Siwe-java library greatly simplifies the Wallet Connect verification logic. The library implements the EIP-4361 standard, providing methods to create, parse, and validate Siwe messages, helping developers quickly integrate Wallet Connect functionality.

This is exactly the method of Embed.ws to complete the login wallet test in the Java service. Everyone can try.

Top comments (0)