-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: isUserVerified helper & react bindings (#118)
feature implementation, import cleanup
- Loading branch information
1 parent
41faf32
commit ab8ba8d
Showing
8 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { createPublicClient, http } from "viem"; | ||
import { worldchain } from "viem/chains"; | ||
|
||
const worldIdAddressBookContractAddress = | ||
"0x57b930D551e677CC36e2fA036Ae2fe8FdaE0330D"; | ||
const addressVerifiedUntilAbi = [ | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "", | ||
type: "address", | ||
}, | ||
], | ||
name: "addressVerifiedUntil", | ||
outputs: [ | ||
{ | ||
internalType: "uint256", | ||
name: "", | ||
type: "uint256", | ||
}, | ||
], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
]; | ||
|
||
export const getIsUserVerified = async ( | ||
walletAddress: string, | ||
rpcUrl?: string | ||
): Promise<boolean> => { | ||
const publicClient = createPublicClient({ | ||
chain: worldchain, | ||
transport: http( | ||
rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public" | ||
), | ||
}); | ||
|
||
try { | ||
const verifiedUntilResponse = (await publicClient.readContract({ | ||
address: worldIdAddressBookContractAddress, | ||
abi: addressVerifiedUntilAbi, | ||
functionName: "addressVerifiedUntil", | ||
args: [walletAddress], | ||
})) as BigInt; | ||
|
||
const verifiedUntil = Number(verifiedUntilResponse.toString()); | ||
|
||
if (!Number.isFinite(verifiedUntil)) { | ||
console.warn("Invalid verifiedUntil value:", verifiedUntil); | ||
return false; | ||
} | ||
|
||
const currentTime = Math.floor(Date.now() / 1000); | ||
return verifiedUntil > currentTime; | ||
} catch (error) { | ||
console.error("Error verifying user:", error); | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
packages/core/helpers/siwe/validate-wallet-auth-command-input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { WalletAuthInput } from "types/commands"; | ||
import {} from "types/responses"; | ||
|
||
type ValidationResult = | ||
| { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { useIsUserVerified } from "./is-verified"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useEffect, useState } from "react"; | ||
import { getIsUserVerified } from "@worldcoin/minikit-js"; | ||
|
||
/** | ||
* Checks if a user is Orb verified | ||
* | ||
* @param walletAddress - The wallet address of the user | ||
* @param rpcUrl - Your preferred RPC node URL, https://worldchain-mainnet.g.alchemy.com/public by default | ||
*/ | ||
export const useIsUserVerified = (walletAddress: string, rpcUrl?: string) => { | ||
const [isUserVerified, setIsUserVerified] = useState<boolean | null>(null); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [isError, setIsError] = useState<any>(null); | ||
|
||
useEffect(() => { | ||
const fetchIsUserVerified = async () => { | ||
try { | ||
const data = await getIsUserVerified(walletAddress); | ||
setIsUserVerified(data); | ||
} catch (err) { | ||
setIsError(err); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
fetchIsUserVerified(); | ||
}, [walletAddress]); | ||
|
||
return { isUserVerified, isLoading, isError }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { useWaitForTransactionReceipt } from "./transaction/hooks"; | ||
export { useIsUserVerified } from "./address-book/is-verified"; | ||
export * from "./types/client"; | ||
export * from "./components"; |