@solana/web3.js 1.87.6 → 1.87.7
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.browser.esm.js
CHANGED
|
@@ -672,6 +672,31 @@ class CompiledKeys {
|
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
679
|
+
*/
|
|
680
|
+
function guardedShift(byteArray) {
|
|
681
|
+
if (byteArray.length === 0) {
|
|
682
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
683
|
+
}
|
|
684
|
+
return byteArray.shift();
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
689
|
+
* the array.
|
|
690
|
+
*/
|
|
691
|
+
function guardedSplice(byteArray, ...args) {
|
|
692
|
+
const [start] = args;
|
|
693
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
694
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
695
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
696
|
+
}
|
|
697
|
+
return byteArray.splice(...args);
|
|
698
|
+
}
|
|
699
|
+
|
|
675
700
|
/**
|
|
676
701
|
* An instruction to execute by a program
|
|
677
702
|
*
|
|
@@ -813,32 +838,28 @@ class Message {
|
|
|
813
838
|
static from(buffer) {
|
|
814
839
|
// Slice up wire data
|
|
815
840
|
let byteArray = [...buffer];
|
|
816
|
-
const numRequiredSignatures = byteArray
|
|
841
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
817
842
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
818
843
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
819
844
|
}
|
|
820
|
-
const numReadonlySignedAccounts = byteArray
|
|
821
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
845
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
846
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
822
847
|
const accountCount = decodeLength(byteArray);
|
|
823
848
|
let accountKeys = [];
|
|
824
849
|
for (let i = 0; i < accountCount; i++) {
|
|
825
|
-
const account = byteArray
|
|
826
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
850
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
827
851
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
828
852
|
}
|
|
829
|
-
const recentBlockhash = byteArray
|
|
830
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
853
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
831
854
|
const instructionCount = decodeLength(byteArray);
|
|
832
855
|
let instructions = [];
|
|
833
856
|
for (let i = 0; i < instructionCount; i++) {
|
|
834
|
-
const programIdIndex = byteArray
|
|
857
|
+
const programIdIndex = guardedShift(byteArray);
|
|
835
858
|
const accountCount = decodeLength(byteArray);
|
|
836
|
-
const accounts = byteArray
|
|
837
|
-
byteArray = byteArray.slice(accountCount);
|
|
859
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
838
860
|
const dataLength = decodeLength(byteArray);
|
|
839
|
-
const dataSlice = byteArray
|
|
861
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
840
862
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
841
|
-
byteArray = byteArray.slice(dataLength);
|
|
842
863
|
instructions.push({
|
|
843
864
|
programIdIndex,
|
|
844
865
|
accounts,
|
|
@@ -1043,30 +1064,30 @@ class MessageV0 {
|
|
|
1043
1064
|
}
|
|
1044
1065
|
static deserialize(serializedMessage) {
|
|
1045
1066
|
let byteArray = [...serializedMessage];
|
|
1046
|
-
const prefix = byteArray
|
|
1067
|
+
const prefix = guardedShift(byteArray);
|
|
1047
1068
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1048
1069
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1049
1070
|
const version = maskedPrefix;
|
|
1050
1071
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1051
1072
|
const header = {
|
|
1052
|
-
numRequiredSignatures: byteArray
|
|
1053
|
-
numReadonlySignedAccounts: byteArray
|
|
1054
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1073
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1074
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1075
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1055
1076
|
};
|
|
1056
1077
|
const staticAccountKeys = [];
|
|
1057
1078
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1058
1079
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1059
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1080
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1060
1081
|
}
|
|
1061
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1082
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1062
1083
|
const instructionCount = decodeLength(byteArray);
|
|
1063
1084
|
const compiledInstructions = [];
|
|
1064
1085
|
for (let i = 0; i < instructionCount; i++) {
|
|
1065
|
-
const programIdIndex = byteArray
|
|
1086
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1066
1087
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1067
|
-
const accountKeyIndexes = byteArray
|
|
1088
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1068
1089
|
const dataLength = decodeLength(byteArray);
|
|
1069
|
-
const data = new Uint8Array(byteArray
|
|
1090
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1070
1091
|
compiledInstructions.push({
|
|
1071
1092
|
programIdIndex,
|
|
1072
1093
|
accountKeyIndexes,
|
|
@@ -1076,11 +1097,11 @@ class MessageV0 {
|
|
|
1076
1097
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1077
1098
|
const addressTableLookups = [];
|
|
1078
1099
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1079
|
-
const accountKey = new PublicKey(byteArray
|
|
1100
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1080
1101
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1081
|
-
const writableIndexes = byteArray
|
|
1102
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1082
1103
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1083
|
-
const readonlyIndexes = byteArray
|
|
1104
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1084
1105
|
addressTableLookups.push({
|
|
1085
1106
|
accountKey,
|
|
1086
1107
|
writableIndexes,
|
|
@@ -1852,8 +1873,7 @@ class Transaction {
|
|
|
1852
1873
|
const signatureCount = decodeLength(byteArray);
|
|
1853
1874
|
let signatures = [];
|
|
1854
1875
|
for (let i = 0; i < signatureCount; i++) {
|
|
1855
|
-
const signature = byteArray
|
|
1856
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1876
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1857
1877
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1858
1878
|
}
|
|
1859
1879
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -2028,7 +2048,7 @@ class VersionedTransaction {
|
|
|
2028
2048
|
const signatures = [];
|
|
2029
2049
|
const signaturesLength = decodeLength(byteArray);
|
|
2030
2050
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2031
|
-
signatures.push(new Uint8Array(byteArray
|
|
2051
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2032
2052
|
}
|
|
2033
2053
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
2034
2054
|
return new VersionedTransaction(message, signatures);
|
|
@@ -5050,7 +5070,7 @@ const LogsNotificationResult = type({
|
|
|
5050
5070
|
|
|
5051
5071
|
/** @internal */
|
|
5052
5072
|
const COMMON_HTTP_HEADERS = {
|
|
5053
|
-
'solana-client': `js/${"
|
|
5073
|
+
'solana-client': `js/${"1.87.7" }`
|
|
5054
5074
|
};
|
|
5055
5075
|
|
|
5056
5076
|
/**
|
|
@@ -9985,10 +10005,8 @@ class ValidatorInfo {
|
|
|
9985
10005
|
if (configKeyCount !== 2) return null;
|
|
9986
10006
|
const configKeys = [];
|
|
9987
10007
|
for (let i = 0; i < 2; i++) {
|
|
9988
|
-
const publicKey = new PublicKey(byteArray
|
|
9989
|
-
|
|
9990
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9991
|
-
byteArray = byteArray.slice(1);
|
|
10008
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
10009
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9992
10010
|
configKeys.push({
|
|
9993
10011
|
publicKey,
|
|
9994
10012
|
isSigner
|