@worldcoin/idkit 0.4.9 → 0.5.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.
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ type Props = {
3
+ value: string;
4
+ onChange: (value: string) => void;
5
+ };
6
+ declare const CountryCodeSelect: ({ value, onChange }: Props) => JSX.Element;
7
+ export default CountryCodeSelect;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const EnterPhoneState: () => JSX.Element;
3
+ export default EnterPhoneState;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const SelectMethodState: () => JSX.Element;
3
+ export default SelectMethodState;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const VerifyCodeState: () => JSX.Element;
3
+ export default VerifyCodeState;
@@ -0,0 +1,3 @@
1
+ import type { FC, HTMLAttributes } from 'react';
2
+ declare const DevicePhoneMobileIcon: FC<HTMLAttributes<SVGElement>>;
3
+ export default DevicePhoneMobileIcon;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ declare const _default: import("react").MemoExoticComponent<({ disabled, onSubmit }: {
3
+ disabled?: boolean | undefined;
4
+ onSubmit?: (() => void | Promise<void>) | undefined;
5
+ }) => JSX.Element>;
6
+ export default _default;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const _default: import("react").MemoExoticComponent<() => JSX.Element>;
3
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import type { RefObject } from 'react';
2
+ declare const _default: import("react").MemoExoticComponent<({ submitRef, disabled }: {
3
+ submitRef: RefObject<HTMLButtonElement>;
4
+ disabled?: boolean | undefined;
5
+ }) => JSX.Element>;
6
+ export default _default;
@@ -1,6 +1,6 @@
1
1
  import type { FC } from 'react';
2
2
  import type { IDKitConfig, WidgetConfig } from '../types/config';
