@solana/web3.js 1.36.0 → 1.36.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 +23 -23
- 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
|
@@ -2120,6 +2120,36 @@ function encodeLength(bytes, len) {
|
|
|
2120
2120
|
}
|
|
2121
2121
|
}
|
|
2122
2122
|
|
|
2123
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2124
|
+
/**
|
|
2125
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2126
|
+
*/
|
|
2127
|
+
|
|
2128
|
+
function guardedShift(byteArray) {
|
|
2129
|
+
if (byteArray.length === 0) {
|
|
2130
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
return byteArray.shift();
|
|
2134
|
+
}
|
|
2135
|
+
/**
|
|
2136
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2137
|
+
* the array.
|
|
2138
|
+
*/
|
|
2139
|
+
|
|
2140
|
+
function guardedSplice(byteArray, ...args) {
|
|
2141
|
+
var _args$;
|
|
2142
|
+
|
|
2143
|
+
const [start] = args;
|
|
2144
|
+
|
|
2145
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2146
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2147
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
return byteArray.splice(...args);
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2123
2153
|
/**
|
|
2124
2154
|
* The message header, identifying signed and read-only account
|
|
2125
2155
|
*/
|
|
@@ -2218,32 +2248,28 @@ class Message {
|
|
|
2218
2248
|
static from(buffer) {
|
|
2219
2249
|
// Slice up wire data
|
|
2220
2250
|
let byteArray = [...buffer];
|
|
2221
|
-
const numRequiredSignatures = byteArray
|
|
2222
|
-
const numReadonlySignedAccounts = byteArray
|
|
2223
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2251
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2252
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2253
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2224
2254
|
const accountCount = decodeLength(byteArray);
|
|
2225
2255
|
let accountKeys = [];
|
|
2226
2256
|
|
|
2227
2257
|
for (let i = 0; i < accountCount; i++) {
|
|
2228
|
-
const account = byteArray
|
|
2229
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2258
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2230
2259
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
2231
2260
|
}
|
|
2232
2261
|
|
|
2233
|
-
const recentBlockhash = byteArray
|
|
2234
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2262
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2235
2263
|
const instructionCount = decodeLength(byteArray);
|
|
2236
2264
|
let instructions = [];
|
|
2237
2265
|
|
|
2238
2266
|
for (let i = 0; i < instructionCount; i++) {
|
|
2239
|
-
const programIdIndex = byteArray
|
|
2267
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2240
2268
|
const accountCount = decodeLength(byteArray);
|
|
2241
|
-
const accounts = byteArray
|
|
2242
|
-
byteArray = byteArray.slice(accountCount);
|
|
2269
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2243
2270
|
const dataLength = decodeLength(byteArray);
|
|
2244
|
-
const dataSlice = byteArray
|
|
2271
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2245
2272
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
2246
|
-
byteArray = byteArray.slice(dataLength);
|
|
2247
2273
|
instructions.push({
|
|
2248
2274
|
programIdIndex,
|
|
2249
2275
|
accounts,
|
|
@@ -2272,6 +2298,10 @@ function assert (condition, message) {
|
|
|
2272
2298
|
}
|
|
2273
2299
|
}
|
|
2274
2300
|
|
|
2301
|
+
/**
|
|
2302
|
+
* Transaction signature as base-58 encoded string
|
|
2303
|
+
*/
|
|
2304
|
+
|
|
2275
2305
|
/**
|
|
2276
2306
|
* Default (empty) signature
|
|
2277
2307
|
*
|
|
@@ -2858,8 +2888,7 @@ class Transaction {
|
|
|
2858
2888
|
let signatures = [];
|
|
2859
2889
|
|
|
2860
2890
|
for (let i = 0; i < signatureCount; i++) {
|
|
2861
|
-
const signature = byteArray
|
|
2862
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2891
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
2863
2892
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2864
2893
|
}
|
|
2865
2894
|
|
|
@@ -9134,10 +9163,8 @@ class ValidatorInfo {
|
|
|
9134
9163
|
const configKeys = [];
|
|
9135
9164
|
|
|
9136
9165
|
for (let i = 0; i < 2; i++) {
|
|
9137
|
-
const publicKey = new PublicKey(byteArray
|
|
9138
|
-
|
|
9139
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9140
|
-
byteArray = byteArray.slice(1);
|
|
9166
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
9167
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9141
9168
|
configKeys.push({
|
|
9142
9169
|
publicKey,
|
|
9143
9170
|
isSigner
|