@solana/web3.js 1.12.0 → 1.12.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
|
@@ -469,6 +469,36 @@ function encodeLength(bytes, len) {
|
|
|
469
469
|
}
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
473
|
+
/**
|
|
474
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
475
|
+
*/
|
|
476
|
+
|
|
477
|
+
function guardedShift(byteArray) {
|
|
478
|
+
if (byteArray.length === 0) {
|
|
479
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return byteArray.shift();
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
486
|
+
* the array.
|
|
487
|
+
*/
|
|
488
|
+
|
|
489
|
+
function guardedSplice(byteArray, ...args) {
|
|
490
|
+
var _args$;
|
|
491
|
+
|
|
492
|
+
const [start] = args;
|
|
493
|
+
|
|
494
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
495
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
496
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
return byteArray.splice(...args);
|
|
500
|
+
}
|
|
501
|
+
|
|
472
502
|
/**
|
|
473
503
|
* The message header, identifying signed and read-only account
|
|
474
504
|
*/
|
|
@@ -545,32 +575,28 @@ class Message {
|
|
|
545
575
|
static from(buffer$1) {
|
|
546
576
|
// Slice up wire data
|
|
547
577
|
let byteArray = [...buffer$1];
|
|
548
|
-
const numRequiredSignatures = byteArray
|
|
549
|
-
const numReadonlySignedAccounts = byteArray
|
|
550
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
578
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
579
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
580
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
551
581
|
const accountCount = decodeLength(byteArray);
|
|
552
582
|
let accountKeys = [];
|
|
553
583
|
|
|
554
584
|
for (let i = 0; i < accountCount; i++) {
|
|
555
|
-
const account = byteArray
|
|
556
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
585
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
557
586
|
accountKeys.push(bs58__default['default'].encode(buffer.Buffer.from(account)));
|
|
558
587
|
}
|
|
559
588
|
|
|
560
|
-
const recentBlockhash = byteArray
|
|
561
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
589
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
562
590
|
const instructionCount = decodeLength(byteArray);
|
|
563
591
|
let instructions = [];
|
|
564
592
|
|
|
565
593
|
for (let i = 0; i < instructionCount; i++) {
|
|
566
|
-
const programIdIndex = byteArray
|
|
594
|
+
const programIdIndex = guardedShift(byteArray);
|
|
567
595
|
const accountCount = decodeLength(byteArray);
|
|
568
|
-
const accounts = byteArray
|
|
569
|
-
byteArray = byteArray.slice(accountCount);
|
|
596
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
570
597
|
const dataLength = decodeLength(byteArray);
|
|
571
|
-
const dataSlice = byteArray
|
|
598
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
572
599
|
const data = bs58__default['default'].encode(buffer.Buffer.from(dataSlice));
|
|
573
|
-
byteArray = byteArray.slice(dataLength);
|
|
574
600
|
instructions.push({
|
|
575
601
|
programIdIndex,
|
|
576
602
|
accounts,
|
|
@@ -593,6 +619,10 @@ class Message {
|
|
|
593
619
|
|
|
594
620
|
}
|
|
595
621
|
|
|
622
|
+
/**
|
|
623
|
+
* Transaction signature as base-58 encoded string
|
|
624
|
+
*/
|
|
625
|
+
|
|
596
626
|
/**
|
|
597
627
|
* Default (empty) signature
|
|
598
628
|
*
|
|
@@ -1176,8 +1206,7 @@ class Transaction {
|
|
|
1176
1206
|
let signatures = [];
|
|
1177
1207
|
|
|
1178
1208
|
for (let i = 0; i < signatureCount; i++) {
|
|
1179
|
-
const signature = byteArray
|
|
1180
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1209
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1181
1210
|
signatures.push(bs58__default['default'].encode(buffer.Buffer.from(signature)));
|
|
1182
1211
|
}
|
|
1183
1212
|
|
|
@@ -6210,10 +6239,8 @@ class ValidatorInfo {
|
|
|
6210
6239
|
const configKeys = [];
|
|
6211
6240
|
|
|
6212
6241
|
for (let i = 0; i < 2; i++) {
|
|
6213
|
-
const publicKey = new PublicKey(byteArray
|
|
6214
|
-
|
|
6215
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
6216
|
-
byteArray = byteArray.slice(1);
|
|
6242
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
6243
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
6217
6244
|
configKeys.push({
|
|
6218
6245
|
publicKey,
|
|
6219
6246
|
isSigner
|