@0xarchive/sdk 0.9.0 → 0.9.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.
package/dist/index.d.ts CHANGED
@@ -363,6 +363,8 @@ interface Candle {
363
363
  interface CandleHistoryParams extends CursorPaginationParams {
364
364
  /** Candle interval (default: 1h) */
365
365
  interval?: CandleInterval;
366
+ /** Maximum number of results to return (default: 100, max: 10000 for candles) */
367
+ limit?: number;
366
368
  }
367
369
  /** Pre-aggregated liquidation volume bucket */
368
370
  interface LiquidationVolume {
@@ -734,6 +736,77 @@ interface WsEventHandlers {
734
736
  onMessage?: (message: WsServerMessage) => void;
735
737
  onStateChange?: (state: WsConnectionState) => void;
736
738
  }
739
+ /** SIWE challenge message returned by the challenge endpoint */
740
+ interface SiweChallenge {
741
+ /** The SIWE message to sign with personal_sign (EIP-191) */
742
+ message: string;
743
+ /** Single-use nonce (expires after 10 minutes) */
744
+ nonce: string;
745
+ }
746
+ /** Result of creating a free-tier account via wallet signature */
747
+ interface Web3SignupResult {
748
+ /** The generated API key */
749
+ apiKey: string;
750
+ /** Account tier (e.g., 'free') */
751
+ tier: string;
752
+ /** The wallet address that owns this key */
753
+ walletAddress: string;
754
+ }
755
+ /** An API key record returned by the keys endpoint */
756
+ interface Web3ApiKey {
757
+ /** Unique key ID (UUID) */
758
+ id: string;
759
+ /** Key name */
760
+ name: string;
761
+ /** First characters of the key for identification */
762
+ keyPrefix: string;
763
+ /** Whether the key is currently active */
764
+ isActive: boolean;
765
+ /** Last usage timestamp (ISO 8601) */
766
+ lastUsedAt?: string;
767
+ /** Creation timestamp (ISO 8601) */
768
+ createdAt: string;
769
+ }
770
+ /** List of API keys for a wallet */
771
+ interface Web3KeysList {
772
+ /** All API keys belonging to this wallet */
773
+ keys: Web3ApiKey[];
774
+ /** The wallet address */
775
+ walletAddress: string;
776
+ }
777
+ /** Result of revoking an API key */
778
+ interface Web3RevokeResult {
779
+ /** Confirmation message */
780
+ message: string;
781
+ /** The wallet address that owned the key */
782
+ walletAddress: string;
783
+ }
784
+ /** x402 payment details returned by subscribe (402 response) */
785
+ interface Web3PaymentRequired {
786
+ /** Amount in smallest unit (e.g., "49000000" for $49 USDC) */
787
+ amount: string;
788
+ /** Payment asset (e.g., "USDC") */
789
+ asset: string;
790
+ /** Blockchain network (e.g., "base") */
791
+ network: string;
792
+ /** Address to send payment to */
793
+ payTo: string;
794
+ /** Token contract address */
795
+ assetAddress: string;
796
+ }
797
+ /** Result of a successful x402 subscription */
798
+ interface Web3SubscribeResult {
799
+ /** The generated API key */
800
+ apiKey: string;
801
+ /** Subscription tier */
802
+ tier: string;
803
+ /** Expiration timestamp (ISO 8601) */
804
+ expiresAt: string;
805
+ /** The wallet address that owns the subscription */
806
+ walletAddress: string;
807
+ /** On-chain transaction hash */
808
+ txHash?: string;
809
+ }
737
810
  /**
738
811
  * API error response
739
812
  */
@@ -1049,6 +1122,10 @@ declare class HttpClient {
1049
1122
  constructor(options: HttpClientOptions);
1050
1123
  /** Whether validation is enabled */
1051
1124
  get validationEnabled(): boolean;
1125
+ /** Base URL for raw requests (used by web3 subscribe) */
1126
+ getBaseUrl(): string;
1127
+ /** Timeout in ms for raw requests (used by web3 subscribe) */
1128
+ getTimeout(): number;
1052
1129
  /**
1053
1130
  * Make a GET request to the API
1054
1131
  *
@@ -1057,6 +1134,14 @@ declare class HttpClient {
1057
1134
  * @param schema - Optional Zod schema for validation (used when validation is enabled)
1058
1135
  */
1059
1136
  get<T>(path: string, params?: Record<string, unknown>, schema?: z.ZodType<T>): Promise<T>;
1137
+ /**
1138
+ * Make a POST request to the API
1139
+ *
1140
+ * @param path - API endpoint path
1141
+ * @param body - JSON request body
1142
+ * @param schema - Optional Zod schema for validation (used when validation is enabled)
1143
+ */
1144
+ post<T>(path: string, body?: Record<string, unknown>, schema?: z.ZodType<T>): Promise<T>;
1060
1145
  }
1061
1146
 
1062
1147
  /**
@@ -1695,7 +1780,7 @@ declare class OpenInterestResource {
1695
1780
  * start: Date.now() - 86400000,
1696
1781
  * end: Date.now(),
1697
1782
  * interval: '1h',
1698
- * limit: 1000
1783
+ * limit: 10000
1699
1784
  * });
1700
1785
  *
1701
1786
  * // Get all pages
@@ -1706,7 +1791,7 @@ declare class OpenInterestResource {
1706
1791
  * end: Date.now(),
1707
1792
  * interval: '1h',
1708
1793
  * cursor: result.nextCursor,
1709
- * limit: 1000
1794
+ * limit: 10000
1710
1795
  * });
1711
1796
  * allCandles.push(...result.data);
1712
1797
  * }
@@ -1977,6 +2062,82 @@ declare class DataQualityResource {
1977
2062
  sla(params?: SlaParams): Promise<SlaResponse>;
1978
2063
  }
1979
2064
 
2065
+ /**
2066
+ * Wallet-based authentication: get API keys via SIWE signature.
2067
+ *
2068
+ * No API key is required for these endpoints. Use an Ethereum wallet to
2069
+ * create a free-tier account, list keys, or revoke keys — all programmatically.
2070
+ *
2071
+ * @example
2072
+ * ```typescript
2073
+ * const client = new OxArchive({ apiKey: 'placeholder' });
2074
+ *
2075
+ * // Step 1: Get a challenge
2076
+ * const challenge = await client.web3.challenge('0x742d35Cc6634C0532925a3b844Bc9e7595f2bD18');
2077
+ *
2078
+ * // Step 2: Sign the message with your wallet, then submit
2079
+ * const result = await client.web3.signup(challenge.message, signature);
2080
+ * console.log(`API key: ${result.apiKey}`);
2081
+ * ```
2082
+ */
2083
+ declare class Web3Resource {
2084
+ private http;
2085
+ constructor(http: HttpClient);
2086
+ /**
2087
+ * Get a SIWE challenge message to sign.
2088
+ *
2089
+ * @param address - Ethereum wallet address
2090
+ * @returns SIWE message and nonce. Sign the message with personal_sign (EIP-191).
2091
+ */
2092
+ challenge(address: string): Promise<SiweChallenge>;
2093
+ /**
2094
+ * Create a free-tier account and get an API key.
2095
+ *
2096
+ * @param message - The SIWE message from {@link challenge}
2097
+ * @param signature - Hex-encoded signature from personal_sign
2098
+ * @returns API key, tier, and wallet address
2099
+ */
2100
+ signup(message: string, signature: string): Promise<Web3SignupResult>;
2101
+ /**
2102
+ * List all API keys for the authenticated wallet.
2103
+ *
2104
+ * @param message - The SIWE message from {@link challenge}
2105
+ * @param signature - Hex-encoded signature from personal_sign
2106
+ * @returns List of API keys and wallet address
2107
+ */
2108
+ listKeys(message: string, signature: string): Promise<Web3KeysList>;
2109
+ /**
2110
+ * Revoke a specific API key.
2111
+ *
2112
+ * @param message - The SIWE message from {@link challenge}
2113
+ * @param signature - Hex-encoded signature from personal_sign
2114
+ * @param keyId - UUID of the key to revoke
2115
+ * @returns Confirmation message and wallet address
2116
+ */
2117
+ revokeKey(message: string, signature: string, keyId: string): Promise<Web3RevokeResult>;
2118
+ /**
2119
+ * Get pricing info for a paid subscription (x402 flow, step 1).
2120
+ *
2121
+ * Returns the payment details needed to sign a USDC transfer on Base.
2122
+ * After signing, pass the payment signature to {@link subscribe}.
2123
+ *
2124
+ * @param tier - Subscription tier: 'build' ($49/mo) or 'pro' ($199/mo)
2125
+ * @returns Payment details (amount, asset, network, pay-to address)
2126
+ */
2127
+ subscribeQuote(tier: 'build' | 'pro'): Promise<Web3PaymentRequired>;
2128
+ /**
2129
+ * Complete a paid subscription with a signed x402 payment (step 2).
2130
+ *
2131
+ * Requires a payment signature from signing a USDC transfer (EIP-3009)
2132
+ * for the amount returned by {@link subscribeQuote}.
2133
+ *
2134
+ * @param tier - Subscription tier: 'build' or 'pro'
2135
+ * @param paymentSignature - Signed x402 payment (from EIP-3009 USDC transfer on Base)
2136
+ * @returns API key, tier, expiration, and wallet address
2137
+ */
2138
+ subscribe(tier: 'build' | 'pro', paymentSignature: string): Promise<Web3SubscribeResult>;
2139
+ }
2140
+
1980
2141
  /**
1981
2142
  * Hyperliquid exchange client
1982
2143
  *
@@ -2085,7 +2246,30 @@ declare class Hip3Client {
2085
2246
  * OHLCV candle data
2086
2247
  */
2087
2248
  readonly candles: CandlesResource;
2249
+ private http;
2088
2250
  constructor(http: HttpClient);
2251
+ /**
2252
+ * Get per-coin data freshness across all data types
2253
+ *
2254
+ * @param coin - The coin symbol (case-sensitive, e.g., 'km:US500')
2255
+ * @returns Per-coin freshness with last_updated and lag_ms for each data type
2256
+ */
2257
+ freshness(coin: string): Promise<CoinFreshness>;
2258
+ /**
2259
+ * Get combined market summary (price, funding, OI) in one call
2260
+ *
2261
+ * @param coin - The coin symbol (case-sensitive, e.g., 'km:US500')
2262
+ * @returns Combined market summary
2263
+ */
2264
+ summary(coin: string): Promise<CoinSummary>;
2265
+ /**
2266
+ * Get mark/oracle/mid price history (projected from OI data)
2267
+ *
2268
+ * @param coin - The coin symbol (case-sensitive, e.g., 'km:US500')
2269
+ * @param params - Time range, cursor, and interval parameters
2270
+ * @returns CursorResponse with price snapshots
2271
+ */
2272
+ priceHistory(coin: string, params: PriceHistoryParams): Promise<CursorResponse<PriceSnapshot[]>>;
2089
2273
  }
2090
2274
  /**
2091
2275
  * Lighter.xyz exchange client
@@ -2126,7 +2310,30 @@ declare class LighterClient {
2126
2310
  * OHLCV candle data
2127
2311
  */
2128
2312
  readonly candles: CandlesResource;
2313
+ private http;
2129
2314
  constructor(http: HttpClient);
2315
+ /**
2316
+ * Get per-coin data freshness across all data types
2317
+ *
2318
+ * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
2319
+ * @returns Per-coin freshness with last_updated and lag_ms for each data type
2320
+ */
2321
+ freshness(coin: string): Promise<CoinFreshness>;
2322
+ /**
2323
+ * Get combined market summary (price, funding, OI) in one call
2324
+ *
2325
+ * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
2326
+ * @returns Combined market summary
2327
+ */
2328
+ summary(coin: string): Promise<CoinSummary>;
2329
+ /**
2330
+ * Get mark/oracle price history (projected from OI data)
2331
+ *
2332
+ * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
2333
+ * @param params - Time range, cursor, and interval parameters
2334
+ * @returns CursorResponse with price snapshots
2335
+ */
2336
+ priceHistory(coin: string, params: PriceHistoryParams): Promise<CursorResponse<PriceSnapshot[]>>;
2130
2337
  }
