@worldcoin/idkit-core 4.0.14 → 4.0.15
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/dist/index.cjs +71 -94
- package/dist/index.js +71 -94
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1976,37 +1976,32 @@ function createNativeRequest(wasmPayload, config, signalHashes = {}, legacySigna
|
|
|
1976
1976
|
var NativeIDKitRequest = class {
|
|
1977
1977
|
constructor(wasmPayload, config, signalHashes = {}, legacySignalHash, version = 2) {
|
|
1978
1978
|
this.connectorURI = "";
|
|
1979
|
-
|
|
1980
|
-
this.
|
|
1981
|
-
this.
|
|
1982
|
-
this.resolvedResult = null;
|
|
1979
|
+
// Non-null once the request is done (success, error, cancel, or timeout).
|
|
1980
|
+
this.completionResult = null;
|
|
1981
|
+
this.resolveFn = null;
|
|
1983
1982
|
this.messageHandler = null;
|
|
1984
1983
|
this.miniKitHandler = null;
|
|
1985
|
-
this.rejectFn = null;
|
|
1986
1984
|
this.requestId = crypto.randomUUID?.() ?? `native-${Date.now()}-${++_requestCounter}`;
|
|
1987
|
-
this.resultPromise = new Promise((resolve
|
|
1988
|
-
this.
|
|
1985
|
+
this.resultPromise = new Promise((resolve) => {
|
|
1986
|
+
this.resolveFn = resolve;
|
|
1989
1987
|
const handleIncomingPayload = (responsePayload) => {
|
|
1990
|
-
if (this.
|
|
1988
|
+
if (this.completionResult) return;
|
|
1991
1989
|
if (responsePayload?.status === "error") {
|
|
1992
|
-
this.
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
)
|
|
1997
|
-
);
|
|
1990
|
+
this.complete({
|
|
1991
|
+
success: false,
|
|
1992
|
+
error: responsePayload.error_code ?? "generic_error" /* GenericError */
|
|
1993
|
+
});
|
|
1998
1994
|
return;
|
|
1999
1995
|
}
|
|
2000
|
-
this.
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
resolve(result);
|
|
1996
|
+
this.complete({
|
|
1997
|
+
success: true,
|
|
1998
|
+
result: nativeResultToIDKitResult(
|
|
1999
|
+
responsePayload,
|
|
2000
|
+
config,
|
|
2001
|
+
signalHashes,
|
|
2002
|
+
legacySignalHash
|
|
2003
|
+
)
|
|
2004
|
+
});
|
|
2010
2005
|
};
|
|
2011
2006
|
const handler = (event) => {
|
|
2012
2007
|
const data = event.data;
|
|
@@ -2032,38 +2027,39 @@ var NativeIDKitRequest = class {
|
|
|
2032
2027
|
version,
|
|
2033
2028
|
payload: wasmPayload
|
|
2034
2029
|
};
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
w.webkit
|
|
2038
|
-
|
|
2039
|
-
w.Android
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2030
|
+
try {
|
|
2031
|
+
const w = window;
|
|
2032
|
+
if (w.webkit?.messageHandlers?.minikit) {
|
|
2033
|
+
w.webkit.messageHandlers.minikit.postMessage(sendPayload);
|
|
2034
|
+
} else if (w.Android) {
|
|
2035
|
+
w.Android.postMessage(JSON.stringify(sendPayload));
|
|
2036
|
+
} else {
|
|
2037
|
+
this.complete({
|
|
2038
|
+
success: false,
|
|
2039
|
+
error: "generic_error" /* GenericError */
|
|
2040
|
+
});
|
|
2041
|
+
}
|
|
2042
|
+
} catch {
|
|
2043
|
+
this.complete({
|
|
2044
|
+
success: false,
|
|
2045
|
+
error: "generic_error" /* GenericError */
|
|
2046
|
+
});
|
|
2051
2047
|
}
|
|
2052
2048
|
});
|
|
2053
2049
|
}
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
cancel() {
|
|
2059
|
-
if (this.resolved || this.cancelled) return;
|
|
2060
|
-
this.cancelled = true;
|
|
2050
|
+
// Single entry point for finishing the request. Idempotent — first caller wins.
|
|
2051
|
+
complete(result) {
|
|
2052
|
+
if (this.completionResult) return;
|
|
2053
|
+
this.completionResult = result;
|
|
2061
2054
|
this.cleanup();
|
|
2062
|
-
this.
|
|
2055
|
+
this.resolveFn?.(result);
|
|
2063
2056
|
if (_activeNativeRequest === this) {
|
|
2064
2057
|
_activeNativeRequest = null;
|
|
2065
2058
|
}
|
|
2066
2059
|
}
|
|
2060
|
+
cancel() {
|
|
2061
|
+
this.complete({ success: false, error: "cancelled" /* Cancelled */ });
|
|
2062
|
+
}
|
|
2067
2063
|
cleanup() {
|
|
2068
2064
|
if (this.messageHandler) {
|
|
2069
2065
|
window.removeEventListener("message", this.messageHandler);
|
|
@@ -2079,67 +2075,48 @@ var NativeIDKitRequest = class {
|
|
|
2079
2075
|
}
|
|
2080
2076
|
}
|
|
2081
2077
|
isPending() {
|
|
2082
|
-
return
|
|
2078
|
+
return this.completionResult === null;
|
|
2083
2079
|
}
|
|
2084
2080
|
async pollOnce() {
|
|
2085
|
-
if (this.
|
|
2086
|
-
return { type: "
|
|
2081
|
+
if (!this.completionResult) {
|
|
2082
|
+
return { type: "awaiting_confirmation" };
|
|
2083
|
+
}
|
|
2084
|
+
if (this.completionResult.success) {
|
|
2085
|
+
return { type: "confirmed", result: this.completionResult.result };
|
|
2087
2086
|
}
|
|
2088
|
-
return { type: "
|
|
2087
|
+
return { type: "failed", error: this.completionResult.error };
|
|
2089
2088
|
}
|
|
2090
2089
|
async pollUntilCompletion(options) {
|
|
2091
2090
|
const timeout = options?.timeout ?? 3e5;
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2091
|
+
const timeoutId = setTimeout(() => {
|
|
2092
|
+
this.complete({ success: false, error: "timeout" /* Timeout */ });
|
|
2093
|
+
}, timeout);
|
|
2094
|
+
const abortHandler = options?.signal ? () => {
|
|
2095
|
+
this.complete({ success: false, error: "cancelled" /* Cancelled */ });
|
|
2096
|
+
} : null;
|
|
2097
|
+
if (abortHandler) {
|
|
2098
|
+
if (options.signal.aborted) {
|
|
2099
|
+
abortHandler();
|
|
2100
|
+
} else {
|
|
2101
|
+
options.signal.addEventListener("abort", abortHandler, {
|
|
2102
|
+
once: true
|
|
2103
|
+
});
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2095
2106
|
try {
|
|
2096
|
-
|
|
2097
|
-
this.resultPromise,
|
|
2098
|
-
new Promise((_, reject) => {
|
|
2099
|
-
if (options?.signal) {
|
|
2100
|
-
abortHandler = () => {
|
|
2101
|
-
waiterTerminationCode = "cancelled" /* Cancelled */;
|
|
2102
|
-
reject(new NativeVerifyError("cancelled" /* Cancelled */));
|
|
2103
|
-
};
|
|
2104
|
-
if (options.signal.aborted) {
|
|
2105
|
-
abortHandler();
|
|
2106
|
-
return;
|
|
2107
|
-
}
|
|
2108
|
-
options.signal.addEventListener("abort", abortHandler, {
|
|
2109
|
-
once: true
|
|
2110
|
-
});
|
|
2111
|
-
}
|
|
2112
|
-
timeoutId = setTimeout(() => {
|
|
2113
|
-
waiterTerminationCode = "timeout" /* Timeout */;
|
|
2114
|
-
reject(new NativeVerifyError("timeout" /* Timeout */));
|
|
2115
|
-
}, timeout);
|
|
2116
|
-
})
|
|
2117
|
-
]);
|
|
2118
|
-
return { success: true, result };
|
|
2107
|
+
return await this.resultPromise;
|
|
2119
2108
|
} catch (error) {
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
}
|
|
2124
|
-
return { success: false, error: error.code };
|
|
2125
|
-
}
|
|
2126
|
-
return { success: false, error: "generic_error" /* GenericError */ };
|
|
2109
|
+
console.error("Unexpected rejection in native resultPromise", error);
|
|
2110
|
+
this.complete({ success: false, error: "generic_error" /* GenericError */ });
|
|
2111
|
+
return this.completionResult;
|
|
2127
2112
|
} finally {
|
|
2128
|
-
|
|
2129
|
-
clearTimeout(timeoutId);
|
|
2130
|
-
}
|
|
2113
|
+
clearTimeout(timeoutId);
|
|
2131
2114
|
if (options?.signal && abortHandler) {
|
|
2132
2115
|
options.signal.removeEventListener("abort", abortHandler);
|
|
2133
2116
|
}
|
|
2134
2117
|
}
|
|
2135
2118
|
}
|
|
2136
2119
|
};
|
|
2137
|
-
var NativeVerifyError = class extends Error {
|
|
2138
|
-
constructor(code) {
|
|
2139
|
-
super(code);
|
|
2140
|
-
this.code = code;
|
|
2141
|
-
}
|
|
2142
|
-
};
|
|
2143
2120
|
function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHash) {
|
|
2144
2121
|
const p = payload;
|
|
2145
2122
|
const rpNonce = config.rp_context?.nonce ?? "";
|
package/dist/index.js
CHANGED
|
@@ -1973,37 +1973,32 @@ function createNativeRequest(wasmPayload, config, signalHashes = {}, legacySigna
|
|
|
1973
1973
|
var NativeIDKitRequest = class {
|
|
1974
1974
|
constructor(wasmPayload, config, signalHashes = {}, legacySignalHash, version = 2) {
|
|
1975
1975
|
this.connectorURI = "";
|
|
1976
|
-
|
|
1977
|
-
this.
|
|
1978
|
-
this.
|
|
1979
|
-
this.resolvedResult = null;
|
|
1976
|
+
// Non-null once the request is done (success, error, cancel, or timeout).
|
|
1977
|
+
this.completionResult = null;
|
|
1978
|
+
this.resolveFn = null;
|
|
1980
1979
|
this.messageHandler = null;
|
|
1981
1980
|
this.miniKitHandler = null;
|
|
1982
|
-
this.rejectFn = null;
|
|
1983
1981
|
this.requestId = crypto.randomUUID?.() ?? `native-${Date.now()}-${++_requestCounter}`;
|
|
1984
|
-
this.resultPromise = new Promise((resolve
|
|
1985
|
-
this.
|
|
1982
|
+
this.resultPromise = new Promise((resolve) => {
|
|
1983
|
+
this.resolveFn = resolve;
|
|
1986
1984
|
const handleIncomingPayload = (responsePayload) => {
|
|
1987
|
-
if (this.
|
|
1985
|
+
if (this.completionResult) return;
|
|
1988
1986
|
if (responsePayload?.status === "error") {
|
|
1989
|
-
this.
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
)
|
|
1994
|
-
);
|
|
1987
|
+
this.complete({
|
|
1988
|
+
success: false,
|
|
1989
|
+
error: responsePayload.error_code ?? "generic_error" /* GenericError */
|
|
1990
|
+
});
|
|
1995
1991
|
return;
|
|
1996
1992
|
}
|
|
1997
|
-
this.
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
resolve(result);
|
|
1993
|
+
this.complete({
|
|
1994
|
+
success: true,
|
|
1995
|
+
result: nativeResultToIDKitResult(
|
|
1996
|
+
responsePayload,
|
|
1997
|
+
config,
|
|
1998
|
+
signalHashes,
|
|
1999
|
+
legacySignalHash
|
|
2000
|
+
)
|
|
2001
|
+
});
|
|
2007
2002
|
};
|
|
2008
2003
|
const handler = (event) => {
|
|
2009
2004
|
const data = event.data;
|
|
@@ -2029,38 +2024,39 @@ var NativeIDKitRequest = class {
|
|
|
2029
2024
|
version,
|
|
2030
2025
|
payload: wasmPayload
|
|
2031
2026
|
};
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
w.webkit
|
|
2035
|
-
|
|
2036
|
-
w.Android
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2027
|
+
try {
|
|
2028
|
+
const w = window;
|
|
2029
|
+
if (w.webkit?.messageHandlers?.minikit) {
|
|
2030
|
+
w.webkit.messageHandlers.minikit.postMessage(sendPayload);
|
|
2031
|
+
} else if (w.Android) {
|
|
2032
|
+
w.Android.postMessage(JSON.stringify(sendPayload));
|
|
2033
|
+
} else {
|
|
2034
|
+
this.complete({
|
|
2035
|
+
success: false,
|
|
2036
|
+
error: "generic_error" /* GenericError */
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
2039
|
+
} catch {
|
|
2040
|
+
this.complete({
|
|
2041
|
+
success: false,
|
|
2042
|
+
error: "generic_error" /* GenericError */
|
|
2043
|
+
});
|
|
2048
2044
|
}
|
|
2049
2045
|
});
|
|
2050
2046
|
}
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
cancel() {
|
|
2056
|
-
if (this.resolved || this.cancelled) return;
|
|
2057
|
-
this.cancelled = true;
|
|
2047
|
+
// Single entry point for finishing the request. Idempotent — first caller wins.
|
|
2048
|
+
complete(result) {
|
|
2049
|
+
if (this.completionResult) return;
|
|
2050
|
+
this.completionResult = result;
|
|
2058
2051
|
this.cleanup();
|
|
2059
|
-
this.
|
|
2052
|
+
this.resolveFn?.(result);
|
|
2060
2053
|
if (_activeNativeRequest === this) {
|
|
2061
2054
|
_activeNativeRequest = null;
|
|
2062
2055
|
}
|
|
2063
2056
|
}
|
|
2057
|
+
cancel() {
|
|
2058
|
+
this.complete({ success: false, error: "cancelled" /* Cancelled */ });
|
|
2059
|
+
}
|
|
2064
2060
|
cleanup() {
|
|
2065
2061
|
if (this.messageHandler) {
|
|
2066
2062
|
window.removeEventListener("message", this.messageHandler);
|
|
@@ -2076,67 +2072,48 @@ var NativeIDKitRequest = class {
|
|
|
2076
2072
|
}
|
|
2077
2073
|
}
|
|
2078
2074
|
isPending() {
|
|
2079
|
-
return
|
|
2075
|
+
return this.completionResult === null;
|
|
2080
2076
|
}
|
|
2081
2077
|
async pollOnce() {
|
|
2082
|
-
if (this.
|
|
2083
|
-
return { type: "
|
|
2078
|
+
if (!this.completionResult) {
|
|
2079
|
+
return { type: "awaiting_confirmation" };
|
|
2080
|
+
}
|
|
2081
|
+
if (this.completionResult.success) {
|
|
2082
|
+
return { type: "confirmed", result: this.completionResult.result };
|
|
2084
2083
|
}
|
|
2085
|
-
return { type: "
|
|
2084
|
+
return { type: "failed", error: this.completionResult.error };
|
|
2086
2085
|
}
|
|
2087
2086
|
async pollUntilCompletion(options) {
|
|
2088
2087
|
const timeout = options?.timeout ?? 3e5;
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2088
|
+
const timeoutId = setTimeout(() => {
|
|
2089
|
+
this.complete({ success: false, error: "timeout" /* Timeout */ });
|
|
2090
|
+
}, timeout);
|
|
2091
|
+
const abortHandler = options?.signal ? () => {
|
|
2092
|
+
this.complete({ success: false, error: "cancelled" /* Cancelled */ });
|
|
2093
|
+
} : null;
|
|
2094
|
+
if (abortHandler) {
|
|
2095
|
+
if (options.signal.aborted) {
|
|
2096
|
+
abortHandler();
|
|
2097
|
+
} else {
|
|
2098
|
+
options.signal.addEventListener("abort", abortHandler, {
|
|
2099
|
+
once: true
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2092
2103
|
try {
|
|
2093
|
-
|
|
2094
|
-
this.resultPromise,
|
|
2095
|
-
new Promise((_, reject) => {
|
|
2096
|
-
if (options?.signal) {
|
|
2097
|
-
abortHandler = () => {
|
|
2098
|
-
waiterTerminationCode = "cancelled" /* Cancelled */;
|
|
2099
|
-
reject(new NativeVerifyError("cancelled" /* Cancelled */));
|
|
2100
|
-
};
|
|
2101
|
-
if (options.signal.aborted) {
|
|
2102
|
-
abortHandler();
|
|
2103
|
-
return;
|
|
2104
|
-
}
|
|
2105
|
-
options.signal.addEventListener("abort", abortHandler, {
|
|
2106
|
-
once: true
|
|
2107
|
-
});
|
|
2108
|
-
}
|
|
2109
|
-
timeoutId = setTimeout(() => {
|
|
2110
|
-
waiterTerminationCode = "timeout" /* Timeout */;
|
|
2111
|
-
reject(new NativeVerifyError("timeout" /* Timeout */));
|
|
2112
|
-
}, timeout);
|
|
2113
|
-
})
|
|
2114
|
-
]);
|
|
2115
|
-
return { success: true, result };
|
|
2104
|
+
return await this.resultPromise;
|
|
2116
2105
|
} catch (error) {
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
}
|
|
2121
|
-
return { success: false, error: error.code };
|
|
2122
|
-
}
|
|
2123
|
-
return { success: false, error: "generic_error" /* GenericError */ };
|
|
2106
|
+
console.error("Unexpected rejection in native resultPromise", error);
|
|
2107
|
+
this.complete({ success: false, error: "generic_error" /* GenericError */ });
|
|
2108
|
+
return this.completionResult;
|
|
2124
2109
|
} finally {
|
|
2125
|
-
|
|
2126
|
-
clearTimeout(timeoutId);
|
|
2127
|
-
}
|
|
2110
|
+
clearTimeout(timeoutId);
|
|
2128
2111
|
if (options?.signal && abortHandler) {
|
|
2129
2112
|
options.signal.removeEventListener("abort", abortHandler);
|
|
2130
2113
|
}
|
|
2131
2114
|
}
|
|
2132
2115
|
}
|
|
2133
2116
|
};
|
|
2134
|
-
var NativeVerifyError = class extends Error {
|
|
2135
|
-
constructor(code) {
|
|
2136
|
-
super(code);
|
|
2137
|
-
this.code = code;
|
|
2138
|
-
}
|
|
2139
|
-
};
|
|
2140
2117
|
function nativeResultToIDKitResult(payload, config, signalHashes, legacySignalHash) {
|
|
2141
2118
|
const p = payload;
|
|
2142
2119
|
const rpNonce = config.rp_context?.nonce ?? "";
|