@solana/web3.js 1.52.0 → 1.54.1

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.
Files changed (62) hide show
  1. package/lib/index.browser.cjs.js +6188 -7481
  2. package/lib/index.browser.cjs.js.map +1 -1
  3. package/lib/index.browser.esm.js +6183 -7482
  4. package/lib/index.browser.esm.js.map +1 -1
  5. package/lib/index.cjs.js +6219 -7531
  6. package/lib/index.cjs.js.map +1 -1
  7. package/lib/index.d.ts +957 -832
  8. package/lib/index.esm.js +6214 -7532
  9. package/lib/index.esm.js.map +1 -1
  10. package/lib/index.iife.js +20976 -27402
  11. package/lib/index.iife.js.map +1 -1
  12. package/lib/index.iife.min.js +8 -5
  13. package/lib/index.iife.min.js.map +1 -1
  14. package/lib/index.native.js +6188 -7480
  15. package/lib/index.native.js.map +1 -1
  16. package/package.json +5 -7
  17. package/src/account-data.ts +39 -0
  18. package/src/account.ts +19 -10
  19. package/src/connection.ts +40 -14
  20. package/src/index.ts +3 -14
  21. package/src/keypair.ts +19 -24
  22. package/src/layout.ts +7 -0
  23. package/src/loader.ts +4 -5
  24. package/src/message/index.ts +45 -0
  25. package/src/{message.ts → message/legacy.ts} +46 -27
  26. package/src/message/v0.ts +324 -0
  27. package/src/message/versioned.ts +27 -0
  28. package/src/nonce-account.ts +1 -1
  29. package/src/{address-lookup-table-program.ts → programs/address-lookup-table/index.ts} +8 -6
  30. package/src/programs/address-lookup-table/state.ts +84 -0
  31. package/src/{compute-budget.ts → programs/compute-budget.ts} +4 -4
  32. package/src/{ed25519-program.ts → programs/ed25519.ts} +6 -6
  33. package/src/programs/index.ts +7 -0
  34. package/src/{secp256k1-program.ts → programs/secp256k1.ts} +10 -9
  35. package/src/{stake-program.ts → programs/stake.ts} +7 -7
  36. package/src/{system-program.ts → programs/system.ts} +8 -8
  37. package/src/{vote-program.ts → programs/vote.ts} +28 -7
  38. package/src/publickey.ts +16 -75
  39. package/src/{transaction-constants.ts → transaction/constants.ts} +2 -0
  40. package/src/{util/tx-expiry-custom-errors.ts → transaction/expiry-custom-errors.ts} +0 -0
  41. package/src/transaction/index.ts +4 -0
  42. package/src/{transaction.ts → transaction/legacy.ts} +13 -18
  43. package/src/transaction/versioned.ts +105 -0
  44. package/src/{util → utils}/assert.ts +0 -0
  45. package/src/{util → utils}/bigint.ts +0 -0
  46. package/src/{util → utils}/borsh-schema.ts +0 -0
  47. package/src/{util → utils}/cluster.ts +0 -0
  48. package/src/utils/ed25519.ts +46 -0
  49. package/src/utils/index.ts +5 -0
  50. package/src/utils/makeWebsocketUrl.ts +26 -0
  51. package/src/{util → utils}/promise-timeout.ts +0 -0
  52. package/src/utils/secp256k1.ts +18 -0
  53. package/src/{util → utils}/send-and-confirm-raw-transaction.ts +0 -0
  54. package/src/{util → utils}/send-and-confirm-transaction.ts +0 -0
  55. package/src/{util → utils}/shortvec-encoding.ts +0 -0
  56. package/src/{util → utils}/sleep.ts +0 -0
  57. package/src/{util → utils}/to-buffer.ts +0 -0
  58. package/src/validator-info.ts +4 -6
  59. package/src/vote-account.ts +1 -1
  60. package/src/util/__forks__/react-native/url-impl.ts +0 -2
  61. package/src/util/makeWebsocketUrl.ts +0 -20
  62. package/src/util/url-impl.ts +0 -2
package/src/publickey.ts CHANGED
@@ -1,17 +1,22 @@
1
1
  import BN from 'bn.js';
2
2
  import bs58 from 'bs58';
