1+ import type { ApiKey } from '@polymarket/bindings' ;
12import {
23 type ApiKeyCreds ,
34 ApiKeyCredsSchema ,
4- type ApiKeysResponse ,
55 ApiKeysResponseSchema ,
6+ type BuilderApiKey ,
7+ type BuilderApiKeyCreds ,
8+ BuilderApiKeyCredsSchema ,
9+ BuilderApiKeysResponseSchema ,
610} from '@polymarket/bindings/clob' ;
711import { type EvmAddress , type Signature , unwrap } from '@polymarket/types' ;
812import { z } from 'zod' ;
@@ -145,9 +149,7 @@ export type FetchApiKeysError =
145149 * @throws {@link FetchApiKeysError }
146150 * Thrown when request signing fails, or the request is rejected, rate limited, interrupted by transport issues, or returns an unexpected response.
147151 */
148- export async function fetchApiKeys (
149- client : SecureClient ,
150- ) : Promise < ApiKeysResponse [ 'apiKeys' ] > {
152+ export async function fetchApiKeys ( client : SecureClient ) : Promise < ApiKey [ ] > {
151153 const response = await unwrap (
152154 client . secureClob
153155 . get ( '/auth/api-keys' )
@@ -171,7 +173,9 @@ export type DeleteApiKeyError =
171173 * This is a low-level auth action that most SDK consumers will not need.
172174 *
173175 * @example
174- *
176+ * ```ts
177+ * await deleteApiKey(client);
178+ * ```
175179 *
176180 * @throws {@link DeleteApiKeyError }
177181 * Thrown when request signing fails, or the request is rejected, rate limited,
@@ -185,6 +189,100 @@ export async function deleteApiKey(client: SecureClient): Promise<void> {
185189 ) ;
186190}
187191
192+ export type CreateBuilderApiKeyError =
193+ | RateLimitError
194+ | RequestRejectedError
195+ | SigningError
196+ | TransportError
197+ | UnexpectedResponseError ;
198+
199+ /**
200+ * Creates a new builder API key for the authenticated client.
201+ *
202+ * @remarks
203+ * This is a low-level auth action that most SDK consumers will not need.
204+ *
205+ * @example
206+ * ```ts
207+ * const builderApiKey = await createBuilderApiKey(client);
208+ * ```
209+ *
210+ * @throws {@link CreateBuilderApiKeyError }
211+ * Thrown when request signing fails, or the request is rejected, rate limited,
212+ * interrupted by transport issues, or returns an unexpected response.
213+ */
214+ export async function createBuilderApiKey (
215+ client : SecureClient ,
216+ ) : Promise < BuilderApiKeyCreds > {
217+ return unwrap (
218+ client . secureClob
219+ . post ( '/auth/builder-api-key' )
220+ . andThen ( validateWith ( BuilderApiKeyCredsSchema ) ) ,
221+ ) ;
222+ }
223+
224+ export type FetchBuilderApiKeysError =
225+ | RateLimitError
226+ | RequestRejectedError
227+ | SigningError
228+ | TransportError
229+ | UnexpectedResponseError ;
230+
231+ /**
232+ * Fetches builder API keys associated with the authenticated client.
233+ *
234+ * @remarks
235+ * This is a low-level auth action that most SDK consumers will not need.
236+ *
237+ * @example
238+ * ```ts
239+ * const builderApiKeys = await fetchBuilderApiKeys(client);
240+ * ```
241+ *
242+ * @throws {@link FetchBuilderApiKeysError }
243+ * Thrown when request signing fails, or the request is rejected, rate limited,
244+ * interrupted by transport issues, or returns an unexpected response.
245+ */
246+ export async function fetchBuilderApiKeys (
247+ client : SecureClient ,
248+ ) : Promise < BuilderApiKey [ ] > {
249+ return unwrap (
250+ client . secureClob
251+ . get ( '/auth/builder-api-key' )
252+ . andThen ( validateWith ( BuilderApiKeysResponseSchema ) ) ,
253+ ) ;
254+ }
255+
256+ export type RevokeBuilderApiKeyError =
257+ | RateLimitError
258+ | RequestRejectedError
259+ | SigningError
260+ | TransportError
261+ | UnexpectedResponseError ;
262+
263+ /**
264+ * Revokes a builder API key.
265+ *
266+ * @remarks
267+ * This is a low-level auth action that most SDK consumers will not need.
268+ *
269+ * @example
270+ * ```ts
271+ * await revokeBuilderApiKey(client);
272+ * ```
273+ *
274+ * @throws {@link RevokeBuilderApiKeyError }
275+ * Thrown when request signing fails, or the request is rejected, rate limited,
276+ * interrupted by transport issues, or returns an unexpected response.
277+ */
278+ export async function revokeBuilderApiKey ( client : Client ) : Promise < void > {
279+ await unwrap (
280+ client . clob
281+ . del ( '/auth/builder-api-key' )
282+ . andThen ( validateWith ( z . literal ( 'OK' ) ) ) ,
283+ ) ;
284+ }
285+
188286function toL1Headers ( auth : ApiKeyAuthRequest ) : HeadersInit {
189287 return {
190288 POLY_ADDRESS : auth . address ,
0 commit comments