@solana/web3.js 1.31.0 → 1.31.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.esm.js +45 -18
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +45 -18
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +45 -18
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +45 -18
- 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/package.json +27 -27
- package/src/message.ts +9 -12
- package/src/transaction.ts +2 -2
- package/src/util/guarded-array-utils.ts +37 -0
- package/src/validator-info.ts +5 -4
package/lib/index.browser.esm.js
CHANGED
|
@@ -2109,6 +2109,36 @@ function encodeLength(bytes, len) {
|
|
|
2109
2109
|
}
|
|
2110
2110
|
}
|
|
2111
2111
|
|
|
2112
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2113
|
+
/**
|
|
2114
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2115
|
+
*/
|
|
2116
|
+
|
|
2117
|
+
function guardedShift(byteArray) {
|
|
2118
|
+
if (byteArray.length === 0) {
|
|
2119
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2122
|
+
return byteArray.shift();
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2126
|
+
* the array.
|
|
2127
|
+
*/
|
|
2128
|
+
|
|
2129
|
+
function guardedSplice(byteArray, ...args) {
|
|
2130
|
+
var _args$;
|
|
2131
|
+
|
|
2132
|
+
const [start] = args;
|
|
2133
|
+
|
|
2134
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2135
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2136
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
return byteArray.splice(...args);
|
|
2140
|
+
}
|
|
2141
|
+
|
|
2112
2142
|
/**
|
|
2113
2143
|
* The message header, identifying signed and read-only account
|
|
2114
2144
|
*/
|
|
@@ -2207,32 +2237,28 @@ class Message {
|
|
|
2207
2237
|
static from(buffer) {
|
|
2208
2238
|
// Slice up wire data
|
|
2209
2239
|
let byteArray = [...buffer];
|
|
2210
|
-
const numRequiredSignatures = byteArray
|
|
2211
|
-
const numReadonlySignedAccounts = byteArray
|
|
2212
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2240
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2241
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2242
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2213
2243
|
const accountCount = decodeLength(byteArray);
|
|
2214
2244
|
let accountKeys = [];
|
|
2215
2245
|
|
|
2216
2246
|
for (let i = 0; i < accountCount; i++) {
|
|
2217
|
-
const account = byteArray
|
|
2218
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2247
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2219
2248
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
2220
2249
|
}
|
|
2221
2250
|
|
|
2222
|
-
const recentBlockhash = byteArray
|
|
2223
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2251
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2224
2252
|
const instructionCount = decodeLength(byteArray);
|
|
2225
2253
|
let instructions = [];
|
|
2226
2254
|
|
|
2227
2255
|
for (let i = 0; i < instructionCount; i++) {
|
|
2228
|
-
const programIdIndex = byteArray
|
|
2256
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2229
2257
|
const accountCount = decodeLength(byteArray);
|
|
2230
|
-
const accounts = byteArray
|
|
2231
|
-
byteArray = byteArray.slice(accountCount);
|
|
2258
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2232
2259
|
const dataLength = decodeLength(byteArray);
|
|
2233
|
-
const dataSlice = byteArray
|
|
2260
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2234
2261
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
2235
|
-
byteArray = byteArray.slice(dataLength);
|
|
2236
2262
|
instructions.push({
|
|
2237
2263
|
programIdIndex,
|
|
2238
2264
|
accounts,
|
|
@@ -2261,6 +2287,10 @@ function assert (condition, message) {
|
|
|
2261
2287
|
}
|
|
2262
2288
|
}
|
|
2263
2289
|
|
|
2290
|
+
/**
|
|
2291
|
+
* Transaction signature as base-58 encoded string
|
|
2292
|
+
*/
|
|
2293
|
+
|
|
2264
2294
|
/**
|
|
2265
2295
|
* Default (empty) signature
|
|
2266
2296
|
*
|
|
@@ -2846,8 +2876,7 @@ class Transaction {
|
|
|
2846
2876
|
let signatures = [];
|
|
2847
2877
|
|
|
2848
2878
|
for (let i = 0; i < signatureCount; i++) {
|
|
2849
|
-
const signature = byteArray
|
|
2850
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2879
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
2851
2880
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2852
2881
|
}
|
|
2853
2882
|
|
|
@@ -8863,10 +8892,8 @@ class ValidatorInfo {
|
|
|
8863
8892
|
const configKeys = [];
|
|
8864
8893
|
|
|
8865
8894
|
for (let i = 0; i < 2; i++) {
|
|
8866
|
-
const publicKey = new PublicKey(byteArray
|
|
8867
|
-
|
|
8868
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8869
|
-
byteArray = byteArray.slice(1);
|
|
8895
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
8896
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8870
8897
|
configKeys.push({
|
|
8871
8898
|
publicKey,
|
|
8872
8899
|
isSigner
|