@solana/web3.js 1.58.0 → 1.58.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.esm.js
CHANGED
|
@@ -723,6 +723,36 @@ class CompiledKeys {
|
|
|
723
723
|
|
|
724
724
|
}
|
|
725
725
|
|
|
726
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
727
|
+
/**
|
|
728
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
729
|
+
*/
|
|
730
|
+
|
|
731
|
+
function guardedShift(byteArray) {
|
|
732
|
+
if (byteArray.length === 0) {
|
|
733
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
return byteArray.shift();
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
740
|
+
* the array.
|
|
741
|
+
*/
|
|
742
|
+
|
|
743
|
+
function guardedSplice(byteArray, ...args) {
|
|
744
|
+
var _args$;
|
|
745
|
+
|
|
746
|
+
const [start] = args;
|
|
747
|
+
|
|
748
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
749
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
750
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
return byteArray.splice(...args);
|
|
754
|
+
}
|
|
755
|
+
|
|
726
756
|
/**
|
|
727
757
|
* An instruction to execute by a program
|
|
728
758
|
*
|
|
@@ -864,37 +894,33 @@ class Message {
|
|
|
864
894
|
static from(buffer) {
|
|
865
895
|
// Slice up wire data
|
|
866
896
|
let byteArray = [...buffer];
|
|
867
|
-
const numRequiredSignatures = byteArray
|
|
897
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
868
898
|
|
|
869
899
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
870
900
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
871
901
|
}
|
|
872
902
|
|
|
873
|
-
const numReadonlySignedAccounts = byteArray
|
|
874
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
903
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
904
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
875
905
|
const accountCount = decodeLength(byteArray);
|
|
876
906
|
let accountKeys = [];
|
|
877
907
|
|
|
878
908
|
for (let i = 0; i < accountCount; i++) {
|
|
879
|
-
const account = byteArray
|
|
880
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
909
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
881
910
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
882
911
|
}
|
|
883
912
|
|
|
884
|
-
const recentBlockhash = byteArray
|
|
885
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
913
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
886
914
|
const instructionCount = decodeLength(byteArray);
|
|
887
915
|
let instructions = [];
|
|
888
916
|
|
|
889
917
|
for (let i = 0; i < instructionCount; i++) {
|
|
890
|
-
const programIdIndex = byteArray
|
|
918
|
+
const programIdIndex = guardedShift(byteArray);
|
|
891
919
|
const accountCount = decodeLength(byteArray);
|
|
892
|
-
const accounts = byteArray
|
|
893
|
-
byteArray = byteArray.slice(accountCount);
|
|
920
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
894
921
|
const dataLength = decodeLength(byteArray);
|
|
895
|
-
const dataSlice = byteArray
|
|
922
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
896
923
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
897
|
-
byteArray = byteArray.slice(dataLength);
|
|
898
924
|
instructions.push({
|
|
899
925
|
programIdIndex,
|
|
900
926
|
accounts,
|
|
@@ -1107,33 +1133,33 @@ class MessageV0 {
|
|
|
1107
1133
|
|
|
1108
1134
|
static deserialize(serializedMessage) {
|
|
1109
1135
|
let byteArray = [...serializedMessage];
|
|
1110
|
-
const prefix = byteArray
|
|
1136
|
+
const prefix = guardedShift(byteArray);
|
|
1111
1137
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1112
1138
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1113
1139
|
const version = maskedPrefix;
|
|
1114
1140
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1115
1141
|
const header = {
|
|
1116
|
-
numRequiredSignatures: byteArray
|
|
1117
|
-
numReadonlySignedAccounts: byteArray
|
|
1118
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1142
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1143
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1144
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1119
1145
|
};
|
|
1120
1146
|
const staticAccountKeys = [];
|
|
1121
1147
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1122
1148
|
|
|
1123
1149
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1124
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1150
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1125
1151
|
}
|
|
1126
1152
|
|
|
1127
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1153
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1128
1154
|
const instructionCount = decodeLength(byteArray);
|
|
1129
1155
|
const compiledInstructions = [];
|
|
1130
1156
|
|
|
1131
1157
|
for (let i = 0; i < instructionCount; i++) {
|
|
1132
|
-
const programIdIndex = byteArray
|
|
1158
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1133
1159
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1134
|
-
const accountKeyIndexes = byteArray
|
|
1160
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1135
1161
|
const dataLength = decodeLength(byteArray);
|
|
1136
|
-
const data = new Uint8Array(byteArray
|
|
1162
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1137
1163
|
compiledInstructions.push({
|
|
1138
1164
|
programIdIndex,
|
|
1139
1165
|
accountKeyIndexes,
|
|
@@ -1145,11 +1171,11 @@ class MessageV0 {
|
|
|
1145
1171
|
const addressTableLookups = [];
|
|
1146
1172
|
|
|
1147
1173
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1148
|
-
const accountKey = new PublicKey(byteArray
|
|
1174
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1149
1175
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1150
|
-
const writableIndexes = byteArray
|
|
1176
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1151
1177
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1152
|
-
const readonlyIndexes = byteArray
|
|
1178
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1153
1179
|
addressTableLookups.push({
|
|
1154
1180
|
accountKey,
|
|
1155
1181
|
writableIndexes,
|
|
@@ -1880,8 +1906,7 @@ class Transaction {
|
|
|
1880
1906
|
let signatures = [];
|
|
1881
1907
|
|
|
1882
1908
|
for (let i = 0; i < signatureCount; i++) {
|
|
1883
|
-
const signature = byteArray
|
|
1884
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1909
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1885
1910
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1886
1911
|
}
|
|
1887
1912
|
|
|
@@ -2081,7 +2106,7 @@ class VersionedTransaction {
|
|
|
2081
2106
|
const signaturesLength = decodeLength(byteArray);
|
|
2082
2107
|
|
|
2083
2108
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2084
|
-
signatures.push(new Uint8Array(byteArray
|
|
2109
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2085
2110
|
}
|
|
2086
2111
|
|
|
2087
2112
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4480,7 +4505,7 @@ const LogsNotificationResult = type({
|
|
|
4480
4505
|
|
|
4481
4506
|
/** @internal */
|
|
4482
4507
|
const COMMON_HTTP_HEADERS = {
|
|
4483
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4508
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.58.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4484
4509
|
};
|
|
4485
4510
|
/**
|
|
4486
4511
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9320,10 +9345,8 @@ class ValidatorInfo {
|
|
|
9320
9345
|
const configKeys = [];
|
|
9321
9346
|
|
|
9322
9347
|
for (let i = 0; i < 2; i++) {
|
|
9323
|
-
const publicKey = new PublicKey(byteArray
|
|
9324
|
-
|
|
9325
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9326
|
-
byteArray = byteArray.slice(1);
|
|
9348
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9349
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9327
9350
|
configKeys.push({
|
|
9328
9351
|
publicKey,
|
|
9329
9352
|
isSigner
|