@solana/web3.js 1.56.1 → 1.56.3
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.cjs.js +67 -34
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +67 -34
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +67 -34
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +4 -0
- package/lib/index.esm.js +67 -34
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +67 -34
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +67 -34
- package/lib/index.native.js.map +1 -1
- package/package.json +22 -22
- package/src/connection.ts +6 -0
- package/src/message/legacy.ts +9 -12
- package/src/message/v0.ts +29 -12
- package/src/transaction/legacy.ts +2 -2
- package/src/transaction/versioned.ts +2 -1
- package/src/utils/guarded-array-utils.ts +34 -0
- package/src/validator-info.ts +5 -4
package/lib/index.browser.esm.js
CHANGED
|
@@ -531,6 +531,44 @@ function encodeLength(bytes, len) {
|
|
|
531
531
|
}
|
|
532
532
|
}
|
|
533
533
|
|
|
534
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
535
|
+
/**
|
|
536
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
537
|
+
*/
|
|
538
|
+
|
|
539
|
+
function guardedShift(byteArray) {
|
|
540
|
+
if (byteArray.length === 0) {
|
|
541
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
return byteArray.shift();
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
548
|
+
* the array.
|
|
549
|
+
*/
|
|
550
|
+
|
|
551
|
+
function guardedSplice(byteArray, ...args) {
|
|
552
|
+
var _args$;
|
|
553
|
+
|
|
554
|
+
const [start] = args;
|
|
555
|
+
|
|
556
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
557
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
558
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
return byteArray.splice(...args);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* An instruction to execute by a program
|
|
566
|
+
*
|
|
567
|
+
* @property {number} programIdIndex
|
|
568
|
+
* @property {number[]} accounts
|
|
569
|
+
* @property {string} data
|
|
570
|
+
*/
|
|
571
|
+
|
|
534
572
|
/**
|
|
535
573
|
* List of instructions to be processed atomically
|
|
536
574
|
*/
|
|
@@ -643,37 +681,33 @@ class Message {
|
|
|
643
681
|
static from(buffer) {
|
|
644
682
|
// Slice up wire data
|
|
645
683
|
let byteArray = [...buffer];
|
|
646
|
-
const numRequiredSignatures = byteArray
|
|
684
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
647
685
|
|
|
648
686
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
649
687
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
650
688
|
}
|
|
651
689
|
|
|
652
|
-
const numReadonlySignedAccounts = byteArray
|
|
653
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
690
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
691
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
654
692
|
const accountCount = decodeLength(byteArray);
|
|
655
693
|
let accountKeys = [];
|
|
656
694
|
|
|
657
695
|
for (let i = 0; i < accountCount; i++) {
|
|
658
|
-
const account = byteArray
|
|
659
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
696
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
660
697
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
661
698
|
}
|
|
662
699
|
|
|
663
|
-
const recentBlockhash = byteArray
|
|
664
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
700
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
665
701
|
const instructionCount = decodeLength(byteArray);
|
|
666
702
|
let instructions = [];
|
|
667
703
|
|
|
668
704
|
for (let i = 0; i < instructionCount; i++) {
|
|
669
|
-
const programIdIndex = byteArray
|
|
705
|
+
const programIdIndex = guardedShift(byteArray);
|
|
670
706
|
const accountCount = decodeLength(byteArray);
|
|
671
|
-
const accounts = byteArray
|
|
672
|
-
byteArray = byteArray.slice(accountCount);
|
|
707
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
673
708
|
const dataLength = decodeLength(byteArray);
|
|
674
|
-
const dataSlice = byteArray
|
|
709
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
675
710
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
676
|
-
byteArray = byteArray.slice(dataLength);
|
|
677
711
|
instructions.push({
|
|
678
712
|
programIdIndex,
|
|
679
713
|
accounts,
|
|
@@ -796,33 +830,33 @@ class MessageV0 {
|
|
|
796
830
|
|
|
797
831
|
static deserialize(serializedMessage) {
|
|
798
832
|
let byteArray = [...serializedMessage];
|
|
799
|
-
const prefix = byteArray
|
|
833
|
+
const prefix = guardedShift(byteArray);
|
|
800
834
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
801
835
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
802
836
|
const version = maskedPrefix;
|
|
803
837
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
804
838
|
const header = {
|
|
805
|
-
numRequiredSignatures: byteArray
|
|
806
|
-
numReadonlySignedAccounts: byteArray
|
|
807
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
839
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
840
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
841
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
808
842
|
};
|
|
809
843
|
const staticAccountKeys = [];
|
|
810
844
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
811
845
|
|
|
812
846
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
813
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
847
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
814
848
|
}
|
|
815
849
|
|
|
816
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
850
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
817
851
|
const instructionCount = decodeLength(byteArray);
|
|
818
852
|
const compiledInstructions = [];
|
|
819
853
|
|
|
820
854
|
for (let i = 0; i < instructionCount; i++) {
|
|
821
|
-
const programIdIndex = byteArray
|
|
855
|
+
const programIdIndex = guardedShift(byteArray);
|
|
822
856
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
823
|
-
const accountKeyIndexes = byteArray
|
|
857
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
824
858
|
const dataLength = decodeLength(byteArray);
|
|
825
|
-
const data = new Uint8Array(byteArray
|
|
859
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
826
860
|
compiledInstructions.push({
|
|
827
861
|
programIdIndex,
|
|
828
862
|
accountKeyIndexes,
|
|
@@ -834,11 +868,11 @@ class MessageV0 {
|
|
|
834
868
|
const addressTableLookups = [];
|
|
835
869
|
|
|
836
870
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
837
|
-
const accountKey = new PublicKey(byteArray
|
|
871
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
838
872
|
const writableIndexesLength = decodeLength(byteArray);
|
|
839
|
-
const writableIndexes = byteArray
|
|
873
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
840
874
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
841
|
-
const readonlyIndexes = byteArray
|
|
875
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
842
876
|
addressTableLookups.push({
|
|
843
877
|
accountKey,
|
|
844
878
|
writableIndexes,
|
|
@@ -1569,8 +1603,7 @@ class Transaction {
|
|
|
1569
1603
|
let signatures = [];
|
|
1570
1604
|
|
|
1571
1605
|
for (let i = 0; i < signatureCount; i++) {
|
|
1572
|
-
const signature = byteArray
|
|
1573
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1606
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1574
1607
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1575
1608
|
}
|
|
1576
1609
|
|
|
@@ -1662,7 +1695,7 @@ class VersionedTransaction {
|
|
|
1662
1695
|
const signaturesLength = decodeLength(byteArray);
|
|
1663
1696
|
|
|
1664
1697
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1665
|
-
signatures.push(new Uint8Array(byteArray
|
|
1698
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1666
1699
|
}
|
|
1667
1700
|
|
|
1668
1701
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -3882,7 +3915,8 @@ const ConfirmedTransactionMetaResult = type({
|
|
|
3882
3915
|
logMessages: optional(nullable(array(string()))),
|
|
3883
3916
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3884
3917
|
postTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3885
|
-
loadedAddresses: optional(LoadedAddressesResult)
|
|
3918
|
+
loadedAddresses: optional(LoadedAddressesResult),
|
|
3919
|
+
computeUnitsConsumed: optional(number())
|
|
3886
3920
|
});
|
|
3887
3921
|
/**
|
|
3888
3922
|
* @internal
|
|
@@ -3900,7 +3934,8 @@ const ParsedConfirmedTransactionMetaResult = type({
|
|
|
3900
3934
|
logMessages: optional(nullable(array(string()))),
|
|
3901
3935
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3902
3936
|
postTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3903
|
-
loadedAddresses: optional(LoadedAddressesResult)
|
|
3937
|
+
loadedAddresses: optional(LoadedAddressesResult),
|
|
3938
|
+
computeUnitsConsumed: optional(number())
|
|
3904
3939
|
});
|
|
3905
3940
|
const TransactionVersionStruct = union([literal(0), literal('legacy')]);
|
|
3906
3941
|
/**
|
|
@@ -4059,7 +4094,7 @@ const LogsNotificationResult = type({
|
|
|
4059
4094
|
|
|
4060
4095
|
/** @internal */
|
|
4061
4096
|
const COMMON_HTTP_HEADERS = {
|
|
4062
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4097
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.56.3") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4063
4098
|
};
|
|
4064
4099
|
/**
|
|
4065
4100
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -8837,10 +8872,8 @@ class ValidatorInfo {
|
|
|
8837
8872
|
const configKeys = [];
|
|
8838
8873
|
|
|
8839
8874
|
for (let i = 0; i < 2; i++) {
|
|
8840
|
-
const publicKey = new PublicKey(byteArray
|
|
8841
|
-
|
|
8842
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8843
|
-
byteArray = byteArray.slice(1);
|
|
8875
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
8876
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8844
8877
|
configKeys.push({
|
|
8845
8878
|
publicKey,
|
|
8846
8879
|
isSigner
|