@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.cjs.js
CHANGED
|
@@ -2151,6 +2151,36 @@ function encodeLength(bytes, len) {
|
|
|
2151
2151
|
}
|
|
2152
2152
|
}
|
|
2153
2153
|
|
|
2154
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2155
|
+
/**
|
|
2156
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2157
|
+
*/
|
|
2158
|
+
|
|
2159
|
+
function guardedShift(byteArray) {
|
|
2160
|
+
if (byteArray.length === 0) {
|
|
2161
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
return byteArray.shift();
|
|
2165
|
+
}
|
|
2166
|
+
/**
|
|
2167
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2168
|
+
* the array.
|
|
2169
|
+
*/
|
|
2170
|
+
|
|
2171
|
+
function guardedSplice(byteArray, ...args) {
|
|
2172
|
+
var _args$;
|
|
2173
|
+
|
|
2174
|
+
const [start] = args;
|
|
2175
|
+
|
|
2176
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2177
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2178
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
return byteArray.splice(...args);
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2154
2184
|
/**
|
|
2155
2185
|
* The message header, identifying signed and read-only account
|
|
2156
2186
|
*/
|
|
@@ -2249,32 +2279,28 @@ class Message {
|
|
|
2249
2279
|
static from(buffer$1) {
|
|
2250
2280
|
// Slice up wire data
|
|
2251
2281
|
let byteArray = [...buffer$1];
|
|
2252
|
-
const numRequiredSignatures = byteArray
|
|
2253
|
-
const numReadonlySignedAccounts = byteArray
|
|
2254
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2282
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2283
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2284
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2255
2285
|
const accountCount = decodeLength(byteArray);
|
|
2256
2286
|
let accountKeys = [];
|
|
2257
2287
|
|
|
2258
2288
|
for (let i = 0; i < accountCount; i++) {
|
|
2259
|
-
const account = byteArray
|
|
2260
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2289
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2261
2290
|
accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
|
|
2262
2291
|
}
|
|
2263
2292
|
|
|
2264
|
-
const recentBlockhash = byteArray
|
|
2265
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2293
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2266
2294
|
const instructionCount = decodeLength(byteArray);
|
|
2267
2295
|
let instructions = [];
|
|
2268
2296
|
|
|
2269
2297
|
for (let i = 0; i < instructionCount; i++) {
|
|
2270
|
-
const programIdIndex = byteArray
|
|
2298
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2271
2299
|
const accountCount = decodeLength(byteArray);
|
|
2272
|
-
const accounts = byteArray
|
|
2273
|
-
byteArray = byteArray.slice(accountCount);
|
|
2300
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2274
2301
|
const dataLength = decodeLength(byteArray);
|
|
2275
|
-
const dataSlice = byteArray
|
|
2302
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2276
2303
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
2277
|
-
byteArray = byteArray.slice(dataLength);
|
|
2278
2304
|
instructions.push({
|
|
2279
2305
|
programIdIndex,
|
|
2280
2306
|
accounts,
|
|
@@ -2303,6 +2329,10 @@ function assert (condition, message) {
|
|
|
2303
2329
|
}
|
|
2304
2330
|
}
|
|
2305
2331
|
|
|
2332
|
+
/**
|
|
2333
|
+
* Transaction signature as base-58 encoded string
|
|
2334
|
+
*/
|
|
2335
|
+
|
|
2306
2336
|
/**
|
|
2307
2337
|
* Default (empty) signature
|
|
2308
2338
|
*
|
|
@@ -2888,8 +2918,7 @@ class Transaction {
|
|
|
2888
2918
|
let signatures = [];
|
|
2889
2919
|
|
|
2890
2920
|
for (let i = 0; i < signatureCount; i++) {
|
|
2891
|
-
const signature = byteArray
|
|
2892
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2921
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
2893
2922
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
2894
2923
|
}
|
|
2895
2924
|
|
|
@@ -8399,10 +8428,8 @@ class ValidatorInfo {
|
|
|
8399
8428
|
const configKeys = [];
|
|
8400
8429
|
|
|
8401
8430
|
for (let i = 0; i < 2; i++) {
|
|
8402
|
-
const publicKey = new PublicKey(byteArray
|
|
8403
|
-
|
|
8404
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8405
|
-
byteArray = byteArray.slice(1);
|
|
8431
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
8432
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8406
8433
|
configKeys.push({
|
|
8407
8434
|
publicKey,
|
|
8408
8435
|
isSigner
|