@solana/web3.js 1.67.1 → 1.67.3
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 +56 -33
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +56 -33
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +56 -33
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.js +56 -33
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +56 -33
- 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 +56 -33
- package/lib/index.native.js.map +1 -1
- package/package.json +22 -22
- package/src/connection.ts +2 -2
- 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
|
@@ -750,6 +750,36 @@ class CompiledKeys {
|
|
|
750
750
|
|
|
751
751
|
}
|
|
752
752
|
|
|
753
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
754
|
+
/**
|
|
755
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
756
|
+
*/
|
|
757
|
+
|
|
758
|
+
function guardedShift(byteArray) {
|
|
759
|
+
if (byteArray.length === 0) {
|
|
760
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
return byteArray.shift();
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
767
|
+
* the array.
|
|
768
|
+
*/
|
|
769
|
+
|
|
770
|
+
function guardedSplice(byteArray, ...args) {
|
|
771
|
+
var _args$;
|
|
772
|
+
|
|
773
|
+
const [start] = args;
|
|
774
|
+
|
|
775
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
776
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
777
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
return byteArray.splice(...args);
|
|
781
|
+
}
|
|
782
|
+
|
|
753
783
|
/**
|
|
754
784
|
* An instruction to execute by a program
|
|
755
785
|
*
|
|
@@ -901,37 +931,33 @@ class Message {
|
|
|
901
931
|
static from(buffer) {
|
|
902
932
|
// Slice up wire data
|
|
903
933
|
let byteArray = [...buffer];
|
|
904
|
-
const numRequiredSignatures = byteArray
|
|
934
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
905
935
|
|
|
906
936
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
907
937
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
908
938
|
}
|
|
909
939
|
|
|
910
|
-
const numReadonlySignedAccounts = byteArray
|
|
911
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
940
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
941
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
912
942
|
const accountCount = decodeLength(byteArray);
|
|
913
943
|
let accountKeys = [];
|
|
914
944
|
|
|
915
945
|
for (let i = 0; i < accountCount; i++) {
|
|
916
|
-
const account = byteArray
|
|
917
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
946
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
918
947
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
919
948
|
}
|
|
920
949
|
|
|
921
|
-
const recentBlockhash = byteArray
|
|
922
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
950
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
923
951
|
const instructionCount = decodeLength(byteArray);
|
|
924
952
|
let instructions = [];
|
|
925
953
|
|
|
926
954
|
for (let i = 0; i < instructionCount; i++) {
|
|
927
|
-
const programIdIndex = byteArray
|
|
955
|
+
const programIdIndex = guardedShift(byteArray);
|
|
928
956
|
const accountCount = decodeLength(byteArray);
|
|
929
|
-
const accounts = byteArray
|
|
930
|
-
byteArray = byteArray.slice(accountCount);
|
|
957
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
931
958
|
const dataLength = decodeLength(byteArray);
|
|
932
|
-
const dataSlice = byteArray
|
|
959
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
933
960
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
934
|
-
byteArray = byteArray.slice(dataLength);
|
|
935
961
|
instructions.push({
|
|
936
962
|
programIdIndex,
|
|
937
963
|
accounts,
|
|
@@ -1167,33 +1193,33 @@ class MessageV0 {
|
|
|
1167
1193
|
|
|
1168
1194
|
static deserialize(serializedMessage) {
|
|
1169
1195
|
let byteArray = [...serializedMessage];
|
|
1170
|
-
const prefix = byteArray
|
|
1196
|
+
const prefix = guardedShift(byteArray);
|
|
1171
1197
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1172
1198
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1173
1199
|
const version = maskedPrefix;
|
|
1174
1200
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1175
1201
|
const header = {
|
|
1176
|
-
numRequiredSignatures: byteArray
|
|
1177
|
-
numReadonlySignedAccounts: byteArray
|
|
1178
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1202
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1203
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1204
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1179
1205
|
};
|
|
1180
1206
|
const staticAccountKeys = [];
|
|
1181
1207
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1182
1208
|
|
|
1183
1209
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1184
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1210
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1185
1211
|
}
|
|
1186
1212
|
|
|
1187
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1213
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1188
1214
|
const instructionCount = decodeLength(byteArray);
|
|
1189
1215
|
const compiledInstructions = [];
|
|
1190
1216
|
|
|
1191
1217
|
for (let i = 0; i < instructionCount; i++) {
|
|
1192
|
-
const programIdIndex = byteArray
|
|
1218
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1193
1219
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1194
|
-
const accountKeyIndexes = byteArray
|
|
1220
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1195
1221
|
const dataLength = decodeLength(byteArray);
|
|
1196
|
-
const data = new Uint8Array(byteArray
|
|
1222
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1197
1223
|
compiledInstructions.push({
|
|
1198
1224
|
programIdIndex,
|
|
1199
1225
|
accountKeyIndexes,
|
|
@@ -1205,11 +1231,11 @@ class MessageV0 {
|
|
|
1205
1231
|
const addressTableLookups = [];
|
|
1206
1232
|
|
|
1207
1233
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1208
|
-
const accountKey = new PublicKey(byteArray
|
|
1234
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1209
1235
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1210
|
-
const writableIndexes = byteArray
|
|
1236
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1211
1237
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1212
|
-
const readonlyIndexes = byteArray
|
|
1238
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1213
1239
|
addressTableLookups.push({
|
|
1214
1240
|
accountKey,
|
|
1215
1241
|
writableIndexes,
|
|
@@ -1949,8 +1975,7 @@ class Transaction {
|
|
|
1949
1975
|
let signatures = [];
|
|
1950
1976
|
|
|
1951
1977
|
for (let i = 0; i < signatureCount; i++) {
|
|
1952
|
-
const signature = byteArray
|
|
1953
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1978
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1954
1979
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1955
1980
|
}
|
|
1956
1981
|
|
|
@@ -2148,7 +2173,7 @@ class VersionedTransaction {
|
|
|
2148
2173
|
const signaturesLength = decodeLength(byteArray);
|
|
2149
2174
|
|
|
2150
2175
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2151
|
-
signatures.push(new Uint8Array(byteArray
|
|
2176
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2152
2177
|
}
|
|
2153
2178
|
|
|
2154
2179
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4601,7 +4626,7 @@ const LogsNotificationResult = type({
|
|
|
4601
4626
|
|
|
4602
4627
|
/** @internal */
|
|
4603
4628
|
const COMMON_HTTP_HEADERS = {
|
|
4604
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4629
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.67.3") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4605
4630
|
};
|
|
4606
4631
|
/**
|
|
4607
4632
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -5983,7 +6008,7 @@ class Connection {
|
|
|
5983
6008
|
|
|
5984
6009
|
|
|
5985
6010
|
async getFeeForMessage(message, commitment) {
|
|
5986
|
-
const wireMessage = message.serialize().toString('base64');
|
|
6011
|
+
const wireMessage = toBuffer(message.serialize()).toString('base64');
|
|
5987
6012
|
|
|
5988
6013
|
const args = this._buildArgs([wireMessage], commitment);
|
|
5989
6014
|
|
|
@@ -9924,10 +9949,8 @@ class ValidatorInfo {
|
|
|
9924
9949
|
const configKeys = [];
|
|
9925
9950
|
|
|
9926
9951
|
for (let i = 0; i < 2; i++) {
|
|
9927
|
-
const publicKey = new PublicKey(byteArray
|
|
9928
|
-
|
|
9929
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9930
|
-
byteArray = byteArray.slice(1);
|
|
9952
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9953
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9931
9954
|
configKeys.push({
|
|
9932
9955
|
publicKey,
|
|
9933
9956
|
isSigner
|