@solana/web3.js 1.38.0 → 1.38.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 +45 -18
- package/lib/index.browser.cjs.js.map +1 -1
- 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 +22 -22
- 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
|
@@ -2160,6 +2160,36 @@ function encodeLength(bytes, len) {
|
|
|
2160
2160
|
}
|
|
2161
2161
|
}
|
|
2162
2162
|
|
|
2163
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2164
|
+
/**
|
|
2165
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2166
|
+
*/
|
|
2167
|
+
|
|
2168
|
+
function guardedShift(byteArray) {
|
|
2169
|
+
if (byteArray.length === 0) {
|
|
2170
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
return byteArray.shift();
|
|
2174
|
+
}
|
|
2175
|
+
/**
|
|
2176
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2177
|
+
* the array.
|
|
2178
|
+
*/
|
|
2179
|
+
|
|
2180
|
+
function guardedSplice(byteArray, ...args) {
|
|
2181
|
+
var _args$;
|
|
2182
|
+
|
|
2183
|
+
const [start] = args;
|
|
2184
|
+
|
|
2185
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2186
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2187
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
return byteArray.splice(...args);
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2163
2193
|
/**
|
|
2164
2194
|
* The message header, identifying signed and read-only account
|
|
2165
2195
|
*/
|
|
@@ -2258,32 +2288,28 @@ class Message {
|
|
|
2258
2288
|
static from(buffer) {
|
|
2259
2289
|
// Slice up wire data
|
|
2260
2290
|
let byteArray = [...buffer];
|
|
2261
|
-
const numRequiredSignatures = byteArray
|
|
2262
|
-
const numReadonlySignedAccounts = byteArray
|
|
2263
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2291
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2292
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2293
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2264
2294
|
const accountCount = decodeLength(byteArray);
|
|
2265
2295
|
let accountKeys = [];
|
|
2266
2296
|
|
|
2267
2297
|
for (let i = 0; i < accountCount; i++) {
|
|
2268
|
-
const account = byteArray
|
|
2269
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2298
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2270
2299
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
2271
2300
|
}
|
|
2272
2301
|
|
|
2273
|
-
const recentBlockhash = byteArray
|
|
2274
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2302
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2275
2303
|
const instructionCount = decodeLength(byteArray);
|
|
2276
2304
|
let instructions = [];
|
|
2277
2305
|
|
|
2278
2306
|
for (let i = 0; i < instructionCount; i++) {
|
|
2279
|
-
const programIdIndex = byteArray
|
|
2307
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2280
2308
|
const accountCount = decodeLength(byteArray);
|
|
2281
|
-
const accounts = byteArray
|
|
2282
|
-
byteArray = byteArray.slice(accountCount);
|
|
2309
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2283
2310
|
const dataLength = decodeLength(byteArray);
|
|
2284
|
-
const dataSlice = byteArray
|
|
2311
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2285
2312
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
2286
|
-
byteArray = byteArray.slice(dataLength);
|
|
2287
2313
|
instructions.push({
|
|
2288
2314
|
programIdIndex,
|
|
2289
2315
|
accounts,
|
|
@@ -2312,6 +2338,10 @@ function assert (condition, message) {
|
|
|
2312
2338
|
}
|
|
2313
2339
|
}
|
|
2314
2340
|
|
|
2341
|
+
/**
|
|
2342
|
+
* Transaction signature as base-58 encoded string
|
|
2343
|
+
*/
|
|
2344
|
+
|
|
2315
2345
|
/**
|
|
2316
2346
|
* Default (empty) signature
|
|
2317
2347
|
*
|
|
@@ -2906,8 +2936,7 @@ class Transaction {
|
|
|
2906
2936
|
let signatures = [];
|
|
2907
2937
|
|
|
2908
2938
|
for (let i = 0; i < signatureCount; i++) {
|
|
2909
|
-
const signature = byteArray
|
|
2910
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2939
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
2911
2940
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2912
2941
|
}
|
|
2913
2942
|
|
|
@@ -9250,10 +9279,8 @@ class ValidatorInfo {
|
|
|
9250
9279
|
const configKeys = [];
|
|
9251
9280
|
|
|
9252
9281
|
for (let i = 0; i < 2; i++) {
|
|
9253
|
-
const publicKey = new PublicKey(byteArray
|
|
9254
|
-
|
|
9255
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9256
|
-
byteArray = byteArray.slice(1);
|
|
9282
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
9283
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9257
9284
|
configKeys.push({
|
|
9258
9285
|
publicKey,
|
|
9259
9286
|
isSigner
|