@solana/web3.js 1.23.0 → 1.23.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 +3 -3
- 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.browser.esm.js
CHANGED
|
@@ -436,6 +436,36 @@ function encodeLength(bytes, len) {
|
|
|
436
436
|
}
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
440
|
+
/**
|
|
441
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
442
|
+
*/
|
|
443
|
+
|
|
444
|
+
function guardedShift(byteArray) {
|
|
445
|
+
if (byteArray.length === 0) {
|
|
446
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return byteArray.shift();
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
453
|
+
* the array.
|
|
454
|
+
*/
|
|
455
|
+
|
|
456
|
+
function guardedSplice(byteArray, ...args) {
|
|
457
|
+
var _args$;
|
|
458
|
+
|
|
459
|
+
const [start] = args;
|
|
460
|
+
|
|
461
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
462
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
463
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return byteArray.splice(...args);
|
|
467
|
+
}
|
|
468
|
+
|
|
439
469
|
/**
|
|
440
470
|
* The message header, identifying signed and read-only account
|
|
441
471
|
*/
|
|
@@ -520,32 +550,28 @@ class Message {
|
|
|
520
550
|
static from(buffer) {
|
|
521
551
|
// Slice up wire data
|
|
522
552
|
let byteArray = [...buffer];
|
|
523
|
-
const numRequiredSignatures = byteArray
|
|
524
|
-
const numReadonlySignedAccounts = byteArray
|
|
525
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
553
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
554
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
555
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
526
556
|
const accountCount = decodeLength(byteArray);
|
|
527
557
|
let accountKeys = [];
|
|
528
558
|
|
|
529
559
|
for (let i = 0; i < accountCount; i++) {
|
|
530
|
-
const account = byteArray
|
|
531
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
560
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
532
561
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
533
562
|
}
|
|
534
563
|
|
|
535
|
-
const recentBlockhash = byteArray
|
|
536
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
564
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
537
565
|
const instructionCount = decodeLength(byteArray);
|
|
538
566
|
let instructions = [];
|
|
539
567
|
|
|
540
568
|
for (let i = 0; i < instructionCount; i++) {
|
|
541
|
-
const programIdIndex = byteArray
|
|
569
|
+
const programIdIndex = guardedShift(byteArray);
|
|
542
570
|
const accountCount = decodeLength(byteArray);
|
|
543
|
-
const accounts = byteArray
|
|
544
|
-
byteArray = byteArray.slice(accountCount);
|
|
571
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
545
572
|
const dataLength = decodeLength(byteArray);
|
|
546
|
-
const dataSlice = byteArray
|
|
573
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
547
574
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
548
|
-
byteArray = byteArray.slice(dataLength);
|
|
549
575
|
instructions.push({
|
|
550
576
|
programIdIndex,
|
|
551
577
|
accounts,
|
|
@@ -574,6 +600,10 @@ function assert (condition, message) {
|
|
|
574
600
|
}
|
|
575
601
|
}
|
|
576
602
|
|
|
603
|
+
/**
|
|
604
|
+
* Transaction signature as base-58 encoded string
|
|
605
|
+
*/
|
|
606
|
+
|
|
577
607
|
/**
|
|
578
608
|
* Default (empty) signature
|
|
579
609
|
*
|
|
@@ -1167,8 +1197,7 @@ class Transaction {
|
|
|
1167
1197
|
let signatures = [];
|
|
1168
1198
|
|
|
1169
1199
|
for (let i = 0; i < signatureCount; i++) {
|
|
1170
|
-
const signature = byteArray
|
|
1171
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1200
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1172
1201
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1173
1202
|
}
|
|
1174
1203
|
|
|
@@ -6480,10 +6509,8 @@ class ValidatorInfo {
|
|
|
6480
6509
|
const configKeys = [];
|
|
6481
6510
|
|
|
6482
6511
|
for (let i = 0; i < 2; i++) {
|
|
6483
|
-
const publicKey = new PublicKey(byteArray
|
|
6484
|
-
|
|
6485
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
6486
|
-
byteArray = byteArray.slice(1);
|
|
6512
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
6513
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
6487
6514
|
configKeys.push({
|
|
6488
6515
|
publicKey,
|
|
6489
6516
|
isSigner
|