@worldcoin/idkit-core 1.2.0 → 1.2.2

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.
@@ -2,8 +2,7 @@
2
2
  import { Buffer } from "buffer/index.js";
3
3
  import { encodePacked, isBytes, isHex, keccak256 } from "viem";
4
4
  function hashToField(input) {
5
- if (isBytes(input) || isHex(input))
6
- return hashEncodedBytes(input);
5
+ if (isBytes(input) || isHex(input)) return hashEncodedBytes(input);
7
6
  return hashString(input);
8
7
  }
9
8
  function packAndEncode(input) {
@@ -33,15 +32,12 @@ var solidityEncode = (types, values) => {
33
32
  return { types, values };
34
33
  };
35
34
  var generateSignal = (signal) => {
36
- if (!signal || typeof signal === "string")
37
- return hashToField(signal ?? "");
35
+ if (!signal || typeof signal === "string") return hashToField(signal ?? "");
38
36
  return packAndEncode(signal.types.map((type, index) => [type, signal.values[index]]));
39
37
  };
40
38
  var encodeAction = (action) => {
41
- if (!action)
42
- return "";
43
- if (typeof action === "string")
44
- return action;
39
+ if (!action) return "";
40
+ if (typeof action === "string") return action;
45
41
  return action.types.map((type, index) => `${type}(${action.values[index]})`).join(",");
46
42
  };
47
43
 
@@ -32,4 +32,4 @@ type IDKitConfig = {
32
32
  verification_level?: VerificationLevel;
33
33
  };
34
34
 
35
- export { AbiEncodedValue as A, CredentialType as C, IDKitConfig as I, VerificationLevel as V };
35
+ export { type AbiEncodedValue as A, CredentialType as C, type IDKitConfig as I, VerificationLevel as V };
@@ -0,0 +1,35 @@
1
+ declare const brand: unique symbol;
2
+ type Brand<T, TBrand extends string> = T & {
3
+ [brand]: TBrand;
4
+ };
5
+ type AbiEncodedValue = Brand<{
6
+ types: string[];
7
+ values: unknown[];
8
+ }, 'AbiEncodedValue'>;
9
+ /**
10
+ * @deprecated in IDKit@1.0.0, use VerificationLevel instead
11
+ */
12
+ declare enum CredentialType {
13
+ Orb = "orb",
14
+ Device = "device"
15
+ }
16
+ declare enum VerificationLevel {
17
+ Orb = "orb",
18
+ Device = "device"
19
+ }
20
+ type IDKitConfig = {
21
+ /** Unique identifier for the app verifying the action. This should be the app ID obtained from the Developer Portal. */
22
+ app_id: `app_${string}`;
23
+ /** Identifier for the action the user is performing. Should be left blank for [Sign in with Worldcoin](https://docs.worldcoin.org/id/sign-in). */
24
+ action: AbiEncodedValue | string;
25
+ /** The description of the specific action (shown to users in World App). Only recommended for actions created on-the-fly. */
26
+ action_description?: string;
27
+ /** Encodes data into a proof that must match when validating. Read more on the [On-chain section](https://docs.worldcoin.org/advanced/on-chain). */
28
+ signal?: AbiEncodedValue | string;
29
+ /** URL to a third-party bridge to use when connecting to the World App. Optional. */
30
+ bridge_url?: string;
31
+ /** The minimum required level of verification. Defaults to "orb". */
32
+ verification_level?: VerificationLevel;
33
+ };
34
+
35
+ export { type AbiEncodedValue as A, CredentialType as C, type IDKitConfig as I, VerificationLevel as V };
package/build/index.cjs CHANGED
@@ -112,8 +112,7 @@ function validate_bridge_url(bridge_url, is_staging) {
112
112
  var import_buffer = require("buffer/index.js");
113
113
  var import_viem = require("viem");
114
114
  function hashToField(input) {
115
- if ((0, import_viem.isBytes)(input) || (0, import_viem.isHex)(input))
116
- return hashEncodedBytes(input);
115
+ if ((0, import_viem.isBytes)(input) || (0, import_viem.isHex)(input)) return hashEncodedBytes(input);
117
116
  return hashString(input);
118
117
  }
119
118
  function packAndEncode(input) {
@@ -137,15 +136,12 @@ function hashEncodedBytes(input) {
137
136
  return { hash, digest: `0x${rawDigest.padStart(64, "0")}` };
138
137
  }
139
138
  var generateSignal = (signal) => {
140
- if (!signal || typeof signal === "string")
141
- return hashToField(signal ?? "");
139
+ if (!signal || typeof signal === "string") return hashToField(signal ?? "");
142
140
  return packAndEncode(signal.types.map((type, index) => [type, signal.values[index]]));
143
141
  };
144
142
  var encodeAction = (action) => {
145
- if (!action)
146
- return "";
147
- if (typeof action === "string")
148
- return action;
143
+ if (!action) return "";
144
+ if (typeof action === "string") return action;
149
145
  return action.types.map((type, index) => `${type}(${action.values[index]})`).join(",");
150
146
  };
151
147
 
@@ -262,8 +258,7 @@ var useWorldBridgeStore = (0, import_zustand.create)((set, get) => ({
262
258
  },
263
259
  pollForUpdates: async () => {
264
260
  const key = get().key;
265
- if (!key)
266
- throw new Error("No keypair found. Please call `createClient` first.");
261
+ if (!key) throw new Error("No keypair found. Please call `createClient` first.");
267
262
  const res = await fetch(new URL(`/response/${get().requestId}`, get().bridge_url));
268
263
  if (!res.ok) {
269
264
  return set({
package/build/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { I as ISuccessResult, A as AppErrorCodes, V as VerificationState } from './result-01cf95f2.js';
2
- export { a as IErrorState } from './result-01cf95f2.js';
3
- import { I as IDKitConfig, V as VerificationLevel } from './config-f327cc3d.js';
4
- export { A as AbiEncodedValue, C as CredentialType } from './config-f327cc3d.js';
1
+ import { I as ISuccessResult, A as AppErrorCodes, V as VerificationState } from './result-CzLWEJ3W.cjs';
2
+ export { a as IErrorState } from './result-CzLWEJ3W.cjs';
3
+ import { I as IDKitConfig, V as VerificationLevel } from './config-3PagjISh.cjs';
4
+ export { A as AbiEncodedValue, C as CredentialType } from './config-3PagjISh.cjs';
5
5
  import * as zustand from 'zustand';
6
6
 
7
7
  type WorldBridgeStore = {
@@ -27,4 +27,4 @@ declare const DEFAULT_VERIFICATION_LEVEL = VerificationLevel.Orb;
27
27
  */
28
28
  declare const verification_level_to_credential_types: (verification_level: VerificationLevel) => string[];
29
29
 
30
- export { AppErrorCodes, DEFAULT_VERIFICATION_LEVEL, IDKitConfig, ISuccessResult, VerificationLevel, VerificationState, WorldBridgeStore, useWorldBridgeStore, verification_level_to_credential_types };
30
+ export { AppErrorCodes, DEFAULT_VERIFICATION_LEVEL, IDKitConfig, ISuccessResult, VerificationLevel, VerificationState, type WorldBridgeStore, useWorldBridgeStore, verification_level_to_credential_types };
package/build/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { I as ISuccessResult, A as AppErrorCodes, V as VerificationState } from './result-01cf95f2.js';
2
- export { a as IErrorState } from './result-01cf95f2.js';
3
- import { I as IDKitConfig, V as VerificationLevel } from './config-f327cc3d.js';
4
- export { A as AbiEncodedValue, C as CredentialType } from './config-f327cc3d.js';
1
+ import { I as ISuccessResult, A as AppErrorCodes, V as VerificationState } from './result-DBgbUYNh.js';
2
+ export { a as IErrorState } from './result-DBgbUYNh.js';
3
+ import { I as IDKitConfig, V as VerificationLevel } from './config-3PagjISh.js';
4
+ export { A as AbiEncodedValue, C as CredentialType } from './config-3PagjISh.js';
5
5
  import * as zustand from 'zustand';
6
6
 
7
7
  type WorldBridgeStore = {
@@ -27,4 +27,4 @@ declare const DEFAULT_VERIFICATION_LEVEL = VerificationLevel.Orb;
27
27
  */
28
28
  declare const verification_level_to_credential_types: (verification_level: VerificationLevel) => string[];
29
29
 
30
- export { AppErrorCodes, DEFAULT_VERIFICATION_LEVEL, IDKitConfig, ISuccessResult, VerificationLevel, VerificationState, WorldBridgeStore, useWorldBridgeStore, verification_level_to_credential_types };
30
+ export { AppErrorCodes, DEFAULT_VERIFICATION_LEVEL, IDKitConfig, ISuccessResult, VerificationLevel, VerificationState, type WorldBridgeStore, useWorldBridgeStore, verification_level_to_credential_types };
package/build/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  encodeAction,
3
3
  generateSignal
4
- } from "./chunk-XHZXOIDF.js";
4
+ } from "./chunk-QN7JTJAQ.js";
5
5
 
6
6
  // src/types/bridge.ts
7
7
  var AppErrorCodes = /* @__PURE__ */ ((AppErrorCodes2) => {
@@ -194,8 +194,7 @@ var useWorldBridgeStore = create((set, get) => ({
194
194
  },
195
195
  pollForUpdates: async () => {
196
196
  const key = get().key;
197
- if (!key)
198
- throw new Error("No keypair found. Please call `createClient` first.");
197
+ if (!key) throw new Error("No keypair found. Please call `createClient` first.");
199
198
  const res = await fetch(new URL(`/response/${get().requestId}`, get().bridge_url));
200
199
  if (!res.ok) {
201
200
  return set({
@@ -28,8 +28,7 @@ module.exports = __toCommonJS(backend_exports);
28
28
  var import_buffer = require("buffer/index.js");
29
29
  var import_viem = require("viem");
30
30
  function hashToField(input) {
31
- if ((0, import_viem.isBytes)(input) || (0, import_viem.isHex)(input))
32
- return hashEncodedBytes(input);
31
+ if ((0, import_viem.isBytes)(input) || (0, import_viem.isHex)(input)) return hashEncodedBytes(input);
33
32
  return hashString(input);
34
33
  }
35
34
  function hashString(input) {
@@ -1,5 +1,5 @@
1
- import { I as ISuccessResult } from '../result-01cf95f2.js';
2
- import '../config-f327cc3d.js';
1
+ import { I as ISuccessResult } from '../result-CzLWEJ3W.cjs';
2
+ import '../config-3PagjISh.cjs';
3
3
 
4
4
  interface IVerifyResponse {
5
5
  success: boolean;
@@ -9,4 +9,4 @@ interface IVerifyResponse {
9
9
  }
10
10
  declare function verifyCloudProof(proof: ISuccessResult, app_id: `app_${string}`, action: string, signal?: string, endpoint?: URL | string): Promise<IVerifyResponse>;
11
11
 
12
- export { IVerifyResponse, verifyCloudProof };
12
+ export { type IVerifyResponse, verifyCloudProof };
@@ -1,5 +1,5 @@
1
- import { I as ISuccessResult } from '../result-01cf95f2.js';
2
- import '../config-f327cc3d.js';
1
+ import { I as ISuccessResult } from '../result-DBgbUYNh.js';
2
+ import '../config-3PagjISh.js';
3
3
 
4
4
  interface IVerifyResponse {
5
5
  success: boolean;
@@ -9,4 +9,4 @@ interface IVerifyResponse {
9
9
  }
10
10
  declare function verifyCloudProof(proof: ISuccessResult, app_id: `app_${string}`, action: string, signal?: string, endpoint?: URL | string): Promise<IVerifyResponse>;
11
11
 
12
- export { IVerifyResponse, verifyCloudProof };
12
+ export { type IVerifyResponse, verifyCloudProof };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  hashToField
3
- } from "../chunk-XHZXOIDF.js";
3
+ } from "../chunk-QN7JTJAQ.js";
4
4
 
5
5
  // src/lib/backend.ts
6
6
  import { isBrowser } from "browser-or-node";
@@ -30,8 +30,7 @@ module.exports = __toCommonJS(hashing_exports);
30
30
  var import_buffer = require("buffer/index.js");
31
31
  var import_viem = require("viem");
32
32
  function hashToField(input) {
33
- if ((0, import_viem.isBytes)(input) || (0, import_viem.isHex)(input))
34
- return hashEncodedBytes(input);
33
+ if ((0, import_viem.isBytes)(input) || (0, import_viem.isHex)(input)) return hashEncodedBytes(input);
35
34
  return hashString(input);
36
35
  }
37
36
  function packAndEncode(input) {
@@ -61,15 +60,12 @@ var solidityEncode = (types, values) => {
61
60
  return { types, values };
62
61
  };
63
62
  var generateSignal = (signal) => {
64
- if (!signal || typeof signal === "string")
65
- return hashToField(signal ?? "");
63
+ if (!signal || typeof signal === "string") return hashToField(signal ?? "");
66
64
  return packAndEncode(signal.types.map((type, index) => [type, signal.values[index]]));
67
65
  };
68
66
  var encodeAction = (action) => {
69
- if (!action)
70
- return "";
71
- if (typeof action === "string")
72
- return action;
67
+ if (!action) return "";
68
+ if (typeof action === "string") return action;
73
69
  return action.types.map((type, index) => `${type}(${action.values[index]})`).join(",");
74
70
  };
75
71
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,4 +1,4 @@
1
- import { A as AbiEncodedValue, I as IDKitConfig } from '../config-f327cc3d.js';
1
+ import { A as AbiEncodedValue, I as IDKitConfig } from '../config-3PagjISh.cjs';
2
2
 
3
3
  interface HashFunctionOutput {
4
4
  hash: bigint;
@@ -17,4 +17,4 @@ declare const solidityEncode: (types: string[], values: unknown[]) => AbiEncoded
17
17
  declare const generateSignal: (signal: IDKitConfig['signal']) => HashFunctionOutput;
18
18
  declare const encodeAction: (action: IDKitConfig['action']) => string;
19
19
 
20
- export { HashFunctionOutput, encodeAction, generateSignal, hashToField, packAndEncode, solidityEncode };
20
+ export { type HashFunctionOutput, encodeAction, generateSignal, hashToField, packAndEncode, solidityEncode };
@@ -1,4 +1,4 @@
1
- import { A as AbiEncodedValue, I as IDKitConfig } from '../config-f327cc3d.js';
1
+ import { A as AbiEncodedValue, I as IDKitConfig } from '../config-3PagjISh.js';
2
2
 
3
3
  interface HashFunctionOutput {
4
4
  hash: bigint;
@@ -17,4 +17,4 @@ declare const solidityEncode: (types: string[], values: unknown[]) => AbiEncoded
17
17
  declare const generateSignal: (signal: IDKitConfig['signal']) => HashFunctionOutput;
18
18
  declare const encodeAction: (action: IDKitConfig['action']) => string;
19
19
 
20
- export { HashFunctionOutput, encodeAction, generateSignal, hashToField, packAndEncode, solidityEncode };
20
+ export { type HashFunctionOutput, encodeAction, generateSignal, hashToField, packAndEncode, solidityEncode };
@@ -4,7 +4,7 @@ import {
4
4
  hashToField,
5
5
  packAndEncode,
6
6
  solidityEncode
7
- } from "../chunk-XHZXOIDF.js";
7
+ } from "../chunk-QN7JTJAQ.js";
8
8
  export {
9
9
  encodeAction,
10
10
  generateSignal,
@@ -0,0 +1,35 @@
1
+ import { V as VerificationLevel } from './config-3PagjISh.cjs';
2
+
3
+ declare enum AppErrorCodes {
4
+ ConnectionFailed = "connection_failed",
5
+ VerificationRejected = "verification_rejected",
6
+ MaxVerificationsReached = "max_verifications_reached",
7
+ CredentialUnavailable = "credential_unavailable",
8
+ MalformedRequest = "malformed_request",
9
+ InvalidNetwork = "invalid_network",
10
+ InclusionProofFailed = "inclusion_proof_failed",
11
+ InclusionProofPending = "inclusion_proof_pending",
12
+ UnexpectedResponse = "unexpected_response",// NOTE: when the World app returns an unexpected response
13
+ FailedByHostApp = "failed_by_host_app",// NOTE: Host app failed/rejected verification (does not come from World App / simulator)
14
+ GenericError = "generic_error"
15
+ }
16
+ declare enum VerificationState {
17
+ PreparingClient = "loading_widget",
18
+ WaitingForConnection = "awaiting_connection",// Awaiting connection from the wallet
19
+ WaitingForApp = "awaiting_app",// Awaiting user confirmation in wallet
20
+ Confirmed = "confirmed",
21
+ Failed = "failed"
22
+ }
23
+
24
+ interface ISuccessResult {
25
+ proof: string;
26
+ merkle_root: string;
27
+ nullifier_hash: string;
28
+ verification_level: VerificationLevel;
29
+ }
30
+ interface IErrorState {
31
+ code: AppErrorCodes;
32
+ message?: string;
33
+ }
34
+
35
+ export { AppErrorCodes as A, type ISuccessResult as I, VerificationState as V, type IErrorState as a };
@@ -1,4 +1,4 @@
1
- import { V as VerificationLevel } from './config-f327cc3d.js';
1
+ import { V as VerificationLevel } from './config-3PagjISh.js';
2
2
 
3
3
  declare enum AppErrorCodes {
4
4
  ConnectionFailed = "connection_failed",
@@ -32,4 +32,4 @@ interface IErrorState {
32
32
  message?: string;
33
33
  }
34
34
 
35
- export { AppErrorCodes as A, ISuccessResult as I, VerificationState as V, IErrorState as a };
35
+ export { AppErrorCodes as A, type ISuccessResult as I, VerificationState as V, type IErrorState as a };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worldcoin/idkit-core",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "homepage": "https://docs.worldcoin.org/id/idkit",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -58,7 +58,7 @@
58
58
  "dependencies": {
59
59
  "browser-or-node": "3.0.0-pre.0",
60
60
  "buffer": "^6.0.3",
61
- "viem": "^1.19.11",
61
+ "viem": "^2.17.0",
62
62
  "zustand": "^4.5"
63
63
  },
64
64
  "devDependencies": {
@@ -66,7 +66,7 @@
66
66
  "@typescript-eslint/parser": "^6.13.1",
67
67
  "prettier": "^2.7.1",
68
68
  "prettier-plugin-sort-imports-desc": "^1.0.0",
69
- "tsup": "^7.2.0",
69
+ "tsup": "^8.1.0",
70
70
  "typescript": "^5.3.2"
71
71
  },
72
72
  "scripts": {