@solana/web3.js 1.76.0 → 1.76.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.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,
@@ -13510,8 +13531,7 @@ var solanaWeb3 = (function (exports) {
13510
13531
  const signatureCount = decodeLength(byteArray);
13511
13532
  let signatures = [];
13512
13533
  for (let i = 0; i < signatureCount; i++) {
13513
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
13514
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
13534
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
13515
13535
  signatures.push(bs58$1.encode(buffer.Buffer.from(signature)));
13516
13536
  }
13517
13537
  return Transaction.populate(Message.from(byteArray), signatures);
@@ -13681,7 +13701,7 @@ var solanaWeb3 = (function (exports) {
13681
13701
  const signatures = [];
13682
13702
  const signaturesLength = decodeLength(byteArray);
13683
13703
  for (let i = 0; i < signaturesLength; i++) {
13684
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
13704
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
13685
13705
  }
13686
13706
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
13687
13707
  return new VersionedTransaction(message, signatures);
@@ -19310,7 +19330,7 @@ var solanaWeb3 = (function (exports) {
19310
19330
 
19311
19331
  /** @internal */
19312
19332
  const COMMON_HTTP_HEADERS = {
19313
- 'solana-client': `js/${"0.0.0-development" }`
19333
+ 'solana-client': `js/${"1.76.1" }`
19314
19334
  };
19315
19335
 
19316
19336
  /**
@@ -25667,10 +25687,8 @@ var solanaWeb3 = (function (exports) {
25667
25687
  if (configKeyCount !== 2) return null;
25668
25688
  const configKeys = [];
25669
25689
  for (let i = 0; i < 2; i++) {
25670
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
25671
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
25672
- const isSigner = byteArray.slice(0, 1)[0] === 1;
25673
- byteArray = byteArray.slice(1);
25690
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
25691
+ const isSigner = guardedShift(byteArray) === 1;
25674
25692
  configKeys.push({
25675
25693
  publicKey,
25676
25694
  isSigner