@solana/web3.js 1.7.0 → 1.7.2
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 +63 -20
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +63 -20
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +15 -3
- package/lib/index.esm.js +63 -20
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +77 -32
- 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/module.flow.js +19 -4
- package/package.json +30 -30
- package/src/message.ts +9 -12
- package/src/publickey.ts +12 -0
- package/src/stake-program.ts +10 -4
- 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.cjs.js
CHANGED
|
@@ -102,10 +102,13 @@ class PublicKey {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
|
-
*
|
|
105
|
+
* Default public key value. (All zeros)
|
|
106
106
|
*/
|
|
107
107
|
|
|
108
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Checks if two publicKeys are equal
|
|
111
|
+
*/
|
|
109
112
|
equals(publicKey) {
|
|
110
113
|
return this._bn.eq(publicKey._bn);
|
|
111
114
|
}
|
|
@@ -210,9 +213,19 @@ class PublicKey {
|
|
|
210
213
|
|
|
211
214
|
throw new Error("Unable to find a viable program address nonce");
|
|
212
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Check that a pubkey is on the ed25519 curve.
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
static isOnCurve(pubkey) {
|
|
222
|
+
return is_on_curve(pubkey) == 1;
|
|
223
|
+
}
|
|
213
224
|
|
|
214
225
|
} // @ts-ignore
|
|
215
226
|
|
|
227
|
+
_defineProperty__default['default'](PublicKey, "default", new PublicKey('11111111111111111111111111111111'));
|
|
228
|
+
|
|
216
229
|
let naclLowLevel = nacl__default['default'].lowlevel; // Check that a pubkey is on the curve.
|
|
217
230
|
// This function and its dependents were sourced from:
|
|
218
231
|
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
@@ -403,6 +416,36 @@ function encodeLength(bytes, len) {
|
|
|
403
416
|
}
|
|
404
417
|
}
|
|
405
418
|
|
|
419
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
420
|
+
/**
|
|
421
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
422
|
+
*/
|
|
423
|
+
|
|
424
|
+
function guardedShift(byteArray) {
|
|
425
|
+
if (byteArray.length === 0) {
|
|
426
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return byteArray.shift();
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
433
|
+
* the array.
|
|
434
|
+
*/
|
|
435
|
+
|
|
436
|
+
function guardedSplice(byteArray, ...args) {
|
|
437
|
+
var _args$;
|
|
438
|
+
|
|
439
|
+
const [start] = args;
|
|
440
|
+
|
|
441
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
442
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
443
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return byteArray.splice(...args);
|
|
447
|
+
}
|
|
448
|
+
|
|
406
449
|
/**
|
|
407
450
|
* The message header, identifying signed and read-only account
|
|
408
451
|
*/
|
|
@@ -487,32 +530,28 @@ class Message {
|
|
|
487
530
|
static from(buffer$1) {
|
|
488
531
|
// Slice up wire data
|
|
489
532
|
let byteArray = [...buffer$1];
|
|
490
|
-
const numRequiredSignatures = byteArray
|
|
491
|
-
const numReadonlySignedAccounts = byteArray
|
|
492
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
533
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
534
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
535
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
493
536
|
const accountCount = decodeLength(byteArray);
|
|
494
537
|
let accountKeys = [];
|
|
495
538
|
|
|
496
539
|
for (let i = 0; i < accountCount; i++) {
|
|
497
|
-
const account = byteArray
|
|
498
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
540
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
499
541
|
accountKeys.push(bs58__default['default'].encode(buffer.Buffer.from(account)));
|
|
500
542
|
}
|
|
501
543
|
|
|
502
|
-
const recentBlockhash = byteArray
|
|
503
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
544
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
504
545
|
const instructionCount = decodeLength(byteArray);
|
|
505
546
|
let instructions = [];
|
|
506
547
|
|
|
507
548
|
for (let i = 0; i < instructionCount; i++) {
|
|
508
|
-
const programIdIndex = byteArray
|
|
549
|
+
const programIdIndex = guardedShift(byteArray);
|
|
509
550
|
const accountCount = decodeLength(byteArray);
|
|
510
|
-
const accounts = byteArray
|
|
511
|
-
byteArray = byteArray.slice(accountCount);
|
|
551
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
512
552
|
const dataLength = decodeLength(byteArray);
|
|
513
|
-
const dataSlice = byteArray
|
|
553
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
514
554
|
const data = bs58__default['default'].encode(buffer.Buffer.from(dataSlice));
|
|
515
|
-
byteArray = byteArray.slice(dataLength);
|
|
516
555
|
instructions.push({
|
|
517
556
|
programIdIndex,
|
|
518
557
|
accounts,
|
|
@@ -1132,8 +1171,7 @@ class Transaction {
|
|
|
1132
1171
|
let signatures = [];
|
|
1133
1172
|
|
|
1134
1173
|
for (let i = 0; i < signatureCount; i++) {
|
|
1135
|
-
const signature = byteArray
|
|
1136
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1174
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1137
1175
|
signatures.push(bs58__default['default'].encode(buffer.Buffer.from(signature)));
|
|
1138
1176
|
}
|
|
1139
1177
|
|
|
@@ -5140,12 +5178,18 @@ class Lockup {
|
|
|
5140
5178
|
this.epoch = epoch;
|
|
5141
5179
|
this.custodian = custodian;
|
|
5142
5180
|
}
|
|
5181
|
+
/**
|
|
5182
|
+
* Default, inactive Lockup value
|
|
5183
|
+
*/
|
|
5184
|
+
|
|
5143
5185
|
|
|
5144
5186
|
}
|
|
5145
5187
|
/**
|
|
5146
5188
|
* Create stake account transaction params
|
|
5147
5189
|
*/
|
|
5148
5190
|
|
|
5191
|
+
_defineProperty__default['default'](Lockup, "default", new Lockup(0, 0, PublicKey.default));
|
|
5192
|
+
|
|
5149
5193
|
/**
|
|
5150
5194
|
* Stake Instruction class
|
|
5151
5195
|
*/
|
|
@@ -5421,8 +5465,9 @@ class StakeProgram {
|
|
|
5421
5465
|
const {
|
|
5422
5466
|
stakePubkey,
|
|
5423
5467
|
authorized,
|
|
5424
|
-
lockup
|
|
5468
|
+
lockup: maybeLockup
|
|
5425
5469
|
} = params;
|
|
5470
|
+
const lockup = maybeLockup || Lockup.default;
|
|
5426
5471
|
const type = STAKE_INSTRUCTION_LAYOUTS.Initialize;
|
|
5427
5472
|
const data = encodeData(type, {
|
|
5428
5473
|
authorized: {
|
|
@@ -5978,10 +6023,8 @@ class ValidatorInfo {
|
|
|
5978
6023
|
const configKeys = [];
|
|
5979
6024
|
|
|
5980
6025
|
for (let i = 0; i < 2; i++) {
|
|
5981
|
-
const publicKey = new PublicKey(byteArray
|
|
5982
|
-
|
|
5983
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
5984
|
-
byteArray = byteArray.slice(1);
|
|
6026
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
6027
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
5985
6028
|
configKeys.push({
|
|
5986
6029
|
publicKey,
|
|
5987
6030
|
isSigner
|