@solana/web3.js 1.27.0 → 1.27.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.
package/lib/index.cjs.js CHANGED
@@ -479,6 +479,36 @@ function encodeLength(bytes, len) {
479
479
  }
480
480
  }
481
481
 
482
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
483
+ /**
484
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
485
+ */
486
+
487
+ function guardedShift(byteArray) {
488
+ if (byteArray.length === 0) {
489
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
490
+ }
491
+
492
+ return byteArray.shift();
493
+ }
494
+ /**
495
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
496
+ * the array.
497
+ */
498
+
499
+ function guardedSplice(byteArray, ...args) {
500
+ var _args$;
501
+
502
+ const [start] = args;
503
+
504
+ if (args.length === 2 // Implies that `deleteCount` was supplied
505
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
506
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
507
+ }
508
+
509
+ return byteArray.splice(...args);
510
+ }
511
+
482
512
  /**
483
513
  * The message header, identifying signed and read-only account
484
514
  */
@@ -563,32 +593,28 @@ class Message {
563
593
  static from(buffer$1) {
564
594
  // Slice up wire data
565
595
  let byteArray = [...buffer$1];
566
- const numRequiredSignatures = byteArray.shift();
567
- const numReadonlySignedAccounts = byteArray.shift();
568
- const numReadonlyUnsignedAccounts = byteArray.shift();
596
+ const numRequiredSignatures = guardedShift(byteArray);
597
+ const numReadonlySignedAccounts = guardedShift(byteArray);
598
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
569
599
  const accountCount = decodeLength(byteArray);
570
600
  let accountKeys = [];
571
601
 
572
602
  for (let i = 0; i < accountCount; i++) {
573
- const account = byteArray.slice(0, PUBKEY_LENGTH);
574
- byteArray = byteArray.slice(PUBKEY_LENGTH);
603
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
575
604
  accountKeys.push(bs58__default['default'].encode(buffer.Buffer.from(account)));
576
605
  }
577
606
 
578
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
579
- byteArray = byteArray.slice(PUBKEY_LENGTH);
607
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
580
608
  const instructionCount = decodeLength(byteArray);
581
609
  let instructions = [];
582
610
 
583
611
  for (let i = 0; i < instructionCount; i++) {
584
- const programIdIndex = byteArray.shift();
612
+ const programIdIndex = guardedShift(byteArray);
585
613
  const accountCount = decodeLength(byteArray);
586
- const accounts = byteArray.slice(0, accountCount);
587
- byteArray = byteArray.slice(accountCount);
614
+ const accounts = guardedSplice(byteArray, 0, accountCount);
588
615
  const dataLength = decodeLength(byteArray);
589
- const dataSlice = byteArray.slice(0, dataLength);
616
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
590
617
  const data = bs58__default['default'].encode(buffer.Buffer.from(dataSlice));
591
- byteArray = byteArray.slice(dataLength);
592
618
  instructions.push({
593
619
  programIdIndex,
594
620
  accounts,
@@ -617,6 +643,10 @@ function assert (condition, message) {
617
643
  }
618
644
  }
619
645
 
646
+ /**
647
+ * Transaction signature as base-58 encoded string
648
+ */
649
+
620
650
  /**
621
651
  * Default (empty) signature
622
652
  *
@@ -1210,8 +1240,7 @@ class Transaction {
1210
1240
  let signatures = [];
1211
1241
 
1212
1242
  for (let i = 0; i < signatureCount; i++) {
1213
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
1214
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
1243
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
1215
1244
  signatures.push(bs58__default['default'].encode(buffer.Buffer.from(signature)));
1216
1245
  }
1217
1246
 
@@ -6714,10 +6743,8 @@ class ValidatorInfo {
6714
6743
  const configKeys = [];
6715
6744
 
6716
6745
  for (let i = 0; i < 2; i++) {
6717
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
6718
- byteArray = byteArray.slice(PUBKEY_LENGTH);
6719
- const isSigner = byteArray.slice(0, 1)[0] === 1;
6720
- byteArray = byteArray.slice(1);
6746
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
6747
+ const isSigner = guardedShift(byteArray) === 1;
6721
6748
  configKeys.push({
6722
6749
  publicKey,
6723
6750
  isSigner