@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.esm.js
CHANGED
|
@@ -726,6 +726,36 @@ class CompiledKeys {
|
|
|
726
726
|
|
|
727
727
|
}
|
|
728
728
|
|
|
729
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
730
|
+
/**
|
|
731
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
732
|
+
*/
|
|
733
|
+
|
|
734
|
+
function guardedShift(byteArray) {
|
|
735
|
+
if (byteArray.length === 0) {
|
|
736
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
return byteArray.shift();
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
743
|
+
* the array.
|
|
744
|
+
*/
|
|
745
|
+
|
|
746
|
+
function guardedSplice(byteArray, ...args) {
|
|
747
|
+
var _args$;
|
|
748
|
+
|
|
749
|
+
const [start] = args;
|
|
750
|
+
|
|
751
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
752
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
753
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
return byteArray.splice(...args);
|
|
757
|
+
}
|
|
758
|
+
|
|
729
759
|
/**
|
|
730
760
|
* An instruction to execute by a program
|
|
731
761
|
*
|
|
@@ -867,37 +897,33 @@ class Message {
|
|
|
867
897
|
static from(buffer) {
|
|
868
898
|
// Slice up wire data
|
|
869
899
|
let byteArray = [...buffer];
|
|
870
|
-
const numRequiredSignatures = byteArray
|
|
900
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
871
901
|
|
|
872
902
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
873
903
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
874
904
|
}
|
|
875
905
|
|
|
876
|
-
const numReadonlySignedAccounts = byteArray
|
|
877
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
906
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
907
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
878
908
|
const accountCount = decodeLength(byteArray);
|
|
879
909
|
let accountKeys = [];
|
|
880
910
|
|
|
881
911
|
for (let i = 0; i < accountCount; i++) {
|
|
882
|
-
const account = byteArray
|
|
883
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
912
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
884
913
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
885
914
|
}
|
|
886
915
|
|
|
887
|
-
const recentBlockhash = byteArray
|
|
888
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
916
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
889
917
|
const instructionCount = decodeLength(byteArray);
|
|
890
918
|
let instructions = [];
|
|
891
919
|
|
|
892
920
|
for (let i = 0; i < instructionCount; i++) {
|
|
893
|
-
const programIdIndex = byteArray
|
|
921
|
+
const programIdIndex = guardedShift(byteArray);
|
|
894
922
|
const accountCount = decodeLength(byteArray);
|
|
895
|
-
const accounts = byteArray
|
|
896
|
-
byteArray = byteArray.slice(accountCount);
|
|
923
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
897
924
|
const dataLength = decodeLength(byteArray);
|
|
898
|
-
const dataSlice = byteArray
|
|
925
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
899
926
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
900
|
-
byteArray = byteArray.slice(dataLength);
|
|
901
927
|
instructions.push({
|
|
902
928
|
programIdIndex,
|
|
903
929
|
accounts,
|
|
@@ -1110,33 +1136,33 @@ class MessageV0 {
|
|
|
1110
1136
|
|
|
1111
1137
|
static deserialize(serializedMessage) {
|
|
1112
1138
|
let byteArray = [...serializedMessage];
|
|
1113
|
-
const prefix = byteArray
|
|
1139
|
+
const prefix = guardedShift(byteArray);
|
|
1114
1140
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1115
1141
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1116
1142
|
const version = maskedPrefix;
|
|
1117
1143
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1118
1144
|
const header = {
|
|
1119
|
-
numRequiredSignatures: byteArray
|
|
1120
|
-
numReadonlySignedAccounts: byteArray
|
|
1121
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1145
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1146
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1147
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1122
1148
|
};
|
|
1123
1149
|
const staticAccountKeys = [];
|
|
1124
1150
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1125
1151
|
|
|
1126
1152
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1127
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1153
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1128
1154
|
}
|
|
1129
1155
|
|
|
1130
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1156
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1131
1157
|
const instructionCount = decodeLength(byteArray);
|
|
1132
1158
|
const compiledInstructions = [];
|
|
1133
1159
|
|
|
1134
1160
|
for (let i = 0; i < instructionCount; i++) {
|
|
1135
|
-
const programIdIndex = byteArray
|
|
1161
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1136
1162
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1137
|
-
const accountKeyIndexes = byteArray
|
|
1163
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1138
1164
|
const dataLength = decodeLength(byteArray);
|
|
1139
|
-
const data = new Uint8Array(byteArray
|
|
1165
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1140
1166
|
compiledInstructions.push({
|
|
1141
1167
|
programIdIndex,
|
|
1142
1168
|
accountKeyIndexes,
|
|
@@ -1148,11 +1174,11 @@ class MessageV0 {
|
|
|
1148
1174
|
const addressTableLookups = [];
|
|
1149
1175
|
|
|
1150
1176
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1151
|
-
const accountKey = new PublicKey(byteArray
|
|
1177
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1152
1178
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1153
|
-
const writableIndexes = byteArray
|
|
1179
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1154
1180
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1155
|
-
const readonlyIndexes = byteArray
|
|
1181
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1156
1182
|
addressTableLookups.push({
|
|
1157
1183
|
accountKey,
|
|
1158
1184
|
writableIndexes,
|
|
@@ -1883,8 +1909,7 @@ class Transaction {
|
|
|
1883
1909
|
let signatures = [];
|
|
1884
1910
|
|
|
1885
1911
|
for (let i = 0; i < signatureCount; i++) {
|
|
1886
|
-
const signature = byteArray
|
|
1887
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1912
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1888
1913
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1889
1914
|
}
|
|
1890
1915
|
|
|
@@ -2084,7 +2109,7 @@ class VersionedTransaction {
|
|
|
2084
2109
|
const signaturesLength = decodeLength(byteArray);
|
|
2085
2110
|
|
|
2086
2111
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2087
|
-
signatures.push(new Uint8Array(byteArray
|
|
2112
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2088
2113
|
}
|
|
2089
2114
|
|
|
2090
2115
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4543,7 +4568,7 @@ const LogsNotificationResult = type({
|
|
|
4543
4568
|
|
|
4544
4569
|
/** @internal */
|
|
4545
4570
|
const COMMON_HTTP_HEADERS = {
|
|
4546
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4571
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.58.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4547
4572
|
};
|
|
4548
4573
|
/**
|
|
4549
4574
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9383,10 +9408,8 @@ class ValidatorInfo {
|
|
|
9383
9408
|
const configKeys = [];
|
|
9384
9409
|
|
|
9385
9410
|
for (let i = 0; i < 2; i++) {
|
|
9386
|
-
const publicKey = new PublicKey(byteArray
|
|
9387
|
-
|
|
9388
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9389
|
-
byteArray = byteArray.slice(1);
|
|
9411
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9412
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9390
9413
|
configKeys.push({
|
|
9391
9414
|
publicKey,
|
|
9392
9415
|
isSigner
|