@solana/web3.js 1.1.1 → 1.1.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 +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 +2320 -0
- 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/lib/types/index.d.ts.map +1 -1
- package/package.json +26 -26
- 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.esm.js
CHANGED
|
@@ -357,6 +357,36 @@ function encodeLength(bytes, len) {
|
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
361
|
+
/**
|
|
362
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
363
|
+
*/
|
|
364
|
+
|
|
365
|
+
function guardedShift(byteArray) {
|
|
366
|
+
if (byteArray.length === 0) {
|
|
367
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return byteArray.shift();
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
374
|
+
* the array.
|
|
375
|
+
*/
|
|
376
|
+
|
|
377
|
+
function guardedSplice(byteArray, ...args) {
|
|
378
|
+
var _args$;
|
|
379
|
+
|
|
380
|
+
const [start] = args;
|
|
381
|
+
|
|
382
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
383
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
384
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return byteArray.splice(...args);
|
|
388
|
+
}
|
|
389
|
+
|
|
360
390
|
/**
|
|
361
391
|
* The message header, identifying signed and read-only account
|
|
362
392
|
*
|
|
@@ -447,32 +477,28 @@ class Message {
|
|
|
447
477
|
static from(buffer) {
|
|
448
478
|
// Slice up wire data
|
|
449
479
|
let byteArray = [...buffer];
|
|
450
|
-
const numRequiredSignatures = byteArray
|
|
451
|
-
const numReadonlySignedAccounts = byteArray
|
|
452
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
480
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
481
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
482
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
453
483
|
const accountCount = decodeLength(byteArray);
|
|
454
484
|
let accountKeys = [];
|
|
455
485
|
|
|
456
486
|
for (let i = 0; i < accountCount; i++) {
|
|
457
|
-
const account = byteArray
|
|
458
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
487
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
459
488
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
460
489
|
}
|
|
461
490
|
|
|
462
|
-
const recentBlockhash = byteArray
|
|
463
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
491
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
464
492
|
const instructionCount = decodeLength(byteArray);
|
|
465
493
|
let instructions = [];
|
|
466
494
|
|
|
467
495
|
for (let i = 0; i < instructionCount; i++) {
|
|
468
|
-
const programIdIndex = byteArray
|
|
496
|
+
const programIdIndex = guardedShift(byteArray);
|
|
469
497
|
const accountCount = decodeLength(byteArray);
|
|
470
|
-
const accounts = byteArray
|
|
471
|
-
byteArray = byteArray.slice(accountCount);
|
|
498
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
472
499
|
const dataLength = decodeLength(byteArray);
|
|
473
|
-
const dataSlice = byteArray
|
|
500
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
474
501
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
475
|
-
byteArray = byteArray.slice(dataLength);
|
|
476
502
|
instructions.push({
|
|
477
503
|
programIdIndex,
|
|
478
504
|
accounts,
|
|
@@ -1097,8 +1123,7 @@ class Transaction {
|
|
|
1097
1123
|
let signatures = [];
|
|
1098
1124
|
|
|
1099
1125
|
for (let i = 0; i < signatureCount; i++) {
|
|
1100
|
-
const signature = byteArray
|
|
1101
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1126
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1102
1127
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1103
1128
|
}
|
|
1104
1129
|
|
|
@@ -5826,10 +5851,8 @@ class ValidatorInfo {
|
|
|
5826
5851
|
const configKeys = [];
|
|
5827
5852
|
|
|
5828
5853
|
for (let i = 0; i < 2; i++) {
|
|
5829
|
-
const publicKey = new PublicKey(byteArray
|
|
5830
|
-
|
|
5831
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
5832
|
-
byteArray = byteArray.slice(1);
|
|
5854
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
5855
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
5833
5856
|
configKeys.push({
|
|
5834
5857
|
publicKey,
|
|
5835
5858
|
isSigner
|