@chainstream-io/sdk 2.0.7 → 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';
@@ -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,15 @@ var configure = (options) => {
28
50
  retryDelay: exponentialDelay
29
51
  });
30
52
  axiosInstance.interceptors.request.use(async (config) => {
31
- const token = typeof options.accessToken === "string" ? options.accessToken : await options.accessToken.getToken();
32
- 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
+ }
33
62
  config.headers["Content-Type"] = "application/json";
34
63
  if (options.source) {
35
64
  config.headers["X-Source"] = options.source;
@@ -2302,7 +2331,8 @@ var ChainStreamClient = class {
2302
2331
  const streamUrl = options.streamUrl ?? "wss://realtime-dex.chainstream.io/connection/websocket";
2303
2332
  this.requestCtx = { baseUrl, streamUrl, accessToken };
2304
2333
  configure({
2305
- accessToken,
2334
+ accessToken: options.walletSigner ? void 0 : accessToken,
2335
+ walletSigner: options.walletSigner,
2306
2336
  basePath: baseUrl,
2307
2337
  debugging: options.debug
2308
2338
  });