@solana/web3.js 1.61.1 → 1.61.2
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
|
*
|
|
@@ -905,37 +935,33 @@ class Message {
|
|
|
905
935
|
static from(buffer$1) {
|
|
906
936
|
// Slice up wire data
|
|
907
937
|
let byteArray = [...buffer$1];
|
|
908
|
-
const numRequiredSignatures = byteArray
|
|
938
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
909
939
|
|
|
910
940
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
911
941
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
912
942
|
}
|
|
913
943
|
|
|
914
|
-
const numReadonlySignedAccounts = byteArray
|
|
915
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
944
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
945
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
916
946
|
const accountCount = decodeLength(byteArray);
|
|
917
947
|
let accountKeys = [];
|
|
918
948
|
|
|
919
949
|
for (let i = 0; i < accountCount; i++) {
|
|
920
|
-
const account = byteArray
|
|
921
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
950
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
922
951
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
923
952
|
}
|
|
924
953
|
|
|
925
|
-
const recentBlockhash = byteArray
|
|
926
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
954
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
927
955
|
const instructionCount = decodeLength(byteArray);
|
|
928
956
|
let instructions = [];
|
|
929
957
|
|
|
930
958
|
for (let i = 0; i < instructionCount; i++) {
|
|
931
|
-
const programIdIndex = byteArray
|
|
959
|
+
const programIdIndex = guardedShift(byteArray);
|
|
932
960
|
const accountCount = decodeLength(byteArray);
|
|
933
|
-
const accounts = byteArray
|
|
934
|
-
byteArray = byteArray.slice(accountCount);
|
|
961
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
935
962
|
const dataLength = decodeLength(byteArray);
|
|
936
|
-
const dataSlice = byteArray
|
|
963
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
937
964
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
938
|
-
byteArray = byteArray.slice(dataLength);
|
|
939
965
|
instructions.push({
|
|
940
966
|
programIdIndex,
|
|
941
967
|
accounts,
|
|
@@ -1148,33 +1174,33 @@ class MessageV0 {
|
|
|
1148
1174
|
|
|
1149
1175
|
static deserialize(serializedMessage) {
|
|
1150
1176
|
let byteArray = [...serializedMessage];
|
|
1151
|
-
const prefix = byteArray
|
|
1177
|
+
const prefix = guardedShift(byteArray);
|
|
1152
1178
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1153
1179
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1154
1180
|
const version = maskedPrefix;
|
|
1155
1181
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1156
1182
|
const header = {
|
|
1157
|
-
numRequiredSignatures: byteArray
|
|
1158
|
-
numReadonlySignedAccounts: byteArray
|
|
1159
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1183
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1184
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1185
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1160
1186
|
};
|
|
1161
1187
|
const staticAccountKeys = [];
|
|
1162
1188
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1163
1189
|
|
|
1164
1190
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1165
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1191
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1166
1192
|
}
|
|
1167
1193
|
|
|
1168
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
1194
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1169
1195
|
const instructionCount = decodeLength(byteArray);
|
|
1170
1196
|
const compiledInstructions = [];
|
|
1171
1197
|
|
|
1172
1198
|
for (let i = 0; i < instructionCount; i++) {
|
|
1173
|
-
const programIdIndex = byteArray
|
|
1199
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1174
1200
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1175
|
-
const accountKeyIndexes = byteArray
|
|
1201
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1176
1202
|
const dataLength = decodeLength(byteArray);
|
|
1177
|
-
const data = new Uint8Array(byteArray
|
|
1203
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1178
1204
|
compiledInstructions.push({
|
|
1179
1205
|
programIdIndex,
|
|
1180
1206
|
accountKeyIndexes,
|
|
@@ -1186,11 +1212,11 @@ class MessageV0 {
|
|
|
1186
1212
|
const addressTableLookups = [];
|
|
1187
1213
|
|
|
1188
1214
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1189
|
-
const accountKey = new PublicKey(byteArray
|
|
1215
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1190
1216
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1191
|
-
const writableIndexes = byteArray
|
|
1217
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1192
1218
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1193
|
-
const readonlyIndexes = byteArray
|
|
1219
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1194
1220
|
addressTableLookups.push({
|
|
1195
1221
|
accountKey,
|
|
1196
1222
|
writableIndexes,
|
|
@@ -1921,8 +1947,7 @@ class Transaction {
|
|
|
1921
1947
|
let signatures = [];
|
|
1922
1948
|
|
|
1923
1949
|
for (let i = 0; i < signatureCount; i++) {
|
|
1924
|
-
const signature = byteArray
|
|
1925
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1950
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1926
1951
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1927
1952
|
}
|
|
1928
1953
|
|
|
@@ -2120,7 +2145,7 @@ class VersionedTransaction {
|
|
|
2120
2145
|
const signaturesLength = decodeLength(byteArray);
|
|
2121
2146
|
|
|
2122
2147
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2123
|
-
signatures.push(new Uint8Array(byteArray
|
|
2148
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2124
2149
|
}
|
|
2125
2150
|
|
|
2126
2151
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4520,7 +4545,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4520
4545
|
|
|
4521
4546
|
/** @internal */
|
|
4522
4547
|
const COMMON_HTTP_HEADERS = {
|
|
4523
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4548
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.61.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4524
4549
|
};
|
|
4525
4550
|
/**
|
|
4526
4551
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9437,10 +9462,8 @@ class ValidatorInfo {
|
|
|
9437
9462
|
const configKeys = [];
|
|
9438
9463
|
|
|
9439
9464
|
for (let i = 0; i < 2; i++) {
|
|
9440
|
-
const publicKey = new PublicKey(byteArray
|
|
9441
|
-
|
|
9442
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9443
|
-
byteArray = byteArray.slice(1);
|
|
9465
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9466
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9444
9467
|
configKeys.push({
|
|
9445
9468
|
publicKey,
|
|
9446
9469
|
isSigner
|