@solana/web3.js 1.58.0 → 1.58.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 +55 -32
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +55 -32
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +55 -32
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +55 -32
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +55 -32
- 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 +55 -32
- package/lib/index.native.js.map +1 -1
- package/package.json +22 -22
- 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.native.js
CHANGED
|
@@ -754,6 +754,36 @@ class CompiledKeys {
|
|
|
754
754
|
|
|
755
755
|
}
|
|
756
756
|
|
|
757
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
758
|
+
/**
|
|
759
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
760
|
+
*/
|
|
761
|
+
|
|
762
|
+
function guardedShift(byteArray) {
|
|
763
|
+
if (byteArray.length === 0) {
|
|
764
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
return byteArray.shift();
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
771
|
+
* the array.
|
|
772
|
+
*/
|
|
773
|
+
|
|
774
|
+
function guardedSplice(byteArray, ...args) {
|
|
775
|
+
var _args$;
|
|
776
|
+
|
|
777
|
+
const [start] = args;
|
|
778
|
+
|
|
779
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
780
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
781
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
return byteArray.splice(...args);
|
|
785
|
+
}
|
|
786
|
+
|
|
757
787
|
/**
|
|
758
788
|
* An instruction to execute by a program
|
|
759
789
|
*
|
|
@@ -895,37 +925,33 @@ class Message {
|
|
|
895
925
|
static from(buffer$1) {
|
|
896
926
|
// Slice up wire data
|
|
897
927
|
let byteArray = [...buffer$1];
|
|
898
|
-
const numRequiredSignatures = byteArray
|
|
928
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
899
929
|
|
|
900
930
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
901
931
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
902
932
|
}
|
|
903
933
|
|
|
904
|
-
const numReadonlySignedAccounts = byteArray
|
|
905
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
934
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
935
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
906
936
|
const accountCount = decodeLength(byteArray);
|
|
907
937
|
let accountKeys = [];
|
|
908
938
|
|
|
909
939
|
for (let i = 0; i < accountCount; i++) {
|
|
910
|
-
const account = byteArray
|
|
911
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
940
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
912
941
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
913
942
|
}
|
|
914
943
|
|
|
915
|
-
const recentBlockhash = byteArray
|
|
916
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
944
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
917
945
|
const instructionCount = decodeLength(byteArray);
|
|
918
946
|
let instructions = [];
|
|
919
947
|
|
|
920
948
|
for (let i = 0; i < instructionCount; i++) {
|
|
921
|
-
const programIdIndex = byteArray
|
|
949
|
+
const programIdIndex = guardedShift(byteArray);
|
|
922
950
|
const accountCount = decodeLength(byteArray);
|
|
923
|
-
const accounts = byteArray
|
|
924
|
-
byteArray = byteArray.slice(accountCount);
|
|
951
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
925
952
|
const dataLength = decodeLength(byteArray);
|
|
926
|
-
const dataSlice = byteArray
|
|
953
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
927
954
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
928
|
-
byteArray = byteArray.slice(dataLength);
|
|
929
955
|
instructions.push({
|
|
930
956
|
programIdIndex,
|
|
931
957
|
accounts,
|
|
@@ -1138,33 +1164,33 @@ class MessageV0 {
|
|
|
1138
1164
|
|
|
1139
1165
|
static deserialize(serializedMessage) {
|
|
1140
1166
|
let byteArray = [...serializedMessage];
|
|
1141
|
-
const prefix = byteArray
|
|
1167
|
+
const prefix = guardedShift(byteArray);
|
|
1142
1168
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1143
1169
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1144
1170
|
const version = maskedPrefix;
|
|
1145
1171
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1146
1172
|
const header = {
|
|
1147
|
-
numRequiredSignatures: byteArray
|
|
1148
|
-
numReadonlySignedAccounts: byteArray
|
|
1149
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1173
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1174
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1175
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1150
1176
|
};
|
|
1151
1177
|
const staticAccountKeys = [];
|
|
1152
1178
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1153
1179
|
|
|
1154
1180
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1155
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1181
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1156
1182
|
}
|
|
1157
1183
|
|
|
1158
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
1184
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1159
1185
|
const instructionCount = decodeLength(byteArray);
|
|
1160
1186
|
const compiledInstructions = [];
|
|
1161
1187
|
|
|
1162
1188
|
for (let i = 0; i < instructionCount; i++) {
|
|
1163
|
-
const programIdIndex = byteArray
|
|
1189
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1164
1190
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1165
|
-
const accountKeyIndexes = byteArray
|
|
1191
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1166
1192
|
const dataLength = decodeLength(byteArray);
|
|
1167
|
-
const data = new Uint8Array(byteArray
|
|
1193
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1168
1194
|
compiledInstructions.push({
|
|
1169
1195
|
programIdIndex,
|
|
1170
1196
|
accountKeyIndexes,
|
|
@@ -1176,11 +1202,11 @@ class MessageV0 {
|
|
|
1176
1202
|
const addressTableLookups = [];
|
|
1177
1203
|
|
|
1178
1204
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1179
|
-
const accountKey = new PublicKey(byteArray
|
|
1205
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1180
1206
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1181
|
-
const writableIndexes = byteArray
|
|
1207
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1182
1208
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1183
|
-
const readonlyIndexes = byteArray
|
|
1209
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1184
1210
|
addressTableLookups.push({
|
|
1185
1211
|
accountKey,
|
|
1186
1212
|
writableIndexes,
|
|
@@ -1911,8 +1937,7 @@ class Transaction {
|
|
|
1911
1937
|
let signatures = [];
|
|
1912
1938
|
|
|
1913
1939
|
for (let i = 0; i < signatureCount; i++) {
|
|
1914
|
-
const signature = byteArray
|
|
1915
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1940
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1916
1941
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1917
1942
|
}
|
|
1918
1943
|
|
|
@@ -2112,7 +2137,7 @@ class VersionedTransaction {
|
|
|
2112
2137
|
const signaturesLength = decodeLength(byteArray);
|
|
2113
2138
|
|
|
2114
2139
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2115
|
-
signatures.push(new Uint8Array(byteArray
|
|
2140
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2116
2141
|
}
|
|
2117
2142
|
|
|
2118
2143
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4511,7 +4536,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4511
4536
|
|
|
4512
4537
|
/** @internal */
|
|
4513
4538
|
const COMMON_HTTP_HEADERS = {
|
|
4514
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4539
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.58.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4515
4540
|
};
|
|
4516
4541
|
/**
|
|
4517
4542
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9351,10 +9376,8 @@ class ValidatorInfo {
|
|
|
9351
9376
|
const configKeys = [];
|
|
9352
9377
|
|
|
9353
9378
|
for (let i = 0; i < 2; i++) {
|
|
9354
|
-
const publicKey = new PublicKey(byteArray
|
|
9355
|
-
|
|
9356
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9357
|
-
byteArray = byteArray.slice(1);
|
|
9379
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9380
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9358
9381
|
configKeys.push({
|
|
9359
9382
|
publicKey,
|
|
9360
9383
|
isSigner
|