@worldcoin/idkit-core 4.0.0-dev.777cdbe → 4.0.1-dev.8abccc4

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/README.md CHANGED
@@ -53,6 +53,7 @@ const request = await IDKit.request({
53
53
  expires_at: rpSig.expires_at,
54
54
  signature: rpSig.sig,
55
55
  },
56
+ allow_legacy_proofs: false,
56
57
  }).preset(orbLegacy({ signal: "user-123" }));
57
58
 
58
59
  // Display QR code for World App
Binary file
package/dist/index.cjs CHANGED
@@ -245,6 +245,22 @@ function _assertClass(instance, klass) {
245
245
  throw new Error(`expected instance of ${klass.name}`);
246
246
  }
247
247
  }
248
+ function createSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
249
+ const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
250
+ const len0 = WASM_VECTOR_LEN;
251
+ _assertClass(rp_context, RpContextWasm);
252
+ var ptr1 = rp_context.__destroy_into_raw();
253
+ var ptr2 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
254
+ var len2 = WASM_VECTOR_LEN;
255
+ var ptr3 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
256
+ var len3 = WASM_VECTOR_LEN;
257
+ var ptr4 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
258
+ var len4 = WASM_VECTOR_LEN;
259
+ var ptr5 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
260
+ var len5 = WASM_VECTOR_LEN;
261
+ const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
262
+ return IDKitBuilder.__wrap(ret);
263
+ }
248
264
  function request(app_id, action, rp_context, action_description, bridge_url, allow_legacy_proofs, override_connect_base_url, environment) {
249
265
  const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
250
266
  const len0 = WASM_VECTOR_LEN;
@@ -263,9 +279,6 @@ function request(app_id, action, rp_context, action_description, bridge_url, all
263
279
  const ret = wasm.idkitbuilder_new(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, allow_legacy_proofs, ptr5, len5, ptr6, len6);
264
280
  return IDKitBuilder.__wrap(ret);
265
281
  }
266
- function init_wasm() {
267
- wasm.init_wasm();
268
- }
269
282
  function base64Decode(data) {
270
283
  try {
271
284
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
@@ -304,22 +317,6 @@ function proveSession(session_id, app_id, rp_context, action_description, bridge
304
317
  const ret = wasm.idkitbuilder_forProveSession(ptr0, len0, ptr1, len1, ptr2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
305
318
  return IDKitBuilder.__wrap(ret);
306
319
  }
307
- function createSession(app_id, rp_context, action_description, bridge_url, override_connect_base_url, environment) {
308
- const ptr0 = passStringToWasm0(app_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
309
- const len0 = WASM_VECTOR_LEN;
310
- _assertClass(rp_context, RpContextWasm);
311
- var ptr1 = rp_context.__destroy_into_raw();
312
- var ptr2 = isLikeNone(action_description) ? 0 : passStringToWasm0(action_description, wasm.__wbindgen_export, wasm.__wbindgen_export2);
313
- var len2 = WASM_VECTOR_LEN;
314
- var ptr3 = isLikeNone(bridge_url) ? 0 : passStringToWasm0(bridge_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
315
- var len3 = WASM_VECTOR_LEN;
316
- var ptr4 = isLikeNone(override_connect_base_url) ? 0 : passStringToWasm0(override_connect_base_url, wasm.__wbindgen_export, wasm.__wbindgen_export2);
317
- var len4 = WASM_VECTOR_LEN;
318
- var ptr5 = isLikeNone(environment) ? 0 : passStringToWasm0(environment, wasm.__wbindgen_export, wasm.__wbindgen_export2);
319
- var len5 = WASM_VECTOR_LEN;
320
- const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
321
- return IDKitBuilder.__wrap(ret);
322
- }
323
320
  function passArray8ToWasm0(arg, malloc) {
324
321
  const ptr = malloc(arg.length * 1, 1) >>> 0;
325
322
  getUint8ArrayMemory0().set(arg, ptr / 1);
@@ -344,6 +341,28 @@ function base64Encode(data) {
344
341
  wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
345
342
  }
346
343
  }
344
+ function init_wasm() {
345
+ wasm.init_wasm();
346
+ }
347
+ function signRequest(action, signing_key_hex, ttl_seconds) {
348
+ try {
349
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
350
+ const ptr0 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
351
+ const len0 = WASM_VECTOR_LEN;
352
+ const ptr1 = passStringToWasm0(signing_key_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
353
+ const len1 = WASM_VECTOR_LEN;
354
+ wasm.signRequest(retptr, ptr0, len0, ptr1, len1, !isLikeNone(ttl_seconds), isLikeNone(ttl_seconds) ? BigInt(0) : ttl_seconds);
355
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
356
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
357
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
358
+ if (r2) {
359
+ throw takeObject(r1);
360
+ }
361
+ return RpSignature.__wrap(r0);
362
+ } finally {
363
+ wasm.__wbindgen_add_to_stack_pointer(16);
364
+ }
365
+ }
347
366
  function hashSignal(signal) {
348
367
  let deferred2_0;
349
368
  let deferred2_1;
@@ -369,33 +388,14 @@ function hashSignal(signal) {
369
388
  wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
370
389
  }
371
390
  }
372
- function signRequest(action, signing_key_hex, ttl_seconds) {
373
- try {
374
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
375
- const ptr0 = passStringToWasm0(action, wasm.__wbindgen_export, wasm.__wbindgen_export2);
376
- const len0 = WASM_VECTOR_LEN;
377
- const ptr1 = passStringToWasm0(signing_key_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
378
- const len1 = WASM_VECTOR_LEN;
379
- wasm.signRequest(retptr, ptr0, len0, ptr1, len1, !isLikeNone(ttl_seconds), isLikeNone(ttl_seconds) ? BigInt(0) : ttl_seconds);
380
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
381
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
382
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
383
- if (r2) {
384
- throw takeObject(r1);
385
- }
386
- return RpSignature.__wrap(r0);
387
- } finally {
388
- wasm.__wbindgen_add_to_stack_pointer(16);
389
- }
390
- }
391
391
  function __wasm_bindgen_func_elem_960(arg0, arg1, arg2) {
392
392
  wasm.__wasm_bindgen_func_elem_960(arg0, arg1, addHeapObject(arg2));
393
393
  }
394
394
  function __wasm_bindgen_func_elem_597(arg0, arg1) {
395
395
  wasm.__wasm_bindgen_func_elem_597(arg0, arg1);
396
396
  }
397
- function __wasm_bindgen_func_elem_1343(arg0, arg1, arg2, arg3) {
398
- wasm.__wasm_bindgen_func_elem_1343(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
397
+ function __wasm_bindgen_func_elem_1345(arg0, arg1, arg2, arg3) {
398
+ wasm.__wasm_bindgen_func_elem_1345(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
399
399
  }
400
400
  var __wbindgen_enum_RequestCache = ["default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached"];
401
401
  var __wbindgen_enum_RequestCredentials = ["omit", "same-origin", "include"];
@@ -772,6 +772,34 @@ var IDKitBuilder = class _IDKitBuilder {
772
772
  const ret = wasm.idkitbuilder_constraints(ptr, addHeapObject(constraints_json));
773
773
  return takeObject(ret);
774
774
  }
775
+ /**
776
+ * Builds the native payload for constraints (synchronous, no bridge connection).
777
+ *
778
+ * Used by the native transport to get the same payload format as the bridge
779
+ * without creating a network connection.
780
+ *
781
+ * # Errors
782
+ *
783
+ * Returns an error if constraints are invalid or payload construction fails.
784
+ * @param {any} constraints_json
785
+ * @returns {any}
786
+ */
787
+ nativePayload(constraints_json) {
788
+ try {
789
+ const ptr = this.__destroy_into_raw();
790
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
791
+ wasm.idkitbuilder_nativePayload(retptr, ptr, addHeapObject(constraints_json));
792
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
793
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
794
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
795
+ if (r2) {
796
+ throw takeObject(r1);
797
+ }
798
+ return takeObject(r0);
799
+ } finally {
800
+ wasm.__wbindgen_add_to_stack_pointer(16);
801
+ }
802
+ }
775
803
  /**
776
804
  * Creates a new builder for proving an existing session
777
805
  * @param {string} session_id
@@ -827,6 +855,34 @@ var IDKitBuilder = class _IDKitBuilder {
827
855
  const ret = wasm.createSession(ptr0, len0, ptr1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
828
856
  return _IDKitBuilder.__wrap(ret);
829
857
  }
858
+ /**
859
+ * Builds the native payload from a preset (synchronous, no bridge connection).
860
+ *
861
+ * Used by the native transport to get the same payload format as the bridge
862
+ * without creating a network connection.
863
+ *
864
+ * # Errors
865
+ *
866
+ * Returns an error if the preset is invalid or payload construction fails.
867
+ * @param {any} preset_json
868
+ * @returns {any}
869
+ */
870
+ nativePayloadFromPreset(preset_json) {
871
+ try {
872
+ const ptr = this.__destroy_into_raw();
873
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
874
+ wasm.idkitbuilder_nativePayloadFromPreset(retptr, ptr, addHeapObject(preset_json));
875
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
876
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
877
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
878
+ if (r2) {
879
+ throw takeObject(r1);
880
+ }
881
+ return takeObject(r0);
882
+ } finally {
883
+ wasm.__wbindgen_add_to_stack_pointer(16);
884
+ }
885
+ }
830
886
  /**
831
887
  * Creates a new builder for uniqueness requests
832
888
  * @param {string} app_id
@@ -1502,7 +1558,7 @@ function __wbg_get_imports() {
1502
1558
  const a = state0.a;
1503
1559
  state0.a = 0;
1504
1560
  try {
1505
- return __wasm_bindgen_func_elem_1343(a, state0.b, arg02, arg12);
1561
+ return __wasm_bindgen_func_elem_1345(a, state0.b, arg02, arg12);
1506
1562
  } finally {
1507
1563
  state0.a = a;
1508
1564
  }
@@ -1796,6 +1852,10 @@ var idkit_wasm_default = __wbg_init;
1796
1852
  // src/lib/wasm.ts
1797
1853
  var wasmInitialized = false;
1798
1854
  var wasmInitPromise = null;
1855
+ async function importNodeModule(specifier) {
1856
+ const dynamicImport = Function("moduleName", "return import(moduleName)");
1857
+ return dynamicImport(specifier);
1858
+ }
1799
1859
  async function initIDKit() {
1800
1860
  if (wasmInitialized) {
1801
1861
  return;
@@ -1823,10 +1883,18 @@ async function initIDKitServer() {
1823
1883
  }
1824
1884
  wasmInitPromise = (async () => {
1825
1885
  try {
1826
- const { readFile } = await import('fs/promises');
1827
- const { fileURLToPath } = await import('url');
1828
- const wasmUrl = new URL("idkit_wasm_bg.wasm", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
1829
- const wasmBuffer = await readFile(fileURLToPath(wasmUrl));
1886
+ const { readFile } = await importNodeModule(
1887
+ "node:fs/promises"
1888
+ );
1889
+ const { fileURLToPath } = await importNodeModule(
1890
+ "node:url"
1891
+ );
1892
+ const { dirname, join } = await importNodeModule(
1893
+ "node:path"
1894
+ );
1895
+ const modulePath = fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
1896
+ const wasmPath = join(dirname(modulePath), "idkit_wasm_bg.wasm");
1897
+ const wasmBuffer = await readFile(wasmPath);
1830
1898
  await idkit_wasm_default({ module_or_path: wasmBuffer });
1831
1899
  wasmInitialized = true;
1832
1900
  } catch (error) {
@@ -1837,6 +1905,179 @@ async function initIDKitServer() {
1837
1905
  return wasmInitPromise;
1838
1906
  }
1839
1907
 
1908
+ // src/transports/native.ts
1909
+ function isInWorldApp() {
1910
+ return typeof window !== "undefined" && Boolean(window.WorldApp);
1911
+ }
1912
+ var _requestCounter = 0;
1913
+ var _activeNativeRequest = null;
1914
+ function createNativeRequest(wasmPayload, config) {
1915
+ if (_activeNativeRequest) {
1916
+ _activeNativeRequest.cancel();
1917
+ }
1918
+ const request2 = new NativeIDKitRequest(wasmPayload, config);
1919
+ _activeNativeRequest = request2;
1920
+ return request2;
1921
+ }
1922
+ var NativeIDKitRequest = class {
1923
+ constructor(wasmPayload, config) {
1924
+ this.connectorURI = "";
1925
+ this.resolved = false;
1926
+ this.cancelled = false;
1927
+ this.resolvedResult = null;
1928
+ this.messageHandler = null;
1929
+ this.rejectFn = null;
1930
+ this.requestId = crypto.randomUUID?.() ?? `native-${Date.now()}-${++_requestCounter}`;
1931
+ this.resultPromise = new Promise((resolve, reject) => {
1932
+ this.rejectFn = reject;
1933
+ const handler = (event) => {
1934
+ if (this.cancelled) return;
1935
+ const data = event.data;
1936
+ if (data?.type === "miniapp-verify-action" || data?.command === "miniapp-verify-action") {
1937
+ this.cleanup();
1938
+ const responsePayload = data.payload ?? data;
1939
+ if (responsePayload.status === "error") {
1940
+ reject(
1941
+ new NativeVerifyError(
1942
+ responsePayload.error_code ?? "generic_error" /* GenericError */
1943
+ )
1944
+ );
1945
+ } else {
1946
+ this.resolved = true;
1947
+ const result = nativeResultToIDKitResult(responsePayload, config);
1948
+ this.resolvedResult = result;
1949
+ resolve(result);
1950
+ }
1951
+ }
1952
+ };
1953
+ this.messageHandler = handler;
1954
+ window.addEventListener("message", handler);
1955
+ const sendPayload = {
1956
+ command: "verify",
1957
+ version: 2,
1958
+ payload: wasmPayload
1959
+ };
1960
+ const w = window;
1961
+ if (w.webkit?.messageHandlers?.minikit) {
1962
+ w.webkit.messageHandlers.minikit.postMessage(sendPayload);
1963
+ } else if (w.Android) {
1964
+ w.Android.postMessage(JSON.stringify(sendPayload));
1965
+ } else {
1966
+ this.cleanup();
1967
+ reject(new Error("No WebView bridge available"));
1968
+ }
1969
+ });
1970
+ this.resultPromise.catch(() => {
1971
+ }).finally(() => {
1972
+ this.cleanup();
1973
+ if (_activeNativeRequest === this) {
1974
+ _activeNativeRequest = null;
1975
+ }
1976
+ });
1977
+ }
1978
+ /**
1979
+ * Cancel this request. Removes the message listener so it cannot consume
1980
+ * a response meant for a later request, and rejects the pending promise.
1981
+ */
1982
+ cancel() {
1983
+ if (this.resolved || this.cancelled) return;
1984
+ this.cancelled = true;
1985
+ this.cleanup();
1986
+ this.rejectFn?.(new NativeVerifyError("cancelled" /* Cancelled */));
1987
+ if (_activeNativeRequest === this) {
1988
+ _activeNativeRequest = null;
1989
+ }
1990
+ }
1991
+ cleanup() {
1992
+ if (this.messageHandler) {
1993
+ window.removeEventListener("message", this.messageHandler);
1994
+ this.messageHandler = null;
1995
+ }
1996
+ }
1997
+ async pollOnce() {
1998
+ if (this.resolved && this.resolvedResult) {
1999
+ return { type: "confirmed", result: this.resolvedResult };
2000
+ }
2001
+ return { type: "awaiting_confirmation" };
2002
+ }
2003
+ async pollUntilCompletion(options) {
2004
+ const timeout = options?.timeout ?? 3e5;
2005
+ try {
2006
+ const result = await Promise.race([
2007
+ this.resultPromise,
2008
+ new Promise((_, reject) => {
2009
+ if (options?.signal) {
2010
+ options.signal.addEventListener(
2011
+ "abort",
2012
+ () => reject(new NativeVerifyError("cancelled" /* Cancelled */))
2013
+ );
2014
+ }
2015
+ setTimeout(
2016
+ () => reject(new NativeVerifyError("timeout" /* Timeout */)),
2017
+ timeout
2018
+ );
2019
+ })
2020
+ ]);
2021
+ return { success: true, result };
2022
+ } catch (error) {
2023
+ if (error instanceof NativeVerifyError) {
2024
+ return { success: false, error: error.code };
2025
+ }
2026
+ return { success: false, error: "generic_error" /* GenericError */ };
2027
+ }
2028
+ }
2029
+ };
2030
+ var NativeVerifyError = class extends Error {
2031
+ constructor(code) {
2032
+ super(code);
2033
+ this.code = code;
2034
+ }
2035
+ };
2036
+ function nativeResultToIDKitResult(payload, config) {
2037
+ const rpNonce = config.rp_context?.nonce ?? "";
2038
+ if ("responses" in payload && Array.isArray(payload.responses)) {
2039
+ return {
2040
+ protocol_version: payload.protocol_version ?? "4.0",
2041
+ nonce: payload.nonce ?? rpNonce,
2042
+ action: payload.action ?? config.action ?? "",
2043
+ action_description: payload.action_description,
2044
+ session_id: payload.session_id,
2045
+ responses: payload.responses,
2046
+ environment: payload.environment ?? config.environment ?? "production"
2047
+ };
2048
+ }
2049
+ if ("verifications" in payload) {
2050
+ return {
2051
+ protocol_version: "4.0",
2052
+ nonce: rpNonce,
2053
+ action: config.action ?? "",
2054
+ responses: payload.verifications.map((v) => ({
2055
+ identifier: v.verification_level,
2056
+ proof: [v.proof],
2057
+ nullifier: v.nullifier_hash,
2058
+ merkle_root: v.merkle_root,
2059
+ issuer_schema_id: 0,
2060
+ expires_at_min: 0
2061
+ })),
2062
+ environment: "production"
2063
+ };
2064
+ }
2065
+ return {
2066
+ protocol_version: "3.0",
2067
+ nonce: rpNonce,
2068
+ action: config.action ?? "",
2069
+ responses: [
2070
+ {
2071
+ identifier: payload.verification_level,
2072
+ proof: payload.proof,
2073
+ merkle_root: payload.merkle_root,
2074
+ nullifier: payload.nullifier_hash
2075
+ }
2076
+ ],
2077
+ environment: "production"
2078
+ };
2079
+ }
2080
+
1840
2081
  // src/request.ts
1841
2082
  var IDKitRequestImpl = class {
1842
2083
  constructor(wasmRequest) {
@@ -1901,9 +2142,52 @@ function secureDocumentLegacy(opts = {}) {
1901
2142
  function documentLegacy(opts = {}) {
1902
2143
  return { type: "DocumentLegacy", signal: opts.signal };
1903
2144
  }
2145
+ function createWasmBuilderFromConfig(config) {
2146
+ if (!config.rp_context) {
2147
+ throw new Error("rp_context is required for WASM bridge transport");
2148
+ }
2149
+ const rpContext = new idkit_wasm_exports.RpContextWasm(
2150
+ config.rp_context.rp_id,
2151
+ config.rp_context.nonce,
2152
+ BigInt(config.rp_context.created_at),
2153
+ BigInt(config.rp_context.expires_at),
2154
+ config.rp_context.signature
2155
+ );
2156
+ if (config.type === "request") {
2157
+ return idkit_wasm_exports.request(
2158
+ config.app_id,
2159
+ String(config.action ?? ""),
2160
+ rpContext,
2161
+ config.action_description ?? null,
2162
+ config.bridge_url ?? null,
2163
+ config.allow_legacy_proofs ?? false,
2164
+ config.override_connect_base_url ?? null,
2165
+ config.environment ?? null
2166
+ );
2167
+ }
2168
+ if (config.type === "proveSession") {
2169
+ return idkit_wasm_exports.proveSession(
2170
+ config.session_id,
2171
+ config.app_id,
2172
+ rpContext,
2173
+ config.action_description ?? null,
2174
+ config.bridge_url ?? null,
2175
+ config.override_connect_base_url ?? null,
2176
+ config.environment ?? null
2177
+ );
2178
+ }
2179
+ return idkit_wasm_exports.createSession(
2180
+ config.app_id,
2181
+ rpContext,
2182
+ config.action_description ?? null,
2183
+ config.bridge_url ?? null,
2184
+ config.override_connect_base_url ?? null,
2185
+ config.environment ?? null
2186
+ );
2187
+ }
1904
2188
  var IDKitBuilder2 = class {
1905
- constructor(wasmBuilder) {
1906
- this.wasmBuilder = wasmBuilder;
2189
+ constructor(config) {
2190
+ this.config = config;
1907
2191
  }
1908
2192
  /**
1909
2193
  * Creates an IDKit request with the given constraints
@@ -1913,36 +2197,45 @@ var IDKitBuilder2 = class {
1913
2197
  *
1914
2198
  * @example
1915
2199
  * ```typescript
1916
- * const builder = await IDKit.request({ app_id, action, rp_context });
1917
- * const request = await builder.constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
2200
+ * const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: false })
2201
+ * .constraints(any(CredentialRequest('orb'), CredentialRequest('face')));
1918
2202
  * ```
1919
2203
  */
1920
- //TODO: re-enable once this is supported and World ID 4.0 is rolled out live
1921
- // async constraints(constraints: ConstraintNode): Promise<IDKitRequest> {
1922
- // await initIDKit();
1923
- // const wasmRequest = (await this.wasmBuilder.constraints(
1924
- // constraints,
1925
- // )) as unknown as WasmModule.IDKitRequest;
1926
- // return new IDKitRequestImpl(wasmRequest);
1927
- // }
2204
+ async constraints(constraints) {
2205
+ await initIDKit();
2206
+ const wasmBuilder = createWasmBuilderFromConfig(this.config);
2207
+ if (isInWorldApp()) {
2208
+ const payload = wasmBuilder.nativePayload(constraints);
2209
+ return createNativeRequest(payload, this.config);
2210
+ }
2211
+ const wasmRequest = await wasmBuilder.constraints(
2212
+ constraints
2213
+ );
2214
+ return new IDKitRequestImpl(wasmRequest);
2215
+ }
1928
2216
  /**
1929
2217
  * Creates an IDKit request from a preset (works for all request types)
1930
2218
  *
1931
2219
  * Presets provide a simplified way to create requests with predefined
1932
2220
  * credential configurations.
1933
2221
  *
1934
- * @param preset - A preset object from orbLegacy()
2222
+ * @param preset - A preset object from orbLegacy(), secureDocumentLegacy(), or documentLegacy()
1935
2223
  * @returns A new IDKitRequest instance
1936
2224
  *
1937
2225
  * @example
1938
2226
  * ```typescript
1939
- * const builder = await IDKit.request({ app_id, action, rp_context });
1940
- * const request = await builder.preset(orbLegacy({ signal: 'user-123' }));
2227
+ * const request = await IDKit.request({ app_id, action, rp_context, allow_legacy_proofs: true })
2228
+ * .preset(orbLegacy({ signal: 'user-123' }));
1941
2229
  * ```
1942
2230
  */
1943
2231
  async preset(preset) {
1944
2232
  await initIDKit();
1945
- const wasmRequest = await this.wasmBuilder.preset(
2233
+ const wasmBuilder = createWasmBuilderFromConfig(this.config);
2234
+ if (isInWorldApp()) {
2235
+ const payload = wasmBuilder.nativePayloadFromPreset(preset);
2236
+ return createNativeRequest(payload, this.config);
2237
+ }
2238
+ const wasmRequest = await wasmBuilder.preset(
1946
2239
  preset
1947
2240
  );
1948
2241
  return new IDKitRequestImpl(wasmRequest);
@@ -1956,55 +2249,45 @@ function createRequest(config) {
1956
2249
  throw new Error("action is required");
1957
2250
  }
1958
2251
  if (!config.rp_context) {
1959
- throw new Error("rp_context is required");
2252
+ throw new Error(
2253
+ "rp_context is required. Generate it on your backend using signRequest()."
2254
+ );
1960
2255
  }
1961
2256
  if (typeof config.allow_legacy_proofs !== "boolean") {
1962
2257
  throw new Error(
1963
2258
  "allow_legacy_proofs is required. Set to true to accept v3 proofs during migration, or false to only accept v4 proofs."
1964
2259
  );
1965
2260
  }
1966
- const rpContext = new idkit_wasm_exports.RpContextWasm(
1967
- config.rp_context.rp_id,
1968
- config.rp_context.nonce,
1969
- BigInt(config.rp_context.created_at),
1970
- BigInt(config.rp_context.expires_at),
1971
- config.rp_context.signature
1972
- );
1973
- const wasmBuilder = idkit_wasm_exports.request(
1974
- config.app_id,
1975
- String(config.action),
1976
- rpContext,
1977
- config.action_description ?? null,
1978
- config.bridge_url ?? null,
1979
- config.allow_legacy_proofs,
1980
- config.override_connect_base_url ?? null,
1981
- config.environment ?? null
1982
- );
1983
- return new IDKitBuilder2(wasmBuilder);
2261
+ return new IDKitBuilder2({
2262
+ type: "request",
2263
+ app_id: config.app_id,
2264
+ action: String(config.action),
2265
+ rp_context: config.rp_context,
2266
+ action_description: config.action_description,
2267
+ bridge_url: config.bridge_url,
2268
+ allow_legacy_proofs: config.allow_legacy_proofs,
2269
+ override_connect_base_url: config.override_connect_base_url,
2270
+ environment: config.environment
2271
+ });
1984
2272
  }
1985
2273
  function createSession2(config) {
1986
2274
  if (!config.app_id) {
1987
2275
  throw new Error("app_id is required");
1988
2276
  }
1989
2277
  if (!config.rp_context) {
1990
- throw new Error("rp_context is required");
2278
+ throw new Error(
2279
+ "rp_context is required. Generate it on your backend using signRequest()."
2280
+ );
1991
2281
  }
1992
- const rpContext = new idkit_wasm_exports.RpContextWasm(
1993
- config.rp_context.rp_id,
1994
- config.rp_context.nonce,
1995
- BigInt(config.rp_context.created_at),
1996
- BigInt(config.rp_context.expires_at),
1997
- config.rp_context.signature
1998
- );
1999
- const wasmBuilder = idkit_wasm_exports.createSession(
2000
- config.app_id,
2001
- rpContext,
2002
- config.action_description ?? null,
2003
- config.bridge_url ?? null,
2004
- config.override_connect_base_url ?? null,
2005
- config.environment ?? null
2006
- );
2007
- return new IDKitBuilder2(wasmBuilder);
2282
+ return new IDKitBuilder2({
2283
+ type: "session",
2284
+ app_id: config.app_id,
2285
+ rp_context: config.rp_context,
2286
+ action_description: config.action_description,
2287
+ bridge_url: config.bridge_url,
2288
+ override_connect_base_url: config.override_connect_base_url,
2289
+ environment: config.environment
2290
+ });
2008
2291
  }
2009
2292
  function proveSession2(sessionId, config) {
2010
2293
  if (!sessionId) {
@@ -2014,28 +2297,23 @@ function proveSession2(sessionId, config) {
2014
2297
  throw new Error("app_id is required");
2015
2298
  }
2016
2299
  if (!config.rp_context) {
2017
- throw new Error("rp_context is required");
2300
+ throw new Error(
2301
+ "rp_context is required. Generate it on your backend using signRequest()."
2302
+ );
2018
2303
  }
2019
- const rpContext = new idkit_wasm_exports.RpContextWasm(
2020
- config.rp_context.rp_id,
2021
- config.rp_context.nonce,
2022
- BigInt(config.rp_context.created_at),
2023
- BigInt(config.rp_context.expires_at),
2024
- config.rp_context.signature
2025
- );
2026
- const wasmBuilder = idkit_wasm_exports.proveSession(
2027
- sessionId,
2028
- config.app_id,
2029
- rpContext,
2030
- config.action_description ?? null,
2031
- config.bridge_url ?? null,
2032
- config.override_connect_base_url ?? null,
2033
- config.environment ?? null
2034
- );
2035
- return new IDKitBuilder2(wasmBuilder);
2304
+ return new IDKitBuilder2({
2305
+ type: "proveSession",
2306
+ session_id: sessionId,
2307
+ app_id: config.app_id,
2308
+ rp_context: config.rp_context,
2309
+ action_description: config.action_description,
2310
+ bridge_url: config.bridge_url,
2311
+ override_connect_base_url: config.override_connect_base_url,
2312
+ environment: config.environment
2313
+ });
2036
2314
  }
2037
2315
  var IDKit = {
2038
- /** Initialize WASM for browser environments */
2316
+ /** Initialize WASM for browser environments (not needed in World App) */
2039
2317
  init: initIDKit,
2040
2318
  /** Initialize WASM for Node.js/server environments */
2041
2319
  initServer: initIDKitServer,