@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.browser.cjs.js
CHANGED
|
@@ -2218,6 +2218,36 @@ function encodeLength(bytes, len) {
|
|
|
2218
2218
|
}
|
|
2219
2219
|
}
|
|
2220
2220
|
|
|
2221
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2222
|
+
/**
|
|
2223
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
2224
|
+
*/
|
|
2225
|
+
|
|
2226
|
+
function guardedShift(byteArray) {
|
|
2227
|
+
if (byteArray.length === 0) {
|
|
2228
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
return byteArray.shift();
|
|
2232
|
+
}
|
|
2233
|
+
/**
|
|
2234
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
2235
|
+
* the array.
|
|
2236
|
+
*/
|
|
2237
|
+
|
|
2238
|
+
function guardedSplice(byteArray, ...args) {
|
|
2239
|
+
var _args$;
|
|
2240
|
+
|
|
2241
|
+
const [start] = args;
|
|
2242
|
+
|
|
2243
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
2244
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
2245
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
return byteArray.splice(...args);
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2221
2251
|
/**
|
|
2222
2252
|
* The message header, identifying signed and read-only account
|
|
2223
2253
|
*/
|
|
@@ -2316,32 +2346,28 @@ class Message {
|
|
|
2316
2346
|
static from(buffer$1) {
|
|
2317
2347
|
// Slice up wire data
|
|
2318
2348
|
let byteArray = [...buffer$1];
|
|
2319
|
-
const numRequiredSignatures = byteArray
|
|
2320
|
-
const numReadonlySignedAccounts = byteArray
|
|
2321
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
2349
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
2350
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
2351
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
2322
2352
|
const accountCount = decodeLength(byteArray);
|
|
2323
2353
|
let accountKeys = [];
|
|
2324
2354
|
|
|
2325
2355
|
for (let i = 0; i < accountCount; i++) {
|
|
2326
|
-
const account = byteArray
|
|
2327
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2356
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2328
2357
|
accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
|
|
2329
2358
|
}
|
|
2330
2359
|
|
|
2331
|
-
const recentBlockhash = byteArray
|
|
2332
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2360
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
2333
2361
|
const instructionCount = decodeLength(byteArray);
|
|
2334
2362
|
let instructions = [];
|
|
2335
2363
|
|
|
2336
2364
|
for (let i = 0; i < instructionCount; i++) {
|
|
2337
|
-
const programIdIndex = byteArray
|
|
2365
|
+
const programIdIndex = guardedShift(byteArray);
|
|
2338
2366
|
const accountCount = decodeLength(byteArray);
|
|
2339
|
-
const accounts = byteArray
|
|
2340
|
-
byteArray = byteArray.slice(accountCount);
|
|
2367
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
2341
2368
|
const dataLength = decodeLength(byteArray);
|
|
2342
|
-
const dataSlice = byteArray
|
|
2369
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
2343
2370
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
2344
|
-
byteArray = byteArray.slice(dataLength);
|
|
2345
2371
|
instructions.push({
|
|
2346
2372
|
programIdIndex,
|
|
2347
2373
|
accounts,
|
|
@@ -2370,6 +2396,10 @@ function assert (condition, message) {
|
|
|
2370
2396
|
}
|
|
2371
2397
|
}
|
|
2372
2398
|
|
|
2399
|
+
/**
|
|
2400
|
+
* Transaction signature as base-58 encoded string
|
|
2401
|
+
*/
|
|
2402
|
+
|
|
2373
2403
|
exports.TransactionStatus = void 0;
|
|
2374
2404
|
/**
|
|
2375
2405
|
* Default (empty) signature
|
|
@@ -2541,24 +2571,27 @@ class Transaction {
|
|
|
2541
2571
|
return this._message;
|
|
2542
2572
|
}
|
|
2543
2573
|
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
} = this;
|
|
2574
|
+
let recentBlockhash;
|
|
2575
|
+
let instructions;
|
|
2547
2576
|
|
|
2548
|
-
if (
|
|
2549
|
-
|
|
2550
|
-
this.instructions.unshift(nonceInfo.nonceInstruction);
|
|
2551
|
-
}
|
|
2577
|
+
if (this.nonceInfo) {
|
|
2578
|
+
recentBlockhash = this.nonceInfo.nonce;
|
|
2552
2579
|
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2580
|
+
if (this.instructions[0] != this.nonceInfo.nonceInstruction) {
|
|
2581
|
+
instructions = [this.nonceInfo.nonceInstruction, ...this.instructions];
|
|
2582
|
+
} else {
|
|
2583
|
+
instructions = this.instructions;
|
|
2584
|
+
}
|
|
2585
|
+
} else {
|
|
2586
|
+
recentBlockhash = this.recentBlockhash;
|
|
2587
|
+
instructions = this.instructions;
|
|
2588
|
+
}
|
|
2556
2589
|
|
|
2557
2590
|
if (!recentBlockhash) {
|
|
2558
2591
|
throw new Error('Transaction recentBlockhash required');
|
|
2559
2592
|
}
|
|
2560
2593
|
|
|
2561
|
-
if (
|
|
2594
|
+
if (instructions.length < 1) {
|
|
2562
2595
|
console.warn('No instructions provided');
|
|
2563
2596
|
}
|
|
2564
2597
|
|
|
@@ -2573,15 +2606,15 @@ class Transaction {
|
|
|
2573
2606
|
throw new Error('Transaction fee payer required');
|
|
2574
2607
|
}
|
|
2575
2608
|
|
|
2576
|
-
for (let i = 0; i <
|
|
2577
|
-
if (
|
|
2609
|
+
for (let i = 0; i < instructions.length; i++) {
|
|
2610
|
+
if (instructions[i].programId === undefined) {
|
|
2578
2611
|
throw new Error(`Transaction instruction index ${i} has undefined program id`);
|
|
2579
2612
|
}
|
|
2580
2613
|
}
|
|
2581
2614
|
|
|
2582
2615
|
const programIds = [];
|
|
2583
2616
|
const accountMetas = [];
|
|
2584
|
-
|
|
2617
|
+
instructions.forEach(instruction => {
|
|
2585
2618
|
instruction.keys.forEach(accountMeta => {
|
|
2586
2619
|
accountMetas.push({ ...accountMeta
|
|
2587
2620
|
});
|
|
@@ -2691,7 +2724,7 @@ class Transaction {
|
|
|
2691
2724
|
}
|
|
2692
2725
|
});
|
|
2693
2726
|
const accountKeys = signedKeys.concat(unsignedKeys);
|
|
2694
|
-
const
|
|
2727
|
+
const compiledInstructions = instructions.map(instruction => {
|
|
2695
2728
|
const {
|
|
2696
2729
|
data,
|
|
2697
2730
|
programId
|
|
@@ -2702,7 +2735,7 @@ class Transaction {
|
|
|
2702
2735
|
data: bs58__default["default"].encode(data)
|
|
2703
2736
|
};
|
|
2704
2737
|
});
|
|
2705
|
-
|
|
2738
|
+
compiledInstructions.forEach(instruction => {
|
|
2706
2739
|
assert(instruction.programIdIndex >= 0);
|
|
2707
2740
|
instruction.accounts.forEach(keyIndex => assert(keyIndex >= 0));
|
|
2708
2741
|
});
|
|
@@ -2714,7 +2747,7 @@ class Transaction {
|
|
|
2714
2747
|
},
|
|
2715
2748
|
accountKeys,
|
|
2716
2749
|
recentBlockhash,
|
|
2717
|
-
instructions
|
|
2750
|
+
instructions: compiledInstructions
|
|
2718
2751
|
});
|
|
2719
2752
|
}
|
|
2720
2753
|
/**
|
|
@@ -3027,8 +3060,7 @@ class Transaction {
|
|
|
3027
3060
|
let signatures = [];
|
|
3028
3061
|
|
|
3029
3062
|
for (let i = 0; i < signatureCount; i++) {
|
|
3030
|
-
const signature = byteArray
|
|
3031
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
3063
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
3032
3064
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
3033
3065
|
}
|
|
3034
3066
|
|
|
@@ -9288,10 +9320,8 @@ class ValidatorInfo {
|
|
|
9288
9320
|
const configKeys = [];
|
|
9289
9321
|
|
|
9290
9322
|
for (let i = 0; i < 2; i++) {
|
|
9291
|
-
const publicKey = new PublicKey(byteArray
|
|
9292
|
-
|
|
9293
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9294
|
-
byteArray = byteArray.slice(1);
|
|
9323
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
9324
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9295
9325
|
configKeys.push({
|
|
9296
9326
|
publicKey,
|
|
9297
9327
|
isSigner
|