@chainstream-io/sdk 2.0.7 → 2.0.9
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/{chainstream-CB6yyvSf.d.cts → chainstream-LmorAvq7.d.cts} +40 -1
- package/dist/{chainstream-CB6yyvSf.d.ts → chainstream-LmorAvq7.d.ts} +40 -1
- package/dist/chainstream.cjs +36 -3
- package/dist/chainstream.cjs.map +1 -1
- package/dist/chainstream.d.cts +1 -1
- package/dist/chainstream.d.ts +1 -1
- package/dist/chainstream.mjs +36 -3
- package/dist/chainstream.mjs.map +1 -1
- package/dist/index.cjs +40 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +38 -3
- package/dist/index.mjs.map +1 -1
- package/dist/stream/index.d.cts +1 -1
- package/dist/stream/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/chainstream.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { C as ChainStreamClient, y as ChainStreamClientOptions, z as ChainStreamRequestContext,
|
|
1
|
+
export { C as ChainStreamClient, y as ChainStreamClientOptions, z as ChainStreamRequestContext, gI as PostOptions, T as TokenProvider } from './chainstream-LmorAvq7.cjs';
|
|
2
2
|
import 'axios';
|
package/dist/chainstream.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { C as ChainStreamClient, y as ChainStreamClientOptions, z as ChainStreamRequestContext,
|
|
1
|
+
export { C as ChainStreamClient, y as ChainStreamClientOptions, z as ChainStreamRequestContext, gI as PostOptions, T as TokenProvider } from './chainstream-LmorAvq7.js';
|
|
2
2
|
import 'axios';
|
package/dist/chainstream.mjs
CHANGED
|
@@ -12,6 +12,28 @@ import { EventSourcePolyfill } from "event-source-polyfill";
|
|
|
12
12
|
// src/openapi-client/chainstreamApiClient.ts
|
|
13
13
|
import Axios from "axios";
|
|
14
14
|
import axiosRetryImport, { exponentialDelay } from "axios-retry";
|
|
15
|
+
|
|
16
|
+
// src/wallet-auth.ts
|
|
17
|
+
import { randomBytes } from "crypto";
|
|
18
|
+
var SIGNATURE_PREFIX = "chainstream";
|
|
19
|
+
function buildSignMessage(chain, address, timestamp, nonce) {
|
|
20
|
+
return `${SIGNATURE_PREFIX}:${chain}:${address}:${timestamp}:${nonce}`;
|
|
21
|
+
}
|
|
22
|
+
async function createWalletAuthHeaders(signer) {
|
|
23
|
+
const timestamp = Math.floor(Date.now() / 1e3).toString();
|
|
24
|
+
const nonce = randomBytes(16).toString("hex");
|
|
25
|
+
const message = buildSignMessage(signer.chain, signer.address, timestamp, nonce);
|
|
26
|
+
const signature = await signer.signMessage(message);
|
|
27
|
+
return {
|
|
28
|
+
"X-Wallet-Address": signer.address,
|
|
29
|
+
"X-Wallet-Chain": signer.chain,
|
|
30
|
+
"X-Wallet-Signature": signature,
|
|
31
|
+
"X-Wallet-Timestamp": timestamp,
|
|
32
|
+
"X-Wallet-Nonce": nonce
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/openapi-client/chainstreamApiClient.ts
|
|
15
37
|
var axiosRetry = typeof axiosRetryImport === "function" ? axiosRetryImport : axiosRetryImport.default;
|
|
16
38
|
var axiosInstance;
|
|
17
39
|
var currentOptions = void 0;
|
|
@@ -28,8 +50,17 @@ var configure = (options) => {
|
|
|
28
50
|
retryDelay: exponentialDelay
|
|
29
51
|
});
|
|
30
52
|
axiosInstance.interceptors.request.use(async (config) => {
|
|
31
|
-
|
|
32
|
-
|
|
53
|
+
if (options.walletSigner) {
|
|
54
|
+
const walletHeaders = await createWalletAuthHeaders(options.walletSigner);
|
|
55
|
+
Object.entries(walletHeaders).forEach(([key, value]) => {
|
|
56
|
+
config.headers[key] = value;
|
|
57
|
+
});
|
|
58
|
+
} else if (options.apiKey) {
|
|
59
|
+
config.headers["X-API-KEY"] = options.apiKey;
|
|
60
|
+
} else if (options.accessToken) {
|
|
61
|
+
const token = typeof options.accessToken === "string" ? options.accessToken : await options.accessToken.getToken();
|
|
62
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
63
|
+
}
|
|
33
64
|
config.headers["Content-Type"] = "application/json";
|
|
34
65
|
if (options.source) {
|
|
35
66
|
config.headers["X-Source"] = options.source;
|
|
@@ -2302,7 +2333,9 @@ var ChainStreamClient = class {
|
|
|
2302
2333
|
const streamUrl = options.streamUrl ?? "wss://realtime-dex.chainstream.io/connection/websocket";
|
|
2303
2334
|
this.requestCtx = { baseUrl, streamUrl, accessToken };
|
|
2304
2335
|
configure({
|
|
2305
|
-
accessToken,
|
|
2336
|
+
accessToken: options.walletSigner || options.apiKey ? void 0 : accessToken,
|
|
2337
|
+
apiKey: options.apiKey,
|
|
2338
|
+
walletSigner: options.walletSigner,
|
|
2306
2339
|
basePath: baseUrl,
|
|
2307
2340
|
debugging: options.debug
|
|
2308
2341
|
});
|