@solana/web3.js 1.18.0 → 1.18.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 +45 -18
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +45 -18
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +45 -18
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +46 -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 +27 -27
- 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
|
@@ -477,6 +477,36 @@ function encodeLength(bytes, len) {
|
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
479
|
|
|
480
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
481
|
+
/**
|
|
482
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
483
|
+
*/
|
|
484
|
+
|
|
485
|
+
function guardedShift(byteArray) {
|
|
486
|
+
if (byteArray.length === 0) {
|
|
487
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
return byteArray.shift();
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
494
|
+
* the array.
|
|
495
|
+
*/
|
|
496
|
+
|
|
497
|
+
function guardedSplice(byteArray, ...args) {
|
|
498
|
+
var _args$;
|
|
499
|
+
|
|
500
|
+
const [start] = args;
|
|
501
|
+
|
|
502
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
503
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
504
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
return byteArray.splice(...args);
|
|
508
|
+
}
|
|
509
|
+
|
|
480
510
|
/**
|
|
481
511
|
* The message header, identifying signed and read-only account
|
|
482
512
|
*/
|
|
@@ -561,32 +591,28 @@ class Message {
|
|
|
561
591
|
static from(buffer$1) {
|
|
562
592
|
// Slice up wire data
|
|
563
593
|
let byteArray = [...buffer$1];
|
|
564
|
-
const numRequiredSignatures = byteArray
|
|
565
|
-
const numReadonlySignedAccounts = byteArray
|
|
566
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
594
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
595
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
596
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
567
597
|
const accountCount = decodeLength(byteArray);
|
|
568
598
|
let accountKeys = [];
|
|
569
599
|
|
|
570
600
|
for (let i = 0; i < accountCount; i++) {
|
|
571
|
-
const account = byteArray
|
|
572
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
601
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
573
602
|
accountKeys.push(bs58__default['default'].encode(buffer.Buffer.from(account)));
|
|
574
603
|
}
|
|
575
604
|
|
|
576
|
-
const recentBlockhash = byteArray
|
|
577
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
605
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
578
606
|
const instructionCount = decodeLength(byteArray);
|
|
579
607
|
let instructions = [];
|
|
580
608
|
|
|
581
609
|
for (let i = 0; i < instructionCount; i++) {
|
|
582
|
-
const programIdIndex = byteArray
|
|
610
|
+
const programIdIndex = guardedShift(byteArray);
|
|
583
611
|
const accountCount = decodeLength(byteArray);
|
|
584
|
-
const accounts = byteArray
|
|
585
|
-
byteArray = byteArray.slice(accountCount);
|
|
612
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
586
613
|
const dataLength = decodeLength(byteArray);
|
|
587
|
-
const dataSlice = byteArray
|
|
614
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
588
615
|
const data = bs58__default['default'].encode(buffer.Buffer.from(dataSlice));
|
|
589
|
-
byteArray = byteArray.slice(dataLength);
|
|
590
616
|
instructions.push({
|
|
591
617
|
programIdIndex,
|
|
592
618
|
accounts,
|
|
@@ -609,6 +635,10 @@ class Message {
|
|
|
609
635
|
|
|
610
636
|
}
|
|
611
637
|
|
|
638
|
+
/**
|
|
639
|
+
* Transaction signature as base-58 encoded string
|
|
640
|
+
*/
|
|
641
|
+
|
|
612
642
|
/**
|
|
613
643
|
* Default (empty) signature
|
|
614
644
|
*
|
|
@@ -1202,8 +1232,7 @@ class Transaction {
|
|
|
1202
1232
|
let signatures = [];
|
|
1203
1233
|
|
|
1204
1234
|
for (let i = 0; i < signatureCount; i++) {
|
|
1205
|
-
const signature = byteArray
|
|
1206
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1235
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1207
1236
|
signatures.push(bs58__default['default'].encode(buffer.Buffer.from(signature)));
|
|
1208
1237
|
}
|
|
1209
1238
|
|
|
@@ -6459,10 +6488,8 @@ class ValidatorInfo {
|
|
|
6459
6488
|
const configKeys = [];
|
|
6460
6489
|
|
|
6461
6490
|
for (let i = 0; i < 2; i++) {
|
|
6462
|
-
const publicKey = new PublicKey(byteArray
|
|
6463
|
-
|
|
6464
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
6465
|
-
byteArray = byteArray.slice(1);
|
|
6491
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
6492
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
6466
6493
|
configKeys.push({
|
|
6467
6494
|
publicKey,
|
|
6468
6495
|
isSigner
|