@solana/web3.js 1.37.2 → 1.37.3
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 +24 -24
- 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.esm.js
CHANGED
|
@@ -2169,6 +2169,36 @@ function encodeLength(bytes, len) {
|
|
|
2169
2169
|
}
|
|
2170
2170
|
}
|
|
2171
2171
|
|
|
2172
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2173
|
+
/**
|
|
2174
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2175
|
+
*/
|
|
2176
|
+
|
|
2177
|
+
function guardedShift(byteArray) {
|
|
2178
|
+
if (byteArray.length === 0) {
|
|
2179
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
return byteArray.shift();
|
|
2183
|
+
}
|
|
2184
|
+
/**
|
|
2185
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2186
|
+
* the array.
|
|
2187
|
+
*/
|
|
2188
|
+
|
|
2189
|
+
function guardedSplice(byteArray, ...args) {
|
|
2190
|
+
var _args$;
|
|
2191
|
+
|
|
2192
|
+
const [start] = args;
|
|
2193
|
+
|
|
2194
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2195
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2196
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
return byteArray.splice(...args);
|
|
2200
|
+
}
|
|
2201
|
+
|
|
2172
2202
|
/**
|
|
2173
2203
|
* The message header, identifying signed and read-only account
|
|
2174
2204
|
*/
|
|
@@ -2267,32 +2297,28 @@ class Message {
|
|
|
2267
2297
|
static from(buffer) {
|
|
2268
2298
|
// Slice up wire data
|
|
2269
2299
|
let byteArray = [...buffer];
|
|
2270
|
-
const numRequiredSignatures = byteArray
|
|
2271
|
-
const numReadonlySignedAccounts = byteArray
|
|
2272
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2300
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2301
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2302
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2273
2303
|
const accountCount = decodeLength(byteArray);
|
|
2274
2304
|
let accountKeys = [];
|
|
2275
2305
|
|
|
2276
2306
|
for (let i = 0; i < accountCount; i++) {
|
|
2277
|
-
const account = byteArray
|
|
2278
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2307
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2279
2308
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
2280
2309
|
}
|
|
2281
2310
|
|
|
2282
|
-
const recentBlockhash = byteArray
|
|
2283
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2311
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2284
2312
|
const instructionCount = decodeLength(byteArray);
|
|
2285
2313
|
let instructions = [];
|
|
2286
2314
|
|
|
2287
2315
|
for (let i = 0; i < instructionCount; i++) {
|
|
2288
|
-
const programIdIndex = byteArray
|
|
2316
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2289
2317
|
const accountCount = decodeLength(byteArray);
|
|
2290
|
-
const accounts = byteArray
|
|
2291
|
-
byteArray = byteArray.slice(accountCount);
|
|
2318
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2292
2319
|
const dataLength = decodeLength(byteArray);
|
|
2293
|
-
const dataSlice = byteArray
|
|
2320
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2294
2321
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
2295
|
-
byteArray = byteArray.slice(dataLength);
|
|
2296
2322
|
instructions.push({
|
|
2297
2323
|
programIdIndex,
|
|
2298
2324
|
accounts,
|
|
@@ -2321,6 +2347,10 @@ function assert (condition, message) {
|
|
|
2321
2347
|
}
|
|
2322
2348
|
}
|
|
2323
2349
|
|
|
2350
|
+
/**
|
|
2351
|
+
* Transaction signature as base-58 encoded string
|
|
2352
|
+
*/
|
|
2353
|
+
|
|
2324
2354
|
/**
|
|
2325
2355
|
* Default (empty) signature
|
|
2326
2356
|
*
|
|
@@ -2915,8 +2945,7 @@ class Transaction {
|
|
|
2915
2945
|
let signatures = [];
|
|
2916
2946
|
|
|
2917
2947
|
for (let i = 0; i < signatureCount; i++) {
|
|
2918
|
-
const signature = byteArray
|
|
2919
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2948
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
2920
2949
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2921
2950
|
}
|
|
2922
2951
|
|
|
@@ -8753,10 +8782,8 @@ class ValidatorInfo {
|
|
|
8753
8782
|
const configKeys = [];
|
|
8754
8783
|
|
|
8755
8784
|
for (let i = 0; i < 2; i++) {
|
|
8756
|
-
const publicKey = new PublicKey(byteArray
|
|
8757
|
-
|
|
8758
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8759
|
-
byteArray = byteArray.slice(1);
|
|
8785
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
8786
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8760
8787
|
configKeys.push({
|
|
8761
8788
|
publicKey,
|
|
8762
8789
|
isSigner
|