@solana/web3.js 1.9.0 → 1.9.2
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/README.md +1 -1
- 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.d.ts +6 -4
- 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/module.flow.js +12 -4
- package/package.json +30 -31
- package/src/connection.ts +6 -4
- 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
|
@@ -412,6 +412,36 @@ function encodeLength(bytes, len) {
|
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
416
|
+
/**
|
|
417
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
418
|
+
*/
|
|
419
|
+
|
|
420
|
+
function guardedShift(byteArray) {
|
|
421
|
+
if (byteArray.length === 0) {
|
|
422
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return byteArray.shift();
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
429
|
+
* the array.
|
|
430
|
+
*/
|
|
431
|
+
|
|
432
|
+
function guardedSplice(byteArray, ...args) {
|
|
433
|
+
var _args$;
|
|
434
|
+
|
|
435
|
+
const [start] = args;
|
|
436
|
+
|
|
437
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
438
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
439
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
return byteArray.splice(...args);
|
|
443
|
+
}
|
|
444
|
+
|
|
415
445
|
/**
|
|
416
446
|
* The message header, identifying signed and read-only account
|
|
417
447
|
*/
|
|
@@ -488,32 +518,28 @@ class Message {
|
|
|
488
518
|
static from(buffer$1) {
|
|
489
519
|
// Slice up wire data
|
|
490
520
|
let byteArray = [...buffer$1];
|
|
491
|
-
const numRequiredSignatures = byteArray
|
|
492
|
-
const numReadonlySignedAccounts = byteArray
|
|
493
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
521
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
522
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
523
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
494
524
|
const accountCount = decodeLength(byteArray);
|
|
495
525
|
let accountKeys = [];
|
|
496
526
|
|
|
497
527
|
for (let i = 0; i < accountCount; i++) {
|
|
498
|
-
const account = byteArray
|
|
499
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
528
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
500
529
|
accountKeys.push(bs58__default['default'].encode(buffer.Buffer.from(account)));
|
|
501
530
|
}
|
|
502
531
|
|
|
503
|
-
const recentBlockhash = byteArray
|
|
504
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
532
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
505
533
|
const instructionCount = decodeLength(byteArray);
|
|
506
534
|
let instructions = [];
|
|
507
535
|
|
|
508
536
|
for (let i = 0; i < instructionCount; i++) {
|
|
509
|
-
const programIdIndex = byteArray
|
|
537
|
+
const programIdIndex = guardedShift(byteArray);
|
|
510
538
|
const accountCount = decodeLength(byteArray);
|
|
511
|
-
const accounts = byteArray
|
|
512
|
-
byteArray = byteArray.slice(accountCount);
|
|
539
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
513
540
|
const dataLength = decodeLength(byteArray);
|
|
514
|
-
const dataSlice = byteArray
|
|
541
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
515
542
|
const data = bs58__default['default'].encode(buffer.Buffer.from(dataSlice));
|
|
516
|
-
byteArray = byteArray.slice(dataLength);
|
|
517
543
|
instructions.push({
|
|
518
544
|
programIdIndex,
|
|
519
545
|
accounts,
|
|
@@ -1123,8 +1149,7 @@ class Transaction {
|
|
|
1123
1149
|
let signatures = [];
|
|
1124
1150
|
|
|
1125
1151
|
for (let i = 0; i < signatureCount; i++) {
|
|
1126
|
-
const signature = byteArray
|
|
1127
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1152
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1128
1153
|
signatures.push(bs58__default['default'].encode(buffer.Buffer.from(signature)));
|
|
1129
1154
|
}
|
|
1130
1155
|
|
|
@@ -6073,10 +6098,8 @@ class ValidatorInfo {
|
|
|
6073
6098
|
const configKeys = [];
|
|
6074
6099
|
|
|
6075
6100
|
for (let i = 0; i < 2; i++) {
|
|
6076
|
-
const publicKey = new PublicKey(byteArray
|
|
6077
|
-
|
|
6078
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
6079
|
-
byteArray = byteArray.slice(1);
|
|
6101
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
6102
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
6080
6103
|
configKeys.push({
|
|
6081
6104
|
publicKey,
|
|
6082
6105
|
isSigner
|