2131
2338
 
2132
2339
  /**
@@ -2180,6 +2387,10 @@ declare class OxArchive {
2180
2387
  * Data quality metrics: status, coverage, incidents, latency, SLA
2181
2388
  */
2182
2389
  readonly dataQuality: DataQualityResource;
2390
+ /**
2391
+ * Wallet-based auth: get API keys via SIWE signature
2392
+ */
2393
+ readonly web3: Web3Resource;
2183
2394
  /**
2184
2395
  * @deprecated Use client.hyperliquid.orderbook instead
2185
2396
  */
@@ -5032,4 +5243,4 @@ type ValidatedCandle = z.infer<typeof CandleSchema>;
5032
5243
  type ValidatedLiquidation = z.infer<typeof LiquidationSchema>;
5033
5244
  type ValidatedWsServerMessage = z.infer<typeof WsServerMessageSchema>;
5034
5245
 
5035
- export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type Candle, CandleArrayResponseSchema, type CandleHistoryParams, type CandleInterval, CandleIntervalSchema, CandleSchema, type ClientOptions, type CoinFreshness, CoinFreshnessResponseSchema, CoinFreshnessSchema, type CoinSummary, CoinSummaryResponseSchema, CoinSummarySchema, type CompletenessMetrics, type CoverageGap, type CoverageResponse, type CursorResponse, type DataCadence, type DataFreshness, type DataTypeCoverage, type DataTypeFreshnessInfo, DataTypeFreshnessInfoSchema, type DataTypeStatus, type ExchangeCoverage, type ExchangeLatency, type ExchangeStatus, type FundingHistoryParams, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, Hip3Client, type Hip3Instrument, HyperliquidClient, type Incident, type IncidentSeverityValue, type IncidentStatusValue, type IncidentsResponse, type Instrument, InstrumentArrayResponseSchema, InstrumentResponseSchema, InstrumentSchema, type InstrumentType, InstrumentTypeSchema, type LatencyResponse, LighterClient, type LighterGranularity, type LighterInstrument, type Liquidation, LiquidationArrayResponseSchema, type LiquidationHistoryParams, LiquidationSchema, LiquidationSideSchema, type LiquidationVolume, LiquidationVolumeArrayResponseSchema, type LiquidationVolumeParams, LiquidationVolumeSchema, type LiquidationsByUserParams, type ListIncidentsParams, type OiFundingInterval, type OpenInterest, OpenInterestArrayResponseSchema, type OpenInterestHistoryParams, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookReconstructor, OrderBookResponseSchema, OrderBookSchema, type OrderbookDelta, OxArchive, OxArchiveError, OxArchiveWs, type Pagination, type PriceHistoryParams, type PriceLevel, PriceLevelSchema, type PriceSnapshot, PriceSnapshotArrayResponseSchema, PriceSnapshotSchema, type ReconstructOptions, type ReconstructedOrderBook, type RestApiLatency, type SlaActual, type SlaParams, type SlaResponse, type SlaTargets, type StatusResponse, type SymbolCoverageOptions, type SymbolCoverageResponse, type SymbolDataTypeCoverage, type SystemStatusValue, type TickData, type TickHistoryParams, type Timestamp, type TimestampedRecord, TimestampedRecordSchema, type Trade, TradeArrayResponseSchema, type TradeDirection, TradeDirectionSchema, TradeSchema, type TradeSide, TradeSideSchema, type ValidatedApiMeta, type ValidatedCandle, type ValidatedFundingRate, type ValidatedInstrument, type ValidatedLiquidation, type ValidatedOpenInterest, type ValidatedOrderBook, type ValidatedPriceLevel, type ValidatedTrade, type ValidatedWsServerMessage, type WebSocketLatency, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsGapDetected, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsHistoricalTickData, type WsOptions, type WsPing, type WsPong, WsPongSchema, type WsReplay, type WsReplayCompleted, WsReplayCompletedSchema, type WsReplayPause, type WsReplayPaused, WsReplayPausedSchema, type WsReplayResume, type WsReplayResumed, WsReplayResumedSchema, type WsReplaySeek, type WsReplaySnapshot, WsReplaySnapshotSchema, type WsReplayStarted, WsReplayStartedSchema, type WsReplayStop, type WsReplayStopped, WsReplayStoppedSchema, type WsServerMessage, WsServerMessageSchema, type WsStream, type WsStreamCompleted, WsStreamCompletedSchema, type WsStreamProgress, WsStreamProgressSchema, type WsStreamStarted, WsStreamStartedSchema, type WsStreamStop, type WsStreamStopped, WsStreamStoppedSchema, type WsSubscribe, type WsSubscribed, WsSubscribedSchema, type WsUnsubscribe, type WsUnsubscribed, WsUnsubscribedSchema, OxArchive as default, reconstructFinal, reconstructOrderBook };
5246
+ export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type Candle, CandleArrayResponseSchema, type CandleHistoryParams, type CandleInterval, CandleIntervalSchema, CandleSchema, type ClientOptions, type CoinFreshness, CoinFreshnessResponseSchema, CoinFreshnessSchema, type CoinSummary, CoinSummaryResponseSchema, CoinSummarySchema, type CompletenessMetrics, type CoverageGap, type CoverageResponse, type CursorResponse, type DataCadence, type DataFreshness, type DataTypeCoverage, type DataTypeFreshnessInfo, DataTypeFreshnessInfoSchema, type DataTypeStatus, type ExchangeCoverage, type ExchangeLatency, type ExchangeStatus, type FundingHistoryParams, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, Hip3Client, type Hip3Instrument, HyperliquidClient, type Incident, type IncidentSeverityValue, type IncidentStatusValue, type IncidentsResponse, type Instrument, InstrumentArrayResponseSchema, InstrumentResponseSchema, InstrumentSchema, type InstrumentType, InstrumentTypeSchema, type LatencyResponse, LighterClient, type LighterGranularity, type LighterInstrument, type Liquidation, LiquidationArrayResponseSchema, type LiquidationHistoryParams, LiquidationSchema, LiquidationSideSchema, type LiquidationVolume, LiquidationVolumeArrayResponseSchema, type LiquidationVolumeParams, LiquidationVolumeSchema, type LiquidationsByUserParams, type ListIncidentsParams, type OiFundingInterval, type OpenInterest, OpenInterestArrayResponseSchema, type OpenInterestHistoryParams, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookReconstructor, OrderBookResponseSchema, OrderBookSchema, type OrderbookDelta, OxArchive, OxArchiveError, OxArchiveWs, type Pagination, type PriceHistoryParams, type PriceLevel, PriceLevelSchema, type PriceSnapshot, PriceSnapshotArrayResponseSchema, PriceSnapshotSchema, type ReconstructOptions, type ReconstructedOrderBook, type RestApiLatency, type SiweChallenge, type SlaActual, type SlaParams, type SlaResponse, type SlaTargets, type StatusResponse, type SymbolCoverageOptions, type SymbolCoverageResponse, type SymbolDataTypeCoverage, type SystemStatusValue, type TickData, type TickHistoryParams, type Timestamp, type TimestampedRecord, TimestampedRecordSchema, type Trade, TradeArrayResponseSchema, type TradeDirection, TradeDirectionSchema, TradeSchema, type TradeSide, TradeSideSchema, type ValidatedApiMeta, type ValidatedCandle, type ValidatedFundingRate, type ValidatedInstrument, type ValidatedLiquidation, type ValidatedOpenInterest, type ValidatedOrderBook, type ValidatedPriceLevel, type ValidatedTrade, type ValidatedWsServerMessage, type Web3ApiKey, type Web3KeysList, type Web3PaymentRequired, type Web3RevokeResult, type Web3SignupResult, type Web3SubscribeResult, type WebSocketLatency, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsGapDetected, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsHistoricalTickData, type WsOptions, type WsPing, type WsPong, WsPongSchema, type WsReplay, type WsReplayCompleted, WsReplayCompletedSchema, type WsReplayPause, type WsReplayPaused, WsReplayPausedSchema, type WsReplayResume, type WsReplayResumed, WsReplayResumedSchema, type WsReplaySeek, type WsReplaySnapshot, WsReplaySnapshotSchema, type WsReplayStarted, WsReplayStartedSchema, type WsReplayStop, type WsReplayStopped, WsReplayStoppedSchema, type WsServerMessage, WsServerMessageSchema, type WsStream, type WsStreamCompleted, WsStreamCompletedSchema, type WsStreamProgress, WsStreamProgressSchema, type WsStreamStarted, WsStreamStartedSchema, type WsStreamStop, type WsStreamStopped, WsStreamStoppedSchema, type WsSubscribe, type WsSubscribed, WsSubscribedSchema, type WsUnsubscribe, type WsUnsubscribed, WsUnsubscribedSchema, OxArchive as default, reconstructFinal, reconstructOrderBook };
package/dist/index.js CHANGED
@@ -136,6 +136,14 @@ var HttpClient = class {
136
136
  get validationEnabled() {
137
137
  return this.validate;
138
138
  }
139
+ /** Base URL for raw requests (used by web3 subscribe) */
140
+ getBaseUrl() {
141
+ return this.baseUrl;
142
+ }
143
+ /** Timeout in ms for raw requests (used by web3 subscribe) */
144
+ getTimeout() {
145
+ return this.timeout;
146
+ }
139
147
  /**
140
148
  * Make a GET request to the API
141
149
  *
@@ -206,6 +214,66 @@ var HttpClient = class {
206
214
  );
207
215
  }
208
216
  }
217
+ /**
218
+ * Make a POST request to the API
219
+ *
220
+ * @param path - API endpoint path
221
+ * @param body - JSON request body
222
+ * @param schema - Optional Zod schema for validation (used when validation is enabled)
223
+ */
224
+ async post(path, body, schema) {
225
+ const url = `${this.baseUrl}${path}`;
226
+ const controller = new AbortController();
227
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
228
+ try {
229
+ const response = await fetch(url, {
230
+ method: "POST",
231
+ headers: {
232
+ "X-API-Key": this.apiKey,
233
+ "Content-Type": "application/json"
234
+ },
235
+ body: body ? JSON.stringify(body) : void 0,
236
+ signal: controller.signal
237
+ });
238
+ clearTimeout(timeoutId);
239
+ const rawData = await response.json();
240
+ const data = transformKeys(rawData);
241
+ if (!response.ok) {
242
+ const error = data;
243
+ const apiResponse = data;
244
+ throw new OxArchiveError(
245
+ error.error || `Request failed with status ${response.status}`,
246
+ response.status,
247
+ apiResponse.meta?.requestId
248
+ );
249
+ }
250
+ if (this.validate && schema) {
251
+ const result = schema.safeParse(data);
252
+ if (!result.success) {
253
+ const apiResponse = data;
254
+ throw new OxArchiveError(
255
+ `Response validation failed: ${result.error.message}`,
256
+ 422,
257
+ apiResponse.meta?.requestId
258
+ );
259
+ }
260
+ return result.data;
261
+ }
262
+ return data;
263
+ } catch (error) {
264
+ clearTimeout(timeoutId);
265
+ if (error instanceof OxArchiveError) {
266
+ throw error;
267
+ }
268
+ if (error instanceof Error && error.name === "AbortError") {
269
+ throw new OxArchiveError(`Request timeout after ${this.timeout}ms`, 408);
270
+ }
271
+ throw new OxArchiveError(
272
+ error instanceof Error ? error.message : "Unknown error",
273
+ 500
274
+ );
275
+ }
276
+ }
209
277
  };
