@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.
@@ -12,7 +12,6 @@ var bigintBuffer = require('bigint-buffer');
12
12
  var superstruct = require('superstruct');
13
13
  var rpcWebsockets = require('rpc-websockets');
14
14
  var RpcClient = require('jayson/lib/client/browser');
15
- var reactNativeUrlPolyfill = require('react-native-url-polyfill');
16
15
  var secp256k1 = require('secp256k1');
17
16
  var sha3 = require('js-sha3');
18
17
 
@@ -1801,6 +1800,11 @@ const SOLANA_SCHEMA = new Map();
1801
1800
  */
1802
1801
 
1803
1802
  const MAX_SEED_LENGTH = 32;
1803
+ /**
1804
+ * Size of public key in bytes
1805
+ */
1806
+
1807
+ const PUBLIC_KEY_LENGTH = 32;
1804
1808
  /**
1805
1809
  * Value to be converted into public key
1806
1810
  */
@@ -1831,7 +1835,7 @@ class PublicKey extends Struct {
1831
1835
  // assume base 58 encoding by default
1832
1836
  const decoded = bs58__default["default"].decode(value);
1833
1837
 
1834
- if (decoded.length != 32) {
1838
+ if (decoded.length != PUBLIC_KEY_LENGTH) {
1835
1839
  throw new Error(`Invalid public key input`);
1836
1840
  }
1837
1841
 
@@ -1884,7 +1888,7 @@ class PublicKey extends Struct {
1884
1888
  toBuffer() {
1885
1889
  const b = this._bn.toArrayLike(buffer.Buffer);
1886
1890
 
1887
- if (b.length === 32) {
1891
+ if (b.length === PUBLIC_KEY_LENGTH) {
1888
1892
  return b;
1889
1893
  }
1890
1894
 
@@ -2112,6 +2116,7 @@ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader111111111111111
2112
2116
  * 8 bytes is the size of the fragment header
2113
2117
  */
2114
2118
  const PACKET_DATA_SIZE = 1280 - 40 - 8;
2119
+ const VERSION_PREFIX_MASK = 0x7f;
2115
2120
  const SIGNATURE_LENGTH_IN_BYTES = 64;
2116
2121
 
2117
2122
  class TransactionExpiredBlockheightExceededError extends Error {
@@ -2144,6 +2149,13 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
2144
2149
  const publicKey = (property = 'publicKey') => {
2145
2150
  return BufferLayout__namespace.blob(32, property);
2146
2151
  };
2152
+ /**
2153
+ * Layout for a signature
2154
+ */
2155
+
2156
+ const signature = (property = 'signature') => {
2157
+ return BufferLayout__namespace.blob(64, property);
2158
+ };
2147
2159
 
2148
2160
  /**
2149
2161
  * Layout for a Rust String type
@@ -2255,11 +2267,9 @@ function encodeLength(bytes, len) {
2255
2267
  }
2256
2268
  }
2257
2269
 
2258
- const PUBKEY_LENGTH = 32;
2259
2270
  /**
2260
2271
  * List of instructions to be processed atomically
2261
2272
  */
2262
-
2263
2273
  class Message {
2264
2274
  constructor(args) {
2265
2275
  this.header = void 0;
@@ -2274,6 +2284,26 @@ class Message {
2274
2284
  this.instructions.forEach(ix => this.indexToProgramIds.set(ix.programIdIndex, this.accountKeys[ix.programIdIndex]));
2275
2285
  }
2276
2286
 
2287
+ get version() {
2288
+ return 'legacy';
2289
+ }
2290
+
2291
+ get staticAccountKeys() {
2292
+ return this.accountKeys;
2293
+ }
2294
+
2295
+ get compiledInstructions() {
2296
+ return this.instructions.map(ix => ({
2297
+ programIdIndex: ix.programIdIndex,
2298
+ accountKeyIndexes: ix.accounts,
2299
+ data: bs58__default["default"].decode(ix.data)
2300
+ }));
2301
+ }
2302
+
2303
+ get addressTableLookups() {
2304
+ return [];
2305
+ }
2306
+
2277
2307
  isAccountSigner(index) {
2278
2308
  return index < this.header.numRequiredSignatures;
2279
2309
  }
@@ -2350,19 +2380,24 @@ class Message {
2350
2380
  // Slice up wire data
2351
2381
  let byteArray = [...buffer$1];
2352
2382
  const numRequiredSignatures = byteArray.shift();
2383
+
2384
+ if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
2385
+ throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
2386
+ }
2387
+
2353
2388
  const numReadonlySignedAccounts = byteArray.shift();
2354
2389
  const numReadonlyUnsignedAccounts = byteArray.shift();
2355
2390
  const accountCount = decodeLength(byteArray);
2356
2391
  let accountKeys = [];
2357
2392
 
2358
2393
  for (let i = 0; i < accountCount; i++) {
2359
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2360
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2394
+ const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
2395
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
2361
2396
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2362
2397
  }
2363
2398
 
2364
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2365
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2399
+ const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
2400
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
2366
2401
  const instructionCount = decodeLength(byteArray);
2367
2402
  let instructions = [];
2368
2403
 
@@ -2403,6 +2438,182 @@ function assert (condition, message) {
2403
2438
  }
2404
2439
  }
2405
2440
 
2441
+ /**
2442
+ * Message constructor arguments
2443
+ */
2444
+
2445
+ class MessageV0 {
2446
+ constructor(args) {
2447
+ this.header = void 0;
2448
+ this.staticAccountKeys = void 0;
2449
+ this.recentBlockhash = void 0;
2450
+ this.compiledInstructions = void 0;
2451
+ this.addressTableLookups = void 0;
2452
+ this.header = args.header;
2453
+ this.staticAccountKeys = args.staticAccountKeys;
2454
+ this.recentBlockhash = args.recentBlockhash;
2455
+ this.compiledInstructions = args.compiledInstructions;
2456
+ this.addressTableLookups = args.addressTableLookups;
2457
+ }
2458
+
2459
+ get version() {
2460
+ return 0;
2461
+ }
2462
+
2463
+ serialize() {
2464
+ const encodedStaticAccountKeysLength = Array();
2465
+ encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
2466
+ const serializedInstructions = this.serializeInstructions();
2467
+ const encodedInstructionsLength = Array();
2468
+ encodeLength(encodedInstructionsLength, this.compiledInstructions.length);
2469
+ const serializedAddressTableLookups = this.serializeAddressTableLookups();
2470
+ const encodedAddressTableLookupsLength = Array();
2471
+ encodeLength(encodedAddressTableLookupsLength, this.addressTableLookups.length);
2472
+ 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')]);
2473
+ const serializedMessage = new Uint8Array(PACKET_DATA_SIZE);
2474
+ const MESSAGE_VERSION_0_PREFIX = 1 << 7;
2475
+ const serializedMessageLength = messageLayout.encode({
2476
+ prefix: MESSAGE_VERSION_0_PREFIX,
2477
+ header: this.header,
2478
+ staticAccountKeysLength: new Uint8Array(encodedStaticAccountKeysLength),
2479
+ staticAccountKeys: this.staticAccountKeys.map(key => key.toBytes()),
2480
+ recentBlockhash: bs58__default["default"].decode(this.recentBlockhash),
2481
+ instructionsLength: new Uint8Array(encodedInstructionsLength),
2482
+ serializedInstructions,
2483
+ addressTableLookupsLength: new Uint8Array(encodedAddressTableLookupsLength),
2484
+ serializedAddressTableLookups
2485
+ }, serializedMessage);
2486
+ return serializedMessage.slice(0, serializedMessageLength);
2487
+ }
2488
+
2489
+ serializeInstructions() {
2490
+ let serializedLength = 0;
2491
+ const serializedInstructions = new Uint8Array(PACKET_DATA_SIZE);
2492
+
2493
+ for (const instruction of this.compiledInstructions) {
2494
+ const encodedAccountKeyIndexesLength = Array();
2495
+ encodeLength(encodedAccountKeyIndexesLength, instruction.accountKeyIndexes.length);
2496
+ const encodedDataLength = Array();
2497
+ encodeLength(encodedDataLength, instruction.data.length);
2498
+ 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')]);
2499
+ serializedLength += instructionLayout.encode({
2500
+ programIdIndex: instruction.programIdIndex,
2501
+ encodedAccountKeyIndexesLength: new Uint8Array(encodedAccountKeyIndexesLength),
2502
+ accountKeyIndexes: instruction.accountKeyIndexes,
2503
+ encodedDataLength: new Uint8Array(encodedDataLength),
2504
+ data: instruction.data
2505
+ }, serializedInstructions, serializedLength);
2506
+ }
2507
+
2508
+ return serializedInstructions.slice(0, serializedLength);
2509
+ }
2510
+
2511
+ serializeAddressTableLookups() {
2512
+ let serializedLength = 0;
2513
+ const serializedAddressTableLookups = new Uint8Array(PACKET_DATA_SIZE);
2514
+
2515
+ for (const lookup of this.addressTableLookups) {
2516
+ const encodedWritableIndexesLength = Array();
2517
+ encodeLength(encodedWritableIndexesLength, lookup.writableIndexes.length);
2518
+ const encodedReadonlyIndexesLength = Array();
2519
+ encodeLength(encodedReadonlyIndexesLength, lookup.readonlyIndexes.length);
2520
+ 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')]);
2521
+ serializedLength += addressTableLookupLayout.encode({
2522
+ accountKey: lookup.accountKey.toBytes(),
2523
+ encodedWritableIndexesLength: new Uint8Array(encodedWritableIndexesLength),
2524
+ writableIndexes: lookup.writableIndexes,
2525
+ encodedReadonlyIndexesLength: new Uint8Array(encodedReadonlyIndexesLength),
2526
+ readonlyIndexes: lookup.readonlyIndexes
2527
+ }, serializedAddressTableLookups, serializedLength);
2528
+ }
2529
+
2530
+ return serializedAddressTableLookups.slice(0, serializedLength);
2531
+ }
2532
+
2533
+ static deserialize(serializedMessage) {
2534
+ let byteArray = [...serializedMessage];
2535
+ const prefix = byteArray.shift();
2536
+ const maskedPrefix = prefix & VERSION_PREFIX_MASK;
2537
+ assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
2538
+ const version = maskedPrefix;
2539
+ assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
2540
+ const header = {
2541
+ numRequiredSignatures: byteArray.shift(),
2542
+ numReadonlySignedAccounts: byteArray.shift(),
2543
+ numReadonlyUnsignedAccounts: byteArray.shift()
2544
+ };
2545
+ const staticAccountKeys = [];
2546
+ const staticAccountKeysLength = decodeLength(byteArray);
2547
+
2548
+ for (let i = 0; i < staticAccountKeysLength; i++) {
2549
+ staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
2550
+ }
2551
+
2552
+ const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
2553
+ const instructionCount = decodeLength(byteArray);
2554
+ const compiledInstructions = [];
2555
+
2556
+ for (let i = 0; i < instructionCount; i++) {
2557
+ const programIdIndex = byteArray.shift();
2558
+ const accountKeyIndexesLength = decodeLength(byteArray);
2559
+ const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
2560
+ const dataLength = decodeLength(byteArray);
2561
+ const data = new Uint8Array(byteArray.splice(0, dataLength));
2562
+ compiledInstructions.push({
2563
+ programIdIndex,
2564
+ accountKeyIndexes,
2565
+ data
2566
+ });
2567
+ }
2568
+
2569
+ const addressTableLookupsCount = decodeLength(byteArray);
2570
+ const addressTableLookups = [];
2571
+
2572
+ for (let i = 0; i < addressTableLookupsCount; i++) {
2573
+ const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
2574
+ const writableIndexesLength = decodeLength(byteArray);
2575
+ const writableIndexes = byteArray.splice(0, writableIndexesLength);
2576
+ const readonlyIndexesLength = decodeLength(byteArray);
2577
+ const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
2578
+ addressTableLookups.push({
2579
+ accountKey,
2580
+ writableIndexes,
2581
+ readonlyIndexes
2582
+ });
2583
+ }
2584
+
2585
+ return new MessageV0({
2586
+ header,
2587
+ staticAccountKeys,
2588
+ recentBlockhash,
2589
+ compiledInstructions,
2590
+ addressTableLookups
2591
+ });
2592
+ }
2593
+
2594
+ }
2595
+
2596
+ // eslint-disable-next-line no-redeclare
2597
+ const VersionedMessage = {
2598
+ deserialize: serializedMessage => {
2599
+ const prefix = serializedMessage[0];
2600
+ const maskedPrefix = prefix & VERSION_PREFIX_MASK; // if the highest bit of the prefix is not set, the message is not versioned
2601
+
2602
+ if (maskedPrefix === prefix) {
2603
+ return Message.from(serializedMessage);
2604
+ } // the lower 7 bits of the prefix indicate the message version
2605
+
2606
+
2607
+ const version = maskedPrefix;
2608
+
2609
+ if (version === 0) {
2610
+ return MessageV0.deserialize(serializedMessage);
2611
+ } else {
2612
+ throw new Error(`Transaction message version ${version} deserialization is not supported`);
2613
+ }
2614
+ }
2615
+ };
2616
+
2406
2617
  exports.TransactionStatus = void 0;
2407
2618
  /**
2408
2619
  * Default (empty) signature
@@ -3131,6 +3342,70 @@ class Transaction {
3131
3342
 
3132
3343
  }
3133
3344
 
3345
+ /**
3346
+ * Versioned transaction class
3347
+ */
3348
+ class VersionedTransaction {
3349
+ constructor(message, signatures) {
3350
+ this.signatures = void 0;
3351
+ this.message = void 0;
3352
+
3353
+ if (signatures !== undefined) {
3354
+ assert(signatures.length === message.header.numRequiredSignatures, 'Expected signatures length to be equal to the number of required signatures');
3355
+ this.signatures = signatures;
3356
+ } else {
3357
+ const defaultSignatures = [];
3358
+
3359
+ for (let i = 0; i < message.header.numRequiredSignatures; i++) {
3360
+ defaultSignatures.push(new Uint8Array(SIGNATURE_LENGTH_IN_BYTES));
3361
+ }
3362
+
3363
+ this.signatures = defaultSignatures;
3364
+ }
3365
+
3366
+ this.message = message;
3367
+ }
3368
+
3369
+ serialize() {
3370
+ const serializedMessage = this.message.serialize();
3371
+ const encodedSignaturesLength = Array();
3372
+ encodeLength(encodedSignaturesLength, this.signatures.length);
3373
+ 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')]);
3374
+ const serializedTransaction = new Uint8Array(2048);
3375
+ const serializedTransactionLength = transactionLayout.encode({
3376
+ encodedSignaturesLength: new Uint8Array(encodedSignaturesLength),
3377
+ signatures: this.signatures,
3378
+ serializedMessage
3379
+ }, serializedTransaction);
3380
+ return serializedTransaction.slice(0, serializedTransactionLength);
3381
+ }
3382
+
3383
+ static deserialize(serializedTransaction) {
3384
+ let byteArray = [...serializedTransaction];
3385
+ const signatures = [];
3386
+ const signaturesLength = decodeLength(byteArray);
3387
+
3388
+ for (let i = 0; i < signaturesLength; i++) {
3389
+ signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
3390
+ }
3391
+
3392
+ const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
3393
+ return new VersionedTransaction(message, signatures);
3394
+ }
3395
+
3396
+ sign(signers) {
3397
+ const messageData = this.message.serialize();
3398
+ const signerPubkeys = this.message.staticAccountKeys.slice(0, this.message.header.numRequiredSignatures);
3399
+
3400
+ for (const signer of signers) {
3401
+ const signerIndex = signerPubkeys.findIndex(pubkey => pubkey.equals(signer.publicKey));
3402
+ assert(signerIndex >= 0, `Cannot sign with non signer key ${signer.publicKey.toBase58()}`);
3403
+ this.signatures[signerIndex] = nacl__default["default"].sign.detached(messageData, signer.secretKey);
3404
+ }
3405
+ }
3406
+
3407
+ }
3408
+
3134
3409
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3135
3410
  const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3136
3411
  const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
@@ -4524,22 +4799,26 @@ const LookupTableMetaLayout = {
4524
4799
  BufferLayout__namespace.seq(publicKey(), BufferLayout__namespace.offset(BufferLayout__namespace.u8(), -1), 'authority')])
4525
4800
  };
4526
4801
 
4802
+ const URL_RE = /^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i;
4527
4803
  function makeWebsocketUrl(endpoint) {
4528
- let url = new reactNativeUrlPolyfill.URL(endpoint);
4529
- const useHttps = url.protocol === 'https:';
4530
- url.protocol = useHttps ? 'wss:' : 'ws:';
4531
- url.host = ''; // Only shift the port by +1 as a convention for ws(s) only if given endpoint
4804
+ const matches = endpoint.match(URL_RE);
4805
+
4806
+ if (matches == null) {
4807
+ throw TypeError(`Failed to validate endpoint URL \`${endpoint}\``);
4808
+ }
4809
+
4810
+ const [_, // eslint-disable-line @typescript-eslint/no-unused-vars
4811
+ hostish, portWithColon, rest] = matches;
4812
+ const protocol = endpoint.startsWith('https:') ? 'wss:' : 'ws:';
4813
+ const startPort = portWithColon == null ? null : parseInt(portWithColon.slice(1), 10);
4814
+ const websocketPort = // Only shift the port by +1 as a convention for ws(s) only if given endpoint
4532
4815
  // is explictly specifying the endpoint port (HTTP-based RPC), assuming
4533
4816
  // we're directly trying to connect to solana-validator's ws listening port.
4534
4817
  // When the endpoint omits the port, we're connecting to the protocol
4535
4818
  // default ports: http(80) or https(443) and it's assumed we're behind a reverse
4536
4819
  // proxy which manages WebSocket upgrade and backend port redirection.
4537
-
4538
- if (url.port !== '') {
4539
- url.port = String(Number(url.port) + 1);
4540
- }
4541
-
4542
- return url.toString();
4820
+ startPort == null ? '' : `:${startPort + 1}`;
4821
+ return `${protocol}//${hostish}${websocketPort}${rest}`;
4543
4822
  }
4544
4823
 
4545
4824
  var _process$env$npm_pack;
@@ -4559,7 +4838,17 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
4559
4838
  * https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
4560
4839
  */
4561
4840
 
4841
+ /* @internal */
4842
+ function assertEndpointUrl(putativeUrl) {
4843
+ if (/^https?:/.test(putativeUrl) === false) {
4844
+ throw new TypeError('Endpoint URL must start with `http:` or `https:`.');
4845
+ }
4846
+
4847
+ return putativeUrl;
4848
+ }
4562
4849
  /** @internal */
4850
+
4851
+
4563
4852
  function extractCommitmentFromConfig(commitmentOrConfig) {
4564
4853
  let commitment;
4565
4854
  let config;
@@ -4754,7 +5043,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
4754
5043
  * A performance sample
4755
5044
  */
4756
5045
 
4757
- function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
5046
+ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4758
5047
  const fetch = customFetch ? customFetch : fetchImpl;
4759
5048
 
4760
5049
  let fetchWithMiddleware;
@@ -5560,8 +5849,6 @@ class Connection {
5560
5849
  this._subscriptionCallbacksByServerSubscriptionId = {};
5561
5850
  this._subscriptionsByHash = {};
5562
5851
  this._subscriptionsAutoDisposedByRpc = new Set();
5563
- let url = new reactNativeUrlPolyfill.URL(endpoint);
5564
- const useHttps = url.protocol === 'https:';
5565
5852
  let wsEndpoint;
5566
5853
  let httpHeaders;
5567
5854
  let fetch;
@@ -5580,9 +5867,9 @@ class Connection {
5580
5867
  disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
5581
5868
  }
5582
5869
 
5583
- this._rpcEndpoint = endpoint;
5870
+ this._rpcEndpoint = assertEndpointUrl(endpoint);
5584
5871
  this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
5585
- this._rpcClient = createRpcClient(url.toString(), useHttps, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
5872
+ this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
5586
5873
  this._rpcRequest = createRpcRequest(this._rpcClient);
5587
5874
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
5588
5875
  this._rpcWebSocket = new rpcWebsockets.Client(this._rpcWsEndpoint, {
@@ -10123,6 +10410,23 @@ class VoteProgram {
10123
10410
  data
10124
10411
  });
10125
10412
  }
10413
+ /**
10414
+ * Generate a transaction to withdraw safely from a Vote account.
10415
+ *
10416
+ * This function was created as a safeguard for vote accounts running validators, `safeWithdraw`
10417
+ * checks that the withdraw amount will not exceed the specified balance while leaving enough left
10418
+ * to cover rent. If you wish to close the vote account by withdrawing the full amount, call the
10419
+ * `withdraw` method directly.
10420
+ */
10421
+
10422
+
10423
+ static safeWithdraw(params, currentVoteAccountBalance, rentExemptMinimum) {
10424
+ if (params.lamports > currentVoteAccountBalance - rentExemptMinimum) {
10425
+ throw new Error('Withdraw will leave vote account with insuffcient funds.');
10426
+ }
10427
+
10428
+ return VoteProgram.withdraw(params);
10429
+ }
10126
10430
 
10127
10431
  }
10128
10432
  VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
@@ -10174,15 +10478,14 @@ class ValidatorInfo {
10174
10478
 
10175
10479
 
10176
10480
  static fromConfigData(buffer$1) {
10177
- const PUBKEY_LENGTH = 32;
10178
10481
  let byteArray = [...buffer$1];
10179
10482
  const configKeyCount = decodeLength(byteArray);
10180
10483
  if (configKeyCount !== 2) return null;
10181
10484
  const configKeys = [];
10182
10485
 
10183
10486
  for (let i = 0; i < 2; i++) {
10184
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
10185
- byteArray = byteArray.slice(PUBKEY_LENGTH);
10487
+ const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
10488
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
10186
10489
  const isSigner = byteArray.slice(0, 1)[0] === 1;
10187
10490
  byteArray = byteArray.slice(1);
10188
10491
  configKeys.push({
@@ -10418,9 +10721,11 @@ exports.Loader = Loader;
10418
10721
  exports.Lockup = Lockup;
10419
10722
  exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;
10420
10723
  exports.Message = Message;
10724
+ exports.MessageV0 = MessageV0;
10421
10725
  exports.NONCE_ACCOUNT_LENGTH = NONCE_ACCOUNT_LENGTH;
10422
10726
  exports.NonceAccount = NonceAccount;
10423
10727
  exports.PACKET_DATA_SIZE = PACKET_DATA_SIZE;
10728
+ exports.PUBLIC_KEY_LENGTH = PUBLIC_KEY_LENGTH;
10424
10729
  exports.PublicKey = PublicKey;
10425
10730
  exports.SIGNATURE_LENGTH_IN_BYTES = SIGNATURE_LENGTH_IN_BYTES;
10426
10731
  exports.SOLANA_SCHEMA = SOLANA_SCHEMA;
@@ -10451,8 +10756,11 @@ exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheig
10451
10756
  exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
10452
10757
  exports.TransactionInstruction = TransactionInstruction;
10453
10758
  exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
10759
+ exports.VERSION_PREFIX_MASK = VERSION_PREFIX_MASK;
10454
10760
  exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
10455
10761
  exports.ValidatorInfo = ValidatorInfo;
10762
+ exports.VersionedMessage = VersionedMessage;
10763
+ exports.VersionedTransaction = VersionedTransaction;
10456
10764
  exports.VoteAccount = VoteAccount;
10457
10765
  exports.VoteAuthorizationLayout = VoteAuthorizationLayout;
10458
10766
  exports.VoteInit = VoteInit;