@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.d.ts
CHANGED
|
@@ -974,10 +974,12 @@ declare module '@solana/web3.js' {
|
|
|
974
974
|
/**
|
|
975
975
|
* Configuration object for getParsedProgramAccounts
|
|
976
976
|
*/
|
|
977
|
-
export type GetParsedProgramAccountsConfig =
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
977
|
+
export type GetParsedProgramAccountsConfig = {
|
|
978
|
+
/** Optional commitment level */
|
|
979
|
+
commitment?: Commitment;
|
|
980
|
+
/** Optional array of filters to apply to accounts */
|
|
981
|
+
filters?: GetProgramAccountsFilter[];
|
|
982
|
+
};
|
|
981
983
|
/**
|
|
982
984
|
* Information describing an account
|
|
983
985
|
*/
|
package/lib/index.esm.js
CHANGED
|
@@ -374,6 +374,36 @@ function encodeLength(bytes, len) {
|
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
378
|
+
/**
|
|
379
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
380
|
+
*/
|
|
381
|
+
|
|
382
|
+
function guardedShift(byteArray) {
|
|
383
|
+
if (byteArray.length === 0) {
|
|
384
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return byteArray.shift();
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
391
|
+
* the array.
|
|
392
|
+
*/
|
|
393
|
+
|
|
394
|
+
function guardedSplice(byteArray, ...args) {
|
|
395
|
+
var _args$;
|
|
396
|
+
|
|
397
|
+
const [start] = args;
|
|
398
|
+
|
|
399
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
400
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
401
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return byteArray.splice(...args);
|
|
405
|
+
}
|
|
406
|
+
|
|
377
407
|
/**
|
|
378
408
|
* The message header, identifying signed and read-only account
|
|
379
409
|
*/
|
|
@@ -450,32 +480,28 @@ class Message {
|
|
|
450
480
|
static from(buffer) {
|
|
451
481
|
// Slice up wire data
|
|
452
482
|
let byteArray = [...buffer];
|
|
453
|
-
const numRequiredSignatures = byteArray
|
|
454
|
-
const numReadonlySignedAccounts = byteArray
|
|
455
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
483
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
484
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
485
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
456
486
|
const accountCount = decodeLength(byteArray);
|
|
457
487
|
let accountKeys = [];
|
|
458
488
|
|
|
459
489
|
for (let i = 0; i < accountCount; i++) {
|
|
460
|
-
const account = byteArray
|
|
461
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
490
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
462
491
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
463
492
|
}
|
|
464
493
|
|
|
465
|
-
const recentBlockhash = byteArray
|
|
466
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
494
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
467
495
|
const instructionCount = decodeLength(byteArray);
|
|
468
496
|
let instructions = [];
|
|
469
497
|
|
|
470
498
|
for (let i = 0; i < instructionCount; i++) {
|
|
471
|
-
const programIdIndex = byteArray
|
|
499
|
+
const programIdIndex = guardedShift(byteArray);
|
|
472
500
|
const accountCount = decodeLength(byteArray);
|
|
473
|
-
const accounts = byteArray
|
|
474
|
-
byteArray = byteArray.slice(accountCount);
|
|
501
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
475
502
|
const dataLength = decodeLength(byteArray);
|
|
476
|
-
const dataSlice = byteArray
|
|
503
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
477
504
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
478
|
-
byteArray = byteArray.slice(dataLength);
|
|
479
505
|
instructions.push({
|
|
480
506
|
programIdIndex,
|
|
481
507
|
accounts,
|
|
@@ -1085,8 +1111,7 @@ class Transaction {
|
|
|
1085
1111
|
let signatures = [];
|
|
1086
1112
|
|
|
1087
1113
|
for (let i = 0; i < signatureCount; i++) {
|
|
1088
|
-
const signature = byteArray
|
|
1089
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1114
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1090
1115
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1091
1116
|
}
|
|
1092
1117
|
|
|
@@ -6035,10 +6060,8 @@ class ValidatorInfo {
|
|
|
6035
6060
|
const configKeys = [];
|
|
6036
6061
|
|
|
6037
6062
|
for (let i = 0; i < 2; i++) {
|
|
6038
|
-
const publicKey = new PublicKey(byteArray
|
|
6039
|
-
|
|
6040
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
6041
|
-
byteArray = byteArray.slice(1);
|
|
6063
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
6064
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
6042
6065
|
configKeys.push({
|
|
6043
6066
|
publicKey,
|
|
6044
6067
|
isSigner
|