@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.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ declare module '@solana/web3.js' {
|
|
|
13
13
|
* @param value ed25519 public key as buffer or base-58 encoded string
|
|
14
14
|
*/
|
|
15
15
|
constructor(value: number | string | Buffer | Uint8Array | Array<number>);
|
|
16
|
+
/**
|
|
17
|
+
* Default public key value. (All zeros)
|
|
18
|
+
*/
|
|
19
|
+
static default: PublicKey;
|
|
16
20
|
/**
|
|
17
21
|
* Checks if two publicKeys are equal
|
|
18
22
|
*/
|
|
@@ -59,6 +63,10 @@ declare module '@solana/web3.js' {
|
|
|
59
63
|
seeds: Array<Buffer | Uint8Array>,
|
|
60
64
|
programId: PublicKey,
|
|
61
65
|
): Promise<[PublicKey, number]>;
|
|
66
|
+
/**
|
|
67
|
+
* Check that a pubkey is on the ed25519 curve.
|
|
68
|
+
*/
|
|
69
|
+
static isOnCurve(pubkey: Uint8Array): boolean;
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
/**
|
|
@@ -1692,6 +1700,10 @@ declare module '@solana/web3.js' {
|
|
|
1692
1700
|
* Create a new Lockup object
|
|
1693
1701
|
*/
|
|
1694
1702
|
constructor(unixTimestamp: number, epoch: number, custodian: PublicKey);
|
|
1703
|
+
/**
|
|
1704
|
+
* Default, inactive Lockup value
|
|
1705
|
+
*/
|
|
1706
|
+
static default: Lockup;
|
|
1695
1707
|
}
|
|
1696
1708
|
/**
|
|
1697
1709
|
* Create stake account transaction params
|
|
@@ -1704,7 +1716,7 @@ declare module '@solana/web3.js' {
|
|
|
1704
1716
|
/** Authorities of the new stake account */
|
|
1705
1717
|
authorized: Authorized;
|
|
1706
1718
|
/** Lockup of the new stake account */
|
|
1707
|
-
lockup
|
|
1719
|
+
lockup?: Lockup;
|
|
1708
1720
|
/** Funding amount */
|
|
1709
1721
|
lamports: number;
|
|
1710
1722
|
};
|
|
@@ -1717,7 +1729,7 @@ declare module '@solana/web3.js' {
|
|
|
1717
1729
|
basePubkey: PublicKey;
|
|
1718
1730
|
seed: string;
|
|
1719
1731
|
authorized: Authorized;
|
|
1720
|
-
lockup
|
|
1732
|
+
lockup?: Lockup;
|
|
1721
1733
|
lamports: number;
|
|
1722
1734
|
};
|
|
1723
1735
|
/**
|
|
@@ -1726,7 +1738,7 @@ declare module '@solana/web3.js' {
|
|
|
1726
1738
|
export type InitializeStakeParams = {
|
|
1727
1739
|
stakePubkey: PublicKey;
|
|
1728
1740
|
authorized: Authorized;
|
|
1729
|
-
lockup
|
|
1741
|
+
lockup?: Lockup;
|
|
1730
1742
|
};
|
|
1731
1743
|
/**
|
|
1732
1744
|
* Delegate stake instruction params
|
package/lib/index.esm.js
CHANGED
|
@@ -64,10 +64,13 @@ class PublicKey {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
67
|
+
* Default public key value. (All zeros)
|
|
68
68
|
*/
|
|
69
69
|
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Checks if two publicKeys are equal
|
|
73
|
+
*/
|
|
71
74
|
equals(publicKey) {
|
|
72
75
|
return this._bn.eq(publicKey._bn);
|
|
73
76
|
}
|
|
@@ -172,9 +175,19 @@ class PublicKey {
|
|
|
172
175
|
|
|
173
176
|
throw new Error("Unable to find a viable program address nonce");
|
|
174
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Check that a pubkey is on the ed25519 curve.
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
static isOnCurve(pubkey) {
|
|
184
|
+
return is_on_curve(pubkey) == 1;
|
|
185
|
+
}
|
|
175
186
|
|
|
176
187
|
} // @ts-ignore
|
|
177
188
|
|
|
189
|
+
_defineProperty(PublicKey, "default", new PublicKey('11111111111111111111111111111111'));
|
|
190
|
+
|
|
178
191
|
let naclLowLevel = nacl__default.lowlevel; // Check that a pubkey is on the curve.
|
|
179
192
|
// This function and its dependents were sourced from:
|
|
180
193
|
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
@@ -365,6 +378,36 @@ function encodeLength(bytes, len) {
|
|
|
365
378
|
}
|
|
366
379
|
}
|
|
367
380
|
|
|
381
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
382
|
+
/**
|
|
383
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
384
|
+
*/
|
|
385
|
+
|
|
386
|
+
function guardedShift(byteArray) {
|
|
387
|
+
if (byteArray.length === 0) {
|
|
388
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return byteArray.shift();
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
395
|
+
* the array.
|
|
396
|
+
*/
|
|
397
|
+
|
|
398
|
+
function guardedSplice(byteArray, ...args) {
|
|
399
|
+
var _args$;
|
|
400
|
+
|
|
401
|
+
const [start] = args;
|
|
402
|
+
|
|
403
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
404
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
405
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return byteArray.splice(...args);
|
|
409
|
+
}
|
|
410
|
+
|
|
368
411
|
/**
|
|
369
412
|
* The message header, identifying signed and read-only account
|
|
370
413
|
*/
|
|
@@ -449,32 +492,28 @@ class Message {
|
|
|
449
492
|
static from(buffer) {
|
|
450
493
|
// Slice up wire data
|
|
451
494
|
let byteArray = [...buffer];
|
|
452
|
-
const numRequiredSignatures = byteArray
|
|
453
|
-
const numReadonlySignedAccounts = byteArray
|
|
454
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
495
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
496
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
497
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
455
498
|
const accountCount = decodeLength(byteArray);
|
|
456
499
|
let accountKeys = [];
|
|
457
500
|
|
|
458
501
|
for (let i = 0; i < accountCount; i++) {
|
|
459
|
-
const account = byteArray
|
|
460
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
502
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
461
503
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
462
504
|
}
|
|
463
505
|
|
|
464
|
-
const recentBlockhash = byteArray
|
|
465
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
506
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
466
507
|
const instructionCount = decodeLength(byteArray);
|
|
467
508
|
let instructions = [];
|
|
468
509
|
|
|
469
510
|
for (let i = 0; i < instructionCount; i++) {
|
|
470
|
-
const programIdIndex = byteArray
|
|
511
|
+
const programIdIndex = guardedShift(byteArray);
|
|
471
512
|
const accountCount = decodeLength(byteArray);
|
|
472
|
-
const accounts = byteArray
|
|
473
|
-
byteArray = byteArray.slice(accountCount);
|
|
513
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
474
514
|
const dataLength = decodeLength(byteArray);
|
|
475
|
-
const dataSlice = byteArray
|
|
515
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
476
516
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
477
|
-
byteArray = byteArray.slice(dataLength);
|
|
478
517
|
instructions.push({
|
|
479
518
|
programIdIndex,
|
|
480
519
|
accounts,
|
|
@@ -1094,8 +1133,7 @@ class Transaction {
|
|
|
1094
1133
|
let signatures = [];
|
|
1095
1134
|
|
|
1096
1135
|
for (let i = 0; i < signatureCount; i++) {
|
|
1097
|
-
const signature = byteArray
|
|
1098
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1136
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1099
1137
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1100
1138
|
}
|
|
1101
1139
|
|
|
@@ -5102,12 +5140,18 @@ class Lockup {
|
|
|
5102
5140
|
this.epoch = epoch;
|
|
5103
5141
|
this.custodian = custodian;
|
|
5104
5142
|
}
|
|
5143
|
+
/**
|
|
5144
|
+
* Default, inactive Lockup value
|
|
5145
|
+
*/
|
|
5146
|
+
|
|
5105
5147
|
|
|
5106
5148
|
}
|
|
5107
5149
|
/**
|
|
5108
5150
|
* Create stake account transaction params
|
|
5109
5151
|
*/
|
|
5110
5152
|
|
|
5153
|
+
_defineProperty(Lockup, "default", new Lockup(0, 0, PublicKey.default));
|
|
5154
|
+
|
|
5111
5155
|
/**
|
|
5112
5156
|
* Stake Instruction class
|
|
5113
5157
|
*/
|
|
@@ -5383,8 +5427,9 @@ class StakeProgram {
|
|
|
5383
5427
|
const {
|
|
5384
5428
|
stakePubkey,
|
|
5385
5429
|
authorized,
|
|
5386
|
-
lockup
|
|
5430
|
+
lockup: maybeLockup
|
|
5387
5431
|
} = params;
|
|
5432
|
+
const lockup = maybeLockup || Lockup.default;
|
|
5388
5433
|
const type = STAKE_INSTRUCTION_LAYOUTS.Initialize;
|
|
5389
5434
|
const data = encodeData(type, {
|
|
5390
5435
|
authorized: {
|
|
@@ -5940,10 +5985,8 @@ class ValidatorInfo {
|
|
|
5940
5985
|
const configKeys = [];
|
|
5941
5986
|
|
|
5942
5987
|
for (let i = 0; i < 2; i++) {
|
|
5943
|
-
const publicKey = new PublicKey(byteArray
|
|
5944
|
-
|
|
5945
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
5946
|
-
byteArray = byteArray.slice(1);
|
|
5988
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
5989
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
5947
5990
|
configKeys.push({
|
|
5948
5991
|
publicKey,
|
|
5949
5992
|
isSigner
|