@solana/web3.js 1.89.1 → 1.89.2

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
@@ -11862,6 +11862,31 @@ var solanaWeb3 = (function (exports) {
11862
11862
  }
11863
11863
  }
11864
11864
 
11865
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
11866
+
11867
+ /**
11868
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
11869
+ */
11870
+ function guardedShift(byteArray) {
11871
+ if (byteArray.length === 0) {
11872
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
11873
+ }
11874
+ return byteArray.shift();
11875
+ }
11876
+
11877
+ /**
11878
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
11879
+ * the array.
11880
+ */
11881
+ function guardedSplice(byteArray, ...args) {
11882
+ const [start] = args;
11883
+ if (args.length === 2 // Implies that `deleteCount` was supplied
11884
+ ? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
11885
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
11886
+ }
11887
+ return byteArray.splice(...args);
11888
+ }
11889
+
11865
11890
  /**
11866
11891
  * An instruction to execute by a program
11867
11892
  *
@@ -12003,32 +12028,28 @@ var solanaWeb3 = (function (exports) {
12003
12028
  static from(buffer$1) {
12004
12029
  // Slice up wire data
12005
12030
  let byteArray = [...buffer$1];
12006
- const numRequiredSignatures = byteArray.shift();
12031
+ const numRequiredSignatures = guardedShift(byteArray);
12007
12032
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
12008
12033
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
12009
12034
  }
12010
- const numReadonlySignedAccounts = byteArray.shift();
12011
- const numReadonlyUnsignedAccounts = byteArray.shift();
12035
+ const numReadonlySignedAccounts = guardedShift(byteArray);
12036
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
12012
12037
  const accountCount = decodeLength(byteArray);
12013
12038
  let accountKeys = [];
12014
12039
  for (let i = 0; i < accountCount; i++) {
12015
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
12016
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
12040
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
12017
12041
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
12018
12042
  }
12019
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
12020
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
12043
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
12021
12044
  const instructionCount = decodeLength(byteArray);
12022
12045
  let instructions = [];
12023
12046
  for (let i = 0; i < instructionCount; i++) {
12024
- const programIdIndex = byteArray.shift();
12047
+ const programIdIndex = guardedShift(byteArray);
12025
12048
  const accountCount = decodeLength(byteArray);
12026
- const accounts = byteArray.slice(0, accountCount);
12027
- byteArray = byteArray.slice(accountCount);
12049
+ const accounts = guardedSplice(byteArray, 0, accountCount);
12028
12050
  const dataLength = decodeLength(byteArray);
12029
- const dataSlice = byteArray.slice(0, dataLength);
12051
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
12030
12052
  const data = bs58$1.encode(buffer.Buffer.from(dataSlice));
12031
- byteArray = byteArray.slice(dataLength);
12032
12053
  instructions.push({
12033
12054
  programIdIndex,
12034
12055
  accounts,
@@ -12233,30 +12254,30 @@ var solanaWeb3 = (function (exports) {
12233
12254
  }
12234
12255
  static deserialize(serializedMessage) {
12235
12256
  let byteArray = [...serializedMessage];
12236
- const prefix = byteArray.shift();
12257
+ const prefix = guardedShift(byteArray);
12237
12258
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
12238
12259
  assert$1(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
12239
12260
  const version = maskedPrefix;
12240
12261
  assert$1(version === 0, `Expected versioned message with version 0 but found version ${version}`);
12241
12262
  const header = {
12242
- numRequiredSignatures: byteArray.shift(),
12243
- numReadonlySignedAccounts: byteArray.shift(),
12244
- numReadonlyUnsignedAccounts: byteArray.shift()
12263
+ numRequiredSignatures: guardedShift(byteArray),
12264
+ numReadonlySignedAccounts: guardedShift(byteArray),
12265
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
12245
12266
  };
12246
12267
  const staticAccountKeys = [];
12247
12268
  const staticAccountKeysLength = decodeLength(byteArray);
12248
12269
  for (let i = 0; i < staticAccountKeysLength; i++) {
12249
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
12270
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
12250
12271
  }
12251
- const recentBlockhash = bs58$1.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
12272
+ const recentBlockhash = bs58$1.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
12252
12273
  const instructionCount = decodeLength(byteArray);
12253
12274
  const compiledInstructions = [];
12254
12275
  for (let i = 0; i < instructionCount; i++) {
12255
- const programIdIndex = byteArray.shift();
12276
+ const programIdIndex = guardedShift(byteArray);
12256
12277
  const accountKeyIndexesLength = decodeLength(byteArray);
12257
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
12278
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
12258
12279
  const dataLength = decodeLength(byteArray);
12259
- const data = new Uint8Array(byteArray.splice(0, dataLength));
12280
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
12260
12281
  compiledInstructions.push({
12261
12282
  programIdIndex,
12262
12283
  accountKeyIndexes,
@@ -12266,11 +12287,11 @@ var solanaWeb3 = (function (exports) {
12266
12287
  const addressTableLookupsCount = decodeLength(byteArray);
12267
12288
  const addressTableLookups = [];
12268
12289
  for (let i = 0; i < addressTableLookupsCount; i++) {
12269
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
12290
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
12270
12291
  const writableIndexesLength = decodeLength(byteArray);
12271
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
12292
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
12272
12293
  const readonlyIndexesLength = decodeLength(byteArray);
12273
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
12294
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
12274
12295
  addressTableLookups.push({
12275
12296
  accountKey,
12276
12297
  writableIndexes,
@@ -13061,8 +13082,7 @@ var solanaWeb3 = (function (exports) {
13061
13082
  const signatureCount = decodeLength(byteArray);
13062
13083
  let signatures = [];
13063
13084
  for (let i = 0; i < signatureCount; i++) {
13064
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
13065
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
13085
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
13066
13086
  signatures.push(bs58$1.encode(buffer.Buffer.from(signature)));
13067
13087
  }
13068
13088
  return Transaction.populate(Message.from(byteArray), signatures);
@@ -13237,7 +13257,7 @@ var solanaWeb3 = (function (exports) {
13237
13257
  const signatures = [];
13238
13258
  const signaturesLength = decodeLength(byteArray);
13239
13259
  for (let i = 0; i < signaturesLength; i++) {
13240
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
13260
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
13241
13261
  }
13242
13262
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
13243
13263
  return new VersionedTransaction(message, signatures);
@@ -19364,7 +19384,7 @@ var solanaWeb3 = (function (exports) {
19364
19384
 
19365
19385
  /** @internal */
19366
19386
  const COMMON_HTTP_HEADERS = {
19367
- 'solana-client': `js/${"0.0.0-development" }`
19387
+ 'solana-client': `js/${"1.89.2" }`
19368
19388
  };
19369
19389
 
19370
19390
  /**
@@ -25605,10 +25625,8 @@ var solanaWeb3 = (function (exports) {
25605
25625
  if (configKeyCount !== 2) return null;
25606
25626
  const configKeys = [];
25607
25627
  for (let i = 0; i < 2; i++) {
25608
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
25609
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
25610
- const isSigner = byteArray.slice(0, 1)[0] === 1;
25611
- byteArray = byteArray.slice(1);
25628
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
25629
+ const isSigner = guardedShift(byteArray) === 1;
25612
25630
  configKeys.push({
25613
25631
  publicKey,
25614
25632
  isSigner