1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;
pub struct PasskeysClient {
pub http_client: HttpClient,
}
impl PasskeysClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
/// Lists the authenticated user's own passkeys, newest first. The list is always the caller's own; there is no parameter for reading another user's passkeys. Requires a user session: an API key or an OAuth token is refused, because a passkey confirms the account holder before a sensitive action and no app may enumerate one.
///
/// # Arguments
///
/// * `first` - The number of passkeys to return (default 20, max 100).
/// * `after` - A cursor; returns passkeys after this position.
/// * `last` - The number of passkeys to return from the end of the range.
/// * `before` - A cursor; returns passkeys before this position.
/// * `order` - The field to sort passkeys by.
/// * `direction` - Sort direction.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .users
/// .passkeys
/// .list(
/// &UsersPasskeysListQueryRequest {
/// ..Default::default()
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn list(
&self,
request: &UsersPasskeysListQueryRequest,
options: Option<RequestOptions>,
) -> Result<ListPasskeysResponse, ApiError> {
let options = {
let mut o = options.unwrap_or_default();
o.additional_headers
.entry("Api-Version-Date".to_string())
.or_insert_with(|| "2026-08-21-1".to_string());
Some(o)
};
self.http_client
.execute_request(
Method::GET,
"users/me/passkeys",
None,
QueryBuilder::new()
.int("first", request.first.clone())
.string("after", request.after.clone())
.int("last", request.last.clone())
.string("before", request.before.clone())
.serialize("order", request.order.clone())
.serialize("direction", request.direction.clone())
.build(),
options,
)
.await
}
/// Registers a passkey for the authenticated user from the attestation a browser produced for a `registration` challenge. Mint that challenge first with `POST /users/me/passkeys/challenge`; it is single-use and expires 5 minutes after it is issued. Requires a user session.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .users
/// .passkeys
/// .create(
/// &CreatePasskeysRequest {
/// attestation_object: "YXR0ZXN0YXRpb24".to_string(),
/// client_data_json: "Y2xpZW50LWRhdGE".to_string(),
/// credential_id: "bmV3LWNyZWRlbnRpYWw".to_string(),
/// nickname: "Work laptop".to_string(),
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn create(
&self,
request: &CreatePasskeysRequest,
options: Option<RequestOptions>,
) -> Result<Passkey, ApiError> {
let options = {
let mut o = options.unwrap_or_default();
o.additional_headers
.entry("Api-Version-Date".to_string())
.or_insert_with(|| "2026-08-21-1".to_string());
Some(o)
};
self.http_client
.execute_request(
Method::POST,
"users/me/passkeys",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Mints the challenge a browser needs to run a WebAuthn ceremony against the authenticated user's own passkeys. A `registration` challenge enrolls a new passkey; a `deletion` challenge is bound to the one passkey named by `passkey_id` and proves the user still holds it. Challenges are single-use and expire 5 minutes after they are issued, so send a fresh `Idempotency-Key` per ceremony — a replayed key returns the original challenge, which may already have expired. Requires a user session.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .users
/// .passkeys
/// .challenge(
/// &ChallengePasskeysRequest {
/// challenge_type: ChallengePasskeysRequestChallengeType::Registration,
/// passkey_id: None,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn challenge(
&self,
request: &ChallengePasskeysRequest,
options: Option<RequestOptions>,
) -> Result<ChallengePasskeysResponse, ApiError> {
let options = {
let mut o = options.unwrap_or_default();
o.additional_headers
.entry("Api-Version-Date".to_string())
.or_insert_with(|| "2026-08-21-1".to_string());
Some(o)
};
self.http_client
.execute_request(
Method::POST,
"users/me/passkeys/challenge",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Deletes one of the authenticated user's own passkeys. The request body carries a WebAuthn assertion from the passkey being deleted, so possession of the credential is proven before it is removed: mint a `deletion` challenge for it first, run the ceremony with that passkey, and send the result here. Deleting the user's last passkey is allowed — their other step-up factors remain. Requires a user session.
///
/// # Arguments
///
/// * `id` - Passkey ID, prefixed `wcred_`.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .users
/// .passkeys
/// .delete(
/// &"id".to_string(),
/// &DeletePasskeysRequest {
/// authenticator_data: "YXV0aGVudGljYXRvci1kYXRh".to_string(),
/// client_data_json: "Y2xpZW50LWRhdGE".to_string(),
/// signature: "c2lnbmF0dXJl".to_string(),
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn delete(
&self,
id: &str,
request: &DeletePasskeysRequest,
options: Option<RequestOptions>,
) -> Result<DeletePasskeysResponse, ApiError> {
let options = {
let mut o = options.unwrap_or_default();
o.additional_headers
.entry("Api-Version-Date".to_string())
.or_insert_with(|| "2026-08-21-1".to_string());
Some(o)
};
self.http_client
.execute_request(
Method::DELETE,
&format!("users/me/passkeys/{}", id),
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
}