@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.
@@ -1800,6 +1800,11 @@ const SOLANA_SCHEMA = new Map();
1800
1800
  */
1801
1801
 
1802
1802
  const MAX_SEED_LENGTH = 32;
1803
+ /**
1804
+ * Size of public key in bytes
1805
+ */
1806
+
1807
+ const PUBLIC_KEY_LENGTH = 32;
1803
1808
  /**
1804
1809
  * Value to be converted into public key
1805
1810
  */
@@ -1830,7 +1835,7 @@ class PublicKey extends Struct {
1830
1835
  // assume base 58 encoding by default
1831
1836
  const decoded = bs58__default["default"].decode(value);
1832
1837
 
1833
- if (decoded.length != 32) {
1838
+ if (decoded.length != PUBLIC_KEY_LENGTH) {
1834
1839
  throw new Error(`Invalid public key input`);
1835
1840
  }
1836
1841
 
@@ -1883,7 +1888,7 @@ class PublicKey extends Struct {
1883
1888
  toBuffer() {
1884
1889
  const b = this._bn.toArrayLike(buffer.Buffer);
1885
1890
 
1886
- if (b.length === 32) {
1891
+ if (b.length === PUBLIC_KEY_LENGTH) {
1887
1892
  return b;
1888
1893
  }
1889
1894
 
@@ -2111,6 +2116,7 @@ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader111111111111111
2111
2116
  * 8 bytes is the size of the fragment header
2112
2117
  */
2113
2118
  const PACKET_DATA_SIZE = 1280 - 40 - 8;
2119
+ const VERSION_PREFIX_MASK = 0x7f;
2114
2120
  const SIGNATURE_LENGTH_IN_BYTES = 64;
2115
2121
 
2116
2122
  class TransactionExpiredBlockheightExceededError extends Error {
@@ -2143,6 +2149,13 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
2143
2149
  const publicKey = (property = 'publicKey') => {
2144
2150
  return BufferLayout__namespace.blob(32, property);
2145
2151
  };
2152
+ /**
2153
+ * Layout for a signature
2154
+ */
2155
+
2156
+ const signature = (property = 'signature') => {
2157
+ return BufferLayout__namespace.blob(64, property);
2158
+ };
2146
2159
 
2147
2160
  /**
2148
2161
  * Layout for a Rust String type
@@ -2254,11 +2267,9 @@ function encodeLength(bytes, len) {
2254
2267
  }
2255
2268
  }
2256
2269
 
2257
- const PUBKEY_LENGTH = 32;
2258
2270
  /**
2259
2271
  * List of instructions to be processed atomically
2260
2272
  */
2261
-
2262
2273
  class Message {
2263
2274
  constructor(args) {
2264
2275
  this.header = void 0;
@@ -2273,6 +2284,26 @@ class Message {
2273
2284
  this.instructions.forEach(ix => this.indexToProgramIds.set(ix.programIdIndex, this.accountKeys[ix.programIdIndex]));
2274
2285
  }
2275
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
+
2276
2307
  isAccountSigner(index) {
2277
2308
  return index < this.header.numRequiredSignatures;
2278
2309
  }
@@ -2349,19 +2380,24 @@ class Message {
2349
2380
  // Slice up wire data
2350
2381
  let byteArray = [...buffer$1];
2351
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
+
2352
2388
  const numReadonlySignedAccounts = byteArray.shift();
2353
2389
  const numReadonlyUnsignedAccounts = byteArray.shift();
2354
2390
  const accountCount = decodeLength(byteArray);
2355
2391
  let accountKeys = [];
2356
2392
 
2357
2393
  for (let i = 0; i < accountCount; i++) {
2358
- const account = byteArray.slice(0, PUBKEY_LENGTH);
2359
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2394
+ const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
2395
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
2360
2396
  accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
2361
2397
  }
2362
2398
 
2363
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
2364
- byteArray = byteArray.slice(PUBKEY_LENGTH);
2399
+ const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
2400
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
2365
2401
  const instructionCount = decodeLength(byteArray);
2366
2402
  let instructions = [];
2367
2403
 
@@ -2402,6 +2438,182 @@ function assert (condition, message) {
2402
2438
  }
2403
2439
  }
2404
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
+
2405
2617
  exports.TransactionStatus = void 0;
2406
2618
  /**
2407
2619
  * Default (empty) signature
@@ -3130,6 +3342,70 @@ class Transaction {
3130
3342
 
3131
3343
  }
3132
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
+
3133
3409
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
3134
3410
  const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
3135
3411
  const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
@@ -4523,24 +4799,26 @@ const LookupTableMetaLayout = {
4523
4799
  BufferLayout__namespace.seq(publicKey(), BufferLayout__namespace.offset(BufferLayout__namespace.u8(), -1), 'authority')])
4524
4800
  };
4525
4801
 
4526
- const URL = globalThis.URL;
4527
-
4802
+ const URL_RE = /^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i;
4528
4803
  function makeWebsocketUrl(endpoint) {
4529
- let url = new URL(endpoint);
4530
- const useHttps = url.protocol === 'https:';
4531
- url.protocol = useHttps ? 'wss:' : 'ws:';
4532
- 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
4533
4815
  // is explictly specifying the endpoint port (HTTP-based RPC), assuming
4534
4816
  // we're directly trying to connect to solana-validator's ws listening port.
4535
4817
  // When the endpoint omits the port, we're connecting to the protocol
4536
4818
  // default ports: http(80) or https(443) and it's assumed we're behind a reverse
4537
4819
  // proxy which manages WebSocket upgrade and backend port redirection.
4538
-
4539
- if (url.port !== '') {
4540
- url.port = String(Number(url.port) + 1);
4541
- }
4542
-
4543
- return url.toString();
4820
+ startPort == null ? '' : `:${startPort + 1}`;
4821
+ return `${protocol}//${hostish}${websocketPort}${rest}`;
4544
4822
  }
4545
4823
 
4546
4824
  var _process$env$npm_pack;
@@ -4560,7 +4838,17 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
4560
4838
  * https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
4561
4839
  */
4562
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
+ }
4563
4849
  /** @internal */
4850
+
4851
+
4564
4852
  function extractCommitmentFromConfig(commitmentOrConfig) {
4565
4853
  let commitment;
4566
4854
  let config;
@@ -4755,7 +5043,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
4755
5043
  * A performance sample
4756
5044
  */
4757
5045
 
4758
- function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
5046
+ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4759
5047
  const fetch = customFetch ? customFetch : fetchImpl;
4760
5048
 
4761
5049
  let fetchWithMiddleware;
@@ -5561,8 +5849,6 @@ class Connection {
5561
5849
  this._subscriptionCallbacksByServerSubscriptionId = {};
5562
5850
  this._subscriptionsByHash = {};
5563
5851
  this._subscriptionsAutoDisposedByRpc = new Set();
5564
- let url = new URL(endpoint);
5565
- const useHttps = url.protocol === 'https:';
5566
5852
  let wsEndpoint;
5567
5853
  let httpHeaders;
5568
5854
  let fetch;
@@ -5581,9 +5867,9 @@ class Connection {
5581
5867
  disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
5582
5868
  }
5583
5869
 
5584
- this._rpcEndpoint = endpoint;
5870
+ this._rpcEndpoint = assertEndpointUrl(endpoint);
5585
5871
  this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
5586
- this._rpcClient = createRpcClient(url.toString(), useHttps, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
5872
+ this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
5587
5873
  this._rpcRequest = createRpcRequest(this._rpcClient);
5588
5874
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
5589
5875
  this._rpcWebSocket = new rpcWebsockets.Client(this._rpcWsEndpoint, {
@@ -10124,6 +10410,23 @@ class VoteProgram {
10124
10410
  data
10125
10411
  });
10126
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
+ }
10127
10430
 
10128
10431
  }
10129
10432
  VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
@@ -10175,15 +10478,14 @@ class ValidatorInfo {
10175
10478
 
10176
10479
 
10177
10480
  static fromConfigData(buffer$1) {
10178
- const PUBKEY_LENGTH = 32;
10179
10481
  let byteArray = [...buffer$1];
10180
10482
  const configKeyCount = decodeLength(byteArray);
10181
10483
  if (configKeyCount !== 2) return null;
10182
10484
  const configKeys = [];
10183
10485
 
10184
10486
  for (let i = 0; i < 2; i++) {
10185
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
10186
- byteArray = byteArray.slice(PUBKEY_LENGTH);
10487
+ const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
10488
+ byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
10187
10489
  const isSigner = byteArray.slice(0, 1)[0] === 1;
10188
10490
  byteArray = byteArray.slice(1);
10189
10491
  configKeys.push({
@@ -10419,9 +10721,11 @@ exports.Loader = Loader;
10419
10721
  exports.Lockup = Lockup;
10420
10722
  exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;
10421
10723
  exports.Message = Message;
10724
+ exports.MessageV0 = MessageV0;
10422
10725
  exports.NONCE_ACCOUNT_LENGTH = NONCE_ACCOUNT_LENGTH;
10423
10726
  exports.NonceAccount = NonceAccount;
10424
10727
  exports.PACKET_DATA_SIZE = PACKET_DATA_SIZE;
10728
+ exports.PUBLIC_KEY_LENGTH = PUBLIC_KEY_LENGTH;
10425
10729
  exports.PublicKey = PublicKey;
10426
10730
  exports.SIGNATURE_LENGTH_IN_BYTES = SIGNATURE_LENGTH_IN_BYTES;
10427
10731
  exports.SOLANA_SCHEMA = SOLANA_SCHEMA;
@@ -10452,8 +10756,11 @@ exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheig
10452
10756
  exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
10453
10757
  exports.TransactionInstruction = TransactionInstruction;
10454
10758
  exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
10759
+ exports.VERSION_PREFIX_MASK = VERSION_PREFIX_MASK;
10455
10760
  exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
10456
10761
  exports.ValidatorInfo = ValidatorInfo;
10762
+ exports.VersionedMessage = VersionedMessage;
10763
+ exports.VersionedTransaction = VersionedTransaction;
10457
10764
  exports.VoteAccount = VoteAccount;
10458
10765
  exports.VoteAuthorizationLayout = VoteAuthorizationLayout;
10459
10766
  exports.VoteInit = VoteInit;