@solana/web3.js 1.76.0 → 1.76.1
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 +50 -32
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +50 -32
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +50 -32
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +50 -32
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +50 -32
- 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/index.native.js +50 -32
- package/lib/index.native.js.map +1 -1
- package/package.json +21 -21
- 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
|
@@ -707,6 +707,31 @@ class CompiledKeys {
|
|
|
707
707
|
}
|
|
708
708
|
}
|
|
709
709
|
|
|
710
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
714
|
+
*/
|
|
715
|
+
function guardedShift(byteArray) {
|
|
716
|
+
if (byteArray.length === 0) {
|
|
717
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
718
|
+
}
|
|
719
|
+
return byteArray.shift();
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
724
|
+
* the array.
|
|
725
|
+
*/
|
|
726
|
+
function guardedSplice(byteArray, ...args) {
|
|
727
|
+
const [start] = args;
|
|
728
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
729
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
730
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
731
|
+
}
|
|
732
|
+
return byteArray.splice(...args);
|
|
733
|
+
}
|
|
734
|
+
|
|
710
735
|
/**
|
|
711
736
|
* An instruction to execute by a program
|
|
712
737
|
*
|
|
@@ -844,32 +869,28 @@ class Message {
|
|
|
844
869
|
static from(buffer$1) {
|
|
845
870
|
// Slice up wire data
|
|
846
871
|
let byteArray = [...buffer$1];
|
|
847
|
-
const numRequiredSignatures = byteArray
|
|
872
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
848
873
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
849
874
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
850
875
|
}
|
|
851
|
-
const numReadonlySignedAccounts = byteArray
|
|
852
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
876
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
877
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
853
878
|
const accountCount = decodeLength(byteArray);
|
|
854
879
|
let accountKeys = [];
|
|
855
880
|
for (let i = 0; i < accountCount; i++) {
|
|
856
|
-
const account = byteArray
|
|
857
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
881
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
858
882
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
859
883
|
}
|
|
860
|
-
const recentBlockhash = byteArray
|
|
861
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
884
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
862
885
|
const instructionCount = decodeLength(byteArray);
|
|
863
886
|
let instructions = [];
|
|
864
887
|
for (let i = 0; i < instructionCount; i++) {
|
|
865
|
-
const programIdIndex = byteArray
|
|
888
|
+
const programIdIndex = guardedShift(byteArray);
|
|
866
889
|
const accountCount = decodeLength(byteArray);
|
|
867
|
-
const accounts = byteArray
|
|
868
|
-
byteArray = byteArray.slice(accountCount);
|
|
890
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
869
891
|
const dataLength = decodeLength(byteArray);
|
|
870
|
-
const dataSlice = byteArray
|
|
892
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
871
893
|
const data = bs58__default.default.encode(buffer.Buffer.from(dataSlice));
|
|
872
|
-
byteArray = byteArray.slice(dataLength);
|
|
873
894
|
instructions.push({
|
|
874
895
|
programIdIndex,
|
|
875
896
|
accounts,
|
|
@@ -1074,30 +1095,30 @@ class MessageV0 {
|
|
|
1074
1095
|
}
|
|
1075
1096
|
static deserialize(serializedMessage) {
|
|
1076
1097
|
let byteArray = [...serializedMessage];
|
|
1077
|
-
const prefix = byteArray
|
|
1098
|
+
const prefix = guardedShift(byteArray);
|
|
1078
1099
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1079
1100
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1080
1101
|
const version = maskedPrefix;
|
|
1081
1102
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1082
1103
|
const header = {
|
|
1083
|
-
numRequiredSignatures: byteArray
|
|
1084
|
-
numReadonlySignedAccounts: byteArray
|
|
1085
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1104
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1105
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1106
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1086
1107
|
};
|
|
1087
1108
|
const staticAccountKeys = [];
|
|
1088
1109
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1089
1110
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1090
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1111
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1091
1112
|
}
|
|
1092
|
-
const recentBlockhash = bs58__default.default.encode(byteArray
|
|
1113
|
+
const recentBlockhash = bs58__default.default.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1093
1114
|
const instructionCount = decodeLength(byteArray);
|
|
1094
1115
|
const compiledInstructions = [];
|
|
1095
1116
|
for (let i = 0; i < instructionCount; i++) {
|
|
1096
|
-
const programIdIndex = byteArray
|
|
1117
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1097
1118
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1098
|
-
const accountKeyIndexes = byteArray
|
|
1119
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1099
1120
|
const dataLength = decodeLength(byteArray);
|
|
1100
|
-
const data = new Uint8Array(byteArray
|
|
1121
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1101
1122
|
compiledInstructions.push({
|
|
1102
1123
|
programIdIndex,
|
|
1103
1124
|
accountKeyIndexes,
|
|
@@ -1107,11 +1128,11 @@ class MessageV0 {
|
|
|
1107
1128
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1108
1129
|
const addressTableLookups = [];
|
|
1109
1130
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1110
|
-
const accountKey = new PublicKey(byteArray
|
|
1131
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1111
1132
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1112
|
-
const writableIndexes = byteArray
|
|
1133
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1113
1134
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1114
|
-
const readonlyIndexes = byteArray
|
|
1135
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1115
1136
|
addressTableLookups.push({
|
|
1116
1137
|
accountKey,
|
|
1117
1138
|
writableIndexes,
|
|
@@ -1786,8 +1807,7 @@ class Transaction {
|
|
|
1786
1807
|
const signatureCount = decodeLength(byteArray);
|
|
1787
1808
|
let signatures = [];
|
|
1788
1809
|
for (let i = 0; i < signatureCount; i++) {
|
|
1789
|
-
const signature = byteArray
|
|
1790
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1810
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1791
1811
|
signatures.push(bs58__default.default.encode(buffer.Buffer.from(signature)));
|
|
1792
1812
|
}
|
|
1793
1813
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -1957,7 +1977,7 @@ class VersionedTransaction {
|
|
|
1957
1977
|
const signatures = [];
|
|
1958
1978
|
const signaturesLength = decodeLength(byteArray);
|
|
1959
1979
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1960
|
-
signatures.push(new Uint8Array(byteArray
|
|
1980
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1961
1981
|
}
|
|
1962
1982
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
1963
1983
|
return new VersionedTransaction(message, signatures);
|
|
@@ -6957,7 +6977,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
6957
6977
|
|
|
6958
6978
|
/** @internal */
|
|
6959
6979
|
const COMMON_HTTP_HEADERS = {
|
|
6960
|
-
'solana-client': `js/${"
|
|
6980
|
+
'solana-client': `js/${"1.76.1" }`
|
|
6961
6981
|
};
|
|
6962
6982
|
|
|
6963
6983
|
/**
|
|
@@ -11744,10 +11764,8 @@ class ValidatorInfo {
|
|
|
11744
11764
|
if (configKeyCount !== 2) return null;
|
|
11745
11765
|
const configKeys = [];
|
|
11746
11766
|
for (let i = 0; i < 2; i++) {
|
|
11747
|
-
const publicKey = new PublicKey(byteArray
|
|
11748
|
-
|
|
11749
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
11750
|
-
byteArray = byteArray.slice(1);
|
|
11767
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
11768
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
11751
11769
|
configKeys.push({
|
|
11752
11770
|
publicKey,
|
|
11753
11771
|
isSigner
|