@worldcoin/idkit 2.3.0 → 2.4.1

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,233 +0,0 @@
1
- // src/lang/index.ts
2
- var translations = {};
3
- var getLang = () => {
4
- if (!navigator?.languages) return;
5
- const supportedLang = navigator.languages.find((l) => translations[l] != void 0) ?? "";
6
- return translations[supportedLang];
7
- };
8
- var replaceParams = (str, params) => {
9
- let replaced = str;
10
- for (const [key, value] of Object.entries(params ?? {})) replaced = str.replace(`:${key}`, value);
11
- return replaced;
12
- };
13
- function __(str, params) {
14
- if (typeof navigator === "undefined") return str;
15
- return replaceParams(getLang()?.[str] ?? str, params);
16
- }
17
-
18
- // src/store/idkit.ts
19
- import { shallow } from "zustand/shallow";
20
- import { createWithEqualityFn } from "zustand/traditional";
21
- import {
22
- AppErrorCodes,
23
- DEFAULT_VERIFICATION_LEVEL
24
- } from "@worldcoin/idkit-core";
25
- var SELF_HOSTED_APP_ID = "self_hosted";
26
- var useIDKitStore = createWithEqualityFn()(
27
- (set, get) => ({
28
- app_id: "",
29
- signal: "",
30
- action: "",
31
- action_description: "",
32
- bridge_url: "",
33
- verification_level: DEFAULT_VERIFICATION_LEVEL,
34
- partner: false,
35
- open: false,
36
- result: null,
37
- errorTitle: "",
38
- errorDetail: "",
39
- autoClose: true,
40
- errorState: null,
41
- processing: false,
42
- errorCallbacks: {},
43
- verifyCallbacks: {},
44
- successCallbacks: {},
45
- stage: "WORLD_ID" /* WORLD_ID */,
46
- setStage: (stage) => set({ stage }),
47
- setErrorState: (errorState) => set({ errorState }),
48
- setProcessing: (processing) => set({ processing }),
49
- retryFlow: () => {
50
- set({ stage: "WORLD_ID" /* WORLD_ID */, errorState: null });
51
- },
52
- addErrorCallback: (cb, source) => {
53
- set((state) => {
54
- state.errorCallbacks[source] = cb;
55
- return state;
56
- });
57
- },
58
- addSuccessCallback: (cb, source) => {
59
- set((state) => {
60
- state.successCallbacks[source] = cb;
61
- return state;
62
- });
63
- },
64
- addVerificationCallback: (cb, source) => {
65
- set((state) => {
66
- state.verifyCallbacks[source] = cb;
67
- return state;
68
- });
69
- },
70
- setOptions: ({
71
- handleVerify,
72
- onSuccess,
73
- signal,
74
- action,
75
- app_id,
76
- partner,
77
- onError,
78
- verification_level,
79
- action_description,
80
- bridge_url,
81
- autoClose,
82
- advanced
83
- }, source) => {
84
- set({
85
- signal,
86
- action,
87
- bridge_url,
88
- action_description,
89
- autoClose: autoClose ?? true,
90
- app_id: advanced?.self_hosted ? SELF_HOSTED_APP_ID : app_id,
91
- verification_level: verification_level ?? DEFAULT_VERIFICATION_LEVEL,
92
- partner
93
- });
94
- get().addSuccessCallback(onSuccess, source);
95
- if (onError) get().addErrorCallback(onError, source);
96
- if (handleVerify) get().addVerificationCallback(handleVerify, source);
97
- },
98
- handleVerify: (result) => {
99
- set({ stage: "HOST_APP_VERIFICATION" /* HOST_APP_VERIFICATION */, processing: false });
100
- Promise.all(Object.values(get().verifyCallbacks).map(async (cb) => cb?.(result))).then(
101
- () => {
102
- set({ stage: "SUCCESS" /* SUCCESS */, result });
103
- if (get().autoClose) setTimeout(() => get().onOpenChange(false), 2500);
104
- },
105
- (response) => {
106
- let errorMessage = void 0;
107
- if (response && typeof response === "object" && response.message) {
108
- errorMessage = response.message;
109
- }
110
- set({
111
- stage: "ERROR" /* ERROR */,
112
- errorState: {
113
- code: AppErrorCodes.FailedByHostApp,
114
- message: errorMessage ? __(errorMessage) : void 0
115
- }
116
- });
117
- }
118
- );
119
- },
120
- onOpenChange: (open) => {
121
- if (open) {
122
- return set({ open });
123
- }
124
- const errorState = get().errorState;
125
- if (get().stage === "ERROR" /* ERROR */ && errorState) {
126
- const callbacks = get().errorCallbacks;
127
- requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(errorState)));
128
- }
129
- const result = get().result;
130
- if (get().stage == "SUCCESS" /* SUCCESS */ && result) {
131
- const callbacks = get().successCallbacks;
132
- requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(result)));
133
- }
134
- set({
135
- open,
136
- result: null,
137
- errorState: null,
138
- processing: false,
139
- stage: "WORLD_ID" /* WORLD_ID */
140
- });
141
- }
142
- }),
143
- shallow
144
- );
145
- var idkit_default = useIDKitStore;
146
-
147
- // src/types/config.ts
148
- var ConfigSource = /* @__PURE__ */ ((ConfigSource2) => {
149
- ConfigSource2["HOOK"] = "hook";
150
- ConfigSource2["PROPS"] = "props";
151
- ConfigSource2["MANUAL"] = "manual";
152
- return ConfigSource2;
153
- })(ConfigSource || {});
154
-
155
- // src/components/QRCode.tsx
156
- import { memo, useMemo } from "react";
157
- import QRCodeUtil from "qrcode/lib/core/qrcode.js";
158
- import { jsx } from "react/jsx-runtime";
159
- var generateMatrix = (data) => {
160
- const arr = QRCodeUtil.create(data, { errorCorrectionLevel: "M" }).modules.data;
161
- const sqrt = Math.sqrt(arr.length);
162
- return arr.reduce(
163
- (rows, key, index) => {
164
- if (index % sqrt === 0) rows.push([key]);
165
- else rows[rows.length - 1].push(key);
166
- return rows;
167
- },
168
- []
169
- );
170
- };
171
- var Qrcode = ({ data, size = 300 }) => {
172
- const dots = useMemo(() => {
173
- const dots2 = [];
174
- const matrix = generateMatrix(data);
175
- const cellSize = size / matrix.length;
176
- const qrList = [
177
- { x: 0, y: 0 },
178
- { x: 1, y: 0 },
179
- { x: 0, y: 1 }
180
- ];
181
- qrList.forEach(({ x, y }) => {
182
- const x1 = (matrix.length - 7) * cellSize * x;
183
- const y1 = (matrix.length - 7) * cellSize * y;
184
- for (let i = 0; i < 3; i++) {
185
- dots2.push(
186
- /* @__PURE__ */ jsx(
187
- "rect",
188
- {
189
- fill: "currentColor",
190
- x: x1 + cellSize * i,
191
- y: y1 + cellSize * i,
192
- width: cellSize * (7 - i * 2),
193
- height: cellSize * (7 - i * 2),
194
- rx: (i - 2) * -5,
195
- ry: (i - 2) * -5,
196
- className: i % 3 === 0 ? "text-black" : i % 3 === 1 ? "text-white" : "text-black"
197
- },
198
- `${i}-${x}-${y}`
199
- )
200
- );
201
- }
202
- });
203
- matrix.forEach((row, i) => {
204
- row.forEach((_, j) => {
205
- if (!matrix[i][j]) return;
206
- if (i < 7 && j < 7 || i > matrix.length - 8 && j < 7 || i < 7 && j > matrix.length - 8) return;
207
- dots2.push(
208
- /* @__PURE__ */ jsx(
209
- "circle",
210
- {
211
- fill: "currentColor",
212
- r: cellSize / 2.2,
213
- cx: i * cellSize + cellSize / 2,
214
- cy: j * cellSize + cellSize / 2,
215
- className: "text-black dark:text-white"
216
- },
217
- `circle-${i}-${j}`
218
- )
219
- );
220
- });
221
- });
222
- return dots2;
223
- }, [size, data]);
224
- return /* @__PURE__ */ jsx("svg", { height: size, width: size, "data-test-id": "qr-code", children: dots });
225
- };
226
- var QRCode_default = memo(Qrcode);
227
-
228
- export {
229
- __,
230
- idkit_default,
231
- ConfigSource,
232
- QRCode_default
233
- };