3
- type Props = Omit<WidgetConfig, 'autoClose'> & Pick<IDKitConfig, 'app_id' | 'walletConnectProjectId'> & {
3
+ type Props = Omit<WidgetConfig, 'autoClose' | 'experimental_methods' | 'handleVerify'> & Pick<IDKitConfig, 'app_id' | 'walletConnectProjectId'> & {
4
4
  nonce?: string;
5
5
  onSuccess: (jwt: string) => void;
6
6
  children?: ({ open }: {
@@ -1,5 +1,5 @@
1
1
  import type { Config } from '../types/config';
2
- type HookConfig = Pick<Config, 'handleVerify' | 'onSuccess'>;
2
+ type HookConfig = Partial<Pick<Config, 'handleVerify' | 'onSuccess'>>;
3
3
  declare const useIDKit: ({ handleVerify, onSuccess }?: HookConfig) => {
4
4
  open: boolean;
5
5
  setOpen: (open: boolean) => void;
@@ -4,6 +4,7 @@ import { CredentialType } from './types';
4
4
  import type { ISuccessResult } from './types';
5
5
  import { solidityEncode } from './lib/hashing';
6
6
  import IDKitWidget from './components/IDKitWidget';
7
+ import SignInButton from './components/SignInButton';
7
8
  import type { WidgetProps, Config } from './types/config';
8
9
  import { VerificationState, AppErrorCodes } from './types/app';
9
10
  import SignInWithWorldID from './components/SignInWithWorldID';
@@ -29,5 +30,5 @@ declare const internal: {
29
30
  VerificationState: typeof VerificationState;
30
31
  AppErrorCodes: typeof AppErrorCodes;
31
32
  };
32
- export { IDKitWidget, useIDKit, solidityEncode, internal, SignInWithWorldID, CredentialType };
33
+ export { IDKitWidget, useIDKit, solidityEncode, internal, SignInWithWorldID, CredentialType, SignInButton };
33
34
  export type { ISuccessResult, Config, WidgetProps };
@@ -0,0 +1,9 @@
1
+ type CleanWord<T> = T extends `${string}${' ' | ',' | '!' | '?' | '.' | '`'}${string}` ? never : T extends '' ? never : T;
2
+ type ExtractPlaceholders<S extends string> = S extends `${string}:${infer Placeholder}` ? Placeholder extends `${infer Word}${' ' | ',' | '!' | '?' | '.' | '`'}${infer Rest}` ? CleanWord<Word> | ExtractPlaceholders<Rest> : never : never;
3
+ type NoPlaceholder<S extends string> = S extends `${string}:${string}` ? never : S;
4
+ type PlaceholderValues<S extends string> = {
5
+ [K in ExtractPlaceholders<S>]: string;
6
+ };
7
+ export declare function __<S extends `${string}:${string}`>(str: S, params: PlaceholderValues<S>): string;
8
+ export declare function __<S extends string>(str: NoPlaceholder<S>): string;
9
+ export {};
@@ -1,11 +1,9 @@
1
- /// <reference types="node" />
2
1
  import type { AbiEncodedValue } from '../types';
3
2
  import type { IDKitConfig } from '../types/config';
4
- import type { BytesLike } from '@ethersproject/bytes';
5
- export interface HashFunctionOutput {
3
+ export type HashFunctionOutput = {
6
4
  hash: BigInt;
7
- digest: string;
8
- }
5
+ digest: `0x${string}`;
6
+ };
9
7
  /**
10
8
  * Hashes an input using the `keccak256` hashing function used across the World ID protocol, to be used as
11
9
  * a ZKP input. The function will try to determine the best hashing mechanism, if the string already looks like hex-encoded
@@ -13,7 +11,7 @@ export interface HashFunctionOutput {
13
11
  * @param input Any string, hex-like string, bytes represented as a hex string.
14
12
  * @returns
15
13
  */
16
- export declare function hashToField(input: Buffer | BytesLike): HashFunctionOutput;
14
+ export declare function hashToField(input: Uint8Array | string | `0x${string}`): HashFunctionOutput;
17
15
  export declare function packAndEncode(input: [string, unknown][]): HashFunctionOutput;
18
16
  export declare const validateABILikeEncoding: (value: string) => boolean;
19
17
  export declare const solidityEncode: (types: string[], values: unknown[]) => AbiEncodedValue;
@@ -1,3 +1,6 @@
1
+ import type { PhoneVerificationChannel } from '../types';
1
2
  export declare const getTelemetryId: () => string;
2
3
  export declare const initTelemetry: (enableTelemetry?: boolean) => void;
3
4
  export declare const telemetryModalOpened: () => void;
5
+ export declare const telemetryPhoneTyped: () => void;
6
+ export declare const telemetryRetryCode: (channel: PhoneVerificationChannel) => void;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * This module is fully experimental. Usage is not yet supported except as individually shared.
3
+ */
4
+ import type { PhoneRequestErrorCodes, PhoneSignalProof, PhoneVerificationChannel } from '../types';
5
+ export declare function requestCode(phone_number: string, app_id: string, channel: PhoneVerificationChannel, ph_distinct_id: string): Promise<void>;
6
+ interface VerifyCodeSuccess extends Pick<PhoneSignalProof, 'signature' | 'timestamp'> {
7
+ success: true;
8
+ nullifier_hash: string;
9
+ }
10
+ export declare function verifyCode(phone_number: string, code: string, app_id: string, ph_distinct_id: string): Promise<VerifyCodeSuccess>;
11
+ interface RequestCodeError {
12
+ code: PhoneRequestErrorCodes;
13
+ detail: string;
14
+ }
15
+ export declare function isRequestCodeError(error: unknown): error is RequestCodeError;
16
+ export interface VerifyCodeError {
17
+ code: 'invalid_code';
18
+ details: string;
19
+ }
20
+ export declare function isVerifyCodeError(error: unknown): error is VerifyCodeError;
21
+ export {};
@@ -1,6 +1,7 @@
1
1
  import { IDKITStage } from '../types';
2
- import type { CallbackFn, IErrorState, ISuccessResult } from '../types';
2
+ import type { VerificationMethods } from '../types/config';
3
3
  import type { Config, ConfigSource, IDKitConfig } from '../types/config';
4
+ import type { CallbackFn, IErrorState, IExperimentalSuccessResult, ISuccessResult } from '../types';
4
5
  export type IDKitStore = {
5
6
  app_id: IDKitConfig['app_id'];
6
7
  action: IDKitConfig['action'];
@@ -8,30 +9,33 @@ export type IDKitStore = {
8
9
  action_description?: IDKitConfig['action_description'];
9
10
  walletConnectProjectId?: IDKitConfig['walletConnectProjectId'];
10
11
  credential_types?: IDKitConfig['credential_types'];
12
+ phoneNumber: string;
11
13
  code: string;
12
14
  open: boolean;
13
15
  stage: IDKITStage;
14
16
  autoClose: boolean;
15
17
  processing: boolean;
16
- copy: Config['copy'];
17
18
  theme: Config['theme'];
18
- result: ISuccessResult | null;
19
+ result: IExperimentalSuccessResult | ISuccessResult | null;
20
+ methods: VerificationMethods[];
19
21
  errorState: IErrorState | null;
20
- verifyCallbacks: Record<ConfigSource, CallbackFn | undefined> | Record<string, never>;
21
- successCallbacks: Record<ConfigSource, CallbackFn | undefined> | Record<string, never>;
22
+ verifyCallbacks: Record<ConfigSource, CallbackFn<IExperimentalSuccessResult> | CallbackFn<ISuccessResult> | undefined> | Record<string, never>;
23
+ successCallbacks: Record<ConfigSource, CallbackFn<IExperimentalSuccessResult> | CallbackFn<ISuccessResult> | undefined> | Record<string, never>;
22
24
  computed: {
23
25
  canGoBack: (stage: IDKITStage) => boolean;
26
+ getDefaultStage: (methods?: Config['experimental_methods']) => IDKITStage;
24
27
  };
25
28
  retryFlow: () => void;
26
29
  setCode: (code: string) => void;
27
30
  setStage: (stage: IDKITStage) => void;
28
31
  onOpenChange: (open: boolean) => void;
29
32
  setProcessing: (processing: boolean) => void;
30
- handleVerify: (result: ISuccessResult) => void;
33
+ handleVerify: (result: IExperimentalSuccessResult | ISuccessResult) => void;
31
34
  setErrorState: (state: IErrorState | null) => void;
32
35
  setOptions: (options: Config, source: ConfigSource) => void;
33
- addSuccessCallback: (cb: CallbackFn, source: ConfigSource) => void;
34
- addVerificationCallback: (cb: CallbackFn, source: ConfigSource) => void;
36
+ addSuccessCallback: (cb: CallbackFn<IExperimentalSuccessResult> | CallbackFn<ISuccessResult>, source: ConfigSource) => void;
37
+ addVerificationCallback: (cb: CallbackFn<IExperimentalSuccessResult> | CallbackFn<ISuccessResult>, source: ConfigSource) => void;
38
+ setPhoneNumber: (phoneNumber: string) => void;
35
39
  };
36
40
  declare const useIDKitStore: import("zustand").UseBoundStore<import("zustand").StoreApi<IDKitStore>>;
37
41
  export default useIDKitStore;
@@ -10,7 +10,8 @@ export declare enum AppErrorCodes {
10
10
  InclusionProofPending = "inclusion_proof_pending",
11
11
  UnexpectedResponse = "unexpected_response",
12
12
  FailedByHostApp = "failed_by_host_app",
13
- GenericError = "generic_error"
13
+ GenericError = "generic_error",
14
+ InvalidPhoneOTP = "invalid_phone_otp"
14
15
  }
15
16
  export declare enum VerificationState {
16
17
  LoadingWidget = "loading_widget",
@@ -1,31 +1,45 @@
1
1
  /// <reference types="react" />
2
- import type { AbiEncodedValue, CallbackFn, CredentialType } from '.';
2
+ import type { AbiEncodedValue, CallbackFn, CredentialType, IExperimentalSuccessResult, ISuccessResult } from '.';
3
+ export type VerificationMethods = 'orb' | 'phone';
3
4
  export declare enum ConfigSource {
4
5
  HOOK = "hook",
5
6
  PROPS = "props",
6
7
  MANUAL = "manual"
7
8
  }
8
9
  export type IDKitConfig = {
10
+ /** Unique identifier for the app verifying the action. This should be the app ID obtained from the Developer Portal. */
9
11
  app_id: string;
12
+ /** The description of the specific action (shown to users in World App). Only recommended for actions created on-the-fly. */
10
13
  action_description?: string;
11
- walletConnectProjectId?: string;
14
+ /** Encodes data into a proof that must match when validating. Read more on the [On-chain section](https://docs.worldcoin.org/advanced/on-chain). */
12
15
  signal?: AbiEncodedValue | string;
16
+ /** Identifier for the action the user is performing. Should be left blank for [Sign in with Worldcoin](https://docs.worldcoin.org/id/sign-in). */
13
17
  action?: AbiEncodedValue | string;
18
+ walletConnectProjectId?: string;
19
+ /** An array of credential types to allow for verification. Will accept any combination of "orb" & "phone". Defaults to orb. TypeScript apps can use the `CredentialType` enum. */
14
20
  credential_types?: CredentialType[];
15
21
  };
16
22
  export type WidgetConfig = {
23
+ /** Whether to automatically close the widget after a successful verification. Defaults to `false`. */
17
24
  autoClose?: boolean;
18
- onSuccess?: CallbackFn;
25
+ /** The theme to apply to the widget's UI. Defaults to `light`. */
19
26
  theme?: 'dark' | 'light';
27
+ /** Whether opt-in telemetry is enabled. Very few events are sent, with no PII to help improve the project. Defaults to `false`. */
20
28
  enableTelemetry?: boolean;
21
- handleVerify?: CallbackFn;
22
- copy?: {
23
- title?: string;
24
- heading?: string;
25
- subheading?: string;
26
- success?: string;
27
- };
28
- };
29
+ } & ({
30
+ /** Optionally enable the experimental verification flow. This flow is not recommended for production apps. */
31
+ experimental_methods?: VerificationMethods[];
32
+ /** Function to trigger when verification is successful. Should receive a single parameter of type `IExperimentalSuccessResult` which contains the proof details. */
33
+ onSuccess: CallbackFn<IExperimentalSuccessResult>;
34
+ /** Called after the proof is returned from the World App, but before showing the success screen. Throwing an error in this screen will show the user a custom error. Used to perform additional validation when needed. */
35
+ handleVerify?: CallbackFn<IExperimentalSuccessResult>;
36
+ } | {
37
+ experimental_methods?: never;
38
+ /** Function to trigger when verification is successful. Should receive a single parameter of type `ISuccessResult` which contains the proof details. */
39
+ onSuccess: CallbackFn<ISuccessResult>;
40
+ /** 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. */
41
+ handleVerify?: CallbackFn<ISuccessResult>;
42
+ });
29
43
  export type Config = IDKitConfig & Required<Pick<IDKitConfig, 'action'>> & WidgetConfig;
30
44
  export type WidgetProps = Config & {
31
45
  children?: ({ open }: {
@@ -1,4 +1,5 @@
1
1
  import type { AppErrorCodes } from './app';
2
+ import type { VerificationMethods } from './config';
2
3
  declare const brand: unique symbol;
3
4
  type Brand<T, TBrand extends string> = T & {
4
5
  [brand]: TBrand;
@@ -8,6 +9,9 @@ export type AbiEncodedValue = Brand<{
8
9
  values: unknown[];
9
10
  }, 'AbiEncodedValue'>;
10
11
  export declare enum IDKITStage {
12
+ SELECT_METHOD = "SELECT_METHOD",
13
+ ENTER_PHONE = "ENTER_PHONE",
14
+ ENTER_CODE = "ENTER_CODE",
11
15
  WORLD_ID = "WORLD_ID",
12
16
  PRIVACY = "PRIVACY",
13
17
  SUCCESS = "SUCCESS",
@@ -18,13 +22,18 @@ export declare enum CredentialType {
18
22
  Orb = "orb",
19
23
  Phone = "phone"
20
24
  }
25
+ export interface IExperimentalSuccessResult {
26
+ nullifier_hash: string;
27
+ credential_type: VerificationMethods;
28
+ proof_payload: OrbSignalProof | PhoneSignalProof;
29
+ }
21
30
  export interface ISuccessResult {
22
31
  proof: string;
23
32
  merkle_root: string;
24
33
  nullifier_hash: string;
25
34
  credential_type: CredentialType;
26
35
  }
27
- export type CallbackFn = (result: ISuccessResult) => Promise<void> | void;
36
+ export type CallbackFn<T> = (result: T) => Promise<void> | void;
28
37
  export interface ExpectedErrorResponse {
29
38
  message: string;
30
39
  stack: string;
@@ -33,4 +42,22 @@ export interface IErrorState {
33
42
  code: AppErrorCodes;
34
43
  message?: string;
35
44
  }
45
+ export declare enum PhoneVerificationChannel {
46
+ SMS = "sms",
47
+ Call = "call"
48
+ }
49
+ export declare enum PhoneRequestErrorCodes {
50
+ MAX_ATTEMPTS = "max_attempts",
51
+ TIMEOUT = "timeout",
52
+ UNSUPPORTED_COUNTRY = "unsupported_country",
53
+ SERVER_ERROR = "server_error"
54
+ }
55
+ export interface OrbSignalProof {
56
+ merkle_root: string;
57
+ proof: string;
58
+ }
59
+ export interface PhoneSignalProof {
60
+ timestamp: number;
61
+ signature: string;
62
+ }
36
63
  export {};