@solana/web3.js 1.57.0 → 1.57.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
@@ -11087,6 +11087,44 @@ var solanaWeb3 = (function (exports) {
11087
11087
  }
11088
11088
  }
11089
11089
 
11090
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
11091
+ /**
11092
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
11093
+ */
11094
+
11095
+ function guardedShift(byteArray) {
11096
+ if (byteArray.length === 0) {
11097
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
11098
+ }
11099
+
11100
+ return byteArray.shift();
11101
+ }
11102
+ /**
11103
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
11104
+ * the array.
11105
+ */
11106
+
11107
+ function guardedSplice(byteArray, ...args) {
11108
+ var _args$;
11109
+
11110
+ const [start] = args;
11111
+
11112
+ if (args.length === 2 // Implies that `deleteCount` was supplied
11113
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
11114
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
11115
+ }
11116
+
11117
+ return byteArray.splice(...args);
11118
+ }
11119
+
11120
+ /**
11121
+ * An instruction to execute by a program
11122
+ *
11123
+ * @property {number} programIdIndex
11124
+ * @property {number[]} accounts
11125
+ * @property {string} data
11126
+ */
11127
+
11090
11128
  /**
11091
11129
  * List of instructions to be processed atomically
11092
11130
  */
@@ -11199,37 +11237,33 @@ var solanaWeb3 = (function (exports) {
11199
11237
  static from(buffer$1) {
11200
11238
  // Slice up wire data
11201
11239
  let byteArray = [...buffer$1];
11202
- const numRequiredSignatures = byteArray.shift();
11240
+ const numRequiredSignatures = guardedShift(byteArray);
11203
11241
 
11204
11242
  if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
11205
11243
  throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
11206
11244
  }
11207
11245
 
11208
- const numReadonlySignedAccounts = byteArray.shift();
11209
- const numReadonlyUnsignedAccounts = byteArray.shift();
11246
+ const numReadonlySignedAccounts = guardedShift(byteArray);
11247
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
11210
11248
  const accountCount = decodeLength(byteArray);
11211
11249
  let accountKeys = [];
11212
11250
 
11213
11251
  for (let i = 0; i < accountCount; i++) {
11214
- const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
11215
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
11252
+ const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
11216
11253
  accountKeys.push(bs58$1.encode(buffer.Buffer.from(account)));
11217
11254
  }
11218
11255
 
11219
- const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
11220
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
11256
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
11221
11257
  const instructionCount = decodeLength(byteArray);
11222
11258
  let instructions = [];
11223
11259
 
11224
11260
  for (let i = 0; i < instructionCount; i++) {
11225
- const programIdIndex = byteArray.shift();
11261
+ const programIdIndex = guardedShift(byteArray);
11226
11262
  const accountCount = decodeLength(byteArray);
11227
- const accounts = byteArray.slice(0, accountCount);
11228
- byteArray = byteArray.slice(accountCount);
11263
+ const accounts = guardedSplice(byteArray, 0, accountCount);
11229
11264
  const dataLength = decodeLength(byteArray);
11230
- const dataSlice = byteArray.slice(0, dataLength);
11265
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
11231
11266
  const data = bs58$1.encode(buffer.Buffer.from(dataSlice));
11232
- byteArray = byteArray.slice(dataLength);
11233
11267
  instructions.push({
11234
11268
  programIdIndex,
11235
11269
  accounts,
@@ -11496,33 +11530,33 @@ var solanaWeb3 = (function (exports) {
11496
11530
 
11497
11531
  static deserialize(serializedMessage) {
11498
11532
  let byteArray = [...serializedMessage];
11499
- const prefix = byteArray.shift();
11533
+ const prefix = guardedShift(byteArray);
11500
11534
  const maskedPrefix = prefix & VERSION_PREFIX_MASK;
11501
11535
  assert$1(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
11502
11536
  const version = maskedPrefix;
11503
11537
  assert$1(version === 0, `Expected versioned message with version 0 but found version ${version}`);
11504
11538
  const header = {
11505
- numRequiredSignatures: byteArray.shift(),
11506
- numReadonlySignedAccounts: byteArray.shift(),
11507
- numReadonlyUnsignedAccounts: byteArray.shift()
11539
+ numRequiredSignatures: guardedShift(byteArray),
11540
+ numReadonlySignedAccounts: guardedShift(byteArray),
11541
+ numReadonlyUnsignedAccounts: guardedShift(byteArray)
11508
11542
  };
11509
11543
  const staticAccountKeys = [];
11510
11544
  const staticAccountKeysLength = decodeLength(byteArray);
11511
11545
 
11512
11546
  for (let i = 0; i < staticAccountKeysLength; i++) {
11513
- staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
11547
+ staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
11514
11548
  }
11515
11549
 
11516
- const recentBlockhash = bs58$1.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
11550
+ const recentBlockhash = bs58$1.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
11517
11551
  const instructionCount = decodeLength(byteArray);
11518
11552
  const compiledInstructions = [];
11519
11553
 
11520
11554
  for (let i = 0; i < instructionCount; i++) {
11521
- const programIdIndex = byteArray.shift();
11555
+ const programIdIndex = guardedShift(byteArray);
11522
11556
  const accountKeyIndexesLength = decodeLength(byteArray);
11523
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
11557
+ const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
11524
11558
  const dataLength = decodeLength(byteArray);
11525
- const data = new Uint8Array(byteArray.splice(0, dataLength));
11559
+ const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
11526
11560
  compiledInstructions.push({
11527
11561
  programIdIndex,
11528
11562
  accountKeyIndexes,
@@ -11534,11 +11568,11 @@ var solanaWeb3 = (function (exports) {
11534
11568
  const addressTableLookups = [];
11535
11569
 
11536
11570
  for (let i = 0; i < addressTableLookupsCount; i++) {
11537
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
11571
+ const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
11538
11572
  const writableIndexesLength = decodeLength(byteArray);
11539
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
11573
+ const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
11540
11574
  const readonlyIndexesLength = decodeLength(byteArray);
11541
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
11575
+ const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
11542
11576
  addressTableLookups.push({
11543
11577
  accountKey,
11544
11578
  writableIndexes,
@@ -12269,8 +12303,7 @@ var solanaWeb3 = (function (exports) {
12269
12303
  let signatures = [];
12270
12304
 
12271
12305
  for (let i = 0; i < signatureCount; i++) {
12272
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
12273
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
12306
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
12274
12307
  signatures.push(bs58$1.encode(buffer.Buffer.from(signature)));
12275
12308
  }
12276
12309
 
@@ -12362,7 +12395,7 @@ var solanaWeb3 = (function (exports) {
12362
12395
  const signaturesLength = decodeLength(byteArray);
12363
12396
 
12364
12397
  for (let i = 0; i < signaturesLength; i++) {
12365
- signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
12398
+ signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
12366
12399
  }
12367
12400
 
12368
12401
  const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
@@ -17926,7 +17959,7 @@ var solanaWeb3 = (function (exports) {
17926
17959
 
17927
17960
  /** @internal */
17928
17961
  const COMMON_HTTP_HEADERS = {
17929
- 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
17962
+ 'solana-client': `js/${(_process$env$npm_pack = "1.57.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
17930
17963
  };
17931
17964
  /**
17932
17965
  * A connection to a fullnode JSON RPC endpoint
@@ -24376,10 +24409,8 @@ var solanaWeb3 = (function (exports) {
24376
24409
  const configKeys = [];
24377
24410
 
24378
24411
  for (let i = 0; i < 2; i++) {
24379
- const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
24380
- byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
24381
- const isSigner = byteArray.slice(0, 1)[0] === 1;
24382
- byteArray = byteArray.slice(1);
24412
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
24413
+ const isSigner = guardedShift(byteArray) === 1;
24383
24414
  configKeys.push({
24384
24415
  publicKey,
24385
24416
  isSigner