@worldcoin/idkit 2.4.2 → 4.0.0-dev.fe98789

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,413 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/internal.ts
31
- var internal_exports = {};
32
- __export(internal_exports, {
33
- ConfigSource: () => ConfigSource,
34
- QRCode: () => QRCode_default,
35
- __: () => __,
36
- getCurrentLanguage: () => getCurrentLanguage,
37
- getLocalizationConfig: () => getLocalizationConfig,
38
- getSupportedLanguages: () => getSupportedLanguages,
39
- setLocalizationConfig: () => setLocalizationConfig,
40
- useIDKitStore: () => idkit_default
41
- });
42
- module.exports = __toCommonJS(internal_exports);
43
-
44
- // src/lang/translations/en.ts
45
- var en = {
46
- "All set!": "All set!",
47
- "Your World ID is now connected": "Your World ID is now connected",
48
- "Transmitting verification to host app. Please wait...": "Transmitting verification to host app. Please wait...",
49
- "Something went wrong": "Something went wrong",
50
- "Verification Declined": "Verification Declined",
51
- "Request cancelled": "Request cancelled",
52
- "Connection to your wallet failed. Please try again.": "Connection to your wallet failed. Please try again.",
53
- "You've cancelled the request in World App.": "You've cancelled the request in World App.",
54
- "You have already verified the maximum number of times for this action.": "You have already verified the maximum number of times for this action.",
55
- "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.",
56
- "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.",
57
- "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.",
58
- "We couldn't complete your request. Please try again.": "We couldn't complete your request. Please try again.",
59
- "Try Again": "Try Again",
60
- "Open World App": "Open World App",
61
- "Hide QR Code": "Hide QR Code",
62
- "Display QR Code": "Display QR Code",
63
- "QR Code copied": "QR Code copied",
64
- "Connect your World ID": "Connect your World ID",
65
- "Use phone camera to scan the QR code": "Use phone camera to scan the QR code",
66
- "Connecting...": "Connecting...",
67
- "Please continue in app": "Please continue in app",
68
- "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",
69
- "Action cannot be an empty string.": "Action cannot be an empty string.",
70
- "Invalid IDKitStage :stage.": "Invalid IDKitStage :stage.",
71
- "Terms & Privacy": "Terms & Privacy"
72
- };
73
-
74
- // src/lang/translations/es.ts
75
- var es = {
76
- "All set!": "\xA1Todo listo!",
77
- "Your World ID is now connected": "Tu World ID ahora est\xE1 conectado",
78
- "Transmitting verification to host app. Please wait...": "Transmitiendo verificaci\xF3n a la aplicaci\xF3n host. Por favor espera...",
79
- "Something went wrong": "Algo sali\xF3 mal",
80
- "Verification Declined": "Verificaci\xF3n rechazada",
81
- "Request cancelled": "Solicitud cancelada",
82
- "Connection to your wallet failed. Please try again.": "La conexi\xF3n a tu billetera fall\xF3. Por favor intenta de nuevo.",
83
- "You've cancelled the request in World App.": "Has cancelado la solicitud en World App.",
84
- "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.",
85
- "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.",
86
- "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.",
87
- "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.",
88
- "We couldn't complete your request. Please try again.": "No pudimos completar tu solicitud. Por favor intenta de nuevo.",
89
- "Try Again": "Intentar de nuevo",
90
- "Open World App": "Abrir World App",
91
- "Hide QR Code": "Ocultar c\xF3digo QR",
92
- "Display QR Code": "Mostrar c\xF3digo QR",
93
- "QR Code copied": "C\xF3digo QR copiado",
94
- "Connect your World ID": "Conecta tu World ID",
95
- "Use phone camera to scan the QR code": "Usa la c\xE1mara del tel\xE9fono para escanear el c\xF3digo QR",
96
- "Connecting...": "Conectando...",
97
- "Please continue in app": "Por favor contin\xFAa en la aplicaci\xF3n",
98
- "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",
99
- "Action cannot be an empty string.": "La acci\xF3n no puede ser una cadena vac\xEDa.",
100
- "Invalid IDKitStage :stage.": "IDKitStage inv\xE1lido :stage.",
101
- "Terms & Privacy": "T\xE9rminos y privacidad"
102
- };
103
-
104
- // src/lang/translations/th.ts
105
- var th = {
106
- "All set!": "\u0E40\u0E23\u0E35\u0E22\u0E1A\u0E23\u0E49\u0E2D\u0E22!",
107
- "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",
108
- "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...",
109
- "Something went wrong": "\u0E40\u0E01\u0E34\u0E14\u0E02\u0E49\u0E2D\u0E1C\u0E34\u0E14\u0E1E\u0E25\u0E32\u0E14",
110
- "Verification Declined": "\u0E01\u0E32\u0E23\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E16\u0E39\u0E01\u0E1B\u0E0F\u0E34\u0E40\u0E2A\u0E18",
111
- "Request cancelled": "\u0E04\u0E33\u0E02\u0E2D\u0E16\u0E39\u0E01\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01",
112
- "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",
113
- "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",
114
- "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",
115
- "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",
116
- "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",
117
- "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",
118
- "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",
119
- "Try Again": "\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07",
120
- "Open World App": "\u0E40\u0E1B\u0E34\u0E14 World App",
121
- "Hide QR Code": "\u0E0B\u0E48\u0E2D\u0E19 QR Code",
122
- "Display QR Code": "\u0E41\u0E2A\u0E14\u0E07 QR Code",
123
- "QR Code copied": "\u0E04\u0E31\u0E14\u0E25\u0E2D\u0E01 QR Code \u0E41\u0E25\u0E49\u0E27",
124
- "Connect your World ID": "\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D World ID \u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13",
125
- "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",
126
- "Connecting...": "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E40\u0E0A\u0E37\u0E48\u0E2D\u0E21\u0E15\u0E48\u0E2D...",
127
- "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",
128
- "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",
129
- "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",
130
- "Invalid IDKitStage :stage.": "IDKitStage \u0E44\u0E21\u0E48\u0E16\u0E39\u0E01\u0E15\u0E49\u0E2D\u0E07 :stage.",
131
- "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"
132
- };
133
-
134
- // src/lang/translations/index.ts
135
- var translations = {
136
- en,
137
- es,
138
- th
139
- };
140
-
141
- // src/lang/localization.ts
142
- var currentConfig = {};
143
- var setLocalizationConfig = (config) => {
144
- currentConfig = config;
145
- };
146
- var getLocalizationConfig = () => currentConfig;
147
- var detectBrowserLanguage = () => {
148
- for (const lang of navigator.languages) {
149
- const [language] = lang.split("-");
150
- const normalizedLang = language.toLowerCase();
151
- if (normalizedLang in translations) {
152
- return normalizedLang;
153
- }
154
- }
155
- return void 0;
156
- };
157
- var getCurrentLanguage = () => {
158
- const config = getLocalizationConfig();
159
- if (config.language && config.language in translations) {
160
- return config.language;
161
- }
162
- const browserLang = detectBrowserLanguage();
163
- if (browserLang) {
164
- return browserLang;
165
- }
166
- return "en";
167
- };
168
- var getTranslations = () => {
169
- const currentLang = getCurrentLanguage();
170
- return translations[currentLang];
171
- };
172
- var getSupportedLanguages = () => {
173
- return Object.keys(translations);
174
- };
175
-
176
- // src/lang/index.ts
177
- var getLang = () => {
178
- return getTranslations();
179
- };
180
- var replaceParams = (str, params) => {
181
- if (!params) return str;
182
- let result = str;
183
- for (const [key, value] of Object.entries(params)) {
184
- result = result.replace(`:${key}`, value);
185
- }
186
- return result;
187
- };
188
- function __(str, ...args) {
189
- const [params] = args;
190
- if (typeof navigator === "undefined" && typeof window === "undefined") {
191
- return replaceParams(str, params);
192
- }
193
- const translated = getLang()?.[str] ?? str;
194
- return replaceParams(translated, params);
195
- }
196
-
197
- // src/components/QRCode.tsx
198
- var import_react = require("react");
199
- var import_qrcode = __toESM(require("qrcode/lib/core/qrcode.js"), 1);
200
- var import_jsx_runtime = require("react/jsx-runtime");
201
- var generateMatrix = (data) => {
202
- const arr = import_qrcode.default.create(data, { errorCorrectionLevel: "M" }).modules.data;
203
- const sqrt = Math.sqrt(arr.length);
204
- return arr.reduce(
205
- (rows, key, index) => {
206
- if (index % sqrt === 0) rows.push([key]);
207
- else rows[rows.length - 1].push(key);
208
- return rows;
209
- },
210
- []
211
- );
212
- };
213
- var Qrcode = ({ data, size = 300 }) => {
214
- const dots = (0, import_react.useMemo)(() => {
215
- const dots2 = [];
216
- const matrix = generateMatrix(data);
217
- const cellSize = size / matrix.length;
218
- const qrList = [
219
- { x: 0, y: 0 },
220
- { x: 1, y: 0 },
221
- { x: 0, y: 1 }
222
- ];
223
- qrList.forEach(({ x, y }) => {
224
- const x1 = (matrix.length - 7) * cellSize * x;
225
- const y1 = (matrix.length - 7) * cellSize * y;
226
- for (let i = 0; i < 3; i++) {
227
- dots2.push(
228
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
229
- "rect",
230
- {
231
- fill: "currentColor",
232
- x: x1 + cellSize * i,
233
- y: y1 + cellSize * i,
234
- width: cellSize * (7 - i * 2),
235
- height: cellSize * (7 - i * 2),
236
- rx: (i - 2) * -5,
237
- ry: (i - 2) * -5,
238
- className: i % 3 === 0 ? "text-black" : i % 3 === 1 ? "text-white" : "text-black"
239
- },
240
- `${i}-${x}-${y}`
241
- )
242
- );
243
- }
244
- });
245
- matrix.forEach((row, i) => {
246
- row.forEach((_, j) => {
247
- if (!matrix[i][j]) return;
248
- if (i < 7 && j < 7 || i > matrix.length - 8 && j < 7 || i < 7 && j > matrix.length - 8) return;
249
- dots2.push(
250
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
251
- "circle",
252
- {
253
- fill: "currentColor",
254
- r: cellSize / 2.2,
255
- cx: i * cellSize + cellSize / 2,
256
- cy: j * cellSize + cellSize / 2,
257
- className: "text-black dark:text-white"
258
- },
259
- `circle-${i}-${j}`
260
- )
261
- );
262
- });
263
- });
264
- return dots2;
265
- }, [size, data]);
266
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { height: size, width: size, "data-test-id": "qr-code", children: dots });
267
- };
268
- var QRCode_default = (0, import_react.memo)(Qrcode);
269
-
270
- // src/store/idkit.ts
271
- var import_shallow = require("zustand/shallow");
272
- var import_traditional = require("zustand/traditional");
273
- var import_idkit_core = require("@worldcoin/idkit-core");
274
- var SELF_HOSTED_APP_ID = "self_hosted";
275
- var useIDKitStore = (0, import_traditional.createWithEqualityFn)()(
276
- (set, get) => ({
277
- app_id: "",
278
- signal: "",
279
- action: "",
280
- action_description: "",
281
- bridge_url: "",
282
- verification_level: import_idkit_core.DEFAULT_VERIFICATION_LEVEL,
283
- partner: false,
284
- open: false,
285
- result: null,
286
- errorTitle: "",
287
- errorDetail: "",
288
- autoClose: true,
289
- errorState: null,
290
- processing: false,
291
- errorCallbacks: {},
292
- verifyCallbacks: {},
293
- successCallbacks: {},
294
- stage: "WORLD_ID" /* WORLD_ID */,
295
- setStage: (stage) => set({ stage }),
296
- setErrorState: (errorState) => set({ errorState }),
297
- setProcessing: (processing) => set({ processing }),
298
- retryFlow: () => {
299
- set({ stage: "WORLD_ID" /* WORLD_ID */, errorState: null });
300
- },
301
- addErrorCallback: (cb, source) => {
302
- set((state) => {
303
- state.errorCallbacks[source] = cb;
304
- return state;
305
- });
306
- },
307
- addSuccessCallback: (cb, source) => {
308
- set((state) => {
309
- state.successCallbacks[source] = cb;
310
- return state;
311
- });
312
- },
313
- addVerificationCallback: (cb, source) => {
314
- set((state) => {
315
- state.verifyCallbacks[source] = cb;
316
- return state;
317
- });
318
- },
319
- setOptions: ({
320
- handleVerify,
321
- onSuccess,
322
- signal,
323
- action,
324
- app_id,
325
- partner,
326
- onError,
327
- verification_level,
328
- action_description,
329
- bridge_url,
330
- autoClose,
331
- advanced
332
- }, source) => {
333
- set({
334
- signal,
335
- action,
336
- bridge_url,
337
- action_description,
338
- autoClose: autoClose ?? true,
339
- app_id: advanced?.self_hosted ? SELF_HOSTED_APP_ID : app_id,
340
- verification_level: verification_level ?? import_idkit_core.DEFAULT_VERIFICATION_LEVEL,
341
- partner
342
- });
343
- get().addSuccessCallback(onSuccess, source);
344
- if (onError) get().addErrorCallback(onError, source);
345
- if (handleVerify) get().addVerificationCallback(handleVerify, source);
346
- },
347
- handleVerify: (result) => {
348
- set({ stage: "HOST_APP_VERIFICATION" /* HOST_APP_VERIFICATION */, processing: false });
349
- Promise.all(Object.values(get().verifyCallbacks).map(async (cb) => cb?.(result))).then(
350
- () => {
351
- set({ stage: "SUCCESS" /* SUCCESS */, result });
352
- if (get().autoClose) setTimeout(() => get().onOpenChange(false), 2500);
353
- },
354
- (response) => {
355
- let errorMessage = void 0;
356
- if (response && typeof response === "object" && response.message) {
357
- errorMessage = response.message;
358
- }
359
- set({
360
- stage: "ERROR" /* ERROR */,
361
- errorState: {
362
- code: import_idkit_core.AppErrorCodes.FailedByHostApp,
363
- message: errorMessage ? __(errorMessage) : void 0
364
- }
365
- });
366
- }
367
- );
368
- },
369
- onOpenChange: (open) => {
370
- if (open) {
371
- return set({ open });
372
- }
373
- const errorState = get().errorState;
374
- if (get().stage === "ERROR" /* ERROR */ && errorState) {
375
- const callbacks = get().errorCallbacks;
376
- requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(errorState)));
377
- }
378
- const result = get().result;
379
- if (get().stage == "SUCCESS" /* SUCCESS */ && result) {
380
- const callbacks = get().successCallbacks;
381
- requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(result)));
382
- }
383
- set({
384
- open,
385
- result: null,
386
- errorState: null,
387
- processing: false,
388
- stage: "WORLD_ID" /* WORLD_ID */
389
- });
390
- }
391
- }),
392
- import_shallow.shallow
393
- );
394
- var idkit_default = useIDKitStore;
395
-
396
- // src/types/config.ts
397
- var ConfigSource = /* @__PURE__ */ ((ConfigSource2) => {
398
- ConfigSource2["HOOK"] = "hook";
399
- ConfigSource2["PROPS"] = "props";
400
- ConfigSource2["MANUAL"] = "manual";
401
- return ConfigSource2;
402
- })(ConfigSource || {});
403
- // Annotate the CommonJS export names for ESM import in node:
404
- 0 && (module.exports = {
405
- ConfigSource,
406
- QRCode,
407
- __,
408
- getCurrentLanguage,
409
- getLocalizationConfig,
410
- getSupportedLanguages,
411
- setLocalizationConfig,
412
- useIDKitStore
413
- });
@@ -1,68 +0,0 @@
1
- import * as react from 'react';
2
- import * as zustand_traditional from 'zustand/traditional';
3
- import * as zustand_vanilla from 'zustand/vanilla';
4
- import { I as IDKITStage, c as ConfigSource, d as CallbackFn, C as Config } from './config-SH5TbLYj.cjs';
5
- export { S as SupportedLanguage, a as getCurrentLanguage, g as getLocalizationConfig, b as getSupportedLanguages, s as setLocalizationConfig } from './config-SH5TbLYj.cjs';
6
- import { IDKitConfig, ISuccessResult, IErrorState } from '@worldcoin/idkit-core';
7
-
8
- /**
9
- * ## Adding Translations
10
- * To add a new language:
11
- * 1. Create a new translation file in `src/lang/translations/[lang].ts`
12
- * 2. Implement all translation strings in the new file
13
- * 3. Add the language to the `translations` index
14
- * 4. Update the `SupportedLanguage` type in `src/lang/types.ts`
15
- */
16
- /**
17
- * Translation function with type-safe parameter support
18
- *
19
- * Examples:
20
- * - __('Hello world') // No parameters needed
21
- * - __('Invalid IDKitStage :stage.', { stage: 'init' }) // Parameter required
22
- */
23
- type HasPlaceholder<T extends string> = T extends `${string}:${string}` ? true : false;
24
- type GetPlaceholderName<T extends string> = T extends `:${infer Name}${infer Rest}` ? Name extends `${infer Word}${' ' | ',' | ':' | '!' | '?' | '.'}${string}` ? Word : Name : never;
25
- type GetAllPlaceholders<T extends string> = T extends `${infer Before}:${infer After}` ? GetAllPlaceholders<After> | GetPlaceholderName<`:${After}`> : never;
26
- type TranslationParams<T extends string> = GetAllPlaceholders<T> extends never ? never : {
27
- [K in GetAllPlaceholders<T>]: string;
28
- };
29
- declare function __<T extends string>(str: T, ...args: HasPlaceholder<T> extends true ? [params: TranslationParams<T>] : []): string;
30
-
31
- type Props = {
32
- data: string;
33
- size?: number;
34
- };
35
- declare const _default: react.MemoExoticComponent<({ data, size }: Props) => JSX.Element>;
36
-
37
- declare const SELF_HOSTED_APP_ID = "self_hosted";
38
- type IDKitStore = {
39
- app_id: IDKitConfig['app_id'] | typeof SELF_HOSTED_APP_ID | '';
40
- action: IDKitConfig['action'];
41
- signal: IDKitConfig['signal'];
42
- bridge_url?: IDKitConfig['bridge_url'];
43
- action_description?: IDKitConfig['action_description'];
44
- verification_level: NonNullable<IDKitConfig['verification_level']>;
45
- partner?: IDKitConfig['partner'];
46
- open: boolean;
47
- stage: IDKITStage;
48
- autoClose: boolean;
49
- processing: boolean;
50
- result: ISuccessResult | null;
51
- errorState: IErrorState | null;
52
- errorCallbacks: Record<ConfigSource, CallbackFn<IErrorState> | undefined> | Record<string, never>;
53
- verifyCallbacks: Record<ConfigSource, CallbackFn<ISuccessResult> | undefined> | Record<string, never>;
54
- successCallbacks: Record<ConfigSource, CallbackFn<ISuccessResult> | undefined> | Record<string, never>;
55
- retryFlow: () => void;
56
- setStage: (stage: IDKITStage) => void;
57
- onOpenChange: (open: boolean) => void;
58
- setProcessing: (processing: boolean) => void;
59
- handleVerify: (result: ISuccessResult) => void;
60
- setErrorState: (state: IErrorState | null) => void;
61
- setOptions: (options: Config, source: ConfigSource) => void;
62
- addErrorCallback: (cb: CallbackFn<IErrorState>, source: ConfigSource) => void;
63
- addSuccessCallback: (cb: CallbackFn<ISuccessResult>, source: ConfigSource) => void;
64
- addVerificationCallback: (cb: CallbackFn<ISuccessResult>, source: ConfigSource) => void;
65
- };
66
- declare const useIDKitStore: zustand_traditional.UseBoundStoreWithEqualityFn<zustand_vanilla.StoreApi<IDKitStore>>;
67
-
68
- export { ConfigSource, _default as QRCode, __, useIDKitStore };
@@ -1,68 +0,0 @@
1
- import * as react from 'react';
2
- import * as zustand_traditional from 'zustand/traditional';
3
- import * as zustand_vanilla from 'zustand/vanilla';
4
- import { I as IDKITStage, c as ConfigSource, d as CallbackFn, C as Config } from './config-SH5TbLYj.js';
5
- export { S as SupportedLanguage, a as getCurrentLanguage, g as getLocalizationConfig, b as getSupportedLanguages, s as setLocalizationConfig } from './config-SH5TbLYj.js';
6
- import { IDKitConfig, ISuccessResult, IErrorState } from '@worldcoin/idkit-core';
7
-
8
- /**
9
- * ## Adding Translations
10
- * To add a new language:
11
- * 1. Create a new translation file in `src/lang/translations/[lang].ts`
12
- * 2. Implement all translation strings in the new file
13
- * 3. Add the language to the `translations` index
14
- * 4. Update the `SupportedLanguage` type in `src/lang/types.ts`
15
- */
16
- /**
17
- * Translation function with type-safe parameter support
18
- *
19
- * Examples:
20
- * - __('Hello world') // No parameters needed
21
- * - __('Invalid IDKitStage :stage.', { stage: 'init' }) // Parameter required
22
- */
23
- type HasPlaceholder<T extends string> = T extends `${string}:${string}` ? true : false;
24
- type GetPlaceholderName<T extends string> = T extends `:${infer Name}${infer Rest}` ? Name extends `${infer Word}${' ' | ',' | ':' | '!' | '?' | '.'}${string}` ? Word : Name : never;
25
- type GetAllPlaceholders<T extends string> = T extends `${infer Before}:${infer After}` ? GetAllPlaceholders<After> | GetPlaceholderName<`:${After}`> : never;
26
- type TranslationParams<T extends string> = GetAllPlaceholders<T> extends never ? never : {
27
- [K in GetAllPlaceholders<T>]: string;
28
- };
29
- declare function __<T extends string>(str: T, ...args: HasPlaceholder<T> extends true ? [params: TranslationParams<T>] : []): string;
30
-
31
- type Props = {
32
- data: string;
33
- size?: number;
34
- };
35
- declare const _default: react.MemoExoticComponent<({ data, size }: Props) => JSX.Element>;
36
-
37
- declare const SELF_HOSTED_APP_ID = "self_hosted";
38
- type IDKitStore = {
39
- app_id: IDKitConfig['app_id'] | typeof SELF_HOSTED_APP_ID | '';
40
- action: IDKitConfig['action'];
41
- signal: IDKitConfig['signal'];
42
- bridge_url?: IDKitConfig['bridge_url'];
43
- action_description?: IDKitConfig['action_description'];
44
- verification_level: NonNullable<IDKitConfig['verification_level']>;
45
- partner?: IDKitConfig['partner'];
46
- open: boolean;
47
- stage: IDKITStage;
48
- autoClose: boolean;
49
- processing: boolean;
50
- result: ISuccessResult | null;
51
- errorState: IErrorState | null;
52
- errorCallbacks: Record<ConfigSource, CallbackFn<IErrorState> | undefined> | Record<string, never>;
53
- verifyCallbacks: Record<ConfigSource, CallbackFn<ISuccessResult> | undefined> | Record<string, never>;
54
- successCallbacks: Record<ConfigSource, CallbackFn<ISuccessResult> | undefined> | Record<string, never>;
55
- retryFlow: () => void;
56
- setStage: (stage: IDKITStage) => void;
57
- onOpenChange: (open: boolean) => void;
58
- setProcessing: (processing: boolean) => void;
59
- handleVerify: (result: ISuccessResult) => void;
60
- setErrorState: (state: IErrorState | null) => void;
61
- setOptions: (options: Config, source: ConfigSource) => void;
62
- addErrorCallback: (cb: CallbackFn<IErrorState>, source: ConfigSource) => void;
63
- addSuccessCallback: (cb: CallbackFn<ISuccessResult>, source: ConfigSource) => void;
64
- addVerificationCallback: (cb: CallbackFn<ISuccessResult>, source: ConfigSource) => void;
65
- };
66
- declare const useIDKitStore: zustand_traditional.UseBoundStoreWithEqualityFn<zustand_vanilla.StoreApi<IDKitStore>>;
67
-
68
- export { ConfigSource, _default as QRCode, __, useIDKitStore };
package/build/internal.js DELETED
@@ -1,20 +0,0 @@
1
- import {
2
- ConfigSource,
3
- QRCode_default,
4
- __,
5
- getCurrentLanguage,
6
- getLocalizationConfig,
7
- getSupportedLanguages,
8
- idkit_default,
9
- setLocalizationConfig
10
- } from "./chunk-PWFTYFSZ.js";
11
- export {
12
- ConfigSource,
13
- QRCode_default as QRCode,
14
- __,
15
- getCurrentLanguage,
16
- getLocalizationConfig,
17
- getSupportedLanguages,
18
- setLocalizationConfig,
19
- idkit_default as useIDKitStore
20
- };
package/src/index.ts DELETED
@@ -1,28 +0,0 @@
1
- import useIDKit from './hooks/useIDKit'
2
- import IDKitWidget from '@/components/IDKitWidget/index'
3
- import type { WidgetProps, Config } from '@/types/config'
4
- import { solidityEncode } from '@worldcoin/idkit-core/hashing'
5
- import { verifyCloudProof } from '@worldcoin/idkit-core/backend'
6
- import type { IVerifyResponse } from '@worldcoin/idkit-core/backend'
7
- import type { ISuccessResult, IErrorState } from '@worldcoin/idkit-core'
8
- import { VerificationLevel, VerificationState } from '@worldcoin/idkit-core'
9
- import { setLocalizationConfig, getLocalizationConfig, getCurrentLanguage, getSupportedLanguages } from '@/lang'
10
- import type { SupportedLanguage } from '@/lang'
11
-
12
- export {
13
- IDKitWidget,
14
- useIDKit,
15
- solidityEncode,
16
- verifyCloudProof,
17
- VerificationLevel,
18
- VerificationState,
19
- setLocalizationConfig,
20
- getLocalizationConfig,
21
- getCurrentLanguage,
22
- getSupportedLanguages,
23
- }
24
- export type { ISuccessResult, IErrorState, IVerifyResponse, Config, WidgetProps, SupportedLanguage }
25
-
26
- // Session API
27
- export { useSession } from '@/hooks/useSession'
28
- export type { UseSessionConfig, UseSessionResult } from '@/hooks/useSession'