@solana/web3.js 1.66.4 → 1.66.6
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 +90 -37
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +90 -37
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +90 -37
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +90 -37
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +90 -37
- 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 +90 -37
- package/lib/index.native.js.map +1 -1
- package/package.json +22 -22
- package/src/connection.ts +31 -5
- 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
|
@@ -765,6 +765,36 @@ class CompiledKeys {
|
|
|
765
765
|
|
|
766
766
|
}
|
|
767
767
|
|
|
768
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
769
|
+
/**
|
|
770
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
771
|
+
*/
|
|
772
|
+
|
|
773
|
+
function guardedShift(byteArray) {
|
|
774
|
+
if (byteArray.length === 0) {
|
|
775
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
return byteArray.shift();
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
782
|
+
* the array.
|
|
783
|
+
*/
|
|
784
|
+
|
|
785
|
+
function guardedSplice(byteArray, ...args) {
|
|
786
|
+
var _args$;
|
|
787
|
+
|
|
788
|
+
const [start] = args;
|
|
789
|
+
|
|
790
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
791
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
792
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
return byteArray.splice(...args);
|
|
796
|
+
}
|
|
797
|
+
|
|
768
798
|
/**
|
|
769
799
|
* An instruction to execute by a program
|
|
770
800
|
*
|
|
@@ -916,37 +946,33 @@ class Message {
|
|
|
916
946
|
static from(buffer$1) {
|
|
917
947
|
// Slice up wire data
|
|
918
948
|
let byteArray = [...buffer$1];
|
|
919
|
-
const numRequiredSignatures = byteArray
|
|
949
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
920
950
|
|
|
921
951
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
922
952
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
923
953
|
}
|
|
924
954
|
|
|
925
|
-
const numReadonlySignedAccounts = byteArray
|
|
926
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
955
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
956
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
927
957
|
const accountCount = decodeLength(byteArray);
|
|
928
958
|
let accountKeys = [];
|
|
929
959
|
|
|
930
960
|
for (let i = 0; i < accountCount; i++) {
|
|
931
|
-
const account = byteArray
|
|
932
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
961
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
933
962
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
934
963
|
}
|
|
935
964
|
|
|
936
|
-
const recentBlockhash = byteArray
|
|
937
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
965
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
938
966
|
const instructionCount = decodeLength(byteArray);
|
|
939
967
|
let instructions = [];
|
|
940
968
|
|
|
941
969
|
for (let i = 0; i < instructionCount; i++) {
|
|
942
|
-
const programIdIndex = byteArray
|
|
970
|
+
const programIdIndex = guardedShift(byteArray);
|
|
943
971
|
const accountCount = decodeLength(byteArray);
|
|
944
|
-
const accounts = byteArray
|
|
945
|
-
byteArray = byteArray.slice(accountCount);
|
|
972
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
946
973
|
const dataLength = decodeLength(byteArray);
|
|
947
|
-
const dataSlice = byteArray
|
|
974
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
948
975
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
949
|
-
byteArray = byteArray.slice(dataLength);
|
|
950
976
|
instructions.push({
|
|
951
977
|
programIdIndex,
|
|
952
978
|
accounts,
|
|
@@ -1182,33 +1208,33 @@ class MessageV0 {
|
|
|
1182
1208
|
|
|
1183
1209
|
static deserialize(serializedMessage) {
|
|
1184
1210
|
let byteArray = [...serializedMessage];
|
|
1185
|
-
const prefix = byteArray
|
|
1211
|
+
const prefix = guardedShift(byteArray);
|
|
1186
1212
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1187
1213
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1188
1214
|
const version = maskedPrefix;
|
|
1189
1215
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1190
1216
|
const header = {
|
|
1191
|
-
numRequiredSignatures: byteArray
|
|
1192
|
-
numReadonlySignedAccounts: byteArray
|
|
1193
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1217
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1218
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1219
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1194
1220
|
};
|
|
1195
1221
|
const staticAccountKeys = [];
|
|
1196
1222
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1197
1223
|
|
|
1198
1224
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1199
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1225
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1200
1226
|
}
|
|
1201
1227
|
|
|
1202
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
1228
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1203
1229
|
const instructionCount = decodeLength(byteArray);
|
|
1204
1230
|
const compiledInstructions = [];
|
|
1205
1231
|
|
|
1206
1232
|
for (let i = 0; i < instructionCount; i++) {
|
|
1207
|
-
const programIdIndex = byteArray
|
|
1233
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1208
1234
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1209
|
-
const accountKeyIndexes = byteArray
|
|
1235
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1210
1236
|
const dataLength = decodeLength(byteArray);
|
|
1211
|
-
const data = new Uint8Array(byteArray
|
|
1237
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1212
1238
|
compiledInstructions.push({
|
|
1213
1239
|
programIdIndex,
|
|
1214
1240
|
accountKeyIndexes,
|
|
@@ -1220,11 +1246,11 @@ class MessageV0 {
|
|
|
1220
1246
|
const addressTableLookups = [];
|
|
1221
1247
|
|
|
1222
1248
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1223
|
-
const accountKey = new PublicKey(byteArray
|
|
1249
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1224
1250
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1225
|
-
const writableIndexes = byteArray
|
|
1251
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1226
1252
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1227
|
-
const readonlyIndexes = byteArray
|
|
1253
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1228
1254
|
addressTableLookups.push({
|
|
1229
1255
|
accountKey,
|
|
1230
1256
|
writableIndexes,
|
|
@@ -1955,8 +1981,7 @@ class Transaction {
|
|
|
1955
1981
|
let signatures = [];
|
|
1956
1982
|
|
|
1957
1983
|
for (let i = 0; i < signatureCount; i++) {
|
|
1958
|
-
const signature = byteArray
|
|
1959
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1984
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1960
1985
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1961
1986
|
}
|
|
1962
1987
|
|
|
@@ -2154,7 +2179,7 @@ class VersionedTransaction {
|
|
|
2154
2179
|
const signaturesLength = decodeLength(byteArray);
|
|
2155
2180
|
|
|
2156
2181
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2157
|
-
signatures.push(new Uint8Array(byteArray
|
|
2182
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2158
2183
|
}
|
|
2159
2184
|
|
|
2160
2185
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4584,7 +4609,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4584
4609
|
|
|
4585
4610
|
/** @internal */
|
|
4586
4611
|
const COMMON_HTTP_HEADERS = {
|
|
4587
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4612
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.66.6") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4588
4613
|
};
|
|
4589
4614
|
/**
|
|
4590
4615
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -5213,7 +5238,7 @@ class Connection {
|
|
|
5213
5238
|
}
|
|
5214
5239
|
|
|
5215
5240
|
assert(decodedSignature.length === 64, 'signature has invalid length');
|
|
5216
|
-
const
|
|
5241
|
+
const confirmationCommitment = commitment || this.commitment;
|
|
5217
5242
|
let timeoutId;
|
|
5218
5243
|
let signatureSubscriptionId;
|
|
5219
5244
|
let disposeSignatureSubscriptionStateChangeObserver;
|
|
@@ -5231,7 +5256,7 @@ class Connection {
|
|
|
5231
5256
|
__type: exports.TransactionStatus.PROCESSED,
|
|
5232
5257
|
response
|
|
5233
5258
|
});
|
|
5234
|
-
},
|
|
5259
|
+
}, confirmationCommitment);
|
|
5235
5260
|
const subscriptionSetupPromise = new Promise(resolveSubscriptionSetup => {
|
|
5236
5261
|
if (signatureSubscriptionId == null) {
|
|
5237
5262
|
resolveSubscriptionSetup();
|
|
@@ -5259,11 +5284,41 @@ class Connection {
|
|
|
5259
5284
|
value
|
|
5260
5285
|
} = response;
|
|
5261
5286
|
|
|
5287
|
+
if (value == null) {
|
|
5288
|
+
return;
|
|
5289
|
+
}
|
|
5290
|
+
|
|
5262
5291
|
if (value !== null && value !== void 0 && value.err) {
|
|
5263
5292
|
reject(value.err);
|
|
5264
|
-
}
|
|
5293
|
+
} else {
|
|
5294
|
+
switch (confirmationCommitment) {
|
|
5295
|
+
case 'confirmed':
|
|
5296
|
+
case 'single':
|
|
5297
|
+
case 'singleGossip':
|
|
5298
|
+
{
|
|
5299
|
+
if (value.confirmationStatus === 'processed') {
|
|
5300
|
+
return;
|
|
5301
|
+
}
|
|
5302
|
+
|
|
5303
|
+
break;
|
|
5304
|
+
}
|
|
5305
|
+
|
|
5306
|
+
case 'finalized':
|
|
5307
|
+
case 'max':
|
|
5308
|
+
case 'root':
|
|
5309
|
+
{
|
|
5310
|
+
if (value.confirmationStatus === 'processed' || value.confirmationStatus === 'confirmed') {
|
|
5311
|
+
return;
|
|
5312
|
+
}
|
|
5313
|
+
|
|
5314
|
+
break;
|
|
5315
|
+
}
|
|
5316
|
+
// exhaust enums to ensure full coverage
|
|
5317
|
+
|
|
5318
|
+
case 'processed':
|
|
5319
|
+
case 'recent':
|
|
5320
|
+
}
|
|
5265
5321
|
|
|
5266
|
-
if (value) {
|
|
5267
5322
|
done = true;
|
|
5268
5323
|
resolve({
|
|
5269
5324
|
__type: exports.TransactionStatus.PROCESSED,
|
|
@@ -5282,7 +5337,7 @@ class Connection {
|
|
|
5282
5337
|
if (typeof strategy === 'string') {
|
|
5283
5338
|
let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
|
|
5284
5339
|
|
|
5285
|
-
switch (
|
|
5340
|
+
switch (confirmationCommitment) {
|
|
5286
5341
|
case 'processed':
|
|
5287
5342
|
case 'recent':
|
|
5288
5343
|
case 'single':
|
|
@@ -9659,10 +9714,8 @@ class ValidatorInfo {
|
|
|
9659
9714
|
const configKeys = [];
|
|
9660
9715
|
|
|
9661
9716
|
for (let i = 0; i < 2; i++) {
|
|
9662
|
-
const publicKey = new PublicKey(byteArray
|
|
9663
|
-
|
|
9664
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9665
|
-
byteArray = byteArray.slice(1);
|
|
9717
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9718
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9666
9719
|
configKeys.push({
|
|
9667
9720
|
publicKey,
|
|
9668
9721
|
isSigner
|