@solana/web3.js 1.89.0 → 1.89.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 +51 -33
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +51 -33
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +51 -33
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.esm.js +51 -33
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +51 -33
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +51 -33
- package/lib/index.native.js.map +1 -1
- package/package.json +21 -21
- package/src/connection.ts +3 -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.cjs.js
CHANGED
|
@@ -700,6 +700,31 @@ class CompiledKeys {
|
|
|
700
700
|
}
|
|
701
701
|
}
|
|
702
702
|
|
|
703
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
707
|
+
*/
|
|
708
|
+
function guardedShift(byteArray) {
|
|
709
|
+
if (byteArray.length === 0) {
|
|
710
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
711
|
+
}
|
|
712
|
+
return byteArray.shift();
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
717
|
+
* the array.
|
|
718
|
+
*/
|
|
719
|
+
function guardedSplice(byteArray, ...args) {
|
|
720
|
+
const [start] = args;
|
|
721
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
722
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
723
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
724
|
+
}
|
|
725
|
+
return byteArray.splice(...args);
|
|
726
|
+
}
|
|
727
|
+
|
|
703
728
|
/**
|
|
704
729
|
* An instruction to execute by a program
|
|
705
730
|
*
|
|
@@ -841,32 +866,28 @@ class Message {
|
|
|
841
866
|
static from(buffer$1) {
|
|
842
867
|
// Slice up wire data
|
|
843
868
|
let byteArray = [...buffer$1];
|
|
844
|
-
const numRequiredSignatures = byteArray
|
|
869
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
845
870
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
846
871
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
847
872
|
}
|
|
848
|
-
const numReadonlySignedAccounts = byteArray
|
|
849
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
873
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
874
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
850
875
|
const accountCount = decodeLength(byteArray);
|
|
851
876
|
let accountKeys = [];
|
|
852
877
|
for (let i = 0; i < accountCount; i++) {
|
|
853
|
-
const account = byteArray
|
|
854
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
878
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
855
879
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
856
880
|
}
|
|
857
|
-
const recentBlockhash = byteArray
|
|
858
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
881
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
859
882
|
const instructionCount = decodeLength(byteArray);
|
|
860
883
|
let instructions = [];
|
|
861
884
|
for (let i = 0; i < instructionCount; i++) {
|
|
862
|
-
const programIdIndex = byteArray
|
|
885
|
+
const programIdIndex = guardedShift(byteArray);
|
|
863
886
|
const accountCount = decodeLength(byteArray);
|
|
864
|
-
const accounts = byteArray
|
|
865
|
-
byteArray = byteArray.slice(accountCount);
|
|
887
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
866
888
|
const dataLength = decodeLength(byteArray);
|
|
867
|
-
const dataSlice = byteArray
|
|
889
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
868
890
|
const data = bs58__default.default.encode(buffer.Buffer.from(dataSlice));
|
|
869
|
-
byteArray = byteArray.slice(dataLength);
|
|
870
891
|
instructions.push({
|
|
871
892
|
programIdIndex,
|
|
872
893
|
accounts,
|
|
@@ -1071,30 +1092,30 @@ class MessageV0 {
|
|
|
1071
1092
|
}
|
|
1072
1093
|
static deserialize(serializedMessage) {
|
|
1073
1094
|
let byteArray = [...serializedMessage];
|
|
1074
|
-
const prefix = byteArray
|
|
1095
|
+
const prefix = guardedShift(byteArray);
|
|
1075
1096
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1076
1097
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1077
1098
|
const version = maskedPrefix;
|
|
1078
1099
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1079
1100
|
const header = {
|
|
1080
|
-
numRequiredSignatures: byteArray
|
|
1081
|
-
numReadonlySignedAccounts: byteArray
|
|
1082
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1101
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1102
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1103
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1083
1104
|
};
|
|
1084
1105
|
const staticAccountKeys = [];
|
|
1085
1106
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1086
1107
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1087
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1108
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1088
1109
|
}
|
|
1089
|
-
const recentBlockhash = bs58__default.default.encode(byteArray
|
|
1110
|
+
const recentBlockhash = bs58__default.default.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1090
1111
|
const instructionCount = decodeLength(byteArray);
|
|
1091
1112
|
const compiledInstructions = [];
|
|
1092
1113
|
for (let i = 0; i < instructionCount; i++) {
|
|
1093
|
-
const programIdIndex = byteArray
|
|
1114
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1094
1115
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1095
|
-
const accountKeyIndexes = byteArray
|
|
1116
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1096
1117
|
const dataLength = decodeLength(byteArray);
|
|
1097
|
-
const data = new Uint8Array(byteArray
|
|
1118
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1098
1119
|
compiledInstructions.push({
|
|
1099
1120
|
programIdIndex,
|
|
1100
1121
|
accountKeyIndexes,
|
|
@@ -1104,11 +1125,11 @@ class MessageV0 {
|
|
|
1104
1125
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1105
1126
|
const addressTableLookups = [];
|
|
1106
1127
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1107
|
-
const accountKey = new PublicKey(byteArray
|
|
1128
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1108
1129
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1109
|
-
const writableIndexes = byteArray
|
|
1130
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1110
1131
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1111
|
-
const readonlyIndexes = byteArray
|
|
1132
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1112
1133
|
addressTableLookups.push({
|
|
1113
1134
|
accountKey,
|
|
1114
1135
|
writableIndexes,
|
|
@@ -1899,8 +1920,7 @@ class Transaction {
|
|
|
1899
1920
|
const signatureCount = decodeLength(byteArray);
|
|
1900
1921
|
let signatures = [];
|
|
1901
1922
|
for (let i = 0; i < signatureCount; i++) {
|
|
1902
|
-
const signature = byteArray
|
|
1903
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1923
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1904
1924
|
signatures.push(bs58__default.default.encode(buffer.Buffer.from(signature)));
|
|
1905
1925
|
}
|
|
1906
1926
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -2075,7 +2095,7 @@ class VersionedTransaction {
|
|
|
2075
2095
|
const signatures = [];
|
|
2076
2096
|
const signaturesLength = decodeLength(byteArray);
|
|
2077
2097
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2078
|
-
signatures.push(new Uint8Array(byteArray
|
|
2098
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2079
2099
|
}
|
|
2080
2100
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
2081
2101
|
return new VersionedTransaction(message, signatures);
|
|
@@ -4213,7 +4233,7 @@ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disable
|
|
|
4213
4233
|
if (too_many_requests_retries === 0) {
|
|
4214
4234
|
break;
|
|
4215
4235
|
}
|
|
4216
|
-
console.
|
|
4236
|
+
console.error(`Server responded with ${res.status} ${res.statusText}. Retrying after ${waitTime}ms delay...`);
|
|
4217
4237
|
await sleep(waitTime);
|
|
4218
4238
|
waitTime *= 2;
|
|
4219
4239
|
}
|
|
@@ -5121,7 +5141,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
5121
5141
|
|
|
5122
5142
|
/** @internal */
|
|
5123
5143
|
const COMMON_HTTP_HEADERS = {
|
|
5124
|
-
'solana-client': `js/${"
|
|
5144
|
+
'solana-client': `js/${"1.89.2" }`
|
|
5125
5145
|
};
|
|
5126
5146
|
|
|
5127
5147
|
/**
|
|
@@ -10070,10 +10090,8 @@ class ValidatorInfo {
|
|
|
10070
10090
|
if (configKeyCount !== 2) return null;
|
|
10071
10091
|
const configKeys = [];
|
|
10072
10092
|
for (let i = 0; i < 2; i++) {
|
|
10073
|
-
const publicKey = new PublicKey(byteArray
|
|
10074
|
-
|
|
10075
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
10076
|
-
byteArray = byteArray.slice(1);
|
|
10093
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
10094
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
10077
10095
|
configKeys.push({
|
|
10078
10096
|
publicKey,
|
|
10079
10097
|
isSigner
|