@solana/web3.js 1.77.2 → 1.77.4

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.iife.js CHANGED
@@ -12431,6 +12431,31 @@ var solanaWeb3 = (function (exports) {
12431
12431
  }
12432
12432
  }
12433
12433
 
12434
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
12435
+
12436
+ /**
12437
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
12438
+ */
12439
+ function guardedShift(byteArray) {
12440
+ if (byteArray.length === 0) {
12441
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
12442
+ }
12443
+ return byteArray.shift();
12444
+ }
12445
+
12446
+ /**
12447
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
12448
+ * the array.
12449
+ */
12450
+ function guardedSplice(byteArray, ...args) {
12451
+ const [start] = args;
12452
+ if (args.length === 2 // Implies that `deleteCount` was supplied
12453
+ ? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
12454
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
12455
+ }
12456
+ return byteArray.splice(...args);
12457
+ }
12458
+
12434
12459
  /**
12435
12460
  * An instruction to execute by a program
12436
12461
  *
@@ -12568,32 +12593,28 @@ var solanaWeb3 = (function (exports) {
12568
12593
  static from(buffer$1) {
12569
12594
  // Slice up wire data
12570
12595
  let byteArray = [...buffer$1];
12571
- const numRequiredSignatures = byteArray.shift();
12596
+ const numRequiredSignatures = guardedShift(byteArray);
12572
12597
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
12573
12598
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
12574
12599
  }
12575
- const numReadonlySignedAccounts = byteArray.shift();
12576
- const numReadonlyUnsignedAccounts = byteArray.shift();
12600
+ const numReadonlySignedAccounts = guardedShift(byteArray);
12601
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
12577
12602
  const accountCount = decodeLength(byteArray);
12578
12603
  let accountKeys = [];
12579
12604
  for (let i = 0; i < accountCount; i++) {
12580
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
12581
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
12605
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
12582
12606
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
12583
12607
  }
12584
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
12585
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
12608
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
12586
12609
  const instructionCount = decodeLength(byteArray);
12587
12610
  let instructions = [];
12588
12611
  for (let i = 0; i < instructionCount; i++) {
12589
- const programIdIndex = byteArray.shift();
12612
+ const programIdIndex = guardedShift(byteArray);
12590
12613
  const accountCount = decodeLength(byteArray);
12591
- const accounts = byteArray.slice(0, accountCount);
12592
- byteArray = byteArray.slice(accountCount);
12614
+ const accounts = guardedSplice(byteArray, 0, accountCount);
12593
12615
  const dataLength = decodeLength(byteArray);
12594
- const dataSlice = byteArray.slice(0, dataLength);
12616
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
12595
12617
  const data = bs58$1.encode(buffer.Buffer.from(dataSlice));
12596
- byteArray = byteArray.slice(dataLength);
12597
12618
  instructions.push({
12598
12619
  programIdIndex,
12599
12620
  accounts,
@@ -12798,30 +12819,30 @@ var solanaWeb3 = (function (exports) {
12798
12819
  }
12799
12820
  static deserialize(serializedMessage) {
12800
12821
  let byteArray = [...serializedMessage];
12801
- const prefix = byteArray.shift();
12822
+ const prefix = guardedShift(byteArray);
12802
12823
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
12803
12824
  assert$1(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
12804
12825
  const version = maskedPrefix;
12805
12826
  assert$1(version === 0, `Expected versioned message with version 0 but found version ${version}`);
12806
12827
  const header = {
12807
- numRequiredSignatures: byteArray.shift(),
12808
- numReadonlySignedAccounts: byteArray.shift(),
12809
- numReadonlyUnsignedAccounts: byteArray.shift()
12828
+ numRequiredSignatures: guardedShift(byteArray),
12829
+ numReadonlySignedAccounts: guardedShift(byteArray),
12830
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
12810
12831
  };
12811
12832
  const staticAccountKeys = [];
12812
12833
  const staticAccountKeysLength = decodeLength(byteArray);
12813
12834
  for (let i = 0; i < staticAccountKeysLength; i++) {
12814
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
12835
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
12815
12836
  }
12816
- const recentBlockhash = bs58$1.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
12837
+ const recentBlockhash = bs58$1.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
12817
12838
  const instructionCount = decodeLength(byteArray);
12818
12839
  const compiledInstructions = [];
12819
12840
  for (let i = 0; i < instructionCount; i++) {
12820
- const programIdIndex = byteArray.shift();
12841
+ const programIdIndex = guardedShift(byteArray);
12821
12842
  const accountKeyIndexesLength = decodeLength(byteArray);
12822
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
12843
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
12823
12844
  const dataLength = decodeLength(byteArray);
12824
- const data = new Uint8Array(byteArray.splice(0, dataLength));
12845
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
12825
12846
  compiledInstructions.push({
12826
12847
  programIdIndex,
12827
12848
  accountKeyIndexes,
@@ -12831,11 +12852,11 @@ var solanaWeb3 = (function (exports) {
12831
12852
  const addressTableLookupsCount = decodeLength(byteArray);
12832
12853
  const addressTableLookups = [];
12833
12854
  for (let i = 0; i < addressTableLookupsCount; i++) {
12834
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
12855
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
12835
12856
  const writableIndexesLength = decodeLength(byteArray);
12836
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
12857
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
12837
12858
  const readonlyIndexesLength = decodeLength(byteArray);
12838
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
12859
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
12839
12860
  addressTableLookups.push({
12840
12861
  accountKey,
12841
12862
  writableIndexes,
@@ -13518,8 +13539,7 @@ var solanaWeb3 = (function (exports) {
13518
13539
  const signatureCount = decodeLength(byteArray);
13519
13540
  let signatures = [];
13520
13541
  for (let i = 0; i < signatureCount; i++) {
13521
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
13522
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
13542
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
13523
13543
  signatures.push(bs58$1.encode(buffer.Buffer.from(signature)));
13524
13544
  }
13525
13545
  return Transaction.populate(Message.from(byteArray), signatures);
@@ -13689,7 +13709,7 @@ var solanaWeb3 = (function (exports) {
13689
13709
  const signatures = [];
13690
13710
  const signaturesLength = decodeLength(byteArray);
13691
13711
  for (let i = 0; i < signaturesLength; i++) {
13692
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
13712
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
13693
13713
  }
13694
13714
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
13695
13715
  return new VersionedTransaction(message, signatures);
@@ -19346,7 +19366,7 @@ var solanaWeb3 = (function (exports) {
19346
19366
 
19347
19367
  /** @internal */
19348
19368
  const COMMON_HTTP_HEADERS = {
19349
- 'solana-client': `js/${"0.0.0-development" }`
19369
+ 'solana-client': `js/${"1.77.4" }`
19350
19370
  };
19351
19371
 
19352
19372
  /**
@@ -25706,10 +25726,8 @@ var solanaWeb3 = (function (exports) {
25706
25726
  if (configKeyCount !== 2) return null;
25707
25727
  const configKeys = [];
25708
25728
  for (let i = 0; i < 2; i++) {
25709
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
25710
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
25711
- const isSigner = byteArray.slice(0, 1)[0] === 1;
25712
- byteArray = byteArray.slice(1);
25729
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
25730
+ const isSigner = guardedShift(byteArray) === 1;
25713
25731
  configKeys.push({
25714
25732
  publicKey,
25715
25733
  isSigner