@solana/web3.js 1.29.3 → 1.29.4
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 +46 -25
- 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.browser.esm.js
CHANGED
|
@@ -2115,6 +2115,36 @@ function encodeLength(bytes, len) {
|
|
|
2115
2115
|
}
|
|
2116
2116
|
}
|
|
2117
2117
|
|
|
2118
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2119
|
+
/**
|
|
2120
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2121
|
+
*/
|
|
2122
|
+
|
|
2123
|
+
function guardedShift(byteArray) {
|
|
2124
|
+
if (byteArray.length === 0) {
|
|
2125
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
return byteArray.shift();
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2132
|
+
* the array.
|
|
2133
|
+
*/
|
|
2134
|
+
|
|
2135
|
+
function guardedSplice(byteArray, ...args) {
|
|
2136
|
+
var _args$;
|
|
2137
|
+
|
|
2138
|
+
const [start] = args;
|
|
2139
|
+
|
|
2140
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2141
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2142
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
return byteArray.splice(...args);
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2118
2148
|
/**
|
|
2119
2149
|
* The message header, identifying signed and read-only account
|
|
2120
2150
|
*/
|
|
@@ -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
|
*
|
|
@@ -2865,8 +2895,7 @@ class Transaction {
|
|
|
2865
2895
|
let signatures = [];
|
|
2866
2896
|
|
|
2867
2897
|
for (let i = 0; i < signatureCount; i++) {
|
|
2868
|
-
const signature = byteArray
|
|
2869
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2898
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
2870
2899
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2871
2900
|
}
|
|
2872
2901
|
|
|
@@ -8924,10 +8953,8 @@ class ValidatorInfo {
|
|
|
8924
8953
|
const configKeys = [];
|
|
8925
8954
|
|
|
8926
8955
|
for (let i = 0; i < 2; i++) {
|
|
8927
|
-
const publicKey = new PublicKey(byteArray
|
|
8928
|
-
|
|
8929
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8930
|
-
byteArray = byteArray.slice(1);
|
|
8956
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
8957
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8931
8958
|
configKeys.push({
|
|
8932
8959
|
publicKey,
|
|
8933
8960
|
isSigner
|