@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.cjs.js
CHANGED
|
@@ -395,6 +395,36 @@ function encodeLength(bytes, len) {
|
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
399
|
+
/**
|
|
400
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
401
|
+
*/
|
|
402
|
+
|
|
403
|
+
function guardedShift(byteArray) {
|
|
404
|
+
if (byteArray.length === 0) {
|
|
405
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return byteArray.shift();
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
412
|
+
* the array.
|
|
413
|
+
*/
|
|
414
|
+
|
|
415
|
+
function guardedSplice(byteArray, ...args) {
|
|
416
|
+
var _args$;
|
|
417
|
+
|
|
418
|
+
const [start] = args;
|
|
419
|
+
|
|
420
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
421
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
422
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return byteArray.splice(...args);
|
|
426
|
+
}
|
|
427
|
+
|
|
398
428
|
/**
|
|
399
429
|
* The message header, identifying signed and read-only account
|
|
400
430
|
*
|
|
@@ -485,32 +515,28 @@ class Message {
|
|
|
485
515
|
static from(buffer$1) {
|
|
486
516
|
// Slice up wire data
|
|
487
517
|
let byteArray = [...buffer$1];
|
|
488
|
-
const numRequiredSignatures = byteArray
|
|
489
|
-
const numReadonlySignedAccounts = byteArray
|
|
490
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
518
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
519
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
520
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
491
521
|
const accountCount = decodeLength(byteArray);
|
|
492
522
|
let accountKeys = [];
|
|
493
523
|
|
|
494
524
|
for (let i = 0; i < accountCount; i++) {
|
|
495
|
-
const account = byteArray
|
|
496
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
525
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
497
526
|
accountKeys.push(bs58__default['default'].encode(buffer.Buffer.from(account)));
|
|
498
527
|
}
|
|
499
528
|
|
|
500
|
-
const recentBlockhash = byteArray
|
|
501
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
529
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
502
530
|
const instructionCount = decodeLength(byteArray);
|
|
503
531
|
let instructions = [];
|
|
504
532
|
|
|
505
533
|
for (let i = 0; i < instructionCount; i++) {
|
|
506
|
-
const programIdIndex = byteArray
|
|
534
|
+
const programIdIndex = guardedShift(byteArray);
|
|
507
535
|
const accountCount = decodeLength(byteArray);
|
|
508
|
-
const accounts = byteArray
|
|
509
|
-
byteArray = byteArray.slice(accountCount);
|
|
536
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
510
537
|
const dataLength = decodeLength(byteArray);
|
|
511
|
-
const dataSlice = byteArray
|
|
538
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
512
539
|
const data = bs58__default['default'].encode(buffer.Buffer.from(dataSlice));
|
|
513
|
-
byteArray = byteArray.slice(dataLength);
|
|
514
540
|
instructions.push({
|
|
515
541
|
programIdIndex,
|
|
516
542
|
accounts,
|
|
@@ -1135,8 +1161,7 @@ class Transaction {
|
|
|
1135
1161
|
let signatures = [];
|
|
1136
1162
|
|
|
1137
1163
|
for (let i = 0; i < signatureCount; i++) {
|
|
1138
|
-
const signature = byteArray
|
|
1139
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1164
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1140
1165
|
signatures.push(bs58__default['default'].encode(buffer.Buffer.from(signature)));
|
|
1141
1166
|
}
|
|
1142
1167
|
|
|
@@ -5864,10 +5889,8 @@ class ValidatorInfo {
|
|
|
5864
5889
|
const configKeys = [];
|
|
5865
5890
|
|
|
5866
5891
|
for (let i = 0; i < 2; i++) {
|
|
5867
|
-
const publicKey = new PublicKey(byteArray
|
|
5868
|
-
|
|
5869
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
5870
|
-
byteArray = byteArray.slice(1);
|
|
5892
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
5893
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
5871
5894
|
configKeys.push({
|
|
5872
5895
|
publicKey,
|
|
5873
5896
|
isSigner
|