@solana/web3.js 1.10.1 → 1.10.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/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
|
@@ -418,6 +418,36 @@ function encodeLength(bytes, len) {
|
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
420
|
|
|
421
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
422
|
+
/**
|
|
423
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
424
|
+
*/
|
|
425
|
+
|
|
426
|
+
function guardedShift(byteArray) {
|
|
427
|
+
if (byteArray.length === 0) {
|
|
428
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return byteArray.shift();
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
435
|
+
* the array.
|
|
436
|
+
*/
|
|
437
|
+
|
|
438
|
+
function guardedSplice(byteArray, ...args) {
|
|
439
|
+
var _args$;
|
|
440
|
+
|
|
441
|
+
const [start] = args;
|
|
442
|
+
|
|
443
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
444
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
445
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return byteArray.splice(...args);
|
|
449
|
+
}
|
|
450
|
+
|
|
421
451
|
/**
|
|
422
452
|
* The message header, identifying signed and read-only account
|
|
423
453
|
*/
|
|
@@ -494,32 +524,28 @@ class Message {
|
|
|
494
524
|
static from(buffer$1) {
|
|
495
525
|
// Slice up wire data
|
|
496
526
|
let byteArray = [...buffer$1];
|
|
497
|
-
const numRequiredSignatures = byteArray
|
|
498
|
-
const numReadonlySignedAccounts = byteArray
|
|
499
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
527
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
528
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
529
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
500
530
|
const accountCount = decodeLength(byteArray);
|
|
501
531
|
let accountKeys = [];
|
|
502
532
|
|
|
503
533
|
for (let i = 0; i < accountCount; i++) {
|
|
504
|
-
const account = byteArray
|
|
505
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
534
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
506
535
|
accountKeys.push(bs58__default['default'].encode(buffer.Buffer.from(account)));
|
|
507
536
|
}
|
|
508
537
|
|
|
509
|
-
const recentBlockhash = byteArray
|
|
510
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
538
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
511
539
|
const instructionCount = decodeLength(byteArray);
|
|
512
540
|
let instructions = [];
|
|
513
541
|
|
|
514
542
|
for (let i = 0; i < instructionCount; i++) {
|
|
515
|
-
const programIdIndex = byteArray
|
|
543
|
+
const programIdIndex = guardedShift(byteArray);
|
|
516
544
|
const accountCount = decodeLength(byteArray);
|
|
517
|
-
const accounts = byteArray
|
|
518
|
-
byteArray = byteArray.slice(accountCount);
|
|
545
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
519
546
|
const dataLength = decodeLength(byteArray);
|
|
520
|
-
const dataSlice = byteArray
|
|
547
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
521
548
|
const data = bs58__default['default'].encode(buffer.Buffer.from(dataSlice));
|
|
522
|
-
byteArray = byteArray.slice(dataLength);
|
|
523
549
|
instructions.push({
|
|
524
550
|
programIdIndex,
|
|
525
551
|
accounts,
|
|
@@ -542,6 +568,10 @@ class Message {
|
|
|
542
568
|
|
|
543
569
|
}
|
|
544
570
|
|
|
571
|
+
/**
|
|
572
|
+
* Transaction signature as base-58 encoded string
|
|
573
|
+
*/
|
|
574
|
+
|
|
545
575
|
/**
|
|
546
576
|
* Default (empty) signature
|
|
547
577
|
*
|
|
@@ -1125,8 +1155,7 @@ class Transaction {
|
|
|
1125
1155
|
let signatures = [];
|
|
1126
1156
|
|
|
1127
1157
|
for (let i = 0; i < signatureCount; i++) {
|
|
1128
|
-
const signature = byteArray
|
|
1129
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1158
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1130
1159
|
signatures.push(bs58__default['default'].encode(buffer.Buffer.from(signature)));
|
|
1131
1160
|
}
|
|
1132
1161
|
|
|
@@ -6159,10 +6188,8 @@ class ValidatorInfo {
|
|
|
6159
6188
|
const configKeys = [];
|
|
6160
6189
|
|
|
6161
6190
|
for (let i = 0; i < 2; i++) {
|
|
6162
|
-
const publicKey = new PublicKey(byteArray
|
|
6163
|
-
|
|
6164
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
6165
|
-
byteArray = byteArray.slice(1);
|
|
6191
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
6192
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
6166
6193
|
configKeys.push({
|
|
6167
6194
|
publicKey,
|
|
6168
6195
|
isSigner
|