@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.cjs.js
CHANGED
|
@@ -403,6 +403,36 @@ function encodeLength(bytes, len) {
|
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
407
|
+
/**
|
|
408
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
409
|
+
*/
|
|
410
|
+
|
|
411
|
+
function guardedShift(byteArray) {
|
|
412
|
+
if (byteArray.length === 0) {
|
|
413
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
return byteArray.shift();
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
420
|
+
* the array.
|
|
421
|
+
*/
|
|
422
|
+
|
|
423
|
+
function guardedSplice(byteArray, ...args) {
|
|
424
|
+
var _args$;
|
|
425
|
+
|
|
426
|
+
const [start] = args;
|
|
427
|
+
|
|
428
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
429
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
430
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return byteArray.splice(...args);
|
|
434
|
+
}
|
|
435
|
+
|
|
406
436
|
/**
|
|
407
437
|
* The message header, identifying signed and read-only account
|
|
408
438
|
*/
|
|
@@ -487,32 +517,28 @@ class Message {
|
|
|
487
517
|
static from(buffer$1) {
|
|
488
518
|
// Slice up wire data
|
|
489
519
|
let byteArray = [...buffer$1];
|
|
490
|
-
const numRequiredSignatures = byteArray
|
|
491
|
-
const numReadonlySignedAccounts = byteArray
|
|
492
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
520
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
521
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
522
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
493
523
|
const accountCount = decodeLength(byteArray);
|
|
494
524
|
let accountKeys = [];
|
|
495
525
|
|
|
496
526
|
for (let i = 0; i < accountCount; i++) {
|
|
497
|
-
const account = byteArray
|
|
498
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
527
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
499
528
|
accountKeys.push(bs58__default['default'].encode(buffer.Buffer.from(account)));
|
|
500
529
|
}
|
|
501
530
|
|
|
502
|
-
const recentBlockhash = byteArray
|
|
503
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
531
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
504
532
|
const instructionCount = decodeLength(byteArray);
|
|
505
533
|
let instructions = [];
|
|
506
534
|
|
|
507
535
|
for (let i = 0; i < instructionCount; i++) {
|
|
508
|
-
const programIdIndex = byteArray
|
|
536
|
+
const programIdIndex = guardedShift(byteArray);
|
|
509
537
|
const accountCount = decodeLength(byteArray);
|
|
510
|
-
const accounts = byteArray
|
|
511
|
-
byteArray = byteArray.slice(accountCount);
|
|
538
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
512
539
|
const dataLength = decodeLength(byteArray);
|
|
513
|
-
const dataSlice = byteArray
|
|
540
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
514
541
|
const data = bs58__default['default'].encode(buffer.Buffer.from(dataSlice));
|
|
515
|
-
byteArray = byteArray.slice(dataLength);
|
|
516
542
|
instructions.push({
|
|
517
543
|
programIdIndex,
|
|
518
544
|
accounts,
|
|
@@ -1132,8 +1158,7 @@ class Transaction {
|
|
|
1132
1158
|
let signatures = [];
|
|
1133
1159
|
|
|
1134
1160
|
for (let i = 0; i < signatureCount; i++) {
|
|
1135
|
-
const signature = byteArray
|
|
1136
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1161
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1137
1162
|
signatures.push(bs58__default['default'].encode(buffer.Buffer.from(signature)));
|
|
1138
1163
|
}
|
|
1139
1164
|
|
|
@@ -5916,10 +5941,8 @@ class ValidatorInfo {
|
|
|
5916
5941
|
const configKeys = [];
|
|
5917
5942
|
|
|
5918
5943
|
for (let i = 0; i < 2; i++) {
|
|
5919
|
-
const publicKey = new PublicKey(byteArray
|
|
5920
|
-
|
|
5921
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
5922
|
-
byteArray = byteArray.slice(1);
|
|
5944
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
5945
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
5923
5946
|
configKeys.push({
|
|
5924
5947
|
publicKey,
|
|
5925
5948
|
isSigner
|