Skip to content

Commit

Permalink
Remove signing challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1995 committed Feb 5, 2024
1 parent 9e78452 commit d3c2562
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 61 deletions.
60 changes: 0 additions & 60 deletions packages/base/src/adapter/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { post } from "@toruslabs/http-helpers";
import { OPENLOGIN_NETWORK_TYPE } from "@toruslabs/openlogin-utils";
import { jwtDecode } from "jwt-decode";

import { ChainNamespaceType } from "../chain/IChainInterface";
import { authServer } from "../constants";
import log from "../loglevel";
import { storageAvailable } from "../utils";

export const checkIfTokenIsExpired = (token: string) => {
Expand All @@ -18,61 +13,6 @@ export const checkIfTokenIsExpired = (token: string) => {
return false;
};

export const signChallenge = async (payload: Record<string, string | number>, chainNamespace: ChainNamespaceType): Promise<string> => {
const t = chainNamespace === "solana" ? "sip99" : "eip191";
const header = {
t,
};

const network = chainNamespace === "solana" ? "solana" : "ethereum";
const data = {
payload,
header,
network,
};
const res = await post<{ success: boolean; challenge: string }>(`${authServer}/siww/get`, data);
if (!res.success) {
throw new Error("Failed to authenticate user, Please reach out to Web3Auth Support team");
}

return res.challenge;
};

export const verifySignedChallenge = async (
chainNamespace: ChainNamespaceType,
signedMessage: string,
challenge: string,
issuer: string,
sessionTime: number,
clientId?: string,
web3AuthNetwork?: OPENLOGIN_NETWORK_TYPE
): Promise<string> => {
const t = chainNamespace === "solana" ? "sip99" : "eip191";
const sigData = {
signature: {
s: signedMessage,
t,
},
message: challenge,
issuer,
audience: typeof window.location !== "undefined" ? window.location.hostname : "com://reactnative",
timeout: sessionTime,
};

const idTokenRes = await post<{ success: boolean; token: string; error?: string }>(`${authServer}/siww/verify`, sigData, {
headers: {
client_id: clientId,
wallet_provider: issuer,
web3auth_network: web3AuthNetwork,
},
});
if (!idTokenRes.success) {
log.error("Failed to authenticate user, ,message verification failed", idTokenRes.error);
throw new Error("Failed to authenticate user, ,message verification failed");
}
return idTokenRes.token;
};

export const getSavedToken = (userAddress: string, issuer: string) => {
if (storageAvailable("localStorage")) {
return localStorage.getItem(`${userAddress.toLowerCase()}_${issuer}`);
Expand Down
1 change: 0 additions & 1 deletion packages/base/src/constants.ts

This file was deleted.

0 comments on commit d3c2562

Please sign in to comment.