@solana/web3.js 1.59.0 → 1.59.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
@@ -11222,6 +11222,36 @@ var solanaWeb3 = (function (exports) {
11222
11222
 
11223
11223
  }
11224
11224
 
11225
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
11226
+ /**
11227
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
11228
+ */
11229
+
11230
+ function guardedShift(byteArray) {
11231
+ if (byteArray.length === 0) {
11232
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
11233
+ }
11234
+
11235
+ return byteArray.shift();
11236
+ }
11237
+ /**
11238
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
11239
+ * the array.
11240
+ */
11241
+
11242
+ function guardedSplice(byteArray, ...args) {
11243
+ var _args$;
11244
+
11245
+ const [start] = args;
11246
+
11247
+ if (args.length === 2 // Implies that `deleteCount` was supplied
11248
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
11249
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
11250
+ }
11251
+
11252
+ return byteArray.splice(...args);
11253
+ }
11254
+
11225
11255
  /**
11226
11256
  * An instruction to execute by a program
11227
11257
  *
@@ -11363,37 +11393,33 @@ var solanaWeb3 = (function (exports) {
11363
11393
  static from(buffer$1) {
11364
11394
  // Slice up wire data
11365
11395
  let byteArray = [...buffer$1];
11366
- const numRequiredSignatures = byteArray.shift();
11396
+ const numRequiredSignatures = guardedShift(byteArray);
11367
11397
 
11368
11398
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
11369
11399
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
11370
11400
  }
11371
11401
 
11372
- const numReadonlySignedAccounts = byteArray.shift();
11373
- const numReadonlyUnsignedAccounts = byteArray.shift();
11402
+ const numReadonlySignedAccounts = guardedShift(byteArray);
11403
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
11374
11404
  const accountCount = decodeLength(byteArray);
11375
11405
  let accountKeys = [];
11376
11406
 
11377
11407
  for (let i = 0; i < accountCount; i++) {
11378
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
11379
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
11408
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
11380
11409
  accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
11381
11410
  }
11382
11411
 
11383
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
11384
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
11412
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
11385
11413
  const instructionCount = decodeLength(byteArray);
11386
11414
  let instructions = [];
11387
11415
 
11388
11416
  for (let i = 0; i < instructionCount; i++) {
11389
- const programIdIndex = byteArray.shift();
11417
+ const programIdIndex = guardedShift(byteArray);
11390
11418
  const accountCount = decodeLength(byteArray);
11391
- const accounts = byteArray.slice(0, accountCount);
11392
- byteArray = byteArray.slice(accountCount);
11419
+ const accounts = guardedSplice(byteArray, 0, accountCount);
11393
11420
  const dataLength = decodeLength(byteArray);
11394
- const dataSlice = byteArray.slice(0, dataLength);
11421
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
11395
11422
  const data = bs58$1.encode(buffer.Buffer.from(dataSlice));
11396
- byteArray = byteArray.slice(dataLength);
11397
11423
  instructions.push({
11398
11424
  programIdIndex,
11399
11425
  accounts,
@@ -11606,33 +11632,33 @@ var solanaWeb3 = (function (exports) {
11606
11632
 
11607
11633
  static deserialize(serializedMessage) {
11608
11634
  let byteArray = [...serializedMessage];
11609
- const prefix = byteArray.shift();
11635
+ const prefix = guardedShift(byteArray);
11610
11636
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
11611
11637
  assert$1(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
11612
11638
  const version = maskedPrefix;
11613
11639
  assert$1(version === 0, `Expected versioned message with version 0 but found version ${version}`);
11614
11640
  const header = {
11615
- numRequiredSignatures: byteArray.shift(),
11616
- numReadonlySignedAccounts: byteArray.shift(),
11617
- numReadonlyUnsignedAccounts: byteArray.shift()
11641
+ numRequiredSignatures: guardedShift(byteArray),
11642
+ numReadonlySignedAccounts: guardedShift(byteArray),
11643
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
11618
11644
  };
11619
11645
  const staticAccountKeys = [];
11620
11646
  const staticAccountKeysLength = decodeLength(byteArray);
11621
11647
 
11622
11648
  for (let i = 0; i < staticAccountKeysLength; i++) {
11623
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
11649
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
11624
11650
  }
11625
11651
 
11626
- const recentBlockhash = bs58$1.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
11652
+ const recentBlockhash = bs58$1.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
11627
11653
  const instructionCount = decodeLength(byteArray);
11628
11654
  const compiledInstructions = [];
11629
11655
 
11630
11656
  for (let i = 0; i < instructionCount; i++) {
11631
- const programIdIndex = byteArray.shift();
11657
+ const programIdIndex = guardedShift(byteArray);
11632
11658
  const accountKeyIndexesLength = decodeLength(byteArray);
11633
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
11659
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
11634
11660
  const dataLength = decodeLength(byteArray);
11635
- const data = new Uint8Array(byteArray.splice(0, dataLength));
11661
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
11636
11662
  compiledInstructions.push({
11637
11663
  programIdIndex,
11638
11664
  accountKeyIndexes,
@@ -11644,11 +11670,11 @@ var solanaWeb3 = (function (exports) {
11644
11670
  const addressTableLookups = [];
11645
11671
 
11646
11672
  for (let i = 0; i < addressTableLookupsCount; i++) {
11647
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
11673
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
11648
11674
  const writableIndexesLength = decodeLength(byteArray);
11649
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
11675
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
11650
11676
  const readonlyIndexesLength = decodeLength(byteArray);
11651
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
11677
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
11652
11678
  addressTableLookups.push({
11653
11679
  accountKey,
11654
11680
  writableIndexes,
@@ -12379,8 +12405,7 @@ var solanaWeb3 = (function (exports) {
12379
12405
  let signatures = [];
12380
12406
 
12381
12407
  for (let i = 0; i < signatureCount; i++) {
12382
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
12383
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
12408
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
12384
12409
  signatures.push(bs58$1.encode(buffer.Buffer.from(signature)));
12385
12410
  }
12386
12411
 
@@ -12430,10 +12455,10 @@ var solanaWeb3 = (function (exports) {
12430
12455
 
12431
12456
  class TransactionMessage {
12432
12457
  constructor(args) {
12433
- this.accountKeys = void 0;
12458
+ this.payerKey = void 0;
12434
12459
  this.instructions = void 0;
12435
12460
  this.recentBlockhash = void 0;
12436
- this.accountKeys = args.accountKeys;
12461
+ this.payerKey = args.payerKey;
12437
12462
  this.instructions = args.instructions;
12438
12463
  this.recentBlockhash = args.recentBlockhash;
12439
12464
  }
@@ -12454,6 +12479,12 @@ var solanaWeb3 = (function (exports) {
12454
12479
  const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
12455
12480
  assert$1(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
12456
12481
  const accountKeys = message.getAccountKeys(args);
12482
+ const payerKey = accountKeys.get(0);
12483
+
12484
+ if (payerKey === undefined) {
12485
+ throw new Error('Failed to decompile message because no account keys were found');
12486
+ }
12487
+
12457
12488
  const instructions = [];
12458
12489
 
12459
12490
  for (const compiledIx of compiledInstructions) {
@@ -12499,35 +12530,23 @@ var solanaWeb3 = (function (exports) {
12499
12530
  }
12500
12531
 
12501
12532
  return new TransactionMessage({
12502
- accountKeys,
12533
+ payerKey,
12503
12534
  instructions,
12504
12535
  recentBlockhash
12505
12536
  });
12506
12537
  }
12507
12538
 
12508
12539
  compileToLegacyMessage() {
12509
- const payerKey = this.accountKeys.get(0);
12510
-
12511
- if (payerKey === undefined) {
12512
- throw new Error('Failed to compile message because no account keys were found');
12513
- }
12514
-
12515
12540
  return Message.compile({
12516
- payerKey,
12541
+ payerKey: this.payerKey,
12517
12542
  recentBlockhash: this.recentBlockhash,
12518
12543
  instructions: this.instructions
12519
12544
  });
12520
12545
  }
12521
12546
 
12522
12547
  compileToV0Message(addressLookupTableAccounts) {
12523
- const payerKey = this.accountKeys.get(0);
12524
-
12525
- if (payerKey === undefined) {
12526
- throw new Error('Failed to compile message because no account keys were found');
12527
- }
12528
-
12529
12548
  return MessageV0.compile({
12530
- payerKey,
12549
+ payerKey: this.payerKey,
12531
12550
  recentBlockhash: this.recentBlockhash,
12532
12551
  instructions: this.instructions,
12533
12552
  addressLookupTableAccounts
@@ -12580,7 +12599,7 @@ var solanaWeb3 = (function (exports) {
12580
12599
  const signaturesLength = decodeLength(byteArray);
12581
12600
 
12582
12601
  for (let i = 0; i < signaturesLength; i++) {
12583
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
12602
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
12584
12603
  }
12585
12604
 
12586
12605
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -18144,7 +18163,7 @@ var solanaWeb3 = (function (exports) {
18144
18163
 
18145
18164
  /** @internal */
18146
18165
  const COMMON_HTTP_HEADERS = {
18147
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
18166
+ 'solana-client': `js/${(_process$env$npm_pack = "1.59.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
18148
18167
  };
18149
18168
  /**
18150
18169
  * A connection to a fullnode JSON RPC endpoint
@@ -24276,10 +24295,8 @@ var solanaWeb3 = (function (exports) {
24276
24295
  const configKeys = [];
24277
24296
 
24278
24297
  for (let i = 0; i < 2; i++) {
24279
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
24280
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
24281
- const isSigner = byteArray.slice(0, 1)[0] === 1;
24282
- byteArray = byteArray.slice(1);
24298
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
24299
+ const isSigner = guardedShift(byteArray) === 1;
24283
24300
  configKeys.push({
24284
24301
  publicKey,
24285
24302
  isSigner