@solana/web3.js 1.32.1 → 1.32.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.esm.js +53 -19
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +53 -19
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +53 -19
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +53 -19
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/package.json +23 -23
- package/src/connection.ts +10 -1
- 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
|
@@ -2113,6 +2113,36 @@ function encodeLength(bytes, len) {
|
|
|
2113
2113
|
}
|
|
2114
2114
|
}
|
|
2115
2115
|
|
|
2116
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2117
|
+
/**
|
|
2118
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2119
|
+
*/
|
|
2120
|
+
|
|
2121
|
+
function guardedShift(byteArray) {
|
|
2122
|
+
if (byteArray.length === 0) {
|
|
2123
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
return byteArray.shift();
|
|
2127
|
+
}
|
|
2128
|
+
/**
|
|
2129
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2130
|
+
* the array.
|
|
2131
|
+
*/
|
|
2132
|
+
|
|
2133
|
+
function guardedSplice(byteArray, ...args) {
|
|
2134
|
+
var _args$;
|
|
2135
|
+
|
|
2136
|
+
const [start] = args;
|
|
2137
|
+
|
|
2138
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2139
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2140
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
return byteArray.splice(...args);
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2116
2146
|
/**
|
|
2117
2147
|
* The message header, identifying signed and read-only account
|
|
2118
2148
|
*/
|
|
@@ -2211,32 +2241,28 @@ class Message {
|
|
|
2211
2241
|
static from(buffer) {
|
|
2212
2242
|
// Slice up wire data
|
|
2213
2243
|
let byteArray = [...buffer];
|
|
2214
|
-
const numRequiredSignatures = byteArray
|
|
2215
|
-
const numReadonlySignedAccounts = byteArray
|
|
2216
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2244
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2245
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2246
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2217
2247
|
const accountCount = decodeLength(byteArray);
|
|
2218
2248
|
let accountKeys = [];
|
|
2219
2249
|
|
|
2220
2250
|
for (let i = 0; i < accountCount; i++) {
|
|
2221
|
-
const account = byteArray
|
|
2222
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2251
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2223
2252
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
2224
2253
|
}
|
|
2225
2254
|
|
|
2226
|
-
const recentBlockhash = byteArray
|
|
2227
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2255
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2228
2256
|
const instructionCount = decodeLength(byteArray);
|
|
2229
2257
|
let instructions = [];
|
|
2230
2258
|
|
|
2231
2259
|
for (let i = 0; i < instructionCount; i++) {
|
|
2232
|
-
const programIdIndex = byteArray
|
|
2260
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2233
2261
|
const accountCount = decodeLength(byteArray);
|
|
2234
|
-
const accounts = byteArray
|
|
2235
|
-
byteArray = byteArray.slice(accountCount);
|
|
2262
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2236
2263
|
const dataLength = decodeLength(byteArray);
|
|
2237
|
-
const dataSlice = byteArray
|
|
2264
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2238
2265
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
2239
|
-
byteArray = byteArray.slice(dataLength);
|
|
2240
2266
|
instructions.push({
|
|
2241
2267
|
programIdIndex,
|
|
2242
2268
|
accounts,
|
|
@@ -2265,6 +2291,10 @@ function assert (condition, message) {
|
|
|
2265
2291
|
}
|
|
2266
2292
|
}
|
|
2267
2293
|
|
|
2294
|
+
/**
|
|
2295
|
+
* Transaction signature as base-58 encoded string
|
|
2296
|
+
*/
|
|
2297
|
+
|
|
2268
2298
|
/**
|
|
2269
2299
|
* Default (empty) signature
|
|
2270
2300
|
*
|
|
@@ -2851,8 +2881,7 @@ class Transaction {
|
|
|
2851
2881
|
let signatures = [];
|
|
2852
2882
|
|
|
2853
2883
|
for (let i = 0; i < signatureCount; i++) {
|
|
2854
|
-
const signature = byteArray
|
|
2855
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2884
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
2856
2885
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2857
2886
|
}
|
|
2858
2887
|
|
|
@@ -7403,7 +7432,14 @@ class Connection {
|
|
|
7403
7432
|
this._rpcWebSocketIdleTimeout = setTimeout(() => {
|
|
7404
7433
|
this._rpcWebSocketIdleTimeout = null;
|
|
7405
7434
|
|
|
7406
|
-
|
|
7435
|
+
try {
|
|
7436
|
+
this._rpcWebSocket.close();
|
|
7437
|
+
} catch (err) {
|
|
7438
|
+
// swallow error if socket has already been closed.
|
|
7439
|
+
if (err instanceof Error) {
|
|
7440
|
+
console.log(`Error when closing socket connection: ${err.message}`);
|
|
7441
|
+
}
|
|
7442
|
+
}
|
|
7407
7443
|
}, 500);
|
|
7408
7444
|
}
|
|
7409
7445
|
|
|
@@ -9085,10 +9121,8 @@ class ValidatorInfo {
|
|
|
9085
9121
|
const configKeys = [];
|
|
9086
9122
|
|
|
9087
9123
|
for (let i = 0; i < 2; i++) {
|
|
9088
|
-
const publicKey = new PublicKey(byteArray
|
|
9089
|
-
|
|
9090
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9091
|
-
byteArray = byteArray.slice(1);
|
|
9124
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
9125
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9092
9126
|
configKeys.push({
|
|
9093
9127
|
publicKey,
|
|
9094
9128
|
isSigner
|