@solana/web3.js 1.59.1 → 1.59.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.esm.js
CHANGED
|
@@ -734,6 +734,36 @@ class CompiledKeys {
|
|
|
734
734
|
|
|
735
735
|
}
|
|
736
736
|
|
|
737
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
738
|
+
/**
|
|
739
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
740
|
+
*/
|
|
741
|
+
|
|
742
|
+
function guardedShift(byteArray) {
|
|
743
|
+
if (byteArray.length === 0) {
|
|
744
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
return byteArray.shift();
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
751
|
+
* the array.
|
|
752
|
+
*/
|
|
753
|
+
|
|
754
|
+
function guardedSplice(byteArray, ...args) {
|
|
755
|
+
var _args$;
|
|
756
|
+
|
|
757
|
+
const [start] = args;
|
|
758
|
+
|
|
759
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
760
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
761
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
return byteArray.splice(...args);
|
|
765
|
+
}
|
|
766
|
+
|
|
737
767
|
/**
|
|
738
768
|
* An instruction to execute by a program
|
|
739
769
|
*
|
|
@@ -875,37 +905,33 @@ class Message {
|
|
|
875
905
|
static from(buffer) {
|
|
876
906
|
// Slice up wire data
|
|
877
907
|
let byteArray = [...buffer];
|
|
878
|
-
const numRequiredSignatures = byteArray
|
|
908
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
879
909
|
|
|
880
910
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
881
911
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
882
912
|
}
|
|
883
913
|
|
|
884
|
-
const numReadonlySignedAccounts = byteArray
|
|
885
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
914
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
915
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
886
916
|
const accountCount = decodeLength(byteArray);
|
|
887
917
|
let accountKeys = [];
|
|
888
918
|
|
|
889
919
|
for (let i = 0; i < accountCount; i++) {
|
|
890
|
-
const account = byteArray
|
|
891
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
920
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
892
921
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
893
922
|
}
|
|
894
923
|
|
|
895
|
-
const recentBlockhash = byteArray
|
|
896
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
924
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
897
925
|
const instructionCount = decodeLength(byteArray);
|
|
898
926
|
let instructions = [];
|
|
899
927
|
|
|
900
928
|
for (let i = 0; i < instructionCount; i++) {
|
|
901
|
-
const programIdIndex = byteArray
|
|
929
|
+
const programIdIndex = guardedShift(byteArray);
|
|
902
930
|
const accountCount = decodeLength(byteArray);
|
|
903
|
-
const accounts = byteArray
|
|
904
|
-
byteArray = byteArray.slice(accountCount);
|
|
931
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
905
932
|
const dataLength = decodeLength(byteArray);
|
|
906
|
-
const dataSlice = byteArray
|
|
933
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
907
934
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
908
|
-
byteArray = byteArray.slice(dataLength);
|
|
909
935
|
instructions.push({
|
|
910
936
|
programIdIndex,
|
|
911
937
|
accounts,
|
|
@@ -1118,33 +1144,33 @@ class MessageV0 {
|
|
|
1118
1144
|
|
|
1119
1145
|
static deserialize(serializedMessage) {
|
|
1120
1146
|
let byteArray = [...serializedMessage];
|
|
1121
|
-
const prefix = byteArray
|
|
1147
|
+
const prefix = guardedShift(byteArray);
|
|
1122
1148
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1123
1149
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1124
1150
|
const version = maskedPrefix;
|
|
1125
1151
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1126
1152
|
const header = {
|
|
1127
|
-
numRequiredSignatures: byteArray
|
|
1128
|
-
numReadonlySignedAccounts: byteArray
|
|
1129
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1153
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1154
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1155
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1130
1156
|
};
|
|
1131
1157
|
const staticAccountKeys = [];
|
|
1132
1158
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1133
1159
|
|
|
1134
1160
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1135
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1161
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1136
1162
|
}
|
|
1137
1163
|
|
|
1138
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1164
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1139
1165
|
const instructionCount = decodeLength(byteArray);
|
|
1140
1166
|
const compiledInstructions = [];
|
|
1141
1167
|
|
|
1142
1168
|
for (let i = 0; i < instructionCount; i++) {
|
|
1143
|
-
const programIdIndex = byteArray
|
|
1169
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1144
1170
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1145
|
-
const accountKeyIndexes = byteArray
|
|
1171
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1146
1172
|
const dataLength = decodeLength(byteArray);
|
|
1147
|
-
const data = new Uint8Array(byteArray
|
|
1173
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1148
1174
|
compiledInstructions.push({
|
|
1149
1175
|
programIdIndex,
|
|
1150
1176
|
accountKeyIndexes,
|
|
@@ -1156,11 +1182,11 @@ class MessageV0 {
|
|
|
1156
1182
|
const addressTableLookups = [];
|
|
1157
1183
|
|
|
1158
1184
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1159
|
-
const accountKey = new PublicKey(byteArray
|
|
1185
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1160
1186
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1161
|
-
const writableIndexes = byteArray
|
|
1187
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1162
1188
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1163
|
-
const readonlyIndexes = byteArray
|
|
1189
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1164
1190
|
addressTableLookups.push({
|
|
1165
1191
|
accountKey,
|
|
1166
1192
|
writableIndexes,
|
|
@@ -1891,8 +1917,7 @@ class Transaction {
|
|
|
1891
1917
|
let signatures = [];
|
|
1892
1918
|
|
|
1893
1919
|
for (let i = 0; i < signatureCount; i++) {
|
|
1894
|
-
const signature = byteArray
|
|
1895
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1920
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1896
1921
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1897
1922
|
}
|
|
1898
1923
|
|
|
@@ -2086,7 +2111,7 @@ class VersionedTransaction {
|
|
|
2086
2111
|
const signaturesLength = decodeLength(byteArray);
|
|
2087
2112
|
|
|
2088
2113
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2089
|
-
signatures.push(new Uint8Array(byteArray
|
|
2114
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2090
2115
|
}
|
|
2091
2116
|
|
|
2092
2117
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4485,7 +4510,7 @@ const LogsNotificationResult = type({
|
|
|
4485
4510
|
|
|
4486
4511
|
/** @internal */
|
|
4487
4512
|
const COMMON_HTTP_HEADERS = {
|
|
4488
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4513
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.59.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4489
4514
|
};
|
|
4490
4515
|
/**
|
|
4491
4516
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9399,10 +9424,8 @@ class ValidatorInfo {
|
|
|
9399
9424
|
const configKeys = [];
|
|
9400
9425
|
|
|
9401
9426
|
for (let i = 0; i < 2; i++) {
|
|
9402
|
-
const publicKey = new PublicKey(byteArray
|
|
9403
|
-
|
|
9404
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9405
|
-
byteArray = byteArray.slice(1);
|
|
9427
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9428
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9406
9429
|
configKeys.push({
|
|
9407
9430
|
publicKey,
|
|
9408
9431
|
isSigner
|