@solana/web3.js 1.44.2 → 1.44.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.cjs.js +65 -35
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +65 -35
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +65 -35
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +65 -35
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +65 -35
- 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 +22 -22
- package/src/connection.ts +2 -2
- package/src/message.ts +9 -12
- package/src/transaction.ts +21 -14
- package/src/util/guarded-array-utils.ts +34 -0
- package/src/validator-info.ts +5 -4
package/lib/index.esm.js
CHANGED
|
@@ -2211,6 +2211,36 @@ function encodeLength(bytes, len) {
|
|
|
2211
2211
|
}
|
|
2212
2212
|
}
|
|
2213
2213
|
|
|
2214
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2215
|
+
/**
|
|
2216
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2217
|
+
*/
|
|
2218
|
+
|
|
2219
|
+
function guardedShift(byteArray) {
|
|
2220
|
+
if (byteArray.length === 0) {
|
|
2221
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
return byteArray.shift();
|
|
2225
|
+
}
|
|
2226
|
+
/**
|
|
2227
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2228
|
+
* the array.
|
|
2229
|
+
*/
|
|
2230
|
+
|
|
2231
|
+
function guardedSplice(byteArray, ...args) {
|
|
2232
|
+
var _args$;
|
|
2233
|
+
|
|
2234
|
+
const [start] = args;
|
|
2235
|
+
|
|
2236
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2237
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2238
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
return byteArray.splice(...args);
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2214
2244
|
/**
|
|
2215
2245
|
* The message header, identifying signed and read-only account
|
|
2216
2246
|
*/
|
|
@@ -2309,32 +2339,28 @@ class Message {
|
|
|
2309
2339
|
static from(buffer) {
|
|
2310
2340
|
// Slice up wire data
|
|
2311
2341
|
let byteArray = [...buffer];
|
|
2312
|
-
const numRequiredSignatures = byteArray
|
|
2313
|
-
const numReadonlySignedAccounts = byteArray
|
|
2314
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2342
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2343
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2344
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2315
2345
|
const accountCount = decodeLength(byteArray);
|
|
2316
2346
|
let accountKeys = [];
|
|
2317
2347
|
|
|
2318
2348
|
for (let i = 0; i < accountCount; i++) {
|
|
2319
|
-
const account = byteArray
|
|
2320
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2349
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2321
2350
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
2322
2351
|
}
|
|
2323
2352
|
|
|
2324
|
-
const recentBlockhash = byteArray
|
|
2325
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2353
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2326
2354
|
const instructionCount = decodeLength(byteArray);
|
|
2327
2355
|
let instructions = [];
|
|
2328
2356
|
|
|
2329
2357
|
for (let i = 0; i < instructionCount; i++) {
|
|
2330
|
-
const programIdIndex = byteArray
|
|
2358
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2331
2359
|
const accountCount = decodeLength(byteArray);
|
|
2332
|
-
const accounts = byteArray
|
|
2333
|
-
byteArray = byteArray.slice(accountCount);
|
|
2360
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2334
2361
|
const dataLength = decodeLength(byteArray);
|
|
2335
|
-
const dataSlice = byteArray
|
|
2362
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2336
2363
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
2337
|
-
byteArray = byteArray.slice(dataLength);
|
|
2338
2364
|
instructions.push({
|
|
2339
2365
|
programIdIndex,
|
|
2340
2366
|
accounts,
|
|
@@ -2363,6 +2389,10 @@ function assert (condition, message) {
|
|
|
2363
2389
|
}
|
|
2364
2390
|
}
|
|
2365
2391
|
|
|
2392
|
+
/**
|
|
2393
|
+
* Transaction signature as base-58 encoded string
|
|
2394
|
+
*/
|
|
2395
|
+
|
|
2366
2396
|
let TransactionStatus;
|
|
2367
2397
|
/**
|
|
2368
2398
|
* Default (empty) signature
|
|
@@ -2534,24 +2564,27 @@ class Transaction {
|
|
|
2534
2564
|
return this._message;
|
|
2535
2565
|
}
|
|
2536
2566
|
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
} = this;
|
|
2567
|
+
let recentBlockhash;
|
|
2568
|
+
let instructions;
|
|
2540
2569
|
|
|
2541
|
-
if (
|
|
2542
|
-
|
|
2543
|
-
this.instructions.unshift(nonceInfo.nonceInstruction);
|
|
2544
|
-
}
|
|
2570
|
+
if (this.nonceInfo) {
|
|
2571
|
+
recentBlockhash = this.nonceInfo.nonce;
|
|
2545
2572
|
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2573
|
+
if (this.instructions[0] != this.nonceInfo.nonceInstruction) {
|
|
2574
|
+
instructions = [this.nonceInfo.nonceInstruction, ...this.instructions];
|
|
2575
|
+
} else {
|
|
2576
|
+
instructions = this.instructions;
|
|
2577
|
+
}
|
|
2578
|
+
} else {
|
|
2579
|
+
recentBlockhash = this.recentBlockhash;
|
|
2580
|
+
instructions = this.instructions;
|
|
2581
|
+
}
|
|
2549
2582
|
|
|
2550
2583
|
if (!recentBlockhash) {
|
|
2551
2584
|
throw new Error('Transaction recentBlockhash required');
|
|
2552
2585
|
}
|
|
2553
2586
|
|
|
2554
|
-
if (
|
|
2587
|
+
if (instructions.length < 1) {
|
|
2555
2588
|
console.warn('No instructions provided');
|
|
2556
2589
|
}
|
|
2557
2590
|
|
|
@@ -2566,15 +2599,15 @@ class Transaction {
|
|
|
2566
2599
|
throw new Error('Transaction fee payer required');
|
|
2567
2600
|
}
|
|
2568
2601
|
|
|
2569
|
-
for (let i = 0; i <
|
|
2570
|
-
if (
|
|
2602
|
+
for (let i = 0; i < instructions.length; i++) {
|
|
2603
|
+
if (instructions[i].programId === undefined) {
|
|
2571
2604
|
throw new Error(`Transaction instruction index ${i} has undefined program id`);
|
|
2572
2605
|
}
|
|
2573
2606
|
}
|
|
2574
2607
|
|
|
2575
2608
|
const programIds = [];
|
|
2576
2609
|
const accountMetas = [];
|
|
2577
|
-
|
|
2610
|
+
instructions.forEach(instruction => {
|
|
2578
2611
|
instruction.keys.forEach(accountMeta => {
|
|
2579
2612
|
accountMetas.push({ ...accountMeta
|
|
2580
2613
|
});
|
|
@@ -2684,7 +2717,7 @@ class Transaction {
|
|
|
2684
2717
|
}
|
|
2685
2718
|
});
|
|
2686
2719
|
const accountKeys = signedKeys.concat(unsignedKeys);
|
|
2687
|
-
const
|
|
2720
|
+
const compiledInstructions = instructions.map(instruction => {
|
|
2688
2721
|
const {
|
|
2689
2722
|
data,
|
|
2690
2723
|
programId
|
|
@@ -2695,7 +2728,7 @@ class Transaction {
|
|
|
2695
2728
|
data: bs58.encode(data)
|
|
2696
2729
|
};
|
|
2697
2730
|
});
|
|
2698
|
-
|
|
2731
|
+
compiledInstructions.forEach(instruction => {
|
|
2699
2732
|
assert(instruction.programIdIndex >= 0);
|
|
2700
2733
|
instruction.accounts.forEach(keyIndex => assert(keyIndex >= 0));
|
|
2701
2734
|
});
|
|
@@ -2707,7 +2740,7 @@ class Transaction {
|
|
|
2707
2740
|
},
|
|
2708
2741
|
accountKeys,
|
|
2709
2742
|
recentBlockhash,
|
|
2710
|
-
instructions
|
|
2743
|
+
instructions: compiledInstructions
|
|
2711
2744
|
});
|
|
2712
2745
|
}
|
|
2713
2746
|
/**
|
|
@@ -3020,8 +3053,7 @@ class Transaction {
|
|
|
3020
3053
|
let signatures = [];
|
|
3021
3054
|
|
|
3022
3055
|
for (let i = 0; i < signatureCount; i++) {
|
|
3023
|
-
const signature = byteArray
|
|
3024
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
3056
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
3025
3057
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
3026
3058
|
}
|
|
3027
3059
|
|
|
@@ -9339,10 +9371,8 @@ class ValidatorInfo {
|
|
|
9339
9371
|
const configKeys = [];
|
|
9340
9372
|
|
|
9341
9373
|
for (let i = 0; i < 2; i++) {
|
|
9342
|
-
const publicKey = new PublicKey(byteArray
|
|
9343
|
-
|
|
9344
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9345
|
-
byteArray = byteArray.slice(1);
|
|
9374
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
9375
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9346
9376
|
configKeys.push({
|
|
9347
9377
|
publicKey,
|
|
9348
9378
|
isSigner
|