@worldcoin/minikit-js
Version:
minikit-js is our SDK for building mini-apps.
82 lines (79 loc) • 2.56 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/address-book.ts
var address_book_exports = {};
__export(address_book_exports, {
getIsUserVerified: () => getIsUserVerified
});
module.exports = __toCommonJS(address_book_exports);
// src/helpers/address-book.ts
var import_viem = require("viem");
var import_chains = require("viem/chains");
var worldIdAddressBookContractAddress = "0x57b930D551e677CC36e2fA036Ae2fe8FdaE0330D";
var addressVerifiedUntilAbi = [
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
name: "addressVerifiedUntil",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
}
];
var getIsUserVerified = async (walletAddress, rpcUrl) => {
const publicClient = (0, import_viem.createPublicClient)({
chain: import_chains.worldchain,
transport: (0, import_viem.http)(
rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
)
});
try {
const verifiedUntilResponse = await publicClient.readContract({
address: worldIdAddressBookContractAddress,
abi: addressVerifiedUntilAbi,
functionName: "addressVerifiedUntil",
args: [walletAddress]
});
const verifiedUntil = Number(verifiedUntilResponse.toString());
if (!Number.isFinite(verifiedUntil)) {
console.warn("Invalid verifiedUntil value:", verifiedUntil);
return false;
}
const currentTime = Math.floor(Date.now() / 1e3);
return verifiedUntil > currentTime;
} catch (error) {
console.error("Error verifying user:", error);
return false;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getIsUserVerified
});