@worldcoin/idkit 2.1.0 → 2.2.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.
- package/build/config-BRFx4nLT.d.cts +45 -0
- package/build/index.cjs +2356 -0
- package/build/index.d.cts +56 -0
- package/build/index.d.ts +45 -5
- package/build/index.js +44 -1
- package/build/internal.cjs +269 -0
- package/build/internal.d.cts +53 -0
- package/package.json +17 -5
- package/src/index.ts +6 -2
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { C as Config, W as WidgetProps } from './config-BRFx4nLT.cjs';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
export { solidityEncode } from '@worldcoin/idkit-core/hashing';
|
|
4
|
+
export { IVerifyResponse, verifyCloudProof } from '@worldcoin/idkit-core/backend';
|
|
5
|
+
import { IDKitConfig, VerificationState, ISuccessResult, AppErrorCodes } from '@worldcoin/idkit-core';
|
|
6
|
+
export { IErrorState, ISuccessResult, VerificationLevel, VerificationState } from '@worldcoin/idkit-core';
|
|
7
|
+
|
|
8
|
+
type HookConfig = Partial<Pick<Config, 'handleVerify' | 'onSuccess'>>;
|
|
9
|
+
declare const useIDKit: ({ handleVerify, onSuccess }?: HookConfig) => {
|
|
10
|
+
open: boolean;
|
|
11
|
+
setOpen: (open: boolean) => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
declare const _default: react.NamedExoticComponent<WidgetProps>;
|
|
15
|
+
|
|
16
|
+
type UseSessionConfig = IDKitConfig;
|
|
17
|
+
type UseSessionResult = {
|
|
18
|
+
/** The current verification state */
|
|
19
|
+
status: VerificationState;
|
|
20
|
+
/** The QR code URI that users can scan to verify */
|
|
21
|
+
sessionURI: string | null;
|
|
22
|
+
/** The verification result if successful */
|
|
23
|
+
result: ISuccessResult | null;
|
|
24
|
+
/** Error code if verification failed */
|
|
25
|
+
errorCode: AppErrorCodes | null;
|
|
26
|
+
/** Function to reset the session and start over */
|
|
27
|
+
reset: () => void;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A beginner-friendly React hook for World ID verification sessions.
|
|
31
|
+
*
|
|
32
|
+
* This hook automatically:
|
|
33
|
+
* - Creates a verification session
|
|
34
|
+
* - Generates a QR code URI for scanning
|
|
35
|
+
* - Polls for verification updates
|
|
36
|
+
* - Stops polling when verification completes or fails
|
|
37
|
+
*
|
|
38
|
+
* @param config - The World ID configuration object
|
|
39
|
+
* @returns Session state and controls
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* const { status, sessionURI, result, errorCode } = useSession({
|
|
44
|
+
* app_id: 'app_staging_12345',
|
|
45
|
+
* action: 'login',
|
|
46
|
+
* signal: 'user_123'
|
|
47
|
+
* })
|
|
48
|
+
*
|
|
49
|
+
* if (status === VerificationState.WaitingForConnection) {
|
|
50
|
+
* return <QRCodeSVG value={sessionURI} />
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function useSession(config: UseSessionConfig): UseSessionResult;
|
|
55
|
+
|
|
56
|
+
export { Config, _default as IDKitWidget, type UseSessionConfig, type UseSessionResult, WidgetProps, useIDKit, useSession };
|
package/build/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { C as Config } from './config-BRFx4nLT.js';
|
|
2
|
-
export { W as WidgetProps } from './config-BRFx4nLT.js';
|
|
1
|
+
import { C as Config, W as WidgetProps } from './config-BRFx4nLT.js';
|
|
3
2
|
import * as react from 'react';
|
|
4
|
-
export { IErrorState, ISuccessResult, VerificationLevel } from '@worldcoin/idkit-core';
|
|
5
3
|
export { solidityEncode } from '@worldcoin/idkit-core/hashing';
|
|
6
4
|
export { IVerifyResponse, verifyCloudProof } from '@worldcoin/idkit-core/backend';
|
|
5
|
+
import { IDKitConfig, VerificationState, ISuccessResult, AppErrorCodes } from '@worldcoin/idkit-core';
|
|
6
|
+
export { IErrorState, ISuccessResult, VerificationLevel, VerificationState } from '@worldcoin/idkit-core';
|
|
7
7
|
|
|
8
8
|
type HookConfig = Partial<Pick<Config, 'handleVerify' | 'onSuccess'>>;
|
|
9
9
|
declare const useIDKit: ({ handleVerify, onSuccess }?: HookConfig) => {
|
|
@@ -11,6 +11,46 @@ declare const useIDKit: ({ handleVerify, onSuccess }?: HookConfig) => {
|
|
|
11
11
|
setOpen: (open: boolean) => void;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
declare const _default: react.NamedExoticComponent<
|
|
14
|
+
declare const _default: react.NamedExoticComponent<WidgetProps>;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
type UseSessionConfig = IDKitConfig;
|
|
17
|
+
type UseSessionResult = {
|
|
18
|
+
/** The current verification state */
|
|
19
|
+
status: VerificationState;
|
|
20
|
+
/** The QR code URI that users can scan to verify */
|
|
21
|
+
sessionURI: string | null;
|
|
22
|
+
/** The verification result if successful */
|
|
23
|
+
result: ISuccessResult | null;
|
|
24
|
+
/** Error code if verification failed */
|
|
25
|
+
errorCode: AppErrorCodes | null;
|
|
26
|
+
/** Function to reset the session and start over */
|
|
27
|
+
reset: () => void;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A beginner-friendly React hook for World ID verification sessions.
|
|
31
|
+
*
|
|
32
|
+
* This hook automatically:
|
|
33
|
+
* - Creates a verification session
|
|
34
|
+
* - Generates a QR code URI for scanning
|
|
35
|
+
* - Polls for verification updates
|
|
36
|
+
* - Stops polling when verification completes or fails
|
|
37
|
+
*
|
|
38
|
+
* @param config - The World ID configuration object
|
|
39
|
+
* @returns Session state and controls
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* const { status, sessionURI, result, errorCode } = useSession({
|
|
44
|
+
* app_id: 'app_staging_12345',
|
|
45
|
+
* action: 'login',
|
|
46
|
+
* signal: 'user_123'
|
|
47
|
+
* })
|
|
48
|
+
*
|
|
49
|
+
* if (status === VerificationState.WaitingForConnection) {
|
|
50
|
+
* return <QRCodeSVG value={sessionURI} />
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function useSession(config: UseSessionConfig): UseSessionResult;
|
|
55
|
+
|
|
56
|
+
export { Config, _default as IDKitWidget, type UseSessionConfig, type UseSessionResult, WidgetProps, useIDKit, useSession };
|
package/build/index.js
CHANGED
|
@@ -2026,13 +2026,56 @@ var BaseWidget_default = IDKitWidget;
|
|
|
2026
2026
|
var IDKitWidget_default = memo(BaseWidget_default);
|
|
2027
2027
|
|
|
2028
2028
|
// src/index.ts
|
|
2029
|
-
import { VerificationLevel as VerificationLevel2 } from "@worldcoin/idkit-core";
|
|
2030
2029
|
import { solidityEncode } from "@worldcoin/idkit-core/hashing";
|
|
2031
2030
|
import { verifyCloudProof } from "@worldcoin/idkit-core/backend";
|
|
2031
|
+
import { VerificationLevel as VerificationLevel2, VerificationState as VerificationState3 } from "@worldcoin/idkit-core";
|
|
2032
|
+
|
|
2033
|
+
// src/hooks/useSession.ts
|
|
2034
|
+
import { useEffect as useEffect6 } from "react";
|
|
2035
|
+
import { useShallow } from "zustand/react/shallow";
|
|
2036
|
+
import { VerificationState as VerificationState2 } from "@worldcoin/idkit-core";
|
|
2037
|
+
import { useWorldBridgeStore as useWorldBridgeStore2 } from "@worldcoin/idkit-core";
|
|
2038
|
+
var TERMINAL_STATES = [VerificationState2.Confirmed, VerificationState2.Failed];
|
|
2039
|
+
function useSession(config) {
|
|
2040
|
+
const { reset, result, connectorURI, createClient, pollForUpdates, verificationState, errorCode } = useWorldBridgeStore2(
|
|
2041
|
+
useShallow((state) => ({
|
|
2042
|
+
reset: state.reset,
|
|
2043
|
+
result: state.result,
|
|
2044
|
+
connectorURI: state.connectorURI,
|
|
2045
|
+
createClient: state.createClient,
|
|
2046
|
+
pollForUpdates: state.pollForUpdates,
|
|
2047
|
+
verificationState: state.verificationState,
|
|
2048
|
+
errorCode: state.errorCode
|
|
2049
|
+
}))
|
|
2050
|
+
);
|
|
2051
|
+
useEffect6(() => {
|
|
2052
|
+
if (verificationState === VerificationState2.PreparingClient && !connectorURI) {
|
|
2053
|
+
void createClient(config);
|
|
2054
|
+
}
|
|
2055
|
+
}, [verificationState, connectorURI, createClient, config]);
|
|
2056
|
+
useEffect6(() => {
|
|
2057
|
+
if (TERMINAL_STATES.includes(verificationState)) return;
|
|
2058
|
+
const interval = setInterval(() => {
|
|
2059
|
+
void pollForUpdates();
|
|
2060
|
+
}, 3e3);
|
|
2061
|
+
return () => {
|
|
2062
|
+
clearInterval(interval);
|
|
2063
|
+
};
|
|
2064
|
+
}, [verificationState, pollForUpdates]);
|
|
2065
|
+
return {
|
|
2066
|
+
status: verificationState,
|
|
2067
|
+
sessionURI: connectorURI,
|
|
2068
|
+
result,
|
|
2069
|
+
errorCode,
|
|
2070
|
+
reset
|
|
2071
|
+
};
|
|
2072
|
+
}
|
|
2032
2073
|
export {
|
|
2033
2074
|
IDKitWidget_default as IDKitWidget,
|
|
2034
2075
|
VerificationLevel2 as VerificationLevel,
|
|
2076
|
+
VerificationState3 as VerificationState,
|
|
2035
2077
|
solidityEncode,
|
|
2036
2078
|
useIDKit_default as useIDKit,
|
|
2079
|
+
useSession,
|
|
2037
2080
|
verifyCloudProof
|
|
2038
2081
|
};
|
|
@@ -0,0 +1,269 @@
|
|
|
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
|
+
useIDKitStore: () => idkit_default
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(internal_exports);
|
|
39
|
+
|
|
40
|
+
// src/lang/index.ts
|
|
41
|
+
var translations = {};
|
|
42
|
+
var getLang = () => {
|
|
43
|
+
if (!navigator?.languages) return;
|
|
44
|
+
const supportedLang = navigator.languages.find((l) => translations[l] != void 0) ?? "";
|
|
45
|
+
return translations[supportedLang];
|
|
46
|
+
};
|
|
47
|
+
var replaceParams = (str, params) => {
|
|
48
|
+
let replaced = str;
|
|
49
|
+
for (const [key, value] of Object.entries(params ?? {})) replaced = str.replace(`:${key}`, value);
|
|
50
|
+
return replaced;
|
|
51
|
+
};
|
|
52
|
+
function __(str, params) {
|
|
53
|
+
if (typeof navigator === "undefined") return str;
|
|
54
|
+
return replaceParams(getLang()?.[str] ?? str, params);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/components/QRCode.tsx
|
|
58
|
+
var import_react = require("react");
|
|
59
|
+
var import_qrcode = __toESM(require("qrcode/lib/core/qrcode.js"), 1);
|
|
60
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
61
|
+
var generateMatrix = (data) => {
|
|
62
|
+
const arr = import_qrcode.default.create(data, { errorCorrectionLevel: "M" }).modules.data;
|
|
63
|
+
const sqrt = Math.sqrt(arr.length);
|
|
64
|
+
return arr.reduce(
|
|
65
|
+
(rows, key, index) => {
|
|
66
|
+
if (index % sqrt === 0) rows.push([key]);
|
|
67
|
+
else rows[rows.length - 1].push(key);
|
|
68
|
+
return rows;
|
|
69
|
+
},
|
|
70
|
+
[]
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
var Qrcode = ({ data, size = 300 }) => {
|
|
74
|
+
const dots = (0, import_react.useMemo)(() => {
|
|
75
|
+
const dots2 = [];
|
|
76
|
+
const matrix = generateMatrix(data);
|
|
77
|
+
const cellSize = size / matrix.length;
|
|
78
|
+
const qrList = [
|
|
79
|
+
{ x: 0, y: 0 },
|
|
80
|
+
{ x: 1, y: 0 },
|
|
81
|
+
{ x: 0, y: 1 }
|
|
82
|
+
];
|
|
83
|
+
qrList.forEach(({ x, y }) => {
|
|
84
|
+
const x1 = (matrix.length - 7) * cellSize * x;
|
|
85
|
+
const y1 = (matrix.length - 7) * cellSize * y;
|
|
86
|
+
for (let i = 0; i < 3; i++) {
|
|
87
|
+
dots2.push(
|
|
88
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
89
|
+
"rect",
|
|
90
|
+
{
|
|
91
|
+
fill: "currentColor",
|
|
92
|
+
x: x1 + cellSize * i,
|
|
93
|
+
y: y1 + cellSize * i,
|
|
94
|
+
width: cellSize * (7 - i * 2),
|
|
95
|
+
height: cellSize * (7 - i * 2),
|
|
96
|
+
rx: (i - 2) * -5,
|
|
97
|
+
ry: (i - 2) * -5,
|
|
98
|
+
className: i % 3 === 0 ? "text-black" : i % 3 === 1 ? "text-white" : "text-black"
|
|
99
|
+
},
|
|
100
|
+
`${i}-${x}-${y}`
|
|
101
|
+
)
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
matrix.forEach((row, i) => {
|
|
106
|
+
row.forEach((_, j) => {
|
|
107
|
+
if (!matrix[i][j]) return;
|
|
108
|
+
if (i < 7 && j < 7 || i > matrix.length - 8 && j < 7 || i < 7 && j > matrix.length - 8) return;
|
|
109
|
+
dots2.push(
|
|
110
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
111
|
+
"circle",
|
|
112
|
+
{
|
|
113
|
+
fill: "currentColor",
|
|
114
|
+
r: cellSize / 3,
|
|
115
|
+
cx: i * cellSize + cellSize / 2,
|
|
116
|
+
cy: j * cellSize + cellSize / 2,
|
|
117
|
+
className: "text-black dark:text-white"
|
|
118
|
+
},
|
|
119
|
+
`circle-${i}-${j}`
|
|
120
|
+
)
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
return dots2;
|
|
125
|
+
}, [size, data]);
|
|
126
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { height: size, width: size, "data-test-id": "qr-code", children: dots });
|
|
127
|
+
};
|
|
128
|
+
var QRCode_default = (0, import_react.memo)(Qrcode);
|
|
129
|
+
|
|
130
|
+
// src/store/idkit.ts
|
|
131
|
+
var import_shallow = require("zustand/shallow");
|
|
132
|
+
var import_traditional = require("zustand/traditional");
|
|
133
|
+
var import_idkit_core = require("@worldcoin/idkit-core");
|
|
134
|
+
var SELF_HOSTED_APP_ID = "self_hosted";
|
|
135
|
+
var useIDKitStore = (0, import_traditional.createWithEqualityFn)()(
|
|
136
|
+
(set, get) => ({
|
|
137
|
+
app_id: "",
|
|
138
|
+
signal: "",
|
|
139
|
+
action: "",
|
|
140
|
+
action_description: "",
|
|
141
|
+
bridge_url: "",
|
|
142
|
+
verification_level: import_idkit_core.DEFAULT_VERIFICATION_LEVEL,
|
|
143
|
+
partner: false,
|
|
144
|
+
open: false,
|
|
145
|
+
result: null,
|
|
146
|
+
errorTitle: "",
|
|
147
|
+
errorDetail: "",
|
|
148
|
+
autoClose: true,
|
|
149
|
+
errorState: null,
|
|
150
|
+
processing: false,
|
|
151
|
+
errorCallbacks: {},
|
|
152
|
+
verifyCallbacks: {},
|
|
153
|
+
successCallbacks: {},
|
|
154
|
+
stage: "WORLD_ID" /* WORLD_ID */,
|
|
155
|
+
setStage: (stage) => set({ stage }),
|
|
156
|
+
setErrorState: (errorState) => set({ errorState }),
|
|
157
|
+
setProcessing: (processing) => set({ processing }),
|
|
158
|
+
retryFlow: () => {
|
|
159
|
+
set({ stage: "WORLD_ID" /* WORLD_ID */, errorState: null });
|
|
160
|
+
},
|
|
161
|
+
addErrorCallback: (cb, source) => {
|
|
162
|
+
set((state) => {
|
|
163
|
+
state.errorCallbacks[source] = cb;
|
|
164
|
+
return state;
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
addSuccessCallback: (cb, source) => {
|
|
168
|
+
set((state) => {
|
|
169
|
+
state.successCallbacks[source] = cb;
|
|
170
|
+
return state;
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
addVerificationCallback: (cb, source) => {
|
|
174
|
+
set((state) => {
|
|
175
|
+
state.verifyCallbacks[source] = cb;
|
|
176
|
+
return state;
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
setOptions: ({
|
|
180
|
+
handleVerify,
|
|
181
|
+
onSuccess,
|
|
182
|
+
signal,
|
|
183
|
+
action,
|
|
184
|
+
app_id,
|
|
185
|
+
partner,
|
|
186
|
+
onError,
|
|
187
|
+
verification_level,
|
|
188
|
+
action_description,
|
|
189
|
+
bridge_url,
|
|
190
|
+
autoClose,
|
|
191
|
+
advanced
|
|
192
|
+
}, source) => {
|
|
193
|
+
set({
|
|
194
|
+
signal,
|
|
195
|
+
action,
|
|
196
|
+
bridge_url,
|
|
197
|
+
action_description,
|
|
198
|
+
autoClose: autoClose ?? true,
|
|
199
|
+
app_id: advanced?.self_hosted ? SELF_HOSTED_APP_ID : app_id,
|
|
200
|
+
verification_level: verification_level ?? import_idkit_core.DEFAULT_VERIFICATION_LEVEL,
|
|
201
|
+
partner
|
|
202
|
+
});
|
|
203
|
+
get().addSuccessCallback(onSuccess, source);
|
|
204
|
+
if (onError) get().addErrorCallback(onError, source);
|
|
205
|
+
if (handleVerify) get().addVerificationCallback(handleVerify, source);
|
|
206
|
+
},
|
|
207
|
+
handleVerify: (result) => {
|
|
208
|
+
set({ stage: "HOST_APP_VERIFICATION" /* HOST_APP_VERIFICATION */, processing: false });
|
|
209
|
+
Promise.all(Object.values(get().verifyCallbacks).map(async (cb) => cb?.(result))).then(
|
|
210
|
+
() => {
|
|
211
|
+
set({ stage: "SUCCESS" /* SUCCESS */, result });
|
|
212
|
+
if (get().autoClose) setTimeout(() => get().onOpenChange(false), 2500);
|
|
213
|
+
},
|
|
214
|
+
(response) => {
|
|
215
|
+
let errorMessage = void 0;
|
|
216
|
+
if (response && typeof response === "object" && response.message) {
|
|
217
|
+
errorMessage = response.message;
|
|
218
|
+
}
|
|
219
|
+
set({
|
|
220
|
+
stage: "ERROR" /* ERROR */,
|
|
221
|
+
errorState: {
|
|
222
|
+
code: import_idkit_core.AppErrorCodes.FailedByHostApp,
|
|
223
|
+
message: errorMessage ? __(errorMessage) : void 0
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
},
|
|
229
|
+
onOpenChange: (open) => {
|
|
230
|
+
if (open) {
|
|
231
|
+
return set({ open });
|
|
232
|
+
}
|
|
233
|
+
const errorState = get().errorState;
|
|
234
|
+
if (get().stage === "ERROR" /* ERROR */ && errorState) {
|
|
235
|
+
const callbacks = get().errorCallbacks;
|
|
236
|
+
requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(errorState)));
|
|
237
|
+
}
|
|
238
|
+
const result = get().result;
|
|
239
|
+
if (get().stage == "SUCCESS" /* SUCCESS */ && result) {
|
|
240
|
+
const callbacks = get().successCallbacks;
|
|
241
|
+
requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(result)));
|
|
242
|
+
}
|
|
243
|
+
set({
|
|
244
|
+
open,
|
|
245
|
+
result: null,
|
|
246
|
+
errorState: null,
|
|
247
|
+
processing: false,
|
|
248
|
+
stage: "WORLD_ID" /* WORLD_ID */
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}),
|
|
252
|
+
import_shallow.shallow
|
|
253
|
+
);
|
|
254
|
+
var idkit_default = useIDKitStore;
|
|
255
|
+
|
|
256
|
+
// src/types/config.ts
|
|
257
|
+
var ConfigSource = /* @__PURE__ */ ((ConfigSource2) => {
|
|
258
|
+
ConfigSource2["HOOK"] = "hook";
|
|
259
|
+
ConfigSource2["PROPS"] = "props";
|
|
260
|
+
ConfigSource2["MANUAL"] = "manual";
|
|
261
|
+
return ConfigSource2;
|
|
262
|
+
})(ConfigSource || {});
|
|
263
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
264
|
+
0 && (module.exports = {
|
|
265
|
+
ConfigSource,
|
|
266
|
+
QRCode,
|
|
267
|
+
__,
|
|
268
|
+
useIDKitStore
|
|
269
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
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, a as ConfigSource, b as CallbackFn, C as Config } from './config-BRFx4nLT.cjs';
|
|
5
|
+
import { IDKitConfig, ISuccessResult, IErrorState } from '@worldcoin/idkit-core';
|
|
6
|
+
|
|
7
|
+
type CleanWord<T> = T extends `${string}${' ' | ',' | '!' | '?' | '.' | '`'}${string}` ? never : T extends '' ? never : T;
|
|
8
|
+
type ExtractPlaceholders<S extends string> = S extends `${string}:${infer Placeholder}` ? Placeholder extends `${infer Word}${' ' | ',' | '!' | '?' | '.' | '`'}${infer Rest}` ? CleanWord<Word> | ExtractPlaceholders<Rest> : never : never;
|
|
9
|
+
type NoPlaceholder<S extends string> = S extends `${string}:${string}` ? never : S;
|
|
10
|
+
type PlaceholderValues<S extends string> = {
|
|
11
|
+
[K in ExtractPlaceholders<S>]: string;
|
|
12
|
+
};
|
|
13
|
+
declare function __<S extends `${string}:${string}`>(str: S, params: PlaceholderValues<S>): string;
|
|
14
|
+
declare function __<S extends string>(str: NoPlaceholder<S>): string;
|
|
15
|
+
|
|
16
|
+
type Props = {
|
|
17
|
+
data: string;
|
|
18
|
+
size?: number;
|
|
19
|
+
};
|
|
20
|
+
declare const _default: react.MemoExoticComponent<({ data, size }: Props) => JSX.Element>;
|
|
21
|
+
|
|
22
|
+
declare const SELF_HOSTED_APP_ID = "self_hosted";
|
|
23
|
+
type IDKitStore = {
|
|
24
|
+
app_id: IDKitConfig['app_id'] | typeof SELF_HOSTED_APP_ID | '';
|
|
25
|
+
action: IDKitConfig['action'];
|
|
26
|
+
signal: IDKitConfig['signal'];
|
|
27
|
+
bridge_url?: IDKitConfig['bridge_url'];
|
|
28
|
+
action_description?: IDKitConfig['action_description'];
|
|
29
|
+
verification_level: NonNullable<IDKitConfig['verification_level']>;
|
|
30
|
+
partner?: IDKitConfig['partner'];
|
|
31
|
+
open: boolean;
|
|
32
|
+
stage: IDKITStage;
|
|
33
|
+
autoClose: boolean;
|
|
34
|
+
processing: boolean;
|
|
35
|
+
result: ISuccessResult | null;
|
|
36
|
+
errorState: IErrorState | null;
|
|
37
|
+
errorCallbacks: Record<ConfigSource, CallbackFn<IErrorState> | undefined> | Record<string, never>;
|
|
38
|
+
verifyCallbacks: Record<ConfigSource, CallbackFn<ISuccessResult> | undefined> | Record<string, never>;
|
|
39
|
+
successCallbacks: Record<ConfigSource, CallbackFn<ISuccessResult> | undefined> | Record<string, never>;
|
|
40
|
+
retryFlow: () => void;
|
|
41
|
+
setStage: (stage: IDKITStage) => void;
|
|
42
|
+
onOpenChange: (open: boolean) => void;
|
|
43
|
+
setProcessing: (processing: boolean) => void;
|
|
44
|
+
handleVerify: (result: ISuccessResult) => void;
|
|
45
|
+
setErrorState: (state: IErrorState | null) => void;
|
|
46
|
+
setOptions: (options: Config, source: ConfigSource) => void;
|
|
47
|
+
addErrorCallback: (cb: CallbackFn<IErrorState>, source: ConfigSource) => void;
|
|
48
|
+
addSuccessCallback: (cb: CallbackFn<ISuccessResult>, source: ConfigSource) => void;
|
|
49
|
+
addVerificationCallback: (cb: CallbackFn<ISuccessResult>, source: ConfigSource) => void;
|
|
50
|
+
};
|
|
51
|
+
declare const useIDKitStore: zustand_traditional.UseBoundStoreWithEqualityFn<zustand_vanilla.StoreApi<IDKitStore>>;
|
|
52
|
+
|
|
53
|
+
export { ConfigSource, _default as QRCode, __, useIDKitStore };
|
package/package.json
CHANGED
|
@@ -43,12 +43,24 @@
|
|
|
43
43
|
},
|
|
44
44
|
"exports": {
|
|
45
45
|
".": {
|
|
46
|
-
"import":
|
|
47
|
-
|
|
46
|
+
"import": {
|
|
47
|
+
"types": "./build/index.d.ts",
|
|
48
|
+
"default": "./build/index.js"
|
|
49
|
+
},
|
|
50
|
+
"require": {
|
|
51
|
+
"types": "./build/index.d.cts",
|
|
52
|
+
"default": "./build/index.cjs"
|
|
53
|
+
}
|
|
48
54
|
},
|
|
49
55
|
"./internal": {
|
|
50
|
-
"import":
|
|
51
|
-
|
|
56
|
+
"import": {
|
|
57
|
+
"types": "./build/internal.d.ts",
|
|
58
|
+
"default": "./build/internal.js"
|
|
59
|
+
},
|
|
60
|
+
"require": {
|
|
61
|
+
"types": "./build/internal.d.cts",
|
|
62
|
+
"default": "./build/internal.cjs"
|
|
63
|
+
}
|
|
52
64
|
}
|
|
53
65
|
},
|
|
54
66
|
"files": [
|
|
@@ -92,7 +104,7 @@
|
|
|
92
104
|
]
|
|
93
105
|
}
|
|
94
106
|
},
|
|
95
|
-
"version": "2.1
|
|
107
|
+
"version": "2.2.1",
|
|
96
108
|
"scripts": {
|
|
97
109
|
"build": "npm run build:css && tsup",
|
|
98
110
|
"build:css": "npx tailwindcss -i ./src/styles/styles.css -o ./build/index.css --minify",
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import useIDKit from './hooks/useIDKit'
|
|
2
2
|
import IDKitWidget from '@/components/IDKitWidget/index'
|
|
3
3
|
import type { WidgetProps, Config } from '@/types/config'
|
|
4
|
-
import { VerificationLevel } from '@worldcoin/idkit-core'
|
|
5
4
|
import { solidityEncode } from '@worldcoin/idkit-core/hashing'
|
|
6
5
|
import { verifyCloudProof } from '@worldcoin/idkit-core/backend'
|
|
7
6
|
import type { IVerifyResponse } from '@worldcoin/idkit-core/backend'
|
|
8
7
|
import type { ISuccessResult, IErrorState } from '@worldcoin/idkit-core'
|
|
8
|
+
import { VerificationLevel, VerificationState } from '@worldcoin/idkit-core'
|
|
9
9
|
|
|
10
|
-
export { IDKitWidget, useIDKit, solidityEncode, verifyCloudProof, VerificationLevel }
|
|
10
|
+
export { IDKitWidget, useIDKit, solidityEncode, verifyCloudProof, VerificationLevel, VerificationState }
|
|
11
11
|
export type { ISuccessResult, IErrorState, IVerifyResponse, Config, WidgetProps }
|
|
12
|
+
|
|
13
|
+
// Session API
|
|
14
|
+
export { useSession } from '@/hooks/useSession'
|
|
15
|
+
export type { UseSessionConfig, UseSessionResult } from '@/hooks/useSession'
|