@solana/web3.js 1.5.0 → 1.5.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.browser.esm.js +41 -18
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +41 -18
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +41 -18
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +42 -25
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/package.json +28 -28
- package/src/message.ts +9 -12
- package/src/transaction.ts +2 -2
- package/src/util/guarded-array-utils.ts +37 -0
- package/src/validator-info.ts +5 -4
package/lib/index.esm.js
CHANGED
|
@@ -365,6 +365,36 @@ function encodeLength(bytes, len) {
|
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
369
|
+
/**
|
|
370
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
function guardedShift(byteArray) {
|
|
374
|
+
if (byteArray.length === 0) {
|
|
375
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return byteArray.shift();
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
382
|
+
* the array.
|
|
383
|
+
*/
|
|
384
|
+
|
|
385
|
+
function guardedSplice(byteArray, ...args) {
|
|
386
|
+
var _args$;
|
|
387
|
+
|
|
388
|
+
const [start] = args;
|
|
389
|
+
|
|
390
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
391
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
392
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return byteArray.splice(...args);
|
|
396
|
+
}
|
|
397
|
+
|
|
368
398
|
/**
|
|
369
399
|
* The message header, identifying signed and read-only account
|
|
370
400
|
*/
|
|
@@ -449,32 +479,28 @@ class Message {
|
|
|
449
479
|
static from(buffer) {
|
|
450
480
|
// Slice up wire data
|
|
451
481
|
let byteArray = [...buffer];
|
|
452
|
-
const numRequiredSignatures = byteArray
|
|
453
|
-
const numReadonlySignedAccounts = byteArray
|
|
454
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
482
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
483
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
484
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
455
485
|
const accountCount = decodeLength(byteArray);
|
|
456
486
|
let accountKeys = [];
|
|
457
487
|
|
|
458
488
|
for (let i = 0; i < accountCount; i++) {
|
|
459
|
-
const account = byteArray
|
|
460
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
489
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
461
490
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
462
491
|
}
|
|
463
492
|
|
|
464
|
-
const recentBlockhash = byteArray
|
|
465
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
493
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
466
494
|
const instructionCount = decodeLength(byteArray);
|
|
467
495
|
let instructions = [];
|
|
468
496
|
|
|
469
497
|
for (let i = 0; i < instructionCount; i++) {
|
|
470
|
-
const programIdIndex = byteArray
|
|
498
|
+
const programIdIndex = guardedShift(byteArray);
|
|
471
499
|
const accountCount = decodeLength(byteArray);
|
|
472
|
-
const accounts = byteArray
|
|
473
|
-
byteArray = byteArray.slice(accountCount);
|
|
500
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
474
501
|
const dataLength = decodeLength(byteArray);
|
|
475
|
-
const dataSlice = byteArray
|
|
502
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
476
503
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
477
|
-
byteArray = byteArray.slice(dataLength);
|
|
478
504
|
instructions.push({
|
|
479
505
|
programIdIndex,
|
|
480
506
|
accounts,
|
|
@@ -1094,8 +1120,7 @@ class Transaction {
|
|
|
1094
1120
|
let signatures = [];
|
|
1095
1121
|
|
|
1096
1122
|
for (let i = 0; i < signatureCount; i++) {
|
|
1097
|
-
const signature = byteArray
|
|
1098
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1123
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1099
1124
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1100
1125
|
}
|
|
1101
1126
|
|
|
@@ -5878,10 +5903,8 @@ class ValidatorInfo {
|
|
|
5878
5903
|
const configKeys = [];
|
|
5879
5904
|
|
|
5880
5905
|
for (let i = 0; i < 2; i++) {
|
|
5881
|
-
const publicKey = new PublicKey(byteArray
|
|
5882
|
-
|
|
5883
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
5884
|
-
byteArray = byteArray.slice(1);
|
|
5906
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
5907
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
5885
5908
|
configKeys.push({
|
|
5886
5909
|
publicKey,
|
|
5887
5910
|
isSigner
|