@solana/web3.js 1.24.1 → 1.24.3

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.
@@ -436,6 +436,36 @@ function encodeLength(bytes, len) {
436
436
  }
437
437
  }
438
438
 
439
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
440
+ /**
441
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
442
+ */
443
+
444
+ function guardedShift(byteArray) {
445
+ if (byteArray.length === 0) {
446
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
447
+ }
448
+
449
+ return byteArray.shift();
450
+ }
451
+ /**
452
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
453
+ * the array.
454
+ */
455
+
456
+ function guardedSplice(byteArray, ...args) {
457
+ var _args$;
458
+
459
+ const [start] = args;
460
+
461
+ if (args.length === 2 // Implies that `deleteCount` was supplied
462
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
463
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
464
+ }
465
+
466
+ return byteArray.splice(...args);
467
+ }
468
+
439
469
  /**
440
470
  * The message header, identifying signed and read-only account
441
471
  */
@@ -520,32 +550,28 @@ class Message {
520
550
  static from(buffer) {
521
551
  // Slice up wire data
522
552
  let byteArray = [...buffer];
523
- const numRequiredSignatures = byteArray.shift();
524
- const numReadonlySignedAccounts = byteArray.shift();
525
- const numReadonlyUnsignedAccounts = byteArray.shift();
553
+ const numRequiredSignatures = guardedShift(byteArray);
554
+ const numReadonlySignedAccounts = guardedShift(byteArray);
555
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
526
556
  const accountCount = decodeLength(byteArray);
527
557
  let accountKeys = [];
528
558
 
529
559
  for (let i = 0; i < accountCount; i++) {
530
- const account = byteArray.slice(0, PUBKEY_LENGTH);
531
- byteArray = byteArray.slice(PUBKEY_LENGTH);
560
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
532
561
  accountKeys.push(bs58.encode(Buffer.from(account)));
533
562
  }
534
563
 
535
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
536
- byteArray = byteArray.slice(PUBKEY_LENGTH);
564
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
537
565
  const instructionCount = decodeLength(byteArray);
538
566
  let instructions = [];
539
567
 
540
568
  for (let i = 0; i < instructionCount; i++) {
541
- const programIdIndex = byteArray.shift();
569
+ const programIdIndex = guardedShift(byteArray);
542
570
  const accountCount = decodeLength(byteArray);
543
- const accounts = byteArray.slice(0, accountCount);
544
- byteArray = byteArray.slice(accountCount);
571
+ const accounts = guardedSplice(byteArray, 0, accountCount);
545
572
  const dataLength = decodeLength(byteArray);
546
- const dataSlice = byteArray.slice(0, dataLength);
573
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
547
574
  const data = bs58.encode(Buffer.from(dataSlice));
548
- byteArray = byteArray.slice(dataLength);
549
575
  instructions.push({
550
576
  programIdIndex,
551
577
  accounts,
@@ -574,6 +600,10 @@ function assert (condition, message) {
574
600
  }
575
601
  }
576
602
 
603
+ /**
604
+ * Transaction signature as base-58 encoded string
605
+ */
606
+
577
607
  /**
578
608
  * Default (empty) signature
579
609
  *
@@ -1167,8 +1197,7 @@ class Transaction {
1167
1197
  let signatures = [];
1168
1198
 
1169
1199
  for (let i = 0; i < signatureCount; i++) {
1170
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
1171
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
1200
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
1172
1201
  signatures.push(bs58.encode(Buffer.from(signature)));
1173
1202
  }
1174
1203
 
@@ -6538,10 +6567,8 @@ class ValidatorInfo {
6538
6567
  const configKeys = [];
6539
6568
 
6540
6569
  for (let i = 0; i < 2; i++) {
6541
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
6542
- byteArray = byteArray.slice(PUBKEY_LENGTH);
6543
- const isSigner = byteArray.slice(0, 1)[0] === 1;
6544
- byteArray = byteArray.slice(1);
6570
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
6571
+ const isSigner = guardedShift(byteArray) === 1;
6545
6572
  configKeys.push({
6546
6573
  publicKey,
6547
6574
  isSigner
@@ -6707,5 +6734,5 @@ function clusterApiUrl(cluster, tls) {
6707
6734
 
6708
6735
  const LAMPORTS_PER_SOL = 1000000000;
6709
6736
 
6710
- export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
6737
+ export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
6711
6738
  //# sourceMappingURL=index.browser.esm.js.map