@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.cjs.js
CHANGED
|
@@ -2245,6 +2245,36 @@ function encodeLength(bytes, len) {
|
|
|
2245
2245
|
}
|
|
2246
2246
|
}
|
|
2247
2247
|
|
|
2248
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2249
|
+
/**
|
|
2250
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2251
|
+
*/
|
|
2252
|
+
|
|
2253
|
+
function guardedShift(byteArray) {
|
|
2254
|
+
if (byteArray.length === 0) {
|
|
2255
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
return byteArray.shift();
|
|
2259
|
+
}
|
|
2260
|
+
/**
|
|
2261
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2262
|
+
* the array.
|
|
2263
|
+
*/
|
|
2264
|
+
|
|
2265
|
+
function guardedSplice(byteArray, ...args) {
|
|
2266
|
+
var _args$;
|
|
2267
|
+
|
|
2268
|
+
const [start] = args;
|
|
2269
|
+
|
|
2270
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2271
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2272
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
return byteArray.splice(...args);
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2248
2278
|
/**
|
|
2249
2279
|
* The message header, identifying signed and read-only account
|
|
2250
2280
|
*/
|
|
@@ -2343,32 +2373,28 @@ class Message {
|
|
|
2343
2373
|
static from(buffer$1) {
|
|
2344
2374
|
// Slice up wire data
|
|
2345
2375
|
let byteArray = [...buffer$1];
|
|
2346
|
-
const numRequiredSignatures = byteArray
|
|
2347
|
-
const numReadonlySignedAccounts = byteArray
|
|
2348
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2376
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2377
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2378
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2349
2379
|
const accountCount = decodeLength(byteArray);
|
|
2350
2380
|
let accountKeys = [];
|
|
2351
2381
|
|
|
2352
2382
|
for (let i = 0; i < accountCount; i++) {
|
|
2353
|
-
const account = byteArray
|
|
2354
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2383
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2355
2384
|
accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
|
|
2356
2385
|
}
|
|
2357
2386
|
|
|
2358
|
-
const recentBlockhash = byteArray
|
|
2359
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2387
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2360
2388
|
const instructionCount = decodeLength(byteArray);
|
|
2361
2389
|
let instructions = [];
|
|
2362
2390
|
|
|
2363
2391
|
for (let i = 0; i < instructionCount; i++) {
|
|
2364
|
-
const programIdIndex = byteArray
|
|
2392
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2365
2393
|
const accountCount = decodeLength(byteArray);
|
|
2366
|
-
const accounts = byteArray
|
|
2367
|
-
byteArray = byteArray.slice(accountCount);
|
|
2394
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2368
2395
|
const dataLength = decodeLength(byteArray);
|
|
2369
|
-
const dataSlice = byteArray
|
|
2396
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2370
2397
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
2371
|
-
byteArray = byteArray.slice(dataLength);
|
|
2372
2398
|
instructions.push({
|
|
2373
2399
|
programIdIndex,
|
|
2374
2400
|
accounts,
|
|
@@ -2397,6 +2423,10 @@ function assert (condition, message) {
|
|
|
2397
2423
|
}
|
|
2398
2424
|
}
|
|
2399
2425
|
|
|
2426
|
+
/**
|
|
2427
|
+
* Transaction signature as base-58 encoded string
|
|
2428
|
+
*/
|
|
2429
|
+
|
|
2400
2430
|
exports.TransactionStatus = void 0;
|
|
2401
2431
|
/**
|
|
2402
2432
|
* Default (empty) signature
|
|
@@ -2568,24 +2598,27 @@ class Transaction {
|
|
|
2568
2598
|
return this._message;
|
|
2569
2599
|
}
|
|
2570
2600
|
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
} = this;
|
|
2601
|
+
let recentBlockhash;
|
|
2602
|
+
let instructions;
|
|
2574
2603
|
|
|
2575
|
-
if (
|
|
2576
|
-
|
|
2577
|
-
this.instructions.unshift(nonceInfo.nonceInstruction);
|
|
2578
|
-
}
|
|
2604
|
+
if (this.nonceInfo) {
|
|
2605
|
+
recentBlockhash = this.nonceInfo.nonce;
|
|
2579
2606
|
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2607
|
+
if (this.instructions[0] != this.nonceInfo.nonceInstruction) {
|
|
2608
|
+
instructions = [this.nonceInfo.nonceInstruction, ...this.instructions];
|
|
2609
|
+
} else {
|
|
2610
|
+
instructions = this.instructions;
|
|
2611
|
+
}
|
|
2612
|
+
} else {
|
|
2613
|
+
recentBlockhash = this.recentBlockhash;
|
|
2614
|
+
instructions = this.instructions;
|
|
2615
|
+
}
|
|
2583
2616
|
|
|
2584
2617
|
if (!recentBlockhash) {
|
|
2585
2618
|
throw new Error('Transaction recentBlockhash required');
|
|
2586
2619
|
}
|
|
2587
2620
|
|
|
2588
|
-
if (
|
|
2621
|
+
if (instructions.length < 1) {
|
|
2589
2622
|
console.warn('No instructions provided');
|
|
2590
2623
|
}
|
|
2591
2624
|
|
|
@@ -2600,15 +2633,15 @@ class Transaction {
|
|
|
2600
2633
|
throw new Error('Transaction fee payer required');
|
|
2601
2634
|
}
|
|
2602
2635
|
|
|
2603
|
-
for (let i = 0; i <
|
|
2604
|
-
if (
|
|
2636
|
+
for (let i = 0; i < instructions.length; i++) {
|
|
2637
|
+
if (instructions[i].programId === undefined) {
|
|
2605
2638
|
throw new Error(`Transaction instruction index ${i} has undefined program id`);
|
|
2606
2639
|
}
|
|
2607
2640
|
}
|
|
2608
2641
|
|
|
2609
2642
|
const programIds = [];
|
|
2610
2643
|
const accountMetas = [];
|
|
2611
|
-
|
|
2644
|
+
instructions.forEach(instruction => {
|
|
2612
2645
|
instruction.keys.forEach(accountMeta => {
|
|
2613
2646
|
accountMetas.push({ ...accountMeta
|
|
2614
2647
|
});
|
|
@@ -2718,7 +2751,7 @@ class Transaction {
|
|
|
2718
2751
|
}
|
|
2719
2752
|
});
|
|
2720
2753
|
const accountKeys = signedKeys.concat(unsignedKeys);
|
|
2721
|
-
const
|
|
2754
|
+
const compiledInstructions = instructions.map(instruction => {
|
|
2722
2755
|
const {
|
|
2723
2756
|
data,
|
|
2724
2757
|
programId
|
|
@@ -2729,7 +2762,7 @@ class Transaction {
|
|
|
2729
2762
|
data: bs58__default["default"].encode(data)
|
|
2730
2763
|
};
|
|
2731
2764
|
});
|
|
2732
|
-
|
|
2765
|
+
compiledInstructions.forEach(instruction => {
|
|
2733
2766
|
assert(instruction.programIdIndex >= 0);
|
|
2734
2767
|
instruction.accounts.forEach(keyIndex => assert(keyIndex >= 0));
|
|
2735
2768
|
});
|
|
@@ -2741,7 +2774,7 @@ class Transaction {
|
|
|
2741
2774
|
},
|
|
2742
2775
|
accountKeys,
|
|
2743
2776
|
recentBlockhash,
|
|
2744
|
-
instructions
|
|
2777
|
+
instructions: compiledInstructions
|
|
2745
2778
|
});
|
|
2746
2779
|
}
|
|
2747
2780
|
/**
|
|
@@ -3054,8 +3087,7 @@ class Transaction {
|
|
|
3054
3087
|
let signatures = [];
|
|
3055
3088
|
|
|
3056
3089
|
for (let i = 0; i < signatureCount; i++) {
|
|
3057
|
-
const signature = byteArray
|
|
3058
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
3090
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
3059
3091
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
3060
3092
|
}
|
|
3061
3093
|
|
|
@@ -9373,10 +9405,8 @@ class ValidatorInfo {
|
|
|
9373
9405
|
const configKeys = [];
|
|
9374
9406
|
|
|
9375
9407
|
for (let i = 0; i < 2; i++) {
|
|
9376
|
-
const publicKey = new PublicKey(byteArray
|
|
9377
|
-
|
|
9378
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9379
|
-
byteArray = byteArray.slice(1);
|
|
9408
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
9409
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9380
9410
|
configKeys.push({
|
|
9381
9411
|
publicKey,
|
|
9382
9412
|
isSigner
|