210
278
 
211
279
  // src/schemas.ts
@@ -1477,6 +1545,147 @@ var DataQualityResource = class {
1477
1545
  }
1478
1546
  };
1479
1547
 
1548
+ // src/resources/web3.ts
1549
+ var Web3Resource = class {
1550
+ constructor(http) {
1551
+ this.http = http;
1552
+ }
1553
+ /**
1554
+ * Get a SIWE challenge message to sign.
1555
+ *
1556
+ * @param address - Ethereum wallet address
1557
+ * @returns SIWE message and nonce. Sign the message with personal_sign (EIP-191).
1558
+ */
1559
+ async challenge(address) {
1560
+ return this.http.post("/v1/auth/web3/challenge", { address });
1561
+ }
1562
+ /**
1563
+ * Create a free-tier account and get an API key.
1564
+ *
1565
+ * @param message - The SIWE message from {@link challenge}
1566
+ * @param signature - Hex-encoded signature from personal_sign
1567
+ * @returns API key, tier, and wallet address
1568
+ */
1569
+ async signup(message, signature) {
1570
+ return this.http.post("/v1/web3/signup", { message, signature });
1571
+ }
1572
+ /**
1573
+ * List all API keys for the authenticated wallet.
1574
+ *
1575
+ * @param message - The SIWE message from {@link challenge}
1576
+ * @param signature - Hex-encoded signature from personal_sign
1577
+ * @returns List of API keys and wallet address
1578
+ */
1579
+ async listKeys(message, signature) {
1580
+ return this.http.post("/v1/web3/keys", { message, signature });
1581
+ }
1582
+ /**
1583
+ * Revoke a specific API key.
1584
+ *
1585
+ * @param message - The SIWE message from {@link challenge}
1586
+ * @param signature - Hex-encoded signature from personal_sign
1587
+ * @param keyId - UUID of the key to revoke
1588
+ * @returns Confirmation message and wallet address
1589
+ */
1590
+ async revokeKey(message, signature, keyId) {
1591
+ return this.http.post("/v1/web3/keys/revoke", {
1592
+ message,
1593
+ signature,
1594
+ key_id: keyId
1595
+ });
1596
+ }
1597
+ /**
1598
+ * Get pricing info for a paid subscription (x402 flow, step 1).
1599
+ *
1600
+ * Returns the payment details needed to sign a USDC transfer on Base.
1601
+ * After signing, pass the payment signature to {@link subscribe}.
1602
+ *
1603
+ * @param tier - Subscription tier: 'build' ($49/mo) or 'pro' ($199/mo)
1604
+ * @returns Payment details (amount, asset, network, pay-to address)
1605
+ */
1606
+ async subscribeQuote(tier) {
1607
+ const url = `${this.http.getBaseUrl()}/v1/web3/subscribe`;
1608
+ const timeout = this.http.getTimeout();
1609
+ const controller = new AbortController();
1610
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
1611
+ try {
1612
+ const response = await fetch(url, {
1613
+ method: "POST",
1614
+ headers: { "Content-Type": "application/json" },
1615
+ body: JSON.stringify({ tier }),
1616
+ signal: controller.signal
1617
+ });
1618
+ clearTimeout(timeoutId);
1619
+ const rawData = await response.json();
1620
+ const data = transformKeys(rawData);
1621
+ if (response.status === 402) {
1622
+ return data.payment;
1623
+ }
1624
+ throw new OxArchiveError(
1625
+ data.error || `Unexpected status ${response.status}`,
1626
+ response.status
1627
+ );
1628
+ } catch (error) {
1629
+ clearTimeout(timeoutId);
1630
+ if (error instanceof OxArchiveError) throw error;
1631
+ if (error instanceof Error && error.name === "AbortError") {
1632
+ throw new OxArchiveError(`Request timeout after ${timeout}ms`, 408);
1633
+ }
1634
+ throw new OxArchiveError(
1635
+ error instanceof Error ? error.message : "Unknown error",
1636
+ 500
1637
+ );
1638
+ }
1639
+ }
1640
+ /**
1641
+ * Complete a paid subscription with a signed x402 payment (step 2).
1642
+ *
1643
+ * Requires a payment signature from signing a USDC transfer (EIP-3009)
1644
+ * for the amount returned by {@link subscribeQuote}.
1645
+ *
1646
+ * @param tier - Subscription tier: 'build' or 'pro'
1647
+ * @param paymentSignature - Signed x402 payment (from EIP-3009 USDC transfer on Base)
1648
+ * @returns API key, tier, expiration, and wallet address
1649
+ */
1650
+ async subscribe(tier, paymentSignature) {
1651
+ const url = `${this.http.getBaseUrl()}/v1/web3/subscribe`;
1652
+ const timeout = this.http.getTimeout();
1653
+ const controller = new AbortController();
1654
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
1655
+ try {
1656
+ const response = await fetch(url, {
1657
+ method: "POST",
1658
+ headers: {
1659
+ "Content-Type": "application/json",
1660
+ "payment-signature": paymentSignature
1661
+ },
1662
+ body: JSON.stringify({ tier }),
1663
+ signal: controller.signal
1664
+ });
1665
+ clearTimeout(timeoutId);
1666
+ const rawData = await response.json();
1667
+ const data = transformKeys(rawData);
1668
+ if (!response.ok) {
1669
+ throw new OxArchiveError(
1670
+ data.error || "Subscribe failed",
1671
+ response.status
1672
+ );
1673
+ }
1674
+ return data;
1675
+ } catch (error) {
1676
+ clearTimeout(timeoutId);
1677
+ if (error instanceof OxArchiveError) throw error;
1678
+ if (error instanceof Error && error.name === "AbortError") {
1679
+ throw new OxArchiveError(`Request timeout after ${timeout}ms`, 408);
1680
+ }
1681
+ throw new OxArchiveError(
1682
+ error instanceof Error ? error.message : "Unknown error",
1683
+ 500
1684
+ );
1685
+ }
1686
+ }
1687
+ };
1688
+
1480
1689
  // src/exchanges.ts
