@chainstream-io/sdk 2.0.6 → 2.0.8

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.
@@ -1,2 +1,2 @@
1
- export { C as ChainStreamClient, y as ChainStreamClientOptions, z as ChainStreamRequestContext, gF as PostOptions, T as TokenProvider } from './chainstream-CB6yyvSf.cjs';
1
+ export { C as ChainStreamClient, y as ChainStreamClientOptions, z as ChainStreamRequestContext, gI as PostOptions, T as TokenProvider } from './chainstream-Dwm2QHpn.cjs';
2
2
  import 'axios';
@@ -1,2 +1,2 @@
1
- export { C as ChainStreamClient, y as ChainStreamClientOptions, z as ChainStreamRequestContext, gF as PostOptions, T as TokenProvider } from './chainstream-CB6yyvSf.js';
1
+ export { C as ChainStreamClient, y as ChainStreamClientOptions, z as ChainStreamRequestContext, gI as PostOptions, T as TokenProvider } from './chainstream-Dwm2QHpn.js';
2
2
  import 'axios';
@@ -11,7 +11,30 @@ import { EventSourcePolyfill } from "event-source-polyfill";
11
11
 
12
12
  // src/openapi-client/chainstreamApiClient.ts
13
13
  import Axios from "axios";
14
- import axiosRetry, { exponentialDelay } from "axios-retry";
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
37
+ var axiosRetry = typeof axiosRetryImport === "function" ? axiosRetryImport : axiosRetryImport.default;
15
38
  var axiosInstance;
16
39
  var currentOptions = void 0;
17
40
  var configure = (options) => {
@@ -27,8 +50,15 @@ var configure = (options) => {
27
50
  retryDelay: exponentialDelay
28
51
  });
29
52
  axiosInstance.interceptors.request.use(async (config) => {
30
- const token = typeof options.accessToken === "string" ? options.accessToken : await options.accessToken.getToken();
31
- config.headers.Authorization = `Bearer ${token}`;
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.accessToken) {
59
+ const token = typeof options.accessToken === "string" ? options.accessToken : await options.accessToken.getToken();
60
+ config.headers.Authorization = `Bearer ${token}`;
61
+ }
32
62
  config.headers["Content-Type"] = "application/json";
33
63
  if (options.source) {
34
64
  config.headers["X-Source"] = options.source;
@@ -2301,7 +2331,8 @@ var ChainStreamClient = class {
2301
2331
  const streamUrl = options.streamUrl ?? "wss://realtime-dex.chainstream.io/connection/websocket";
2302
2332
  this.requestCtx = { baseUrl, streamUrl, accessToken };
2303
2333
  configure({
2304
- accessToken,
2334
+ accessToken: options.walletSigner ? void 0 : accessToken,
2335
+ walletSigner: options.walletSigner,
2305
2336
  basePath: baseUrl,
2306
2337
  debugging: options.debug
2307
2338
  });