@solana/web3.js 1.70.3 → 1.70.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
@@ -11245,6 +11245,36 @@ var solanaWeb3 = (function (exports) {
11245
11245
 
11246
11246
  }
11247
11247
 
11248
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
11249
+ /**
11250
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
11251
+ */
11252
+
11253
+ function guardedShift(byteArray) {
11254
+ if (byteArray.length === 0) {
11255
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
11256
+ }
11257
+
11258
+ return byteArray.shift();
11259
+ }
11260
+ /**
11261
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
11262
+ * the array.
11263
+ */
11264
+
11265
+ function guardedSplice(byteArray, ...args) {
11266
+ var _args$;
11267
+
11268
+ const [start] = args;
11269
+
11270
+ if (args.length === 2 // Implies that `deleteCount` was supplied
11271
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
11272
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
11273
+ }
11274
+
11275
+ return byteArray.splice(...args);
11276
+ }
11277
+
11248
11278
  /**
11249
11279
  * An instruction to execute by a program
11250
11280
  *
@@ -11396,37 +11426,33 @@ var solanaWeb3 = (function (exports) {
11396
11426
  static from(buffer$1) {
11397
11427
  // Slice up wire data
11398
11428
  let byteArray = [...buffer$1];
11399
- const numRequiredSignatures = byteArray.shift();
11429
+ const numRequiredSignatures = guardedShift(byteArray);
11400
11430
 
11401
11431
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
11402
11432
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
11403
11433
  }
11404
11434
 
11405
- const numReadonlySignedAccounts = byteArray.shift();
11406
- const numReadonlyUnsignedAccounts = byteArray.shift();
11435
+ const numReadonlySignedAccounts = guardedShift(byteArray);
11436
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
11407
11437
  const accountCount = decodeLength(byteArray);
11408
11438
  let accountKeys = [];
11409
11439
 
11410
11440
  for (let i = 0; i < accountCount; i++) {
11411
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
11412
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
11441
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
11413
11442
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
11414
11443
  }
11415
11444
 
11416
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
11417
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
11445
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
11418
11446
  const instructionCount = decodeLength(byteArray);
11419
11447
  let instructions = [];
11420
11448
 
11421
11449
  for (let i = 0; i < instructionCount; i++) {
11422
- const programIdIndex = byteArray.shift();
11450
+ const programIdIndex = guardedShift(byteArray);
11423
11451
  const accountCount = decodeLength(byteArray);
11424
- const accounts = byteArray.slice(0, accountCount);
11425
- byteArray = byteArray.slice(accountCount);
11452
+ const accounts = guardedSplice(byteArray, 0, accountCount);
11426
11453
  const dataLength = decodeLength(byteArray);
11427
- const dataSlice = byteArray.slice(0, dataLength);
11454
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
11428
11455
  const data = bs58$1.encode(buffer.Buffer.from(dataSlice));
11429
- byteArray = byteArray.slice(dataLength);
11430
11456
  instructions.push({
11431
11457
  programIdIndex,
11432
11458
  accounts,
@@ -11662,33 +11688,33 @@ var solanaWeb3 = (function (exports) {
11662
11688
 
11663
11689
  static deserialize(serializedMessage) {
11664
11690
  let byteArray = [...serializedMessage];
11665
- const prefix = byteArray.shift();
11691
+ const prefix = guardedShift(byteArray);
11666
11692
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
11667
11693
  assert$1(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
11668
11694
  const version = maskedPrefix;
11669
11695
  assert$1(version === 0, `Expected versioned message with version 0 but found version ${version}`);
11670
11696
  const header = {
11671
- numRequiredSignatures: byteArray.shift(),
11672
- numReadonlySignedAccounts: byteArray.shift(),
11673
- numReadonlyUnsignedAccounts: byteArray.shift()
11697
+ numRequiredSignatures: guardedShift(byteArray),
11698
+ numReadonlySignedAccounts: guardedShift(byteArray),
11699
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
11674
11700
  };
11675
11701
  const staticAccountKeys = [];
11676
11702
  const staticAccountKeysLength = decodeLength(byteArray);
11677
11703
 
11678
11704
  for (let i = 0; i < staticAccountKeysLength; i++) {
11679
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
11705
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
11680
11706
  }
11681
11707
 
11682
- const recentBlockhash = bs58$1.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
11708
+ const recentBlockhash = bs58$1.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
11683
11709
  const instructionCount = decodeLength(byteArray);
11684
11710
  const compiledInstructions = [];
11685
11711
 
11686
11712
  for (let i = 0; i < instructionCount; i++) {
11687
- const programIdIndex = byteArray.shift();
11713
+ const programIdIndex = guardedShift(byteArray);
11688
11714
  const accountKeyIndexesLength = decodeLength(byteArray);
11689
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
11715
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
11690
11716
  const dataLength = decodeLength(byteArray);
11691
- const data = new Uint8Array(byteArray.splice(0, dataLength));
11717
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
11692
11718
  compiledInstructions.push({
11693
11719
  programIdIndex,
11694
11720
  accountKeyIndexes,
@@ -11700,11 +11726,11 @@ var solanaWeb3 = (function (exports) {
11700
11726
  const addressTableLookups = [];
11701
11727
 
11702
11728
  for (let i = 0; i < addressTableLookupsCount; i++) {
11703
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
11729
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
11704
11730
  const writableIndexesLength = decodeLength(byteArray);
11705
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
11731
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
11706
11732
  const readonlyIndexesLength = decodeLength(byteArray);
11707
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
11733
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
11708
11734
  addressTableLookups.push({
11709
11735
  accountKey,
11710
11736
  writableIndexes,
@@ -12444,8 +12470,7 @@ var solanaWeb3 = (function (exports) {
12444
12470
  let signatures = [];
12445
12471
 
12446
12472
  for (let i = 0; i < signatureCount; i++) {
12447
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
12448
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
12473
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
12449
12474
  signatures.push(bs58$1.encode(buffer.Buffer.from(signature)));
12450
12475
  }
12451
12476
 
@@ -12643,7 +12668,7 @@ var solanaWeb3 = (function (exports) {
12643
12668
  const signaturesLength = decodeLength(byteArray);
12644
12669
 
12645
12670
  for (let i = 0; i < signaturesLength; i++) {
12646
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
12671
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
12647
12672
  }
12648
12673
 
12649
12674
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -18325,7 +18350,7 @@ var solanaWeb3 = (function (exports) {
18325
18350
 
18326
18351
  /** @internal */
18327
18352
  const COMMON_HTTP_HEADERS = {
18328
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
18353
+ 'solana-client': `js/${(_process$env$npm_pack = "1.70.4") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
18329
18354
  };
18330
18355
  /**
18331
18356
  * A connection to a fullnode JSON RPC endpoint
@@ -24961,10 +24986,8 @@ var solanaWeb3 = (function (exports) {
24961
24986
  const configKeys = [];
24962
24987
 
24963
24988
  for (let i = 0; i < 2; i++) {
24964
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
24965
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
24966
- const isSigner = byteArray.slice(0, 1)[0] === 1;
24967
- byteArray = byteArray.slice(1);
24989
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
24990
+ const isSigner = guardedShift(byteArray) === 1;
24968
24991
  configKeys.push({
24969
24992
  publicKey,
24970
24993
  isSigner