@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.cjs.js
CHANGED
|
@@ -568,6 +568,44 @@ function encodeLength(bytes, len) {
|
|
|
568
568
|
}
|
|
569
569
|
}
|
|
570
570
|
|
|
571
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
572
|
+
/**
|
|
573
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
574
|
+
*/
|
|
575
|
+
|
|
576
|
+
function guardedShift(byteArray) {
|
|
577
|
+
if (byteArray.length === 0) {
|
|
578
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
return byteArray.shift();
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
585
|
+
* the array.
|
|
586
|
+
*/
|
|
587
|
+
|
|
588
|
+
function guardedSplice(byteArray, ...args) {
|
|
589
|
+
var _args$;
|
|
590
|
+
|
|
591
|
+
const [start] = args;
|
|
592
|
+
|
|
593
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
594
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
595
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
return byteArray.splice(...args);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* An instruction to execute by a program
|
|
603
|
+
*
|
|
604
|
+
* @property {number} programIdIndex
|
|
605
|
+
* @property {number[]} accounts
|
|
606
|
+
* @property {string} data
|
|
607
|
+
*/
|
|
608
|
+
|
|
571
609
|
/**
|
|
572
610
|
* List of instructions to be processed atomically
|
|
573
611
|
*/
|
|
@@ -680,37 +718,33 @@ class Message {
|
|
|
680
718
|
static from(buffer$1) {
|
|
681
719
|
// Slice up wire data
|
|
682
720
|
let byteArray = [...buffer$1];
|
|
683
|
-
const numRequiredSignatures = byteArray
|
|
721
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
684
722
|
|
|
685
723
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
686
724
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
687
725
|
}
|
|
688
726
|
|
|
689
|
-
const numReadonlySignedAccounts = byteArray
|
|
690
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
727
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
728
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
691
729
|
const accountCount = decodeLength(byteArray);
|
|
692
730
|
let accountKeys = [];
|
|
693
731
|
|
|
694
732
|
for (let i = 0; i < accountCount; i++) {
|
|
695
|
-
const account = byteArray
|
|
696
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
733
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
697
734
|
accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
|
|
698
735
|
}
|
|
699
736
|
|
|
700
|
-
const recentBlockhash = byteArray
|
|
701
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
737
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
702
738
|
const instructionCount = decodeLength(byteArray);
|
|
703
739
|
let instructions = [];
|
|
704
740
|
|
|
705
741
|
for (let i = 0; i < instructionCount; i++) {
|
|
706
|
-
const programIdIndex = byteArray
|
|
742
|
+
const programIdIndex = guardedShift(byteArray);
|
|
707
743
|
const accountCount = decodeLength(byteArray);
|
|
708
|
-
const accounts = byteArray
|
|
709
|
-
byteArray = byteArray.slice(accountCount);
|
|
744
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
710
745
|
const dataLength = decodeLength(byteArray);
|
|
711
|
-
const dataSlice = byteArray
|
|
746
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
712
747
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
713
|
-
byteArray = byteArray.slice(dataLength);
|
|
714
748
|
instructions.push({
|
|
715
749
|
programIdIndex,
|
|
716
750
|
accounts,
|
|
@@ -833,33 +867,33 @@ class MessageV0 {
|
|
|
833
867
|
|
|
834
868
|
static deserialize(serializedMessage) {
|
|
835
869
|
let byteArray = [...serializedMessage];
|
|
836
|
-
const prefix = byteArray
|
|
870
|
+
const prefix = guardedShift(byteArray);
|
|
837
871
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
838
872
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
839
873
|
const version = maskedPrefix;
|
|
840
874
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
841
875
|
const header = {
|
|
842
|
-
numRequiredSignatures: byteArray
|
|
843
|
-
numReadonlySignedAccounts: byteArray
|
|
844
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
876
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
877
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
878
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
845
879
|
};
|
|
846
880
|
const staticAccountKeys = [];
|
|
847
881
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
848
882
|
|
|
849
883
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
850
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
884
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
851
885
|
}
|
|
852
886
|
|
|
853
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
887
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
854
888
|
const instructionCount = decodeLength(byteArray);
|
|
855
889
|
const compiledInstructions = [];
|
|
856
890
|
|
|
857
891
|
for (let i = 0; i < instructionCount; i++) {
|
|
858
|
-
const programIdIndex = byteArray
|
|
892
|
+
const programIdIndex = guardedShift(byteArray);
|
|
859
893
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
860
|
-
const accountKeyIndexes = byteArray
|
|
894
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
861
895
|
const dataLength = decodeLength(byteArray);
|
|
862
|
-
const data = new Uint8Array(byteArray
|
|
896
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
863
897
|
compiledInstructions.push({
|
|
864
898
|
programIdIndex,
|
|
865
899
|
accountKeyIndexes,
|
|
@@ -871,11 +905,11 @@ class MessageV0 {
|
|
|
871
905
|
const addressTableLookups = [];
|
|
872
906
|
|
|
873
907
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
874
|
-
const accountKey = new PublicKey(byteArray
|
|
908
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
875
909
|
const writableIndexesLength = decodeLength(byteArray);
|
|
876
|
-
const writableIndexes = byteArray
|
|
910
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
877
911
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
878
|
-
const readonlyIndexes = byteArray
|
|
912
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
879
913
|
addressTableLookups.push({
|
|
880
914
|
accountKey,
|
|
881
915
|
writableIndexes,
|
|
@@ -1606,8 +1640,7 @@ class Transaction {
|
|
|
1606
1640
|
let signatures = [];
|
|
1607
1641
|
|
|
1608
1642
|
for (let i = 0; i < signatureCount; i++) {
|
|
1609
|
-
const signature = byteArray
|
|
1610
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1643
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1611
1644
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1612
1645
|
}
|
|
1613
1646
|
|
|
@@ -1699,7 +1732,7 @@ class VersionedTransaction {
|
|
|
1699
1732
|
const signaturesLength = decodeLength(byteArray);
|
|
1700
1733
|
|
|
1701
1734
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1702
|
-
signatures.push(new Uint8Array(byteArray
|
|
1735
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1703
1736
|
}
|
|
1704
1737
|
|
|
1705
1738
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -3979,7 +4012,8 @@ const ConfirmedTransactionMetaResult = superstruct.type({
|
|
|
3979
4012
|
logMessages: superstruct.optional(superstruct.nullable(superstruct.array(superstruct.string()))),
|
|
3980
4013
|
preTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
|
|
3981
4014
|
postTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
|
|
3982
|
-
loadedAddresses: superstruct.optional(LoadedAddressesResult)
|
|
4015
|
+
loadedAddresses: superstruct.optional(LoadedAddressesResult),
|
|
4016
|
+
computeUnitsConsumed: superstruct.optional(superstruct.number())
|
|
3983
4017
|
});
|
|
3984
4018
|
/**
|
|
3985
4019
|
* @internal
|
|
@@ -3997,7 +4031,8 @@ const ParsedConfirmedTransactionMetaResult = superstruct.type({
|
|
|
3997
4031
|
logMessages: superstruct.optional(superstruct.nullable(superstruct.array(superstruct.string()))),
|
|
3998
4032
|
preTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
|
|
3999
4033
|
postTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
|
|
4000
|
-
loadedAddresses: superstruct.optional(LoadedAddressesResult)
|
|
4034
|
+
loadedAddresses: superstruct.optional(LoadedAddressesResult),
|
|
4035
|
+
computeUnitsConsumed: superstruct.optional(superstruct.number())
|
|
4001
4036
|
});
|
|
4002
4037
|
const TransactionVersionStruct = superstruct.union([superstruct.literal(0), superstruct.literal('legacy')]);
|
|
4003
4038
|
/**
|
|
@@ -4156,7 +4191,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4156
4191
|
|
|
4157
4192
|
/** @internal */
|
|
4158
4193
|
const COMMON_HTTP_HEADERS = {
|
|
4159
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4194
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.56.3") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4160
4195
|
};
|
|
4161
4196
|
/**
|
|
4162
4197
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -8934,10 +8969,8 @@ class ValidatorInfo {
|
|
|
8934
8969
|
const configKeys = [];
|
|
8935
8970
|
|
|
8936
8971
|
for (let i = 0; i < 2; i++) {
|
|
8937
|
-
const publicKey = new PublicKey(byteArray
|
|
8938
|
-
|
|
8939
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8940
|
-
byteArray = byteArray.slice(1);
|
|
8972
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
8973
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8941
8974
|
configKeys.push({
|
|
8942
8975
|
publicKey,
|
|
8943
8976
|
isSigner
|