3
3
  import {Buffer} from 'buffer';
4
- import nacl from 'tweetnacl';
5
- import {sha256} from '@ethersproject/sha2';
4
+ import {sha256} from '@noble/hashes/sha256';
6
5
 
7
- import {Struct, SOLANA_SCHEMA} from './util/borsh-schema';
8
- import {toBuffer} from './util/to-buffer';
6
+ import {isOnCurve} from './utils/ed25519';
7
+ import {Struct, SOLANA_SCHEMA} from './utils/borsh-schema';
8
+ import {toBuffer} from './utils/to-buffer';
9
9
 
10
10
  /**
11
11
  * Maximum length of derived pubkey seed
12
12
  */
13
13
  export const MAX_SEED_LENGTH = 32;
14
14
 
15
+ /**
16
+ * Size of public key in bytes
17
+ */
18
+ export const PUBLIC_KEY_LENGTH = 32;
19
+
15
20
  /**
16
21
  * Value to be converted into public key
17
22
  */
@@ -54,7 +59,7 @@ export class PublicKey extends Struct {
54
59
  if (typeof value === 'string') {
55
60
  // assume base 58 encoding by default
56
61
  const decoded = bs58.decode(value);
57
- if (decoded.length != 32) {
62
+ if (decoded.length != PUBLIC_KEY_LENGTH) {
58
63
  throw new Error(`Invalid public key input`);
59
64
  }
60
65
  this._bn = new BN(decoded);
@@ -103,7 +108,7 @@ export class PublicKey extends Struct {
103
108
  */
104
109
  toBuffer(): Buffer {
105
110
  const b = this._bn.toArrayLike(Buffer);
106
- if (b.length === 32) {
111
+ if (b.length === PUBLIC_KEY_LENGTH) {
107
112
  return b;
108
113
  }
109
114
 
@@ -135,8 +140,8 @@ export class PublicKey extends Struct {
135
140
  Buffer.from(seed),
136
141
  programId.toBuffer(),
137
142
  ]);
138
- const hash = sha256(new Uint8Array(buffer)).slice(2);
139
- return new PublicKey(Buffer.from(hash, 'hex'));
143
+ const publicKeyBytes = sha256(buffer);
144
+ return new PublicKey(publicKeyBytes);
140
145
  }
141
146
 
142
147
  /**
@@ -159,9 +164,8 @@ export class PublicKey extends Struct {
159
164
  programId.toBuffer(),
160
165
  Buffer.from('ProgramDerivedAddress'),
161
166
  ]);
162
- let hash = sha256(new Uint8Array(buffer)).slice(2);
163
- let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
164
- if (is_on_curve(publicKeyBytes)) {
167
+ const publicKeyBytes = sha256(buffer);
168
+ if (isOnCurve(publicKeyBytes)) {
165
169
  throw new Error(`Invalid seeds, address must fall off the curve`);
166
170
  }
167
171
  return new PublicKey(publicKeyBytes);
@@ -224,7 +228,7 @@ export class PublicKey extends Struct {
224
228
  */
225
229
  static isOnCurve(pubkeyData: PublicKeyInitData): boolean {
226
230
  const pubkey = new PublicKey(pubkeyData);
227
- return is_on_curve(pubkey.toBytes()) == 1;
231
+ return isOnCurve(pubkey.toBytes());
228
232
  }
229
233
  }
230
234
 
@@ -232,66 +236,3 @@ SOLANA_SCHEMA.set(PublicKey, {
232
236
  kind: 'struct',
233
237
  fields: [['_bn', 'u256']],
234
238
  });
235
-
236
- // @ts-ignore
237
- let naclLowLevel = nacl.lowlevel;
238
-
239
- // Check that a pubkey is on the curve.
240
- // This function and its dependents were sourced from:
241
- // https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
242
- function is_on_curve(p: any) {
243
- var r = [
244
- naclLowLevel.gf(),
245
- naclLowLevel.gf(),
246
- naclLowLevel.gf(),
247
- naclLowLevel.gf(),
248
- ];
249
-
250
- var t = naclLowLevel.gf(),
251
- chk = naclLowLevel.gf(),
252
- num = naclLowLevel.gf(),
253
- den = naclLowLevel.gf(),
254
- den2 = naclLowLevel.gf(),
255
- den4 = naclLowLevel.gf(),
256
- den6 = naclLowLevel.gf();
257
-
258
- naclLowLevel.set25519(r[2], gf1);
259
- naclLowLevel.unpack25519(r[1], p);
260
- naclLowLevel.S(num, r[1]);
261
- naclLowLevel.M(den, num, naclLowLevel.D);
262
- naclLowLevel.Z(num, num, r[2]);
263
- naclLowLevel.A(den, r[2], den);
264
-
265
- naclLowLevel.S(den2, den);
266
- naclLowLevel.S(den4, den2);
267
- naclLowLevel.M(den6, den4, den2);
268
- naclLowLevel.M(t, den6, num);
269
- naclLowLevel.M(t, t, den);
270
-
271
- naclLowLevel.pow2523(t, t);
272
- naclLowLevel.M(t, t, num);
273
- naclLowLevel.M(t, t, den);
274
- naclLowLevel.M(t, t, den);
275
- naclLowLevel.M(r[0], t, den);
276
-
277
- naclLowLevel.S(chk, r[0]);
278
- naclLowLevel.M(chk, chk, den);
279
- if (neq25519(chk, num)) naclLowLevel.M(r[0], r[0], I);
280
-
281
- naclLowLevel.S(chk, r[0]);
282
- naclLowLevel.M(chk, chk, den);
283
- if (neq25519(chk, num)) return 0;
284
- return 1;
285
- }
286
- let gf1 = naclLowLevel.gf([1]);
287
- let I = naclLowLevel.gf([
288
- 0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7,
289
- 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83,
290
- ]);
291
- function neq25519(a: any, b: any) {
292
- var c = new Uint8Array(32),
293
- d = new Uint8Array(32);
294
- naclLowLevel.pack25519(c, a);
295
- naclLowLevel.pack25519(d, b);
296
- return naclLowLevel.crypto_verify_32(c, 0, d, 0);
297
- }
@@ -7,4 +7,6 @@
7
7
  */
8
8
  export const PACKET_DATA_SIZE = 1280 - 40 - 8;
9
9
 
10
+ export const VERSION_PREFIX_MASK = 0x7f;
11
+
10
12
  export const SIGNATURE_LENGTH_IN_BYTES = 64;
@@ -0,0 +1,4 @@
1
+ export * from './constants';
2
+ export * from './expiry-custom-errors';
3
+ export * from './legacy';
4
+ export * from './versioned';
@@ -1,20 +1,17 @@
1
- import nacl from 'tweetnacl';
2
1
  import bs58 from 'bs58';
3
2
  import {Buffer} from 'buffer';
4
3
 
5
- import {
6
- PACKET_DATA_SIZE,
7
- SIGNATURE_LENGTH_IN_BYTES,
8
- } from './transaction-constants';
9
- import {Connection} from './connection';
10
- import {Message} from './message';
11
- import {PublicKey} from './publickey';
12
- import * as shortvec from './util/shortvec-encoding';
13
- import {toBuffer} from './util/to-buffer';
14
- import invariant from './util/assert';
15
- import type {Signer} from './keypair';
16
- import type {Blockhash} from './blockhash';
17
- import type {CompiledInstruction} from './message';
4
+ import {PACKET_DATA_SIZE, SIGNATURE_LENGTH_IN_BYTES} from './constants';
5
+ import {Connection} from '../connection';
6
+ import {Message} from '../message';
7
+ import {PublicKey} from '../publickey';
8
+ import * as shortvec from '../utils/shortvec-encoding';
9
+ import {toBuffer} from '../utils/to-buffer';
10
+ import invariant from '../utils/assert';
11
+ import type {Signer} from '../keypair';
12
+ import type {Blockhash} from '../blockhash';
13
+ import type {CompiledInstruction} from '../message';
14
+ import {sign, verify} from '../utils/ed25519';
18
15
 
19
16
  /**
20
17
  * Transaction signature as base-58 encoded string
@@ -661,7 +658,7 @@ export class Transaction {
661
658
  _partialSign(message: Message, ...signers: Array<Signer>) {
662
659
  const signData = message.serialize();
663
660
  signers.forEach(signer => {
664
- const signature = nacl.sign.detached(signData, signer.secretKey);
661
+ const signature = sign(signData, signer.secretKey);
665
662
  this._addSignature(signer.publicKey, toBuffer(signature));
666
663
  });
667
664
  }
@@ -709,9 +706,7 @@ export class Transaction {
709
706
  return false;
710
707
  }
711
708
  } else {
712
- if (
713
- !nacl.sign.detached.verify(signData, signature, publicKey.toBuffer())
714
- ) {
709
+ if (!verify(signature, signData, publicKey.toBuffer())) {
715
710
  return false;
716
711
  }
717
712
  }
@@ -0,0 +1,105 @@
1
+ import * as BufferLayout from '@solana/buffer-layout';
2
+
3
+ import {Signer} from '../keypair';
4
+ import assert from '../utils/assert';
5
+ import {VersionedMessage} from '../message/versioned';
6
+ import {SIGNATURE_LENGTH_IN_BYTES} from './constants';
7
+ import * as shortvec from '../utils/shortvec-encoding';
8
+ import * as Layout from '../layout';
9
+ import {sign} from '../utils/ed25519';
10
+
11
+ export type TransactionVersion = 'legacy' | 0;
12
+
13
+ /**
14
+ * Versioned transaction class
15
+ */
16
+ export class VersionedTransaction {
17
+ signatures: Array<Uint8Array>;
18
+ message: VersionedMessage;
19
+
20
+ constructor(message: VersionedMessage, signatures?: Array<Uint8Array>) {
21
+ if (signatures !== undefined) {
22
+ assert(
23
+ signatures.length === message.header.numRequiredSignatures,
24
+ 'Expected signatures length to be equal to the number of required signatures',
25
+ );
26
+ this.signatures = signatures;
27
+ } else {
28
+ const defaultSignatures = [];
29
+ for (let i = 0; i < message.header.numRequiredSignatures; i++) {
30
+ defaultSignatures.push(new Uint8Array(SIGNATURE_LENGTH_IN_BYTES));
31
+ }
32
+ this.signatures = defaultSignatures;
33
+ }
34
+ this.message = message;
35
+ }
36
+
37
+ serialize(): Uint8Array {
38
+ const serializedMessage = this.message.serialize();
39
+
40
+ const encodedSignaturesLength = Array<number>();
41
+ shortvec.encodeLength(encodedSignaturesLength, this.signatures.length);
42
+
43
+ const transactionLayout = BufferLayout.struct<{
44
+ encodedSignaturesLength: Uint8Array;
45
+ signatures: Array<Uint8Array>;
46
+ serializedMessage: Uint8Array;
47
+ }>([
48
+ BufferLayout.blob(
49
+ encodedSignaturesLength.length,
50
+ 'encodedSignaturesLength',
51
+ ),
52
+ BufferLayout.seq(
53
+ Layout.signature(),
54
+ this.signatures.length,
55
+ 'signatures',
56
+ ),
57
+ BufferLayout.blob(serializedMessage.length, 'serializedMessage'),
58
+ ]);
59
+
60
+ const serializedTransaction = new Uint8Array(2048);
61
+ const serializedTransactionLength = transactionLayout.encode(
62
+ {
63
+ encodedSignaturesLength: new Uint8Array(encodedSignaturesLength),
64
+ signatures: this.signatures,
65
+ serializedMessage,
66
+ },
67
+ serializedTransaction,
68
+ );
69
+
70
+ return serializedTransaction.slice(0, serializedTransactionLength);
71
+ }
72
+
73
+ static deserialize(serializedTransaction: Uint8Array): VersionedTransaction {
74
+ let byteArray = [...serializedTransaction];
75
+
76
+ const signatures = [];
77
+ const signaturesLength = shortvec.decodeLength(byteArray);
78
+ for (let i = 0; i < signaturesLength; i++) {
79
+ signatures.push(
80
+ new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)),
81
+ );
82
+ }
83
+
84
+ const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
85
+ return new VersionedTransaction(message, signatures);
86
+ }
87
+
88
+ sign(signers: Array<Signer>) {
89
+ const messageData = this.message.serialize();
90
+ const signerPubkeys = this.message.staticAccountKeys.slice(
91
+ 0,
92
+ this.message.header.numRequiredSignatures,
93
+ );
94
+ for (const signer of signers) {
95
+ const signerIndex = signerPubkeys.findIndex(pubkey =>
96
+ pubkey.equals(signer.publicKey),
97
+ );
98
+ assert(
99
+ signerIndex >= 0,
100
+ `Cannot sign with non signer key ${signer.publicKey.toBase58()}`,
101
+ );
102
+ this.signatures[signerIndex] = sign(messageData, signer.secretKey);
103
+ }
104
+ }
105
+ }
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,46 @@
1
+ import {sha512} from '@noble/hashes/sha512';
2
+ import * as ed25519 from '@noble/ed25519';
3
+
4
+ /**
5
+ * A 64 byte secret key, the first 32 bytes of which is the
6
+ * private scalar and the last 32 bytes is the public key.
7
+ * Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
8
+ */
9
+ type Ed25519SecretKey = Uint8Array;
10
+
11
+ /**
12
+ * Ed25519 Keypair
13
+ */
14
+ export interface Ed25519Keypair {
15
+ publicKey: Uint8Array;
16
+ secretKey: Ed25519SecretKey;
17
+ }
18
+
19
+ ed25519.utils.sha512Sync = (...m) => sha512(ed25519.utils.concatBytes(...m));
20
+
21
+ export const generatePrivateKey = ed25519.utils.randomPrivateKey;
22
+ export const generateKeypair = (): Ed25519Keypair => {
23
+ const privateScalar = ed25519.utils.randomPrivateKey();
24
+ const publicKey = getPublicKey(privateScalar);
25
+ const secretKey = new Uint8Array(64);
26
+ secretKey.set(privateScalar);
27
+ secretKey.set(publicKey, 32);
28
+ return {
29
+ publicKey,
30
+ secretKey,
31
+ };
32
+ };
33
+ export const getPublicKey = ed25519.sync.getPublicKey;
34
+ export function isOnCurve(publicKey: Uint8Array): boolean {
35
+ try {
36
+ ed25519.Point.fromHex(publicKey, true /* strict */);
37
+ return true;
38
+ } catch {
39
+ return false;
40
+ }
41
+ }
42
+ export const sign = (
43
+ message: Parameters<typeof ed25519.sync.sign>[0],
44
+ secretKey: Ed25519SecretKey,
45
+ ) => ed25519.sync.sign(message, secretKey.slice(0, 32));
46
+ export const verify = ed25519.sync.verify;
@@ -0,0 +1,5 @@
1
+ export * from './borsh-schema';
2
+ export * from './cluster';
3
+ export type {Ed25519Keypair} from './ed25519';
4
+ export * from './send-and-confirm-raw-transaction';
5
+ export * from './send-and-confirm-transaction';
@@ -0,0 +1,26 @@
1
+ const URL_RE = /^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i;
2
+
3
+ export function makeWebsocketUrl(endpoint: string) {
4
+ const matches = endpoint.match(URL_RE);
5
+ if (matches == null) {
6
+ throw TypeError(`Failed to validate endpoint URL \`${endpoint}\``);
7
+ }
8
+ const [
9
+ _, // eslint-disable-line @typescript-eslint/no-unused-vars
10
+ hostish,
11
+ portWithColon,
12
+ rest,
13
+ ] = matches;
14
+ const protocol = endpoint.startsWith('https:') ? 'wss:' : 'ws:';
15
+ const startPort =
16
+ portWithColon == null ? null : parseInt(portWithColon.slice(1), 10);
17
+ const websocketPort =
18
+ // Only shift the port by +1 as a convention for ws(s) only if given endpoint
19
+ // is explictly specifying the endpoint port (HTTP-based RPC), assuming
20
+ // we're directly trying to connect to solana-validator's ws listening port.
21
+ // When the endpoint omits the port, we're connecting to the protocol
22
+ // default ports: http(80) or https(443) and it's assumed we're behind a reverse
23
+ // proxy which manages WebSocket upgrade and backend port redirection.
24
+ startPort == null ? '' : `:${startPort + 1}`;
25
+ return `${protocol}//${hostish}${websocketPort}${rest}`;
26
+ }
File without changes
@@ -0,0 +1,18 @@
1
+ import {hmac} from '@noble/hashes/hmac';
2
+ import {sha256} from '@noble/hashes/sha256';
3
+ import * as secp256k1 from '@noble/secp256k1';
4
+
5
+ // Supply a synchronous hashing algorithm to make this
6
+ // library interoperable with the synchronous APIs in web3.js.
7
+ secp256k1.utils.hmacSha256Sync = (key: Uint8Array, ...msgs: Uint8Array[]) => {
8
+ const h = hmac.create(sha256, key);
9
+ msgs.forEach(msg => h.update(msg));
10
+ return h.digest();
11
+ };
12
+
13
+ export const ecdsaSign = (
14
+ msgHash: Parameters<typeof secp256k1.signSync>[0],
15
+ privKey: Parameters<typeof secp256k1.signSync>[1],
16
+ ) => secp256k1.signSync(msgHash, privKey, {der: false, recovered: true});
17
+ export const isValidPrivateKey = secp256k1.utils.isValidPrivateKey;
18
+ export const publicKeyCreate = secp256k1.getPublicKey;
File without changes
File without changes
File without changes
@@ -7,8 +7,8 @@ import {
7
7
  } from 'superstruct';
8
8
 
9
9
  import * as Layout from './layout';
10
- import * as shortvec from './util/shortvec-encoding';
11
- import {PublicKey} from './publickey';
10
+ import * as shortvec from './utils/shortvec-encoding';
11
+ import {PublicKey, PUBLIC_KEY_LENGTH} from './publickey';
12
12
 
13
13
  export const VALIDATOR_INFO_KEY = new PublicKey(
14
14
  'Va1idator1nfo111111111111111111111111111111',
@@ -77,16 +77,14 @@ export class ValidatorInfo {
77
77
  static fromConfigData(
78
78
  buffer: Buffer | Uint8Array | Array<number>,
79
79
  ): ValidatorInfo | null {
80
- const PUBKEY_LENGTH = 32;
81
-
82
80
  let byteArray = [...buffer];
83
81
  const configKeyCount = shortvec.decodeLength(byteArray);
84
82
  if (configKeyCount !== 2) return null;
85
83
 
86
84
  const configKeys: Array<ConfigKey> = [];
87
85
  for (let i = 0; i < 2; i++) {
88
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
89
- byteArray = byteArray.slice(PUBKEY_LENGTH);
86
+ const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
87
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
90
88
  const isSigner = byteArray.slice(0, 1)[0] === 1;
91
89
  byteArray = byteArray.slice(1);
92
90
  configKeys.push({publicKey, isSigner});
@@ -3,7 +3,7 @@ import type {Buffer} from 'buffer';
3
3
 
4
4
  import * as Layout from './layout';
5
5
  import {PublicKey} from './publickey';
6
- import {toBuffer} from './util/to-buffer';
6
+ import {toBuffer} from './utils/to-buffer';
7
7
 
8
8
  export const VOTE_PROGRAM_ID = new PublicKey(
9
9
  'Vote111111111111111111111111111111111111111',
@@ -1,2 +0,0 @@
1
- export {default} from 'react-native-url-polyfill';
2
- export * from 'react-native-url-polyfill';
@@ -1,20 +0,0 @@
1
- import {URL} from './url-impl';
2
-
3
- export function makeWebsocketUrl(endpoint: string) {
4
- let url = new URL(endpoint);
5
- const useHttps = url.protocol === 'https:';
6
-
7
- url.protocol = useHttps ? 'wss:' : 'ws:';
8
- url.host = '';
9
-
10
- // Only shift the port by +1 as a convention for ws(s) only if given endpoint
11
- // is explictly specifying the endpoint port (HTTP-based RPC), assuming
12
- // we're directly trying to connect to solana-validator's ws listening port.
13
- // When the endpoint omits the port, we're connecting to the protocol
14
- // default ports: http(80) or https(443) and it's assumed we're behind a reverse
15
- // proxy which manages WebSocket upgrade and backend port redirection.
16
- if (url.port !== '') {
17
- url.port = String(Number(url.port) + 1);
18
- }
19
- return url.toString();
20
- }
@@ -1,2 +0,0 @@
1
- export const URL = globalThis.URL;
2
- export const URLSearchParams = globalThis.URLSearchParams;