@solana/web3.js 1.59.0 → 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 +66 -49
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +66 -49
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +66 -49
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.esm.js +66 -49
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +66 -49
- 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 +66 -49
- 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/message.ts +15 -24
- 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.cjs.js
CHANGED
|
@@ -770,6 +770,36 @@ class CompiledKeys {
|
|
|
770
770
|
|
|
771
771
|
}
|
|
772
772
|
|
|
773
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
774
|
+
/**
|
|
775
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
776
|
+
*/
|
|
777
|
+
|
|
778
|
+
function guardedShift(byteArray) {
|
|
779
|
+
if (byteArray.length === 0) {
|
|
780
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
return byteArray.shift();
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
787
|
+
* the array.
|
|
788
|
+
*/
|
|
789
|
+
|
|
790
|
+
function guardedSplice(byteArray, ...args) {
|
|
791
|
+
var _args$;
|
|
792
|
+
|
|
793
|
+
const [start] = args;
|
|
794
|
+
|
|
795
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
796
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
797
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
return byteArray.splice(...args);
|
|
801
|
+
}
|
|
802
|
+
|
|
773
803
|
/**
|
|
774
804
|
* An instruction to execute by a program
|
|
775
805
|
*
|
|
@@ -911,37 +941,33 @@ class Message {
|
|
|
911
941
|
static from(buffer$1) {
|
|
912
942
|
// Slice up wire data
|
|
913
943
|
let byteArray = [...buffer$1];
|
|
914
|
-
const numRequiredSignatures = byteArray
|
|
944
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
915
945
|
|
|
916
946
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
917
947
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
918
948
|
}
|
|
919
949
|
|
|
920
|
-
const numReadonlySignedAccounts = byteArray
|
|
921
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
950
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
951
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
922
952
|
const accountCount = decodeLength(byteArray);
|
|
923
953
|
let accountKeys = [];
|
|
924
954
|
|
|
925
955
|
for (let i = 0; i < accountCount; i++) {
|
|
926
|
-
const account = byteArray
|
|
927
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
956
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
928
957
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
929
958
|
}
|
|
930
959
|
|
|
931
|
-
const recentBlockhash = byteArray
|
|
932
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
960
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
933
961
|
const instructionCount = decodeLength(byteArray);
|
|
934
962
|
let instructions = [];
|
|
935
963
|
|
|
936
964
|
for (let i = 0; i < instructionCount; i++) {
|
|
937
|
-
const programIdIndex = byteArray
|
|
965
|
+
const programIdIndex = guardedShift(byteArray);
|
|
938
966
|
const accountCount = decodeLength(byteArray);
|
|
939
|
-
const accounts = byteArray
|
|
940
|
-
byteArray = byteArray.slice(accountCount);
|
|
967
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
941
968
|
const dataLength = decodeLength(byteArray);
|
|
942
|
-
const dataSlice = byteArray
|
|
969
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
943
970
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
944
|
-
byteArray = byteArray.slice(dataLength);
|
|
945
971
|
instructions.push({
|
|
946
972
|
programIdIndex,
|
|
947
973
|
accounts,
|
|
@@ -1154,33 +1180,33 @@ class MessageV0 {
|
|
|
1154
1180
|
|
|
1155
1181
|
static deserialize(serializedMessage) {
|
|
1156
1182
|
let byteArray = [...serializedMessage];
|
|
1157
|
-
const prefix = byteArray
|
|
1183
|
+
const prefix = guardedShift(byteArray);
|
|
1158
1184
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1159
1185
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1160
1186
|
const version = maskedPrefix;
|
|
1161
1187
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1162
1188
|
const header = {
|
|
1163
|
-
numRequiredSignatures: byteArray
|
|
1164
|
-
numReadonlySignedAccounts: byteArray
|
|
1165
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1189
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1190
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1191
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1166
1192
|
};
|
|
1167
1193
|
const staticAccountKeys = [];
|
|
1168
1194
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1169
1195
|
|
|
1170
1196
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1171
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1197
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1172
1198
|
}
|
|
1173
1199
|
|
|
1174
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
1200
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1175
1201
|
const instructionCount = decodeLength(byteArray);
|
|
1176
1202
|
const compiledInstructions = [];
|
|
1177
1203
|
|
|
1178
1204
|
for (let i = 0; i < instructionCount; i++) {
|
|
1179
|
-
const programIdIndex = byteArray
|
|
1205
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1180
1206
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1181
|
-
const accountKeyIndexes = byteArray
|
|
1207
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1182
1208
|
const dataLength = decodeLength(byteArray);
|
|
1183
|
-
const data = new Uint8Array(byteArray
|
|
1209
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1184
1210
|
compiledInstructions.push({
|
|
1185
1211
|
programIdIndex,
|
|
1186
1212
|
accountKeyIndexes,
|
|
@@ -1192,11 +1218,11 @@ class MessageV0 {
|
|
|
1192
1218
|
const addressTableLookups = [];
|
|
1193
1219
|
|
|
1194
1220
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1195
|
-
const accountKey = new PublicKey(byteArray
|
|
1221
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1196
1222
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1197
|
-
const writableIndexes = byteArray
|
|
1223
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1198
1224
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1199
|
-
const readonlyIndexes = byteArray
|
|
1225
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1200
1226
|
addressTableLookups.push({
|
|
1201
1227
|
accountKey,
|
|
1202
1228
|
writableIndexes,
|
|
@@ -1927,8 +1953,7 @@ class Transaction {
|
|
|
1927
1953
|
let signatures = [];
|
|
1928
1954
|
|
|
1929
1955
|
for (let i = 0; i < signatureCount; i++) {
|
|
1930
|
-
const signature = byteArray
|
|
1931
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1956
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1932
1957
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1933
1958
|
}
|
|
1934
1959
|
|
|
@@ -1978,10 +2003,10 @@ class Transaction {
|
|
|
1978
2003
|
|
|
1979
2004
|
class TransactionMessage {
|
|
1980
2005
|
constructor(args) {
|
|
1981
|
-
this.
|
|
2006
|
+
this.payerKey = void 0;
|
|
1982
2007
|
this.instructions = void 0;
|
|
1983
2008
|
this.recentBlockhash = void 0;
|
|
1984
|
-
this.
|
|
2009
|
+
this.payerKey = args.payerKey;
|
|
1985
2010
|
this.instructions = args.instructions;
|
|
1986
2011
|
this.recentBlockhash = args.recentBlockhash;
|
|
1987
2012
|
}
|
|
@@ -2002,6 +2027,12 @@ class TransactionMessage {
|
|
|
2002
2027
|
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
2003
2028
|
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
2004
2029
|
const accountKeys = message.getAccountKeys(args);
|
|
2030
|
+
const payerKey = accountKeys.get(0);
|
|
2031
|
+
|
|
2032
|
+
if (payerKey === undefined) {
|
|
2033
|
+
throw new Error('Failed to decompile message because no account keys were found');
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2005
2036
|
const instructions = [];
|
|
2006
2037
|
|
|
2007
2038
|
for (const compiledIx of compiledInstructions) {
|
|
@@ -2047,35 +2078,23 @@ class TransactionMessage {
|
|
|
2047
2078
|
}
|
|
2048
2079
|
|
|
2049
2080
|
return new TransactionMessage({
|
|
2050
|
-
|
|
2081
|
+
payerKey,
|
|
2051
2082
|
instructions,
|
|
2052
2083
|
recentBlockhash
|
|
2053
2084
|
});
|
|
2054
2085
|
}
|
|
2055
2086
|
|
|
2056
2087
|
compileToLegacyMessage() {
|
|
2057
|
-
const payerKey = this.accountKeys.get(0);
|
|
2058
|
-
|
|
2059
|
-
if (payerKey === undefined) {
|
|
2060
|
-
throw new Error('Failed to compile message because no account keys were found');
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
2088
|
return Message.compile({
|
|
2064
|
-
payerKey,
|
|
2089
|
+
payerKey: this.payerKey,
|
|
2065
2090
|
recentBlockhash: this.recentBlockhash,
|
|
2066
2091
|
instructions: this.instructions
|
|
2067
2092
|
});
|
|
2068
2093
|
}
|
|
2069
2094
|
|
|
2070
2095
|
compileToV0Message(addressLookupTableAccounts) {
|
|
2071
|
-
const payerKey = this.accountKeys.get(0);
|
|
2072
|
-
|
|
2073
|
-
if (payerKey === undefined) {
|
|
2074
|
-
throw new Error('Failed to compile message because no account keys were found');
|
|
2075
|
-
}
|
|
2076
|
-
|
|
2077
2096
|
return MessageV0.compile({
|
|
2078
|
-
payerKey,
|
|
2097
|
+
payerKey: this.payerKey,
|
|
2079
2098
|
recentBlockhash: this.recentBlockhash,
|
|
2080
2099
|
instructions: this.instructions,
|
|
2081
2100
|
addressLookupTableAccounts
|
|
@@ -2128,7 +2147,7 @@ class VersionedTransaction {
|
|
|
2128
2147
|
const signaturesLength = decodeLength(byteArray);
|
|
2129
2148
|
|
|
2130
2149
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2131
|
-
signatures.push(new Uint8Array(byteArray
|
|
2150
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2132
2151
|
}
|
|
2133
2152
|
|
|
2134
2153
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4587,7 +4606,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4587
4606
|
|
|
4588
4607
|
/** @internal */
|
|
4589
4608
|
const COMMON_HTTP_HEADERS = {
|
|
4590
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4609
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.59.2") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4591
4610
|
};
|
|
4592
4611
|
/**
|
|
4593
4612
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9501,10 +9520,8 @@ class ValidatorInfo {
|
|
|
9501
9520
|
const configKeys = [];
|
|
9502
9521
|
|
|
9503
9522
|
for (let i = 0; i < 2; i++) {
|
|
9504
|
-
const publicKey = new PublicKey(byteArray
|
|
9505
|
-
|
|
9506
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9507
|
-
byteArray = byteArray.slice(1);
|
|
9523
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9524
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9508
9525
|
configKeys.push({
|
|
9509
9526
|
publicKey,
|
|
9510
9527
|
isSigner
|