@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.esm.js
CHANGED
|
@@ -2116,6 +2116,36 @@ function encodeLength(bytes, len) {
|
|
|
2116
2116
|
}
|
|
2117
2117
|
}
|
|
2118
2118
|
|
|
2119
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2120
|
+
/**
|
|
2121
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2122
|
+
*/
|
|
2123
|
+
|
|
2124
|
+
function guardedShift(byteArray) {
|
|
2125
|
+
if (byteArray.length === 0) {
|
|
2126
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
return byteArray.shift();
|
|
2130
|
+
}
|
|
2131
|
+
/**
|
|
2132
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2133
|
+
* the array.
|
|
2134
|
+
*/
|
|
2135
|
+
|
|
2136
|
+
function guardedSplice(byteArray, ...args) {
|
|
2137
|
+
var _args$;
|
|
2138
|
+
|
|
2139
|
+
const [start] = args;
|
|
2140
|
+
|
|
2141
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2142
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2143
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
return byteArray.splice(...args);
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2119
2149
|
/**
|
|
2120
2150
|
* The message header, identifying signed and read-only account
|
|
2121
2151
|
*/
|
|
@@ -2214,32 +2244,28 @@ class Message {
|
|
|
2214
2244
|
static from(buffer) {
|
|
2215
2245
|
// Slice up wire data
|
|
2216
2246
|
let byteArray = [...buffer];
|
|
2217
|
-
const numRequiredSignatures = byteArray
|
|
2218
|
-
const numReadonlySignedAccounts = byteArray
|
|
2219
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2247
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2248
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2249
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2220
2250
|
const accountCount = decodeLength(byteArray);
|
|
2221
2251
|
let accountKeys = [];
|
|
2222
2252
|
|
|
2223
2253
|
for (let i = 0; i < accountCount; i++) {
|
|
2224
|
-
const account = byteArray
|
|
2225
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2254
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2226
2255
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
2227
2256
|
}
|
|
2228
2257
|
|
|
2229
|
-
const recentBlockhash = byteArray
|
|
2230
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2258
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2231
2259
|
const instructionCount = decodeLength(byteArray);
|
|
2232
2260
|
let instructions = [];
|
|
2233
2261
|
|
|
2234
2262
|
for (let i = 0; i < instructionCount; i++) {
|
|
2235
|
-
const programIdIndex = byteArray
|
|
2263
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2236
2264
|
const accountCount = decodeLength(byteArray);
|
|
2237
|
-
const accounts = byteArray
|
|
2238
|
-
byteArray = byteArray.slice(accountCount);
|
|
2265
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2239
2266
|
const dataLength = decodeLength(byteArray);
|
|
2240
|
-
const dataSlice = byteArray
|
|
2267
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2241
2268
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
2242
|
-
byteArray = byteArray.slice(dataLength);
|
|
2243
2269
|
instructions.push({
|
|
2244
2270
|
programIdIndex,
|
|
2245
2271
|
accounts,
|
|
@@ -2268,6 +2294,10 @@ function assert (condition, message) {
|
|
|
2268
2294
|
}
|
|
2269
2295
|
}
|
|
2270
2296
|
|
|
2297
|
+
/**
|
|
2298
|
+
* Transaction signature as base-58 encoded string
|
|
2299
|
+
*/
|
|
2300
|
+
|
|
2271
2301
|
/**
|
|
2272
2302
|
* Default (empty) signature
|
|
2273
2303
|
*
|
|
@@ -2853,8 +2883,7 @@ class Transaction {
|
|
|
2853
2883
|
let signatures = [];
|
|
2854
2884
|
|
|
2855
2885
|
for (let i = 0; i < signatureCount; i++) {
|
|
2856
|
-
const signature = byteArray
|
|
2857
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2886
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
2858
2887
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2859
2888
|
}
|
|
2860
2889
|
|
|
@@ -8364,10 +8393,8 @@ class ValidatorInfo {
|
|
|
8364
8393
|
const configKeys = [];
|
|
8365
8394
|
|
|
8366
8395
|
for (let i = 0; i < 2; i++) {
|
|
8367
|
-
const publicKey = new PublicKey(byteArray
|
|
8368
|
-
|
|
8369
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8370
|
-
byteArray = byteArray.slice(1);
|
|
8396
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
8397
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8371
8398
|
configKeys.push({
|
|
8372
8399
|
publicKey,
|
|
8373
8400
|
isSigner
|