actions/verifyWeb3Challenge
Actions
VerifyWeb3ChallengeFn()
VerifyWeb3ChallengeFn: (
params
) =>Promise
\<AuthSession
>
Verify a challenge for a wallet. The web-sdk can use this to verify a signed message and prove ownership of a wallet.
Parameters
• params: VerifyWalletChallengeRequest
The parameters to verify
Returns
Promise
\<AuthSession
>
A promise that resolves to the auth session
Example
Basic usage:
import { createSdk } from "@compilot/js-sdk";
const compilotSdk = createSdk({ apiKey });
const challengeContent = await compilotSdk.verifyWeb3Challenge({
address: "0xabc",
namespace: "eip155",
blockchainId: "1",
message: ".....", // the challenge message
signedMessage: ".....", // the signed message, some wallets need to process the message before signing
signature: ".....", // the wallet signature of the signed message
signerPublicKey: "0x...",
});
More often used as part of an api to protect the api key. Please find below an example of how to use the verifyWeb3Challenge function in Next.js:
import { createSdk } from "@compilot/js-sdk";
const compilotSdk = createSdk({ apiKey });
export default async function handler(req: NextApiRequest, res: NextApiResponse ) {
if (req.method !== "POST") {
res.setHeader("Allow", ["POST"]);
res.status(405).end(`Method ${req.method} Not Allowed`);
return;
}
const authSession = await compilotSdk.verifyWeb3Challenge({
...req.body
});
// now we know this user is authenticated, save the user address to the local database for future reference
db.update(authSession.externalCustomerId, {
address: req.body.address,
});
// Return the challenge to the client
res.status(200).json(authSession);
}