@solana/web3.js 1.91.1 → 1.91.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.
package/lib/index.iife.js CHANGED
@@ -12061,6 +12061,31 @@ var solanaWeb3 = (function (exports) {
12061
12061
  }
12062
12062
  }
12063
12063
 
12064
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
12065
+
12066
+ /**
12067
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
12068
+ */
12069
+ function guardedShift(byteArray) {
12070
+ if (byteArray.length === 0) {
12071
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
12072
+ }
12073
+ return byteArray.shift();
12074
+ }
12075
+
12076
+ /**
12077
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
12078
+ * the array.
12079
+ */
12080
+ function guardedSplice(byteArray, ...args) {
12081
+ const [start] = args;
12082
+ if (args.length === 2 // Implies that `deleteCount` was supplied
12083
+ ? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
12084
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
12085
+ }
12086
+ return byteArray.splice(...args);
12087
+ }
12088
+
12064
12089
  /**
12065
12090
  * An instruction to execute by a program
12066
12091
  *
@@ -12202,27 +12227,27 @@ var solanaWeb3 = (function (exports) {
12202
12227
  static from(buffer$1) {
12203
12228
  // Slice up wire data
12204
12229
  let byteArray = [...buffer$1];
12205
- const numRequiredSignatures = byteArray.shift();
12230
+ const numRequiredSignatures = guardedShift(byteArray);
12206
12231
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
12207
12232
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
12208
12233
  }
12209
- const numReadonlySignedAccounts = byteArray.shift();
12210
- const numReadonlyUnsignedAccounts = byteArray.shift();
12234
+ const numReadonlySignedAccounts = guardedShift(byteArray);
12235
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
12211
12236
  const accountCount = decodeLength(byteArray);
12212
12237
  let accountKeys = [];
12213
12238
  for (let i = 0; i < accountCount; i++) {
12214
- const account = byteArray.splice(0, PUBLIC_KEY_LENGTH);
12239
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
12215
12240
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
12216
12241
  }
12217
- const recentBlockhash = byteArray.splice(0, PUBLIC_KEY_LENGTH);
12242
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
12218
12243
  const instructionCount = decodeLength(byteArray);
12219
12244
  let instructions = [];
12220
12245
  for (let i = 0; i < instructionCount; i++) {
12221
- const programIdIndex = byteArray.shift();
12246
+ const programIdIndex = guardedShift(byteArray);
12222
12247
  const accountCount = decodeLength(byteArray);
12223
- const accounts = byteArray.splice(0, accountCount);
12248
+ const accounts = guardedSplice(byteArray, 0, accountCount);
12224
12249
  const dataLength = decodeLength(byteArray);
12225
- const dataSlice = byteArray.splice(0, dataLength);
12250
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
12226
12251
  const data = bs58$1.encode(buffer.Buffer.from(dataSlice));
12227
12252
  instructions.push({
12228
12253
  programIdIndex,
@@ -12428,30 +12453,30 @@ var solanaWeb3 = (function (exports) {
12428
12453
  }
12429
12454
  static deserialize(serializedMessage) {
12430
12455
  let byteArray = [...serializedMessage];
12431
- const prefix = byteArray.shift();
12456
+ const prefix = guardedShift(byteArray);
12432
12457
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
12433
12458
  assert$1(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
12434
12459
  const version = maskedPrefix;
12435
12460
  assert$1(version === 0, `Expected versioned message with version 0 but found version ${version}`);
12436
12461
  const header = {
12437
- numRequiredSignatures: byteArray.shift(),
12438
- numReadonlySignedAccounts: byteArray.shift(),
12439
- numReadonlyUnsignedAccounts: byteArray.shift()
12462
+ numRequiredSignatures: guardedShift(byteArray),
12463
+ numReadonlySignedAccounts: guardedShift(byteArray),
12464
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
12440
12465
  };
12441
12466
  const staticAccountKeys = [];
12442
12467
  const staticAccountKeysLength = decodeLength(byteArray);
12443
12468
  for (let i = 0; i < staticAccountKeysLength; i++) {
12444
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
12469
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
12445
12470
  }
12446
- const recentBlockhash = bs58$1.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
12471
+ const recentBlockhash = bs58$1.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
12447
12472
  const instructionCount = decodeLength(byteArray);
12448
12473
  const compiledInstructions = [];
12449
12474
  for (let i = 0; i < instructionCount; i++) {
12450
- const programIdIndex = byteArray.shift();
12475
+ const programIdIndex = guardedShift(byteArray);
12451
12476
  const accountKeyIndexesLength = decodeLength(byteArray);
12452
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
12477
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
12453
12478
  const dataLength = decodeLength(byteArray);
12454
- const data = new Uint8Array(byteArray.splice(0, dataLength));
12479
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
12455
12480
  compiledInstructions.push({
12456
12481
  programIdIndex,
12457
12482
  accountKeyIndexes,
@@ -12461,11 +12486,11 @@ var solanaWeb3 = (function (exports) {
12461
12486
  const addressTableLookupsCount = decodeLength(byteArray);
12462
12487
  const addressTableLookups = [];
12463
12488
  for (let i = 0; i < addressTableLookupsCount; i++) {
12464
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
12489
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
12465
12490
  const writableIndexesLength = decodeLength(byteArray);
12466
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
12491
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
12467
12492
  const readonlyIndexesLength = decodeLength(byteArray);
12468
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
12493
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
12469
12494
  addressTableLookups.push({
12470
12495
  accountKey,
12471
12496
  writableIndexes,
@@ -13256,7 +13281,7 @@ var solanaWeb3 = (function (exports) {
13256
13281
  const signatureCount = decodeLength(byteArray);
13257
13282
  let signatures = [];
13258
13283
  for (let i = 0; i < signatureCount; i++) {
13259
- const signature = byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES);
13284
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
13260
13285
  signatures.push(bs58$1.encode(buffer.Buffer.from(signature)));
13261
13286
  }
13262
13287
  return Transaction.populate(Message.from(byteArray), signatures);
@@ -13431,7 +13456,7 @@ var solanaWeb3 = (function (exports) {
13431
13456
  const signatures = [];
13432
13457
  const signaturesLength = decodeLength(byteArray);
13433
13458
  for (let i = 0; i < signaturesLength; i++) {
13434
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
13459
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
13435
13460
  }
13436
13461
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
13437
13462
  return new VersionedTransaction(message, signatures);
@@ -25986,8 +26011,8 @@ var solanaWeb3 = (function (exports) {
25986
26011
  if (configKeyCount !== 2) return null;
25987
26012
  const configKeys = [];
25988
26013
  for (let i = 0; i < 2; i++) {
25989
- const publicKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
25990
- const isSigner = byteArray.splice(0, 1)[0] === 1;
26014
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
26015
+ const isSigner = guardedShift(byteArray) === 1;
25991
26016
  configKeys.push({
25992
26017
  publicKey,
25993
26018
  isSigner