@worldcoin/idkit
Version:
The identity SDK. Privacy-preserving identity and proof of personhood with World ID.
374 lines (364 loc) • 18.1 kB
JavaScript
// src/lang/translations/en.ts
var en = {
"All set!": "All set!",
"Your World ID is now connected": "Your World ID is now connected",
"Transmitting verification to host app. Please wait...": "Transmitting verification to host app. Please wait...",
"Something went wrong": "Something went wrong",
"Verification Declined": "Verification Declined",
"Request cancelled": "Request cancelled",
"Connection to your wallet failed. Please try again.": "Connection to your wallet failed. Please try again.",
"You've cancelled the request in World App.": "You've cancelled the request in World App.",
"You have already verified the maximum number of times for this action.": "You have already verified the maximum number of times for this action.",
"It seems you do not have the verification level required by this app.": "It seems you do not have the verification level required by this app.",
"Invalid network. If you are the app owner, visit docs.world.org/test for details.": "Invalid network. If you are the app owner, visit docs.world.org/test for details.",
"Your identity is still being registered. Please wait a few minutes and try again.": "Your identity is still being registered. Please wait a few minutes and try again.",
"We couldn't complete your request. Please try again.": "We couldn't complete your request. Please try again.",
"Try Again": "Try Again",
"Open World App": "Open World App",
"Hide QR Code": "Hide QR Code",
"Display QR Code": "Display QR Code",
"QR Code copied": "QR Code copied",
"Connect your World ID": "Connect your World ID",
"Use phone camera to scan the QR code": "Use phone camera to scan the QR code",
"Connecting...": "Connecting...",
"Please continue in app": "Please continue in app",
"You will be redirected to the app, please return to this page once you're done": "You will be redirected to the app, please return to this page once you're done",
"Action cannot be an empty string.": "Action cannot be an empty string.",
"Invalid IDKitStage :stage.": "Invalid IDKitStage :stage.",
"Terms & Privacy": "Terms & Privacy"
};
// src/lang/translations/es.ts
var es = {
"All set!": "\xA1Todo listo!",
"Your World ID is now connected": "Tu World ID ahora est\xE1 conectado",
"Transmitting verification to host app. Please wait...": "Transmitiendo verificaci\xF3n a la aplicaci\xF3n host. Por favor espera...",
"Something went wrong": "Algo sali\xF3 mal",
"Verification Declined": "Verificaci\xF3n rechazada",
"Request cancelled": "Solicitud cancelada",
"Connection to your wallet failed. Please try again.": "La conexi\xF3n a tu billetera fall\xF3. Por favor intenta de nuevo.",
"You've cancelled the request in World App.": "Has cancelado la solicitud en World App.",
"You have already verified the maximum number of times for this action.": "Ya has verificado el n\xFAmero m\xE1ximo de veces para esta acci\xF3n.",
"It seems you do not have the verification level required by this app.": "Parece que no tienes el nivel de verificaci\xF3n requerido por esta aplicaci\xF3n.",
"Invalid network. If you are the app owner, visit docs.world.org/test for details.": "Red inv\xE1lida. Si eres el propietario de la aplicaci\xF3n, visita docs.world.org/test para m\xE1s detalles.",
"Your identity is still being registered. Please wait a few minutes and try again.": "Tu identidad a\xFAn se est\xE1 registrando. Por favor espera unos minutos e intenta de nuevo.",
"We couldn't complete your request. Please try again.": "No pudimos completar tu solicitud. Por favor intenta de nuevo.",
"Try Again": "Intentar de nuevo",
"Open World App": "Abrir World App",
"Hide QR Code": "Ocultar c\xF3digo QR",
"Display QR Code": "Mostrar c\xF3digo QR",
"QR Code copied": "C\xF3digo QR copiado",
"Connect your World ID": "Conecta tu World ID",
"Use phone camera to scan the QR code": "Usa la c\xE1mara del tel\xE9fono para escanear el c\xF3digo QR",
"Connecting...": "Conectando...",
"Please continue in app": "Por favor contin\xFAa en la aplicaci\xF3n",
"You will be redirected to the app, please return to this page once you're done": "Ser\xE1s redirigido a la aplicaci\xF3n, por favor regresa a esta p\xE1gina una vez que hayas terminado",
"Action cannot be an empty string.": "La acci\xF3n no puede ser una cadena vac\xEDa.",
"Invalid IDKitStage :stage.": "IDKitStage inv\xE1lido :stage.",
"Terms & Privacy": "T\xE9rminos y privacidad"
};
// src/lang/translations/th.ts
var th = {
"All set!": "\u0E40\u0E23\u0E35\u0E22\u0E1A\u0E23\u0E49\u0E2D\u0E22!",
"Your World ID is now connected": "World ID \u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E41\u0E25\u0E49\u0E27",
"Transmitting verification to host app. Please wait...": "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E2A\u0E48\u0E07\u0E01\u0E32\u0E23\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E44\u0E1B\u0E22\u0E31\u0E07\u0E41\u0E2D\u0E1B\u0E42\u0E2E\u0E2A\u0E15\u0E4C \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E2D\u0E2A\u0E31\u0E01\u0E04\u0E23\u0E39\u0E48...",
"Something went wrong": "\u0E40\u0E01\u0E34\u0E14\u0E02\u0E49\u0E2D\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14",
"Verification Declined": "\u0E01\u0E32\u0E23\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E16\u0E39\u0E01\u0E1B\u0E0F\u0E34\u0E40\u0E2A\u0E18",
"Request cancelled": "\u0E04\u0E33\u0E02\u0E2D\u0E16\u0E39\u0E01\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01",
"Connection to your wallet failed. Please try again.": "\u0E01\u0E32\u0E23\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D\u0E01\u0E31\u0E1A\u0E01\u0E23\u0E30\u0E40\u0E1B\u0E4B\u0E32\u0E40\u0E07\u0E34\u0E19\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E25\u0E49\u0E21\u0E40\u0E2B\u0E25\u0E27 \u0E01\u0E23\u0E38\u0E13\u0E32\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
"You've cancelled the request in World App.": "\u0E04\u0E38\u0E13\u0E44\u0E14\u0E49\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01\u0E04\u0E33\u0E02\u0E2D\u0E43\u0E19 World App",
"You have already verified the maximum number of times for this action.": "\u0E04\u0E38\u0E13\u0E44\u0E14\u0E49\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E04\u0E23\u0E1A\u0E08\u0E33\u0E19\u0E27\u0E19\u0E04\u0E23\u0E31\u0E49\u0E07\u0E2A\u0E39\u0E07\u0E2A\u0E38\u0E14\u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E01\u0E32\u0E23\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E19\u0E35\u0E49\u0E41\u0E25\u0E49\u0E27",
"It seems you do not have the verification level required by this app.": "\u0E14\u0E39\u0E40\u0E2B\u0E21\u0E37\u0E2D\u0E19\u0E27\u0E48\u0E32\u0E04\u0E38\u0E13\u0E44\u0E21\u0E48\u0E21\u0E35\u0E23\u0E30\u0E14\u0E31\u0E1A\u0E01\u0E32\u0E23\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E17\u0E35\u0E48\u0E41\u0E2D\u0E1B\u0E19\u0E35\u0E49\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E32\u0E23",
"Invalid network. If you are the app owner, visit docs.world.org/test for details.": "\u0E40\u0E04\u0E23\u0E37\u0E2D\u0E02\u0E48\u0E32\u0E22\u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 \u0E2B\u0E32\u0E01\u0E04\u0E38\u0E13\u0E40\u0E1B\u0E47\u0E19\u0E40\u0E08\u0E49\u0E32\u0E02\u0E2D\u0E07\u0E41\u0E2D\u0E1B \u0E42\u0E1B\u0E23\u0E14\u0E44\u0E1B\u0E17\u0E35\u0E48 docs.world.org/test \u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E23\u0E32\u0E22\u0E25\u0E30\u0E40\u0E2D\u0E35\u0E22\u0E14",
"Your identity is still being registered. Please wait a few minutes and try again.": "\u0E15\u0E31\u0E27\u0E15\u0E19\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E22\u0E31\u0E07\u0E2D\u0E22\u0E39\u0E48\u0E23\u0E30\u0E2B\u0E27\u0E48\u0E32\u0E07\u0E01\u0E32\u0E23\u0E25\u0E07\u0E17\u0E30\u0E40\u0E1A\u0E35\u0E22\u0E19 \u0E01\u0E23\u0E38\u0E13\u0E32\u0E23\u0E2D\u0E2A\u0E31\u0E01\u0E04\u0E23\u0E39\u0E48\u0E41\u0E25\u0E49\u0E27\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
"We couldn't complete your request. Please try again.": "\u0E40\u0E23\u0E32\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E15\u0E32\u0E21\u0E04\u0E33\u0E02\u0E2D\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E44\u0E14\u0E49 \u0E01\u0E23\u0E38\u0E13\u0E32\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
"Try Again": "\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
"Open World App": "\u0E40\u0E1B\u0E34\u0E14 World App",
"Hide QR Code": "\u0E0B\u0E48\u0E2D\u0E19 QR Code",
"Display QR Code": "\u0E41\u0E2A\u0E14\u0E07 QR Code",
"QR Code copied": "\u0E04\u0E31\u0E14\u0E25\u0E2D\u0E01 QR Code \u0E41\u0E25\u0E49\u0E27",
"Connect your World ID": "\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D World ID \u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13",
"Use phone camera to scan the QR code": "\u0E43\u0E0A\u0E49\u0E01\u0E25\u0E49\u0E2D\u0E07\u0E42\u0E17\u0E23\u0E28\u0E31\u0E1E\u0E17\u0E4C\u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E2A\u0E41\u0E01\u0E19 QR code",
"Connecting...": "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D...",
"Please continue in app": "\u0E01\u0E23\u0E38\u0E13\u0E32\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E15\u0E48\u0E2D\u0E43\u0E19\u0E41\u0E2D\u0E1B",
"You will be redirected to the app, please return to this page once you're done": "\u0E04\u0E38\u0E13\u0E08\u0E30\u0E16\u0E39\u0E01\u0E19\u0E33\u0E44\u0E1B\u0E22\u0E31\u0E07\u0E41\u0E2D\u0E1B \u0E01\u0E23\u0E38\u0E13\u0E32\u0E01\u0E25\u0E31\u0E1A\u0E21\u0E32\u0E17\u0E35\u0E48\u0E2B\u0E19\u0E49\u0E32\u0E19\u0E35\u0E49\u0E40\u0E21\u0E37\u0E48\u0E2D\u0E40\u0E2A\u0E23\u0E47\u0E08\u0E41\u0E25\u0E49\u0E27",
"Action cannot be an empty string.": "\u0E01\u0E32\u0E23\u0E14\u0E33\u0E40\u0E19\u0E34\u0E19\u0E01\u0E32\u0E23\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E40\u0E1B\u0E47\u0E19\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E27\u0E48\u0E32\u0E07\u0E44\u0E14\u0E49",
"Invalid IDKitStage :stage.": "IDKitStage \u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 :stage.",
"Terms & Privacy": "\u0E02\u0E49\u0E2D\u0E01\u0E33\u0E2B\u0E19\u0E14\u0E41\u0E25\u0E30\u0E04\u0E27\u0E32\u0E21\u0E40\u0E1B\u0E47\u0E19\u0E2A\u0E48\u0E27\u0E19\u0E15\u0E31\u0E27"
};
// src/lang/translations/index.ts
var translations = {
en,
es,
th
};
// src/lang/localization.ts
var currentConfig = {};
var setLocalizationConfig = (config) => {
currentConfig = config;
};
var getLocalizationConfig = () => currentConfig;
var detectBrowserLanguage = () => {
for (const lang of navigator.languages) {
const [language] = lang.split("-");
const normalizedLang = language.toLowerCase();
if (normalizedLang in translations) {
return normalizedLang;
}
}
return void 0;
};
var getCurrentLanguage = () => {
const config = getLocalizationConfig();
if (config.language && config.language in translations) {
return config.language;
}
const browserLang = detectBrowserLanguage();
if (browserLang) {
return browserLang;
}
return "en";
};
var getTranslations = () => {
const currentLang = getCurrentLanguage();
return translations[currentLang];
};
var getSupportedLanguages = () => {
return Object.keys(translations);
};
// src/lang/index.ts
var getLang = () => {
return getTranslations();
};
var replaceParams = (str, params) => {
if (!params) return str;
let result = str;
for (const [key, value] of Object.entries(params)) {
result = result.replace(`:${key}`, value);
}
return result;
};
function __(str, ...args) {
const [params] = args;
if (typeof navigator === "undefined" && typeof window === "undefined") {
return replaceParams(str, params);
}
const translated = getLang()?.[str] ?? str;
return replaceParams(translated, params);
}
// src/store/idkit.ts
import { shallow } from "zustand/shallow";
import { createWithEqualityFn } from "zustand/traditional";
import {
AppErrorCodes,
DEFAULT_VERIFICATION_LEVEL
} from "@worldcoin/idkit-core";
var SELF_HOSTED_APP_ID = "self_hosted";
var useIDKitStore = createWithEqualityFn()(
(set, get) => ({
app_id: "",
signal: "",
action: "",
action_description: "",
bridge_url: "",
verification_level: DEFAULT_VERIFICATION_LEVEL,
partner: false,
open: false,
result: null,
errorTitle: "",
errorDetail: "",
autoClose: true,
errorState: null,
processing: false,
errorCallbacks: {},
verifyCallbacks: {},
successCallbacks: {},
stage: "WORLD_ID" /* WORLD_ID */,
setStage: (stage) => set({ stage }),
setErrorState: (errorState) => set({ errorState }),
setProcessing: (processing) => set({ processing }),
retryFlow: () => {
set({ stage: "WORLD_ID" /* WORLD_ID */, errorState: null });
},
addErrorCallback: (cb, source) => {
set((state) => {
state.errorCallbacks[source] = cb;
return state;
});
},
addSuccessCallback: (cb, source) => {
set((state) => {
state.successCallbacks[source] = cb;
return state;
});
},
addVerificationCallback: (cb, source) => {
set((state) => {
state.verifyCallbacks[source] = cb;
return state;
});
},
setOptions: ({
handleVerify,
onSuccess,
signal,
action,
app_id,
partner,
onError,
verification_level,
action_description,
bridge_url,
autoClose,
advanced
}, source) => {
set({
signal,
action,
bridge_url,
action_description,
autoClose: autoClose ?? true,
app_id: advanced?.self_hosted ? SELF_HOSTED_APP_ID : app_id,
verification_level: verification_level ?? DEFAULT_VERIFICATION_LEVEL,
partner
});
get().addSuccessCallback(onSuccess, source);
if (onError) get().addErrorCallback(onError, source);
if (handleVerify) get().addVerificationCallback(handleVerify, source);
},
handleVerify: (result) => {
set({ stage: "HOST_APP_VERIFICATION" /* HOST_APP_VERIFICATION */, processing: false });
Promise.all(Object.values(get().verifyCallbacks).map(async (cb) => cb?.(result))).then(
() => {
set({ stage: "SUCCESS" /* SUCCESS */, result });
if (get().autoClose) setTimeout(() => get().onOpenChange(false), 2500);
},
(response) => {
let errorMessage = void 0;
if (response && typeof response === "object" && response.message) {
errorMessage = response.message;
}
set({
stage: "ERROR" /* ERROR */,
errorState: {
code: AppErrorCodes.FailedByHostApp,
message: errorMessage ? __(errorMessage) : void 0
}
});
}
);
},
onOpenChange: (open) => {
if (open) {
return set({ open });
}
const errorState = get().errorState;
if (get().stage === "ERROR" /* ERROR */ && errorState) {
const callbacks = get().errorCallbacks;
requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(errorState)));
}
const result = get().result;
if (get().stage == "SUCCESS" /* SUCCESS */ && result) {
const callbacks = get().successCallbacks;
requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(result)));
}
set({
open,
result: null,
errorState: null,
processing: false,
stage: "WORLD_ID" /* WORLD_ID */
});
}
}),
shallow
);
var idkit_default = useIDKitStore;
// src/types/config.ts
var ConfigSource = /* @__PURE__ */ ((ConfigSource2) => {
ConfigSource2["HOOK"] = "hook";
ConfigSource2["PROPS"] = "props";
ConfigSource2["MANUAL"] = "manual";
return ConfigSource2;
})(ConfigSource || {});
// src/components/QRCode.tsx
import { memo, useMemo } from "react";
import QRCodeUtil from "qrcode/lib/core/qrcode.js";
import { jsx } from "react/jsx-runtime";
var generateMatrix = (data) => {
const arr = QRCodeUtil.create(data, { errorCorrectionLevel: "M" }).modules.data;
const sqrt = Math.sqrt(arr.length);
return arr.reduce(
(rows, key, index) => {
if (index % sqrt === 0) rows.push([key]);
else rows[rows.length - 1].push(key);
return rows;
},
[]
);
};
var Qrcode = ({ data, size = 300 }) => {
const dots = useMemo(() => {
const dots2 = [];
const matrix = generateMatrix(data);
const cellSize = size / matrix.length;
const qrList = [
{ x: 0, y: 0 },
{ x: 1, y: 0 },
{ x: 0, y: 1 }
];
qrList.forEach(({ x, y }) => {
const x1 = (matrix.length - 7) * cellSize * x;
const y1 = (matrix.length - 7) * cellSize * y;
for (let i = 0; i < 3; i++) {
dots2.push(
/* @__PURE__ */ jsx(
"rect",
{
fill: "currentColor",
x: x1 + cellSize * i,
y: y1 + cellSize * i,
width: cellSize * (7 - i * 2),
height: cellSize * (7 - i * 2),
rx: (i - 2) * -5,
ry: (i - 2) * -5,
className: i % 3 === 0 ? "text-black" : i % 3 === 1 ? "text-white" : "text-black"
},
`${i}-${x}-${y}`
)
);
}
});
matrix.forEach((row, i) => {
row.forEach((_, j) => {
if (!matrix[i][j]) return;
if (i < 7 && j < 7 || i > matrix.length - 8 && j < 7 || i < 7 && j > matrix.length - 8) return;
dots2.push(
/* @__PURE__ */ jsx(
"circle",
{
fill: "currentColor",
r: cellSize / 2.2,
cx: i * cellSize + cellSize / 2,
cy: j * cellSize + cellSize / 2,
className: "text-black dark:text-white"
},
`circle-${i}-${j}`
)
);
});
});
return dots2;
}, [size, data]);
return /* @__PURE__ */ jsx("svg", { height: size, width: size, "data-test-id": "qr-code", children: dots });
};
var QRCode_default = memo(Qrcode);
export {
setLocalizationConfig,
getLocalizationConfig,
getCurrentLanguage,
getSupportedLanguages,
__,
idkit_default,
ConfigSource,
QRCode_default
};