@solana/web3.js 1.64.0 → 1.64.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.browser.cjs.js
CHANGED
|
@@ -764,6 +764,36 @@ class CompiledKeys {
|
|
|
764
764
|
|
|
765
765
|
}
|
|
766
766
|
|
|
767
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
768
|
+
/**
|
|
769
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
770
|
+
*/
|
|
771
|
+
|
|
772
|
+
function guardedShift(byteArray) {
|
|
773
|
+
if (byteArray.length === 0) {
|
|
774
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
return byteArray.shift();
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
781
|
+
* the array.
|
|
782
|
+
*/
|
|
783
|
+
|
|
784
|
+
function guardedSplice(byteArray, ...args) {
|
|
785
|
+
var _args$;
|
|
786
|
+
|
|
787
|
+
const [start] = args;
|
|
788
|
+
|
|
789
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
790
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
791
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
return byteArray.splice(...args);
|
|
795
|
+
}
|
|
796
|
+
|
|
767
797
|
/**
|
|
768
798
|
* An instruction to execute by a program
|
|
769
799
|
*
|
|
@@ -915,37 +945,33 @@ class Message {
|
|
|
915
945
|
static from(buffer$1) {
|
|
916
946
|
// Slice up wire data
|
|
917
947
|
let byteArray = [...buffer$1];
|
|
918
|
-
const numRequiredSignatures = byteArray
|
|
948
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
919
949
|
|
|
920
950
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
921
951
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
922
952
|
}
|
|
923
953
|
|
|
924
|
-
const numReadonlySignedAccounts = byteArray
|
|
925
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
954
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
955
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
926
956
|
const accountCount = decodeLength(byteArray);
|
|
927
957
|
let accountKeys = [];
|
|
928
958
|
|
|
929
959
|
for (let i = 0; i < accountCount; i++) {
|
|
930
|
-
const account = byteArray
|
|
931
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
960
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
932
961
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
933
962
|
}
|
|
934
963
|
|
|
935
|
-
const recentBlockhash = byteArray
|
|
936
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
964
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
937
965
|
const instructionCount = decodeLength(byteArray);
|
|
938
966
|
let instructions = [];
|
|
939
967
|
|
|
940
968
|
for (let i = 0; i < instructionCount; i++) {
|
|
941
|
-
const programIdIndex = byteArray
|
|
969
|
+
const programIdIndex = guardedShift(byteArray);
|
|
942
970
|
const accountCount = decodeLength(byteArray);
|
|
943
|
-
const accounts = byteArray
|
|
944
|
-
byteArray = byteArray.slice(accountCount);
|
|
971
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
945
972
|
const dataLength = decodeLength(byteArray);
|
|
946
|
-
const dataSlice = byteArray
|
|
973
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
947
974
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
948
|
-
byteArray = byteArray.slice(dataLength);
|
|
949
975
|
instructions.push({
|
|
950
976
|
programIdIndex,
|
|
951
977
|
accounts,
|
|
@@ -1181,33 +1207,33 @@ class MessageV0 {
|
|
|
1181
1207
|
|
|
1182
1208
|
static deserialize(serializedMessage) {
|
|
1183
1209
|
let byteArray = [...serializedMessage];
|
|
1184
|
-
const prefix = byteArray
|
|
1210
|
+
const prefix = guardedShift(byteArray);
|
|
1185
1211
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1186
1212
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1187
1213
|
const version = maskedPrefix;
|
|
1188
1214
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1189
1215
|
const header = {
|
|
1190
|
-
numRequiredSignatures: byteArray
|
|
1191
|
-
numReadonlySignedAccounts: byteArray
|
|
1192
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1216
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1217
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1218
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1193
1219
|
};
|
|
1194
1220
|
const staticAccountKeys = [];
|
|
1195
1221
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1196
1222
|
|
|
1197
1223
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1198
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1224
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1199
1225
|
}
|
|
1200
1226
|
|
|
1201
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
1227
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1202
1228
|
const instructionCount = decodeLength(byteArray);
|
|
1203
1229
|
const compiledInstructions = [];
|
|
1204
1230
|
|
|
1205
1231
|
for (let i = 0; i < instructionCount; i++) {
|
|
1206
|
-
const programIdIndex = byteArray
|
|
1232
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1207
1233
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1208
|
-
const accountKeyIndexes = byteArray
|
|
1234
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1209
1235
|
const dataLength = decodeLength(byteArray);
|
|
1210
|
-
const data = new Uint8Array(byteArray
|
|
1236
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1211
1237
|
compiledInstructions.push({
|
|
1212
1238
|
programIdIndex,
|
|
1213
1239
|
accountKeyIndexes,
|
|
@@ -1219,11 +1245,11 @@ class MessageV0 {
|
|
|
1219
1245
|
const addressTableLookups = [];
|
|
1220
1246
|
|
|
1221
1247
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1222
|
-
const accountKey = new PublicKey(byteArray
|
|
1248
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1223
1249
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1224
|
-
const writableIndexes = byteArray
|
|
1250
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1225
1251
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1226
|
-
const readonlyIndexes = byteArray
|
|
1252
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1227
1253
|
addressTableLookups.push({
|
|
1228
1254
|
accountKey,
|
|
1229
1255
|
writableIndexes,
|
|
@@ -1954,8 +1980,7 @@ class Transaction {
|
|
|
1954
1980
|
let signatures = [];
|
|
1955
1981
|
|
|
1956
1982
|
for (let i = 0; i < signatureCount; i++) {
|
|
1957
|
-
const signature = byteArray
|
|
1958
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1983
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1959
1984
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1960
1985
|
}
|
|
1961
1986
|
|
|
@@ -2153,7 +2178,7 @@ class VersionedTransaction {
|
|
|
2153
2178
|
const signaturesLength = decodeLength(byteArray);
|
|
2154
2179
|
|
|
2155
2180
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2156
|
-
signatures.push(new Uint8Array(byteArray
|
|
2181
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2157
2182
|
}
|
|
2158
2183
|
|
|
2159
2184
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4583,7 +4608,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4583
4608
|
|
|
4584
4609
|
/** @internal */
|
|
4585
4610
|
const COMMON_HTTP_HEADERS = {
|
|
4586
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4611
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.64.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4587
4612
|
};
|
|
4588
4613
|
/**
|
|
4589
4614
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9522,10 +9547,8 @@ class ValidatorInfo {
|
|
|
9522
9547
|
const configKeys = [];
|
|
9523
9548
|
|
|
9524
9549
|
for (let i = 0; i < 2; i++) {
|
|
9525
|
-
const publicKey = new PublicKey(byteArray
|
|
9526
|
-
|
|
9527
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9528
|
-
byteArray = byteArray.slice(1);
|
|
9550
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9551
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9529
9552
|
configKeys.push({
|
|
9530
9553
|
publicKey,
|
|
9531
9554
|
isSigner
|