@worldcoin/idkit 0.5.1 → 1.0.0-alpha.0
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.
- package/LICENSE +7 -0
- package/build/chunk-EXZRURG3.js +246 -0
- package/build/config-cd2f02fe.d.ts +36 -0
- package/build/index.d.ts +31 -0
- package/build/index.js +2094 -3
- package/build/internal.d.ts +55 -0
- package/build/internal.js +12 -0
- package/build/verified-O6D4JQCX.webp +0 -0
- package/package.json +34 -79
- package/src/index.ts +11 -0
- package/build/idkit-js.js +0 -155
- package/build/index.cjs +0 -3
- package/build/index.cjs.map +0 -7
- package/build/index.css +0 -2
- package/build/index.js.map +0 -7
- package/build/jest.config.d.ts +0 -21
- package/build/jest.setup.d.ts +0 -1
- package/build/src/components/AboutWorldID.d.ts +0 -6
- package/build/src/components/Button.d.ts +0 -3
- package/build/src/components/Frame.d.ts +0 -4
- package/build/src/components/IDKitWidget/BaseWidget.d.ts +0 -4
- package/build/src/components/IDKitWidget/States/ErrorState.d.ts +0 -3
- package/build/src/components/IDKitWidget/States/HostAppVerificationState.d.ts +0 -7
- package/build/src/components/IDKitWidget/States/PrivacyState.d.ts +0 -3
- package/build/src/components/IDKitWidget/States/SuccessState.d.ts +0 -3
- package/build/src/components/IDKitWidget/States/WorldID/QRState.d.ts +0 -11
- package/build/src/components/IDKitWidget/States/WorldIDState.d.ts +0 -3
- package/build/src/components/IDKitWidget/experimental/components/CountryCodeSelect.d.ts +0 -7
- package/build/src/components/IDKitWidget/experimental/states/EnterPhoneState.d.ts +0 -3
- package/build/src/components/IDKitWidget/experimental/states/SelectMethodState.d.ts +0 -3
- package/build/src/components/IDKitWidget/experimental/states/VerifyCodeState.d.ts +0 -3
- package/build/src/components/IDKitWidget/index.d.ts +0 -3
- package/build/src/components/Icons/ArrowLongLeftIcon.d.ts +0 -3
- package/build/src/components/Icons/CheckIcon.d.ts +0 -3
- package/build/src/components/Icons/ChevronDownIcon.d.ts +0 -3
- package/build/src/components/Icons/DevicePhoneMobileIcon.d.ts +0 -3
- package/build/src/components/Icons/HumanIcon.d.ts +0 -3
- package/build/src/components/Icons/InfoIcon.d.ts +0 -3
- package/build/src/components/Icons/LoadingIcon.d.ts +0 -5
- package/build/src/components/Icons/LockIcon.d.ts +0 -3
- package/build/src/components/Icons/QuestionMarkIcon.d.ts +0 -5
- package/build/src/components/Icons/WorldIDWordmark.d.ts +0 -3
- package/build/src/components/Icons/WorldcoinIcon.d.ts +0 -3
- package/build/src/components/Icons/XMarkIcon.d.ts +0 -3
- package/build/src/components/PhoneInput.d.ts +0 -6
- package/build/src/components/QRCode.d.ts +0 -7
- package/build/src/components/ResendButton.d.ts +0 -3
- package/build/src/components/SMSCodeInput.d.ts +0 -6
- package/build/src/components/SignInButton.d.ts +0 -7
- package/build/src/components/SignInWithWorldID.d.ts +0 -11
- package/build/src/components/WorldIDIcon.d.ts +0 -7
- package/build/src/hooks/useIDKit.d.ts +0 -7
- package/build/src/hooks/useMedia.d.ts +0 -2
- package/build/src/index.d.ts +0 -34
- package/build/src/lang/index.d.ts +0 -9
- package/build/src/lib/consts.d.ts +0 -1
- package/build/src/lib/hashing.d.ts +0 -20
- package/build/src/lib/qr.d.ts +0 -4
- package/build/src/lib/telemetry.d.ts +0 -6
- package/build/src/lib/utils.d.ts +0 -2
- package/build/src/services/phone.d.ts +0 -21
- package/build/src/services/walletconnect.d.ts +0 -15
- package/build/src/store/idkit.d.ts +0 -41
- package/build/src/types/app.d.ts +0 -22
- package/build/src/types/config.d.ts +0 -48
- package/build/src/types/index.d.ts +0 -63
- package/build/src/vanilla.d.ts +0 -12
- package/build/stitches.config.d.ts +0 -45
- package/build/tests/lib/hashing.test.d.ts +0 -1
- package/build/tsconfig.tsbuildinfo +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2022 Worldcoin Foundation
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// src/lang/index.ts
|
|
2
|
+
var translations = {};
|
|
3
|
+
var getLang = () => {
|
|
4
|
+
if (typeof navigator === "undefined" || !navigator.languages)
|
|
5
|
+
return;
|
|
6
|
+
const supportedLang = navigator.languages.find((l) => translations[l] != void 0) ?? "";
|
|
7
|
+
return translations[supportedLang];
|
|
8
|
+
};
|
|
9
|
+
var replaceParams = (str, params) => {
|
|
10
|
+
let replaced = str;
|
|
11
|
+
for (const [key, value] of Object.entries(params ?? {}))
|
|
12
|
+
replaced = str.replace(`:${key}`, value);
|
|
13
|
+
return replaced;
|
|
14
|
+
};
|
|
15
|
+
function __(str, params) {
|
|
16
|
+
if (typeof navigator === "undefined")
|
|
17
|
+
return str;
|
|
18
|
+
return replaceParams(getLang()?.[str] ?? str, params);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/store/idkit.ts
|
|
22
|
+
import { shallow } from "zustand/shallow";
|
|
23
|
+
import { createWithEqualityFn } from "zustand/traditional";
|
|
24
|
+
import {
|
|
25
|
+
AppErrorCodes,
|
|
26
|
+
CredentialType
|
|
27
|
+
} from "@worldcoin/idkit-core";
|
|
28
|
+
var useIDKitStore = createWithEqualityFn()(
|
|
29
|
+
(set, get) => ({
|
|
30
|
+
app_id: "",
|
|
31
|
+
signal: "",
|
|
32
|
+
action: "",
|
|
33
|
+
action_description: "",
|
|
34
|
+
bridge_url: "",
|
|
35
|
+
credential_types: [],
|
|
36
|
+
open: false,
|
|
37
|
+
result: null,
|
|
38
|
+
theme: "light",
|
|
39
|
+
errorTitle: "",
|
|
40
|
+
errorDetail: "",
|
|
41
|
+
autoClose: true,
|
|
42
|
+
errorState: null,
|
|
43
|
+
processing: false,
|
|
44
|
+
errorCallbacks: {},
|
|
45
|
+
verifyCallbacks: {},
|
|
46
|
+
successCallbacks: {},
|
|
47
|
+
stage: "WORLD_ID" /* WORLD_ID */,
|
|
48
|
+
computed: {
|
|
49
|
+
canGoBack: (stage) => {
|
|
50
|
+
return stage == "PRIVACY" /* PRIVACY */;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
setStage: (stage) => set({ stage }),
|
|
54
|
+
setErrorState: (errorState) => set({ errorState }),
|
|
55
|
+
setProcessing: (processing) => set({ processing }),
|
|
56
|
+
retryFlow: () => {
|
|
57
|
+
set({ stage: "WORLD_ID" /* WORLD_ID */, errorState: null });
|
|
58
|
+
},
|
|
59
|
+
addErrorCallback: (cb, source) => {
|
|
60
|
+
set((state) => {
|
|
61
|
+
state.errorCallbacks[source] = cb;
|
|
62
|
+
return state;
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
addSuccessCallback: (cb, source) => {
|
|
66
|
+
set((state) => {
|
|
67
|
+
state.successCallbacks[source] = cb;
|
|
68
|
+
return state;
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
addVerificationCallback: (cb, source) => {
|
|
72
|
+
set((state) => {
|
|
73
|
+
state.verifyCallbacks[source] = cb;
|
|
74
|
+
return state;
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
setOptions: ({
|
|
78
|
+
handleVerify,
|
|
79
|
+
onSuccess,
|
|
80
|
+
signal,
|
|
81
|
+
action,
|
|
82
|
+
app_id,
|
|
83
|
+
onError,
|
|
84
|
+
credential_types,
|
|
85
|
+
action_description,
|
|
86
|
+
bridge_url,
|
|
87
|
+
autoClose,
|
|
88
|
+
theme
|
|
89
|
+
}, source) => {
|
|
90
|
+
const sanitized_credential_types = credential_types?.filter(
|
|
91
|
+
(type) => Object.values(CredentialType).includes(type)
|
|
92
|
+
);
|
|
93
|
+
set({
|
|
94
|
+
theme,
|
|
95
|
+
signal,
|
|
96
|
+
action,
|
|
97
|
+
app_id,
|
|
98
|
+
autoClose,
|
|
99
|
+
bridge_url,
|
|
100
|
+
credential_types: sanitized_credential_types,
|
|
101
|
+
action_description
|
|
102
|
+
});
|
|
103
|
+
get().addSuccessCallback(onSuccess, source);
|
|
104
|
+
if (onError)
|
|
105
|
+
get().addErrorCallback(onError, source);
|
|
106
|
+
if (handleVerify)
|
|
107
|
+
get().addVerificationCallback(handleVerify, source);
|
|
108
|
+
},
|
|
109
|
+
handleVerify: (result) => {
|
|
110
|
+
set({ stage: "HOST_APP_VERIFICATION" /* HOST_APP_VERIFICATION */, processing: false });
|
|
111
|
+
Promise.all(Object.values(get().verifyCallbacks).map((cb) => cb?.(result))).then(
|
|
112
|
+
() => {
|
|
113
|
+
set({ stage: "SUCCESS" /* SUCCESS */, result });
|
|
114
|
+
if (get().autoClose)
|
|
115
|
+
setTimeout(() => get().onOpenChange(false), 1e3);
|
|
116
|
+
},
|
|
117
|
+
(response) => {
|
|
118
|
+
let errorMessage = void 0;
|
|
119
|
+
if (response && typeof response === "object" && response.message) {
|
|
120
|
+
errorMessage = response.message;
|
|
121
|
+
}
|
|
122
|
+
set({
|
|
123
|
+
stage: "ERROR" /* ERROR */,
|
|
124
|
+
errorState: {
|
|
125
|
+
code: AppErrorCodes.FailedByHostApp,
|
|
126
|
+
message: errorMessage ? __(errorMessage) : void 0
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
},
|
|
132
|
+
onOpenChange: (open) => {
|
|
133
|
+
if (open) {
|
|
134
|
+
return set({ open });
|
|
135
|
+
}
|
|
136
|
+
const errorState = get().errorState;
|
|
137
|
+
if (get().stage === "ERROR" /* ERROR */ && errorState) {
|
|
138
|
+
const callbacks = get().errorCallbacks;
|
|
139
|
+
requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(errorState)));
|
|
140
|
+
}
|
|
141
|
+
const result = get().result;
|
|
142
|
+
if (get().stage == "SUCCESS" /* SUCCESS */ && result) {
|
|
143
|
+
const callbacks = get().successCallbacks;
|
|
144
|
+
requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(result)));
|
|
145
|
+
}
|
|
146
|
+
set({
|
|
147
|
+
open,
|
|
148
|
+
result: null,
|
|
149
|
+
errorState: null,
|
|
150
|
+
processing: false,
|
|
151
|
+
stage: "WORLD_ID" /* WORLD_ID */
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}),
|
|
155
|
+
shallow
|
|
156
|
+
);
|
|
157
|
+
var idkit_default = useIDKitStore;
|
|
158
|
+
|
|
159
|
+
// src/types/config.ts
|
|
160
|
+
var ConfigSource = /* @__PURE__ */ ((ConfigSource2) => {
|
|
161
|
+
ConfigSource2["HOOK"] = "hook";
|
|
162
|
+
ConfigSource2["PROPS"] = "props";
|
|
163
|
+
ConfigSource2["MANUAL"] = "manual";
|
|
164
|
+
return ConfigSource2;
|
|
165
|
+
})(ConfigSource || {});
|
|
166
|
+
|
|
167
|
+
// src/components/QRCode.tsx
|
|
168
|
+
import { memo, useMemo } from "react";
|
|
169
|
+
import QRCodeUtil from "qrcode/lib/core/qrcode";
|
|
170
|
+
import { jsx } from "react/jsx-runtime";
|
|
171
|
+
var generateMatrix = (data) => {
|
|
172
|
+
const arr = QRCodeUtil.create(data, { errorCorrectionLevel: "M" }).modules.data;
|
|
173
|
+
const sqrt = Math.sqrt(arr.length);
|
|
174
|
+
return arr.reduce((rows, key, index) => {
|
|
175
|
+
if (index % sqrt === 0)
|
|
176
|
+
rows.push([key]);
|
|
177
|
+
else
|
|
178
|
+
rows[rows.length - 1].push(key);
|
|
179
|
+
return rows;
|
|
180
|
+
}, []);
|
|
181
|
+
};
|
|
182
|
+
var Qrcode = ({ data, size = 300 }) => {
|
|
183
|
+
const dots = useMemo(() => {
|
|
184
|
+
const dots2 = [];
|
|
185
|
+
const matrix = generateMatrix(data);
|
|
186
|
+
const cellSize = size / matrix.length;
|
|
187
|
+
const qrList = [
|
|
188
|
+
{ x: 0, y: 0 },
|
|
189
|
+
{ x: 1, y: 0 },
|
|
190
|
+
{ x: 0, y: 1 }
|
|
191
|
+
];
|
|
192
|
+
qrList.forEach(({ x, y }) => {
|
|
193
|
+
const x1 = (matrix.length - 7) * cellSize * x;
|
|
194
|
+
const y1 = (matrix.length - 7) * cellSize * y;
|
|
195
|
+
for (let i = 0; i < 3; i++) {
|
|
196
|
+
dots2.push(
|
|
197
|
+
/* @__PURE__ */ jsx(
|
|
198
|
+
"rect",
|
|
199
|
+
{
|
|
200
|
+
fill: "currentColor",
|
|
201
|
+
x: x1 + cellSize * i,
|
|
202
|
+
y: y1 + cellSize * i,
|
|
203
|
+
width: cellSize * (7 - i * 2),
|
|
204
|
+
height: cellSize * (7 - i * 2),
|
|
205
|
+
rx: (i - 2) * -5,
|
|
206
|
+
ry: (i - 2) * -5,
|
|
207
|
+
className: i % 3 === 0 ? "text-black" : i % 3 === 1 ? "text-white" : "text-black"
|
|
208
|
+
},
|
|
209
|
+
`${i}-${x}-${y}`
|
|
210
|
+
)
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
matrix.forEach((row, i) => {
|
|
215
|
+
row.forEach((_, j) => {
|
|
216
|
+
if (!matrix[i][j])
|
|
217
|
+
return;
|
|
218
|
+
if (i < 7 && j < 7 || i > matrix.length - 8 && j < 7 || i < 7 && j > matrix.length - 8)
|
|
219
|
+
return;
|
|
220
|
+
dots2.push(
|
|
221
|
+
/* @__PURE__ */ jsx(
|
|
222
|
+
"circle",
|
|
223
|
+
{
|
|
224
|
+
fill: "currentColor",
|
|
225
|
+
r: cellSize / 3,
|
|
226
|
+
cx: i * cellSize + cellSize / 2,
|
|
227
|
+
cy: j * cellSize + cellSize / 2,
|
|
228
|
+
className: "text-black dark:text-white"
|
|
229
|
+
},
|
|
230
|
+
`circle-${i}-${j}`
|
|
231
|
+
)
|
|
232
|
+
);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
return dots2;
|
|
236
|
+
}, [size, data]);
|
|
237
|
+
return /* @__PURE__ */ jsx("svg", { height: size, width: size, children: dots });
|
|
238
|
+
};
|
|
239
|
+
var QRCode_default = memo(Qrcode);
|
|
240
|
+
|
|
241
|
+
export {
|
|
242
|
+
__,
|
|
243
|
+
idkit_default,
|
|
244
|
+
ConfigSource,
|
|
245
|
+
QRCode_default
|
|
246
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IDKitConfig, ISuccessResult, IErrorState } from '@worldcoin/idkit-core';
|
|
2
|
+
|
|
3
|
+
declare enum IDKITStage {
|
|
4
|
+
WORLD_ID = "WORLD_ID",
|
|
5
|
+
PRIVACY = "PRIVACY",
|
|
6
|
+
SUCCESS = "SUCCESS",
|
|
7
|
+
ERROR = "ERROR",
|
|
8
|
+
HOST_APP_VERIFICATION = "HOST_APP_VERIFICATION"
|
|
9
|
+
}
|
|
10
|
+
type CallbackFn<T> = (result: T) => Promise<void> | void;
|
|
11
|
+
|
|
12
|
+
declare enum ConfigSource {
|
|
13
|
+
HOOK = "hook",
|
|
14
|
+
PROPS = "props",
|
|
15
|
+
MANUAL = "manual"
|
|
16
|
+
}
|
|
17
|
+
type WidgetConfig = {
|
|
18
|
+
/** Whether to automatically close the widget after a successful verification. Defaults to `false`. */
|
|
19
|
+
autoClose?: boolean;
|
|
20
|
+
/** The theme to apply to the widget's UI. Defaults to `light`. */
|
|
21
|
+
theme?: 'dark' | 'light';
|
|
22
|
+
/** Function to trigger when verification is successful. Should receive a single parameter of type `ISuccessResult` which contains the proof details. */
|
|
23
|
+
onSuccess: CallbackFn<ISuccessResult>;
|
|
24
|
+
/** Called after the proof is returned from the World App, but before showing the success screen. Throwing in this screen will show the user a custom error. Used to perform additional validation when needed. */
|
|
25
|
+
handleVerify?: CallbackFn<ISuccessResult>;
|
|
26
|
+
/** Function to trigger when verification is not successful. Should receive a single parameter of type `IErrorState` which contains the error details. */
|
|
27
|
+
onError?: CallbackFn<IErrorState>;
|
|
28
|
+
};
|
|
29
|
+
type Config = IDKitConfig & Required<Pick<IDKitConfig, 'action'>> & WidgetConfig;
|
|
30
|
+
type WidgetProps = Config & {
|
|
31
|
+
children?: ({ open }: {
|
|
32
|
+
open: () => void;
|
|
33
|
+
}) => JSX.Element;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { Config as C, IDKITStage as I, WidgetProps as W, WidgetConfig as a, ConfigSource as b, CallbackFn as c };
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { C as Config, W as WidgetProps, a as WidgetConfig } from './config-cd2f02fe.js';
|
|
2
|
+
import { MotionProps } from 'framer-motion';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { FC, ButtonHTMLAttributes } from 'react';
|
|
5
|
+
import { IDKitConfig } from '@worldcoin/idkit-core';
|
|
6
|
+
export { CredentialType, ISuccessResult } from '@worldcoin/idkit-core';
|
|
7
|
+
export { solidityEncode } from '@worldcoin/idkit-core/hashing';
|
|
8
|
+
|
|
9
|
+
type HookConfig = Partial<Pick<Config, 'handleVerify' | 'onSuccess'>>;
|
|
10
|
+
declare const useIDKit: ({ handleVerify, onSuccess }?: HookConfig) => {
|
|
11
|
+
open: boolean;
|
|
12
|
+
setOpen: (open: boolean) => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type Props$1 = ButtonHTMLAttributes<HTMLButtonElement> & MotionProps & {
|
|
16
|
+
theme?: 'dark' | 'light';
|
|
17
|
+
};
|
|
18
|
+
declare const SignInButton: FC<Props$1>;
|
|
19
|
+
|
|
20
|
+
declare const _default: react.NamedExoticComponent<WidgetProps>;
|
|
21
|
+
|
|
22
|
+
type Props = Omit<WidgetConfig, 'autoClose' | 'handleVerify'> & Pick<IDKitConfig, 'app_id'> & {
|
|
23
|
+
nonce?: string;
|
|
24
|
+
onSuccess: (jwt: string) => void;
|
|
25
|
+
children?: ({ open }: {
|
|
26
|
+
open: () => void;
|
|
27
|
+
}) => JSX.Element;
|
|
28
|
+
};
|
|
29
|
+
declare const SignInWithWorldID: FC<Props>;
|
|
30
|
+
|
|
31
|
+
export { Config, _default as IDKitWidget, SignInButton, SignInWithWorldID, WidgetProps, useIDKit };
|