@solana/web3.js 1.19.0 → 1.19.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
@@ -477,6 +477,36 @@ function encodeLength(bytes, len) {
477
477
  }
478
478
  }
479
479
 
480
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
481
+ /**
482
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
483
+ */
484
+
485
+ function guardedShift(byteArray) {
486
+ if (byteArray.length === 0) {
487
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
488
+ }
489
+
490
+ return byteArray.shift();
491
+ }
492
+ /**
493
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
494
+ * the array.
495
+ */
496
+
497
+ function guardedSplice(byteArray, ...args) {
498
+ var _args$;
499
+
500
+ const [start] = args;
501
+
502
+ if (args.length === 2 // Implies that `deleteCount` was supplied
503
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
504
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
505
+ }
506
+
507
+ return byteArray.splice(...args);
508
+ }
509
+
480
510
  /**
481
511
  * The message header, identifying signed and read-only account
482
512
  */
@@ -561,32 +591,28 @@ class Message {
561
591
  static from(buffer$1) {
562
592
  // Slice up wire data
563
593
  let byteArray = [...buffer$1];
564
- const numRequiredSignatures = byteArray.shift();
565
- const numReadonlySignedAccounts = byteArray.shift();
566
- const numReadonlyUnsignedAccounts = byteArray.shift();
594
+ const numRequiredSignatures = guardedShift(byteArray);
595
+ const numReadonlySignedAccounts = guardedShift(byteArray);
596
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
567
597
  const accountCount = decodeLength(byteArray);
568
598
  let accountKeys = [];
569
599
 
570
600
  for (let i = 0; i < accountCount; i++) {
571
- const account = byteArray.slice(0, PUBKEY_LENGTH);
572
- byteArray = byteArray.slice(PUBKEY_LENGTH);
601
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
573
602
  accountKeys.push(bs58__default['default'].encode(buffer.Buffer.from(account)));
574
603
  }
575
604
 
576
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
577
- byteArray = byteArray.slice(PUBKEY_LENGTH);
605
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
578
606
  const instructionCount = decodeLength(byteArray);
579
607
  let instructions = [];
580
608
 
581
609
  for (let i = 0; i < instructionCount; i++) {
582
- const programIdIndex = byteArray.shift();
610
+ const programIdIndex = guardedShift(byteArray);
583
611
  const accountCount = decodeLength(byteArray);
584
- const accounts = byteArray.slice(0, accountCount);
585
- byteArray = byteArray.slice(accountCount);
612
+ const accounts = guardedSplice(byteArray, 0, accountCount);
586
613
  const dataLength = decodeLength(byteArray);
587
- const dataSlice = byteArray.slice(0, dataLength);
614
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
588
615
  const data = bs58__default['default'].encode(buffer.Buffer.from(dataSlice));
589
- byteArray = byteArray.slice(dataLength);
590
616
  instructions.push({
591
617
  programIdIndex,
592
618
  accounts,
@@ -609,6 +635,10 @@ class Message {
609
635
 
610
636
  }
611
637
 
638
+ /**
639
+ * Transaction signature as base-58 encoded string
640
+ */
641
+
612
642
  /**
613
643
  * Default (empty) signature
614
644
  *
@@ -1202,8 +1232,7 @@ class Transaction {
1202
1232
  let signatures = [];
1203
1233
 
1204
1234
  for (let i = 0; i < signatureCount; i++) {
1205
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
1206
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
1235
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
1207
1236
  signatures.push(bs58__default['default'].encode(buffer.Buffer.from(signature)));
1208
1237
  }
1209
1238
 
@@ -6492,10 +6521,8 @@ class ValidatorInfo {
6492
6521
  const configKeys = [];
6493
6522
 
6494
6523
  for (let i = 0; i < 2; i++) {
6495
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
6496
- byteArray = byteArray.slice(PUBKEY_LENGTH);
6497
- const isSigner = byteArray.slice(0, 1)[0] === 1;
6498
- byteArray = byteArray.slice(1);
6524
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
6525
+ const isSigner = guardedShift(byteArray) === 1;
6499
6526
  configKeys.push({
6500
6527
  publicKey,
6501
6528
  isSigner