@solana/web3.js 1.58.0 → 1.58.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
@@ -11202,6 +11202,36 @@ var solanaWeb3 = (function (exports) {
11202
11202
 
11203
11203
  }
11204
11204
 
11205
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
11206
+ /**
11207
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
11208
+ */
11209
+
11210
+ function guardedShift(byteArray) {
11211
+ if (byteArray.length === 0) {
11212
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
11213
+ }
11214
+
11215
+ return byteArray.shift();
11216
+ }
11217
+ /**
11218
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
11219
+ * the array.
11220
+ */
11221
+
11222
+ function guardedSplice(byteArray, ...args) {
11223
+ var _args$;
11224
+
11225
+ const [start] = args;
11226
+
11227
+ if (args.length === 2 // Implies that `deleteCount` was supplied
11228
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
11229
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
11230
+ }
11231
+
11232
+ return byteArray.splice(...args);
11233
+ }
11234
+
11205
11235
  /**
11206
11236
  * An instruction to execute by a program
11207
11237
  *
@@ -11343,37 +11373,33 @@ var solanaWeb3 = (function (exports) {
11343
11373
  static from(buffer$1) {
11344
11374
  // Slice up wire data
11345
11375
  let byteArray = [...buffer$1];
11346
- const numRequiredSignatures = byteArray.shift();
11376
+ const numRequiredSignatures = guardedShift(byteArray);
11347
11377
 
11348
11378
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
11349
11379
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
11350
11380
  }
11351
11381
 
11352
- const numReadonlySignedAccounts = byteArray.shift();
11353
- const numReadonlyUnsignedAccounts = byteArray.shift();
11382
+ const numReadonlySignedAccounts = guardedShift(byteArray);
11383
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
11354
11384
  const accountCount = decodeLength(byteArray);
11355
11385
  let accountKeys = [];
11356
11386
 
11357
11387
  for (let i = 0; i < accountCount; i++) {
11358
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
11359
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
11388
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
11360
11389
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
11361
11390
  }
11362
11391
 
11363
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
11364
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
11392
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
11365
11393
  const instructionCount = decodeLength(byteArray);
11366
11394
  let instructions = [];
11367
11395
 
11368
11396
  for (let i = 0; i < instructionCount; i++) {
11369
- const programIdIndex = byteArray.shift();
11397
+ const programIdIndex = guardedShift(byteArray);
11370
11398
  const accountCount = decodeLength(byteArray);
11371
- const accounts = byteArray.slice(0, accountCount);
11372
- byteArray = byteArray.slice(accountCount);
11399
+ const accounts = guardedSplice(byteArray, 0, accountCount);
11373
11400
  const dataLength = decodeLength(byteArray);
11374
- const dataSlice = byteArray.slice(0, dataLength);
11401
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
11375
11402
  const data = bs58$1.encode(buffer.Buffer.from(dataSlice));
11376
- byteArray = byteArray.slice(dataLength);
11377
11403
  instructions.push({
11378
11404
  programIdIndex,
11379
11405
  accounts,
@@ -11586,33 +11612,33 @@ var solanaWeb3 = (function (exports) {
11586
11612
 
11587
11613
  static deserialize(serializedMessage) {
11588
11614
  let byteArray = [...serializedMessage];
11589
- const prefix = byteArray.shift();
11615
+ const prefix = guardedShift(byteArray);
11590
11616
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
11591
11617
  assert$1(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
11592
11618
  const version = maskedPrefix;
11593
11619
  assert$1(version === 0, `Expected versioned message with version 0 but found version ${version}`);
11594
11620
  const header = {
11595
- numRequiredSignatures: byteArray.shift(),
11596
- numReadonlySignedAccounts: byteArray.shift(),
11597
- numReadonlyUnsignedAccounts: byteArray.shift()
11621
+ numRequiredSignatures: guardedShift(byteArray),
11622
+ numReadonlySignedAccounts: guardedShift(byteArray),
11623
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
11598
11624
  };
11599
11625
  const staticAccountKeys = [];
11600
11626
  const staticAccountKeysLength = decodeLength(byteArray);
11601
11627
 
11602
11628
  for (let i = 0; i < staticAccountKeysLength; i++) {
11603
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
11629
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
11604
11630
  }
11605
11631
 
11606
- const recentBlockhash = bs58$1.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
11632
+ const recentBlockhash = bs58$1.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
11607
11633
  const instructionCount = decodeLength(byteArray);
11608
11634
  const compiledInstructions = [];
11609
11635
 
11610
11636
  for (let i = 0; i < instructionCount; i++) {
11611
- const programIdIndex = byteArray.shift();
11637
+ const programIdIndex = guardedShift(byteArray);
11612
11638
  const accountKeyIndexesLength = decodeLength(byteArray);
11613
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
11639
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
11614
11640
  const dataLength = decodeLength(byteArray);
11615
- const data = new Uint8Array(byteArray.splice(0, dataLength));
11641
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
11616
11642
  compiledInstructions.push({
11617
11643
  programIdIndex,
11618
11644
  accountKeyIndexes,
@@ -11624,11 +11650,11 @@ var solanaWeb3 = (function (exports) {
11624
11650
  const addressTableLookups = [];
11625
11651
 
11626
11652
  for (let i = 0; i < addressTableLookupsCount; i++) {
11627
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
11653
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
11628
11654
  const writableIndexesLength = decodeLength(byteArray);
11629
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
11655
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
11630
11656
  const readonlyIndexesLength = decodeLength(byteArray);
11631
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
11657
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
11632
11658
  addressTableLookups.push({
11633
11659
  accountKey,
11634
11660
  writableIndexes,
@@ -12359,8 +12385,7 @@ var solanaWeb3 = (function (exports) {
12359
12385
  let signatures = [];
12360
12386
 
12361
12387
  for (let i = 0; i < signatureCount; i++) {
12362
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
12363
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
12388
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
12364
12389
  signatures.push(bs58$1.encode(buffer.Buffer.from(signature)));
12365
12390
  }
12366
12391
 
@@ -12560,7 +12585,7 @@ var solanaWeb3 = (function (exports) {
12560
12585
  const signaturesLength = decodeLength(byteArray);
12561
12586
 
12562
12587
  for (let i = 0; i < signaturesLength; i++) {
12563
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
12588
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
12564
12589
  }
12565
12590
 
12566
12591
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -18124,7 +18149,7 @@ var solanaWeb3 = (function (exports) {
18124
18149
 
18125
18150
  /** @internal */
18126
18151
  const COMMON_HTTP_HEADERS = {
18127
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
18152
+ 'solana-client': `js/${(_process$env$npm_pack = "1.58.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
18128
18153
  };
18129
18154
  /**
18130
18155
  * A connection to a fullnode JSON RPC endpoint
@@ -24636,10 +24661,8 @@ var solanaWeb3 = (function (exports) {
24636
24661
  const configKeys = [];
24637
24662
 
24638
24663
  for (let i = 0; i < 2; i++) {
24639
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
24640
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
24641
- const isSigner = byteArray.slice(0, 1)[0] === 1;
24642
- byteArray = byteArray.slice(1);
24664
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
24665
+ const isSigner = guardedShift(byteArray) === 1;
24643
24666
  configKeys.push({
24644
24667
  publicKey,
24645
24668
  isSigner