@0xarchive/sdk 0.9.1 → 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/README.md +104 -0
- package/dist/index.d.mts +164 -1
- package/dist/index.d.ts +164 -1
- package/dist/index.js +214 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +214 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
/**
|
|
@@ -1756,6 +1965,10 @@ var OxArchive = class {
|
|
|
1756
1965
|
* Data quality metrics: status, coverage, incidents, latency, SLA
|
|
1757
1966
|
*/
|
|
1758
1967
|
dataQuality;
|
|
1968
|
+
/**
|
|
1969
|
+
* Wallet-based auth: get API keys via SIWE signature
|
|
1970
|
+
*/
|
|
1971
|
+
web3;
|
|
1759
1972
|
/**
|
|
1760
1973
|
* @deprecated Use client.hyperliquid.orderbook instead
|
|
1761
1974
|
*/
|
|
@@ -1794,6 +2007,7 @@ var OxArchive = class {
|
|
|
1794
2007
|
this.hyperliquid = new HyperliquidClient(this.http);
|
|
1795
2008
|
this.lighter = new LighterClient(this.http);
|
|
1796
2009
|
this.dataQuality = new DataQualityResource(this.http);
|
|
2010
|
+
this.web3 = new Web3Resource(this.http);
|
|
1797
2011
|
const legacyBase = "/v1/hyperliquid";
|
|
1798
2012
|
this.orderbook = new OrderBookResource(this.http, legacyBase);
|
|
1799
2013
|
this.trades = new TradesResource(this.http, legacyBase);
|