@worldcoin/idkit 2.1.0 → 2.2.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/build/index.d.ts +45 -5
- package/build/index.js +44 -1
- package/package.json +1 -1
- package/src/index.ts +6 -2
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
|
};
|
package/package.json
CHANGED
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'
|