@solana/web3.js 1.53.0 → 1.54.0

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/lib/index.cjs.js CHANGED
@@ -1827,6 +1827,11 @@ const SOLANA_SCHEMA = new Map();
1827
1827
  */
1828
1828
 
1829
1829
  const MAX_SEED_LENGTH = 32;
1830
+ /**
1831
+ * Size of public key in bytes
1832
+ */
1833
+
1834
+ const PUBLIC_KEY_LENGTH = 32;
1830
1835
  /**
1831
1836
  * Value to be converted into public key
1832
1837
  */
@@ -1857,7 +1862,7 @@ class PublicKey extends Struct {
1857
1862
  // assume base 58 encoding by default
1858
1863
  const decoded = bs58__default["default"].decode(value);
1859
1864
 
1860
- if (decoded.length != 32) {
1865
+ if (decoded.length != PUBLIC_KEY_LENGTH) {
1861
1866
  throw new Error(`Invalid public key input`);
1862
1867
  }
1863
1868
 
@@ -1910,7 +1915,7 @@ class PublicKey extends Struct {
1910
1915
  toBuffer() {
1911
1916
  const b = this._bn.toArrayLike(buffer.Buffer);
1912
1917
 
1913
- if (b.length === 32) {
1918
+ if (b.length === PUBLIC_KEY_LENGTH) {
1914
1919
  return b;
1915
1920
  }
1916
1921
 
@@ -2138,6 +2143,7 @@ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader111111111111111
2138
2143
  * 8 bytes is the size of the fragment header
2139
2144
  */
2140
2145
  const PACKET_DATA_SIZE = 1280 - 40 - 8;
2146
+ const VERSION_PREFIX_MASK = 0x7f;
2141
2147
  const SIGNATURE_LENGTH_IN_BYTES = 64;
2142
2148
 
2143
2149
  class TransactionExpiredBlockheightExceededError extends Error {
@@ -2170,6 +2176,13 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
2170
2176
  const publicKey = (property = 'publicKey') => {
2171
2177
  return BufferLayout__namespace.blob(32, property);
2172
2178
  };
2179
+ /**
2180
+ * Layout for a signature
2181
+ */
2182
+
2183
+ const signature = (property = 'signature') => {
2184
+ return BufferLayout__namespace.blob(64, property);
2185
+ };
2173
2186
 
2174
2187
  /**
2175
2188
  * Layout for a Rust String type
@@ -2281,11 +2294,9 @@ function encodeLength(bytes, len) {
2281
2294
  }
2282
2295
  }
2283
2296
 
2284
- const PUBKEY_LENGTH = 32;
2285
2297
  /**
2286
2298
  * List of instructions to be processed atomically
2287
2299
  */
2288
-
2289
2300
  class Message {
2290
2301
  constructor(args) {
2291
2302
  this.header = void 0;
@@ -2300,6 +2311,26 @@ class Message {
2300
2311
  this.instructions.forEach(ix => this.indexToProgramIds.set(ix.programIdIndex, this.accountKeys[ix.programIdIndex]));
2301
2312
  }
2302
2313
 
2314
+ get version() {
2315
+ return 'legacy';
2316
+ }
2317
+
2318
+ get staticAccountKeys() {
2319
+ return this.accountKeys;
2320
+ }
2321
+
2322
+ get compiledInstructions() {
2323
+ return this.instructions.map(ix => ({
2324
+ programIdIndex: ix.programIdIndex,
2325
+ accountKeyIndexes: ix.accounts,
2326
+ data: bs58__default["default"].decode(ix.data)
2327
+ }));
2328
+ }
2329
+
2330
+ get addressTableLookups() {
2331
+ return [];
2332
+ }
2333
+
2303
2334
  isAccountSigner(index) {
2304
2335
  return index < this.header.numRequiredSignatures;
2305
2336
  }
@@ -2376,19 +2407,24 @@ class Message {
2376
2407
  // Slice up wire data
2377
2408
  let byteArray = [...buffer$1];
2378
2409
  const numRequiredSignatures = byteArray.shift();
2410
+
2411
+ if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
2412
+ throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
2413
+ }
2414
+
2379
2415
  const numReadonlySignedAccounts = byteArray.shift();
2380
2416
  const numReadonlyUnsignedAccounts = byteArray.shift();
2381
2417
  const accountCount = decodeLength(byteArray);
2382
2418
  let accountKeys = [];
2383
2419
 
2384
2420
  for (let i = 0; i < accountCount; i++) {
2385
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2386
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2421
+ const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
2422
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
2387
2423
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2388
2424
  }
2389
2425
 
2390
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2391
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2426
+ const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
2427
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
2392
2428
  const instructionCount = decodeLength(byteArray);
2393
2429
  let instructions = [];
2394
2430
 
@@ -2429,6 +2465,182 @@ function assert (condition, message) {
2429
2465
  }
2430
2466
  }
2431
2467
 
2468
+ /**
2469
+ * Message constructor arguments
2470
+ */
2471
+
2472
+ class MessageV0 {
2473
+ constructor(args) {
2474
+ this.header = void 0;
2475
+ this.staticAccountKeys = void 0;
2476
+ this.recentBlockhash = void 0;
2477
+ this.compiledInstructions = void 0;
2478
+ this.addressTableLookups = void 0;
2479
+ this.header = args.header;
2480
+ this.staticAccountKeys = args.staticAccountKeys;
2481
+ this.recentBlockhash = args.recentBlockhash;
2482
+ this.compiledInstructions = args.compiledInstructions;
2483
+ this.addressTableLookups = args.addressTableLookups;
2484
+ }
2485
+
2486
+ get version() {
2487
+ return 0;
2488
+ }
2489
+
2490
+ serialize() {
2491
+ const encodedStaticAccountKeysLength = Array();
2492
+ encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
2493
+ const serializedInstructions = this.serializeInstructions();
2494
+ const encodedInstructionsLength = Array();
2495
+ encodeLength(encodedInstructionsLength, this.compiledInstructions.length);
2496
+ const serializedAddressTableLookups = this.serializeAddressTableLookups();
2497
+ const encodedAddressTableLookupsLength = Array();
2498
+ encodeLength(encodedAddressTableLookupsLength, this.addressTableLookups.length);
2499
+ const messageLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u8('prefix'), BufferLayout__namespace.struct([BufferLayout__namespace.u8('numRequiredSignatures'), BufferLayout__namespace.u8('numReadonlySignedAccounts'), BufferLayout__namespace.u8('numReadonlyUnsignedAccounts')], 'header'), BufferLayout__namespace.blob(encodedStaticAccountKeysLength.length, 'staticAccountKeysLength'), BufferLayout__namespace.seq(publicKey(), this.staticAccountKeys.length, 'staticAccountKeys'), publicKey('recentBlockhash'), BufferLayout__namespace.blob(encodedInstructionsLength.length, 'instructionsLength'), BufferLayout__namespace.blob(serializedInstructions.length, 'serializedInstructions'), BufferLayout__namespace.blob(encodedAddressTableLookupsLength.length, 'addressTableLookupsLength'), BufferLayout__namespace.blob(serializedAddressTableLookups.length, 'serializedAddressTableLookups')]);
2500
+ const serializedMessage = new Uint8Array(PACKET_DATA_SIZE);
2501
+ const MESSAGE_VERSION_0_PREFIX = 1 << 7;
2502
+ const serializedMessageLength = messageLayout.encode({
2503
+ prefix: MESSAGE_VERSION_0_PREFIX,
2504
+ header: this.header,
2505
+ staticAccountKeysLength: new Uint8Array(encodedStaticAccountKeysLength),
2506
+ staticAccountKeys: this.staticAccountKeys.map(key => key.toBytes()),
2507
+ recentBlockhash: bs58__default["default"].decode(this.recentBlockhash),
2508
+ instructionsLength: new Uint8Array(encodedInstructionsLength),
2509
+ serializedInstructions,
2510
+ addressTableLookupsLength: new Uint8Array(encodedAddressTableLookupsLength),
2511
+ serializedAddressTableLookups
2512
+ }, serializedMessage);
2513
+ return serializedMessage.slice(0, serializedMessageLength);
2514
+ }
2515
+
2516
+ serializeInstructions() {
2517
+ let serializedLength = 0;
2518
+ const serializedInstructions = new Uint8Array(PACKET_DATA_SIZE);
2519
+
2520
+ for (const instruction of this.compiledInstructions) {
2521
+ const encodedAccountKeyIndexesLength = Array();
2522
+ encodeLength(encodedAccountKeyIndexesLength, instruction.accountKeyIndexes.length);
2523
+ const encodedDataLength = Array();
2524
+ encodeLength(encodedDataLength, instruction.data.length);
2525
+ const instructionLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u8('programIdIndex'), BufferLayout__namespace.blob(encodedAccountKeyIndexesLength.length, 'encodedAccountKeyIndexesLength'), BufferLayout__namespace.seq(BufferLayout__namespace.u8(), instruction.accountKeyIndexes.length, 'accountKeyIndexes'), BufferLayout__namespace.blob(encodedDataLength.length, 'encodedDataLength'), BufferLayout__namespace.blob(instruction.data.length, 'data')]);
2526
+ serializedLength += instructionLayout.encode({
2527
+ programIdIndex: instruction.programIdIndex,
2528
+ encodedAccountKeyIndexesLength: new Uint8Array(encodedAccountKeyIndexesLength),
2529
+ accountKeyIndexes: instruction.accountKeyIndexes,
2530
+ encodedDataLength: new Uint8Array(encodedDataLength),
2531
+ data: instruction.data
2532
+ }, serializedInstructions, serializedLength);
2533
+ }
2534
+
2535
+ return serializedInstructions.slice(0, serializedLength);
2536
+ }
2537
+
2538
+ serializeAddressTableLookups() {
2539
+ let serializedLength = 0;
2540
+ const serializedAddressTableLookups = new Uint8Array(PACKET_DATA_SIZE);
2541
+
2542
+ for (const lookup of this.addressTableLookups) {
2543
+ const encodedWritableIndexesLength = Array();
2544
+ encodeLength(encodedWritableIndexesLength, lookup.writableIndexes.length);
2545
+ const encodedReadonlyIndexesLength = Array();
2546
+ encodeLength(encodedReadonlyIndexesLength, lookup.readonlyIndexes.length);
2547
+ const addressTableLookupLayout = BufferLayout__namespace.struct([publicKey('accountKey'), BufferLayout__namespace.blob(encodedWritableIndexesLength.length, 'encodedWritableIndexesLength'), BufferLayout__namespace.seq(BufferLayout__namespace.u8(), lookup.writableIndexes.length, 'writableIndexes'), BufferLayout__namespace.blob(encodedReadonlyIndexesLength.length, 'encodedReadonlyIndexesLength'), BufferLayout__namespace.seq(BufferLayout__namespace.u8(), lookup.readonlyIndexes.length, 'readonlyIndexes')]);
2548
+ serializedLength += addressTableLookupLayout.encode({
2549
+ accountKey: lookup.accountKey.toBytes(),
2550
+ encodedWritableIndexesLength: new Uint8Array(encodedWritableIndexesLength),
2551
+ writableIndexes: lookup.writableIndexes,
2552
+ encodedReadonlyIndexesLength: new Uint8Array(encodedReadonlyIndexesLength),
2553
+ readonlyIndexes: lookup.readonlyIndexes
2554
+ }, serializedAddressTableLookups, serializedLength);
2555
+ }
2556
+
2557
+ return serializedAddressTableLookups.slice(0, serializedLength);
2558
+ }
2559
+
2560
+ static deserialize(serializedMessage) {
2561
+ let byteArray = [...serializedMessage];
2562
+ const prefix = byteArray.shift();
2563
+ const maskedPrefix = prefix & VERSION_PREFIX_MASK;
2564
+ assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
2565
+ const version = maskedPrefix;
2566
+ assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
2567
+ const header = {
2568
+ numRequiredSignatures: byteArray.shift(),
2569
+ numReadonlySignedAccounts: byteArray.shift(),
2570
+ numReadonlyUnsignedAccounts: byteArray.shift()
2571
+ };
2572
+ const staticAccountKeys = [];
2573
+ const staticAccountKeysLength = decodeLength(byteArray);
2574
+
2575
+ for (let i = 0; i < staticAccountKeysLength; i++) {
2576
+ staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
2577
+ }
2578
+
2579
+ const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
2580
+ const instructionCount = decodeLength(byteArray);
2581
+ const compiledInstructions = [];
2582
+
2583
+ for (let i = 0; i < instructionCount; i++) {
2584
+ const programIdIndex = byteArray.shift();
2585
+ const accountKeyIndexesLength = decodeLength(byteArray);
2586
+ const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
2587
+ const dataLength = decodeLength(byteArray);
2588
+ const data = new Uint8Array(byteArray.splice(0, dataLength));
2589
+ compiledInstructions.push({
2590
+ programIdIndex,
2591
+ accountKeyIndexes,
2592
+ data
2593
+ });
2594
+ }
2595
+
2596
+ const addressTableLookupsCount = decodeLength(byteArray);
2597
+ const addressTableLookups = [];
2598
+
2599
+ for (let i = 0; i < addressTableLookupsCount; i++) {
2600
+ const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
2601
+ const writableIndexesLength = decodeLength(byteArray);
2602
+ const writableIndexes = byteArray.splice(0, writableIndexesLength);
2603
+ const readonlyIndexesLength = decodeLength(byteArray);
2604
+ const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
2605
+ addressTableLookups.push({
2606
+ accountKey,
2607
+ writableIndexes,
2608
+ readonlyIndexes
2609
+ });
2610
+ }
2611
+
2612
+ return new MessageV0({
2613
+ header,
2614
+ staticAccountKeys,
2615
+ recentBlockhash,
2616
+ compiledInstructions,
2617
+ addressTableLookups
2618
+ });
2619
+ }
2620
+
2621
+ }
2622
+
2623
+ // eslint-disable-next-line no-redeclare
2624
+ const VersionedMessage = {
2625
+ deserialize: serializedMessage => {
2626
+ const prefix = serializedMessage[0];
2627
+ const maskedPrefix = prefix & VERSION_PREFIX_MASK; // if the highest bit of the prefix is not set, the message is not versioned
2628
+
2629
+ if (maskedPrefix === prefix) {
2630
+ return Message.from(serializedMessage);
2631
+ } // the lower 7 bits of the prefix indicate the message version
2632
+
2633
+
2634
+ const version = maskedPrefix;
2635
+
2636
+ if (version === 0) {
2637
+ return MessageV0.deserialize(serializedMessage);
2638
+ } else {
2639
+ throw new Error(`Transaction message version ${version} deserialization is not supported`);
2640
+ }
2641
+ }
2642
+ };
2643
+
2432
2644
  exports.TransactionStatus = void 0;
2433
2645
  /**
2434
2646
  * Default (empty) signature
@@ -3157,6 +3369,70 @@ class Transaction {
3157
3369
 
3158
3370
  }
3159
3371
 
3372
+ /**
3373
+ * Versioned transaction class
3374
+ */
3375
+ class VersionedTransaction {
3376
+ constructor(message, signatures) {
3377
+ this.signatures = void 0;
3378
+ this.message = void 0;
3379
+
3380
+ if (signatures !== undefined) {
3381
+ assert(signatures.length === message.header.numRequiredSignatures, 'Expected signatures length to be equal to the number of required signatures');
3382
+ this.signatures = signatures;
3383
+ } else {
3384
+ const defaultSignatures = [];
3385
+
3386
+ for (let i = 0; i < message.header.numRequiredSignatures; i++) {
3387
+ defaultSignatures.push(new Uint8Array(SIGNATURE_LENGTH_IN_BYTES));
3388
+ }
3389
+
3390
+ this.signatures = defaultSignatures;
3391
+ }
3392
+
3393
+ this.message = message;
3394
+ }
3395
+
3396
+ serialize() {
3397
+ const serializedMessage = this.message.serialize();
3398
+ const encodedSignaturesLength = Array();
3399
+ encodeLength(encodedSignaturesLength, this.signatures.length);
3400
+ const transactionLayout = BufferLayout__namespace.struct([BufferLayout__namespace.blob(encodedSignaturesLength.length, 'encodedSignaturesLength'), BufferLayout__namespace.seq(signature(), this.signatures.length, 'signatures'), BufferLayout__namespace.blob(serializedMessage.length, 'serializedMessage')]);
3401
+ const serializedTransaction = new Uint8Array(2048);
3402
+ const serializedTransactionLength = transactionLayout.encode({
3403
+ encodedSignaturesLength: new Uint8Array(encodedSignaturesLength),
3404
+ signatures: this.signatures,
3405
+ serializedMessage
3406
+ }, serializedTransaction);
3407
+ return serializedTransaction.slice(0, serializedTransactionLength);
3408
+ }
3409
+
3410
+ static deserialize(serializedTransaction) {
3411
+ let byteArray = [...serializedTransaction];
3412
+ const signatures = [];
3413
+ const signaturesLength = decodeLength(byteArray);
3414
+
3415
+ for (let i = 0; i < signaturesLength; i++) {
3416
+ signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
3417
+ }
3418
+
3419
+ const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
3420
+ return new VersionedTransaction(message, signatures);
3421
+ }
3422
+
3423
+ sign(signers) {
3424
+ const messageData = this.message.serialize();
3425
+ const signerPubkeys = this.message.staticAccountKeys.slice(0, this.message.header.numRequiredSignatures);
3426
+
3427
+ for (const signer of signers) {
3428
+ const signerIndex = signerPubkeys.findIndex(pubkey => pubkey.equals(signer.publicKey));
3429
+ assert(signerIndex >= 0, `Cannot sign with non signer key ${signer.publicKey.toBase58()}`);
3430
+ this.signatures[signerIndex] = nacl__default["default"].sign.detached(messageData, signer.secretKey);
3431
+ }
3432
+ }
3433
+
3434
+ }
3435
+
3160
3436
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3161
3437
  const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3162
3438
  const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
@@ -4602,24 +4878,26 @@ const LookupTableMetaLayout = {
4602
4878
  BufferLayout__namespace.seq(publicKey(), BufferLayout__namespace.offset(BufferLayout__namespace.u8(), -1), 'authority')])
4603
4879
  };
4604
4880
 
4605
- const URL = globalThis.URL;
4606
-
4881
+ const URL_RE = /^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i;
4607
4882
  function makeWebsocketUrl(endpoint) {
4608
- let url = new URL(endpoint);
4609
- const useHttps = url.protocol === 'https:';
4610
- url.protocol = useHttps ? 'wss:' : 'ws:';
4611
- url.host = ''; // Only shift the port by +1 as a convention for ws(s) only if given endpoint
4883
+ const matches = endpoint.match(URL_RE);
4884
+
4885
+ if (matches == null) {
4886
+ throw TypeError(`Failed to validate endpoint URL \`${endpoint}\``);
4887
+ }
4888
+
4889
+ const [_, // eslint-disable-line @typescript-eslint/no-unused-vars
4890
+ hostish, portWithColon, rest] = matches;
4891
+ const protocol = endpoint.startsWith('https:') ? 'wss:' : 'ws:';
4892
+ const startPort = portWithColon == null ? null : parseInt(portWithColon.slice(1), 10);
4893
+ const websocketPort = // Only shift the port by +1 as a convention for ws(s) only if given endpoint
4612
4894
  // is explictly specifying the endpoint port (HTTP-based RPC), assuming
4613
4895
  // we're directly trying to connect to solana-validator's ws listening port.
4614
4896
  // When the endpoint omits the port, we're connecting to the protocol
4615
4897
  // default ports: http(80) or https(443) and it's assumed we're behind a reverse
4616
4898
  // proxy which manages WebSocket upgrade and backend port redirection.
4617
-
4618
- if (url.port !== '') {
4619
- url.port = String(Number(url.port) + 1);
4620
- }
4621
-
4622
- return url.toString();
4899
+ startPort == null ? '' : `:${startPort + 1}`;
4900
+ return `${protocol}//${hostish}${websocketPort}${rest}`;
4623
4901
  }
4624
4902
 
4625
4903
  var _process$env$npm_pack;
@@ -4639,7 +4917,17 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
4639
4917
  * https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
4640
4918
  */
4641
4919
 
4920
+ /* @internal */
4921
+ function assertEndpointUrl(putativeUrl) {
4922
+ if (/^https?:/.test(putativeUrl) === false) {
4923
+ throw new TypeError('Endpoint URL must start with `http:` or `https:`.');
4924
+ }
4925
+
4926
+ return putativeUrl;
4927
+ }
4642
4928
  /** @internal */
4929
+
4930
+
4643
4931
  function extractCommitmentFromConfig(commitmentOrConfig) {
4644
4932
  let commitment;
4645
4933
  let config;
@@ -4834,12 +5122,14 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
4834
5122
  * A performance sample
4835
5123
  */
4836
5124
 
4837
- function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
5125
+ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4838
5126
  const fetch = customFetch ? customFetch : fetchImpl;
4839
5127
  let agentManager;
4840
5128
 
4841
5129
  {
4842
- agentManager = new AgentManager(useHttps);
5130
+ agentManager = new AgentManager(url.startsWith('https:')
5131
+ /* useHttps */
5132
+ );
4843
5133
  }
4844
5134
 
4845
5135
  let fetchWithMiddleware;
@@ -5646,8 +5936,6 @@ class Connection {
5646
5936
  this._subscriptionCallbacksByServerSubscriptionId = {};
5647
5937
  this._subscriptionsByHash = {};
5648
5938
  this._subscriptionsAutoDisposedByRpc = new Set();
5649
- let url = new URL(endpoint);
5650
- const useHttps = url.protocol === 'https:';
5651
5939
  let wsEndpoint;
5652
5940
  let httpHeaders;
5653
5941
  let fetch;
@@ -5666,9 +5954,9 @@ class Connection {
5666
5954
  disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
5667
5955
  }
5668
5956
 
5669
- this._rpcEndpoint = endpoint;
5957
+ this._rpcEndpoint = assertEndpointUrl(endpoint);
5670
5958
  this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
5671
- this._rpcClient = createRpcClient(url.toString(), useHttps, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
5959
+ this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
5672
5960
  this._rpcRequest = createRpcRequest(this._rpcClient);
5673
5961
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
5674
5962
  this._rpcWebSocket = new rpcWebsockets.Client(this._rpcWsEndpoint, {
@@ -10209,6 +10497,23 @@ class VoteProgram {
10209
10497
  data
10210
10498
  });
10211
10499
  }
10500
+ /**
10501
+ * Generate a transaction to withdraw safely from a Vote account.
10502
+ *
10503
+ * This function was created as a safeguard for vote accounts running validators, `safeWithdraw`
10504
+ * checks that the withdraw amount will not exceed the specified balance while leaving enough left
10505
+ * to cover rent. If you wish to close the vote account by withdrawing the full amount, call the
10506
+ * `withdraw` method directly.
10507
+ */
10508
+
10509
+
10510
+ static safeWithdraw(params, currentVoteAccountBalance, rentExemptMinimum) {
10511
+ if (params.lamports > currentVoteAccountBalance - rentExemptMinimum) {
10512
+ throw new Error('Withdraw will leave vote account with insuffcient funds.');
10513
+ }
10514
+
10515
+ return VoteProgram.withdraw(params);
10516
+ }
10212
10517
 
10213
10518
  }
10214
10519
  VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
@@ -10260,15 +10565,14 @@ class ValidatorInfo {
10260
10565
 
10261
10566
 
10262
10567
  static fromConfigData(buffer$1) {
10263
- const PUBKEY_LENGTH = 32;
10264
10568
  let byteArray = [...buffer$1];
10265
10569
  const configKeyCount = decodeLength(byteArray);
10266
10570
  if (configKeyCount !== 2) return null;
10267
10571
  const configKeys = [];
10268
10572
 
10269
10573
  for (let i = 0; i < 2; i++) {
10270
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
10271
- byteArray = byteArray.slice(PUBKEY_LENGTH);
10574
+ const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
10575
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
10272
10576
  const isSigner = byteArray.slice(0, 1)[0] === 1;
10273
10577
  byteArray = byteArray.slice(1);
10274
10578
  configKeys.push({
@@ -10504,9 +10808,11 @@ exports.Loader = Loader;
10504
10808
  exports.Lockup = Lockup;
10505
10809
  exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;
10506
10810
  exports.Message = Message;
10811
+ exports.MessageV0 = MessageV0;
10507
10812
  exports.NONCE_ACCOUNT_LENGTH = NONCE_ACCOUNT_LENGTH;
10508
10813
  exports.NonceAccount = NonceAccount;
10509
10814
  exports.PACKET_DATA_SIZE = PACKET_DATA_SIZE;
10815
+ exports.PUBLIC_KEY_LENGTH = PUBLIC_KEY_LENGTH;
10510
10816
  exports.PublicKey = PublicKey;
10511
10817
  exports.SIGNATURE_LENGTH_IN_BYTES = SIGNATURE_LENGTH_IN_BYTES;
10512
10818
  exports.SOLANA_SCHEMA = SOLANA_SCHEMA;
@@ -10537,8 +10843,11 @@ exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheig
10537
10843
  exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
10538
10844
  exports.TransactionInstruction = TransactionInstruction;
10539
10845
  exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
10846
+ exports.VERSION_PREFIX_MASK = VERSION_PREFIX_MASK;
10540
10847
  exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
10541
10848
  exports.ValidatorInfo = ValidatorInfo;
10849
+ exports.VersionedMessage = VersionedMessage;
10850
+ exports.VersionedTransaction = VersionedTransaction;
10542
10851
  exports.VoteAccount = VoteAccount;
10543
10852
  exports.VoteAuthorizationLayout = VoteAuthorizationLayout;
10544
10853
  exports.VoteInit = VoteInit;