1481
1690
  var HyperliquidClient = class {
1482
1691
  /**
@@ -1596,7 +1805,9 @@ var Hip3Client = class {
1596
1805
  * OHLCV candle data
1597
1806
  */
1598
1807
  candles;
1808
+ http;
1599
1809
  constructor(http) {
1810
+ this.http = http;
1600
1811
  const basePath = "/v1/hyperliquid/hip3";
1601
1812
  const coinTransform = (c) => c;
1602
1813
  this.instruments = new Hip3InstrumentsResource(http, basePath, coinTransform);
@@ -1606,6 +1817,52 @@ var Hip3Client = class {
1606
1817
  this.openInterest = new OpenInterestResource(http, basePath, coinTransform);
1607
1818
  this.candles = new CandlesResource(http, basePath, coinTransform);
1608
1819
  }
1820
+ /**
1821
+ * Get per-coin data freshness across all data types
1822
+ *
1823
+ * @param coin - The coin symbol (case-sensitive, e.g., 'km:US500')
1824
+ * @returns Per-coin freshness with last_updated and lag_ms for each data type
1825
+ */
1826
+ async freshness(coin) {
1827
+ const response = await this.http.get(
1828
+ `/v1/hyperliquid/hip3/freshness/${coin}`,
1829
+ void 0,
1830
+ this.http.validationEnabled ? CoinFreshnessResponseSchema : void 0
1831
+ );
1832
+ return response.data;
1833
+ }
1834
+ /**
1835
+ * Get combined market summary (price, funding, OI) in one call
1836
+ *
1837
+ * @param coin - The coin symbol (case-sensitive, e.g., 'km:US500')
1838
+ * @returns Combined market summary
1839
+ */
1840
+ async summary(coin) {
1841
+ const response = await this.http.get(
1842
+ `/v1/hyperliquid/hip3/summary/${coin}`,
1843
+ void 0,
1844
+ this.http.validationEnabled ? CoinSummaryResponseSchema : void 0
1845
+ );
1846
+ return response.data;
1847
+ }
1848
+ /**
1849
+ * Get mark/oracle/mid price history (projected from OI data)
1850
+ *
1851
+ * @param coin - The coin symbol (case-sensitive, e.g., 'km:US500')
1852
+ * @param params - Time range, cursor, and interval parameters
1853
+ * @returns CursorResponse with price snapshots
1854
+ */
1855
+ async priceHistory(coin, params) {
1856
+ const response = await this.http.get(
1857
+ `/v1/hyperliquid/hip3/prices/${coin}`,
1858
+ params,
1859
+ this.http.validationEnabled ? PriceSnapshotArrayResponseSchema : void 0
1860
+ );
1861
+ return {
1862
+ data: response.data,
1863
+ nextCursor: response.meta.nextCursor
1864
+ };
1865
+ }
1609
1866
  };
1610
1867
  var LighterClient = class {
1611
1868
  /**
@@ -1632,7 +1889,9 @@ var LighterClient = class {
1632
1889
  * OHLCV candle data
1633
1890
  */
1634
1891
  candles;
1892
+ http;
1635
1893
  constructor(http) {
1894
+ this.http = http;
1636
1895
  const basePath = "/v1/lighter";
1637
1896
  this.orderbook = new OrderBookResource(http, basePath);
1638
1897
  this.trades = new TradesResource(http, basePath);
@@ -1641,6 +1900,52 @@ var LighterClient = class {
1641
1900
  this.openInterest = new OpenInterestResource(http, basePath);
1642
1901
  this.candles = new CandlesResource(http, basePath);
1643
1902
  }
1903
+ /**
1904
+ * Get per-coin data freshness across all data types
1905
+ *
1906
+ * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1907
+ * @returns Per-coin freshness with last_updated and lag_ms for each data type
1908
+ */
1909
+ async freshness(coin) {
1910
+ const response = await this.http.get(
1911
+ `/v1/lighter/freshness/${coin.toUpperCase()}`,
1912
+ void 0,
1913
+ this.http.validationEnabled ? CoinFreshnessResponseSchema : void 0
1914
+ );
1915
+ return response.data;
1916
+ }
1917
+ /**
1918
+ * Get combined market summary (price, funding, OI) in one call
1919
+ *
1920
+ * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1921
+ * @returns Combined market summary
1922
+ */
1923
+ async summary(coin) {
1924
+ const response = await this.http.get(
1925
+ `/v1/lighter/summary/${coin.toUpperCase()}`,
1926
+ void 0,
1927
+ this.http.validationEnabled ? CoinSummaryResponseSchema : void 0
1928
+ );
1929
+ return response.data;
1930
+ }
1931
+ /**
1932
+ * Get mark/oracle price history (projected from OI data)
1933
+ *
1934
+ * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1935
+ * @param params - Time range, cursor, and interval parameters
1936
+ * @returns CursorResponse with price snapshots
1937
+ */
1938
+ async priceHistory(coin, params) {
1939
+ const response = await this.http.get(
1940
+ `/v1/lighter/prices/${coin.toUpperCase()}`,
1941
+ params,
1942
+ this.http.validationEnabled ? PriceSnapshotArrayResponseSchema : void 0
1943
+ );
1944
+ return {
1945
+ data: response.data,
1946
+ nextCursor: response.meta.nextCursor
1947
+ };
1948
+ }
1644
1949
  };
1645
1950
 
1646
1951
  // src/client.ts
@@ -1660,6 +1965,10 @@ var OxArchive = class {
1660
1965
  * Data quality metrics: status, coverage, incidents, latency, SLA
1661
1966
  */
1662
1967
  dataQuality;
1968
+ /**
1969
+ * Wallet-based auth: get API keys via SIWE signature
1970
+ */
1971
+ web3;
1663
1972
  /**
1664
1973
  * @deprecated Use client.hyperliquid.orderbook instead
1665
1974
  */
@@ -1698,6 +2007,7 @@ var OxArchive = class {
1698
2007
  this.hyperliquid = new HyperliquidClient(this.http);
1699
2008
  this.lighter = new LighterClient(this.http);
1700
2009
  this.dataQuality = new DataQualityResource(this.http);
2010
+ this.web3 = new Web3Resource(this.http);
1701
2011
  const legacyBase = "/v1/hyperliquid";
1702
2012
  this.orderbook = new OrderBookResource(this.http, legacyBase);
1703
2013
  this.trades = new TradesResource(this.http, legacyBase);