@beam-network/sdk 0.2.17 → 0.2.18

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.
@@ -7,6 +7,25 @@ export const BEAM_DEFAULT_NATS_WS_URL = "wss://nats.b1m.ai:443";
7
7
  // messages before the broker rejects them; transfer bytes never flow through NATS.
8
8
  export const BEAM_DEFAULT_MAX_PAYLOAD_BYTES = 24 * 1024 * 1024;
9
9
  export const ROUTE_RECOVERY_SIGN_MESSAGE_TYPE = "transfer.route_recovery.sign";
10
+ function buildConnectionOptions(options) {
11
+ const connectionOptions = {
12
+ servers: options.natsUrl,
13
+ user: options.keyPrefix,
14
+ pass: options.apiKey,
15
+ name: `beam-sdk-${options.keyPrefix}`
16
+ };
17
+ if (options.natsUrl.startsWith("tls://")) {
18
+ const tlsOptions = { handshakeFirst: true };
19
+ try {
20
+ tlsOptions.servername = new URL(options.natsUrl).hostname;
21
+ }
22
+ catch {
23
+ // URL validation stays with the NATS client; TLS-first is still required.
24
+ }
25
+ connectionOptions.tls = tlsOptions;
26
+ }
27
+ return connectionOptions;
28
+ }
10
29
  export class BeamTransferControl {
11
30
  environment;
12
31
  keyPrefix;
@@ -145,12 +164,11 @@ export class BeamTransferControl {
145
164
  async connection() {
146
165
  if (this.nc && !this.nc.isClosed())
147
166
  return this.nc;
148
- this.nc = await connect({
149
- servers: this.natsUrl,
150
- user: this.keyPrefix,
151
- pass: this.apiKey,
152
- name: `beam-sdk-${this.keyPrefix}`
153
- });
167
+ this.nc = await connect(buildConnectionOptions({
168
+ natsUrl: this.natsUrl,
169
+ apiKey: this.apiKey,
170
+ keyPrefix: this.keyPrefix
171
+ }));
154
172
  return this.nc;
155
173
  }
156
174
  async resolveAuthToken() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beam-network/sdk",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "TypeScript SDK for BEAM transfer creation and management.",
5
5
  "type": "module",
6
6
  "license": "MIT",