@solana/web3.js 1.90.0 → 1.90.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.cjs.js +66 -37
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +66 -37
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +66 -37
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.esm.js +66 -37
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +476 -116
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +8 -7
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +66 -37
- package/lib/index.native.js.map +1 -1
- package/package.json +28 -27
- package/src/message/legacy.ts +9 -12
- package/src/message/v0.ts +29 -12
- package/src/programs/stake.ts +22 -5
- package/src/transaction/legacy.ts +2 -2
- package/src/transaction/versioned.ts +2 -1
- package/src/utils/guarded-array-utils.ts +34 -0
- package/src/validator-info.ts +5 -4
package/lib/index.d.ts
CHANGED
|
@@ -844,8 +844,8 @@ export class StakeProgram {
|
|
|
844
844
|
* Max space of a Stake account
|
|
845
845
|
*
|
|
846
846
|
* This is generated from the solana-stake-program StakeState struct as
|
|
847
|
-
* `
|
|
848
|
-
* https://docs.rs/solana-stake-program/latest/solana_stake_program/stake_state/enum.
|
|
847
|
+
* `StakeStateV2::size_of()`:
|
|
848
|
+
* https://docs.rs/solana-stake-program/latest/solana_stake_program/stake_state/enum.StakeStateV2.html
|
|
849
849
|
*/
|
|
850
850
|
static space: number;
|
|
851
851
|
/**
|
|
@@ -880,12 +880,12 @@ export class StakeProgram {
|
|
|
880
880
|
/**
|
|
881
881
|
* Generate a Transaction that splits Stake tokens into another stake account
|
|
882
882
|
*/
|
|
883
|
-
static split(params: SplitStakeParams): Transaction;
|
|
883
|
+
static split(params: SplitStakeParams, rentExemptReserve: number): Transaction;
|
|
884
884
|
/**
|
|
885
885
|
* Generate a Transaction that splits Stake tokens into another account
|
|
886
886
|
* derived from a base public key and seed
|
|
887
887
|
*/
|
|
888
|
-
static splitWithSeed(params: SplitStakeWithSeedParams): Transaction;
|
|
888
|
+
static splitWithSeed(params: SplitStakeWithSeedParams, rentExemptReserve?: number): Transaction;
|
|
889
889
|
/**
|
|
890
890
|
* Generate a Transaction that merges Stake accounts.
|
|
891
891
|
*/
|
package/lib/index.esm.js
CHANGED
|
@@ -676,6 +676,31 @@ class CompiledKeys {
|
|
|
676
676
|
}
|
|
677
677
|
}
|
|
678
678
|
|
|
679
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
683
|
+
*/
|
|
684
|
+
function guardedShift(byteArray) {
|
|
685
|
+
if (byteArray.length === 0) {
|
|
686
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
687
|
+
}
|
|
688
|
+
return byteArray.shift();
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
693
|
+
* the array.
|
|
694
|
+
*/
|
|
695
|
+
function guardedSplice(byteArray, ...args) {
|
|
696
|
+
const [start] = args;
|
|
697
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
698
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
699
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
700
|
+
}
|
|
701
|
+
return byteArray.splice(...args);
|
|
702
|
+
}
|
|
703
|
+
|
|
679
704
|
/**
|
|
680
705
|
* An instruction to execute by a program
|
|
681
706
|
*
|
|
@@ -817,32 +842,28 @@ class Message {
|
|
|
817
842
|
static from(buffer) {
|
|
818
843
|
// Slice up wire data
|
|
819
844
|
let byteArray = [...buffer];
|
|
820
|
-
const numRequiredSignatures = byteArray
|
|
845
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
821
846
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
822
847
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
823
848
|
}
|
|
824
|
-
const numReadonlySignedAccounts = byteArray
|
|
825
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
849
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
850
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
826
851
|
const accountCount = decodeLength(byteArray);
|
|
827
852
|
let accountKeys = [];
|
|
828
853
|
for (let i = 0; i < accountCount; i++) {
|
|
829
|
-
const account = byteArray
|
|
830
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
854
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
831
855
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
832
856
|
}
|
|
833
|
-
const recentBlockhash = byteArray
|
|
834
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
857
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
835
858
|
const instructionCount = decodeLength(byteArray);
|
|
836
859
|
let instructions = [];
|
|
837
860
|
for (let i = 0; i < instructionCount; i++) {
|
|
838
|
-
const programIdIndex = byteArray
|
|
861
|
+
const programIdIndex = guardedShift(byteArray);
|
|
839
862
|
const accountCount = decodeLength(byteArray);
|
|
840
|
-
const accounts = byteArray
|
|
841
|
-
byteArray = byteArray.slice(accountCount);
|
|
863
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
842
864
|
const dataLength = decodeLength(byteArray);
|
|
843
|
-
const dataSlice = byteArray
|
|
865
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
844
866
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
845
|
-
byteArray = byteArray.slice(dataLength);
|
|
846
867
|
instructions.push({
|
|
847
868
|
programIdIndex,
|
|
848
869
|
accounts,
|
|
@@ -1047,30 +1068,30 @@ class MessageV0 {
|
|
|
1047
1068
|
}
|
|
1048
1069
|
static deserialize(serializedMessage) {
|
|
1049
1070
|
let byteArray = [...serializedMessage];
|
|
1050
|
-
const prefix = byteArray
|
|
1071
|
+
const prefix = guardedShift(byteArray);
|
|
1051
1072
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1052
1073
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1053
1074
|
const version = maskedPrefix;
|
|
1054
1075
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1055
1076
|
const header = {
|
|
1056
|
-
numRequiredSignatures: byteArray
|
|
1057
|
-
numReadonlySignedAccounts: byteArray
|
|
1058
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1077
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1078
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1079
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1059
1080
|
};
|
|
1060
1081
|
const staticAccountKeys = [];
|
|
1061
1082
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1062
1083
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1063
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1084
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1064
1085
|
}
|
|
1065
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1086
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1066
1087
|
const instructionCount = decodeLength(byteArray);
|
|
1067
1088
|
const compiledInstructions = [];
|
|
1068
1089
|
for (let i = 0; i < instructionCount; i++) {
|
|
1069
|
-
const programIdIndex = byteArray
|
|
1090
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1070
1091
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1071
|
-
const accountKeyIndexes = byteArray
|
|
1092
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1072
1093
|
const dataLength = decodeLength(byteArray);
|
|
1073
|
-
const data = new Uint8Array(byteArray
|
|
1094
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1074
1095
|
compiledInstructions.push({
|
|
1075
1096
|
programIdIndex,
|
|
1076
1097
|
accountKeyIndexes,
|
|
@@ -1080,11 +1101,11 @@ class MessageV0 {
|
|
|
1080
1101
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1081
1102
|
const addressTableLookups = [];
|
|
1082
1103
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1083
|
-
const accountKey = new PublicKey(byteArray
|
|
1104
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1084
1105
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1085
|
-
const writableIndexes = byteArray
|
|
1106
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1086
1107
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1087
|
-
const readonlyIndexes = byteArray
|
|
1108
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1088
1109
|
addressTableLookups.push({
|
|
1089
1110
|
accountKey,
|
|
1090
1111
|
writableIndexes,
|
|
@@ -1875,8 +1896,7 @@ class Transaction {
|
|
|
1875
1896
|
const signatureCount = decodeLength(byteArray);
|
|
1876
1897
|
let signatures = [];
|
|
1877
1898
|
for (let i = 0; i < signatureCount; i++) {
|
|
1878
|
-
const signature = byteArray
|
|
1879
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1899
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1880
1900
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1881
1901
|
}
|
|
1882
1902
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -2051,7 +2071,7 @@ class VersionedTransaction {
|
|
|
2051
2071
|
const signatures = [];
|
|
2052
2072
|
const signaturesLength = decodeLength(byteArray);
|
|
2053
2073
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2054
|
-
signatures.push(new Uint8Array(byteArray
|
|
2074
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2055
2075
|
}
|
|
2056
2076
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
2057
2077
|
return new VersionedTransaction(message, signatures);
|
|
@@ -5791,7 +5811,7 @@ const LogsNotificationResult = type({
|
|
|
5791
5811
|
|
|
5792
5812
|
/** @internal */
|
|
5793
5813
|
const COMMON_HTTP_HEADERS = {
|
|
5794
|
-
'solana-client': `js/${"
|
|
5814
|
+
'solana-client': `js/${"1.90.2" }`
|
|
5795
5815
|
};
|
|
5796
5816
|
|
|
5797
5817
|
/**
|
|
@@ -10101,12 +10121,14 @@ class StakeProgram {
|
|
|
10101
10121
|
/**
|
|
10102
10122
|
* Generate a Transaction that splits Stake tokens into another stake account
|
|
10103
10123
|
*/
|
|
10104
|
-
static split(params
|
|
10124
|
+
static split(params,
|
|
10125
|
+
// Compute the cost of allocating the new stake account in lamports
|
|
10126
|
+
rentExemptReserve) {
|
|
10105
10127
|
const transaction = new Transaction();
|
|
10106
10128
|
transaction.add(SystemProgram.createAccount({
|
|
10107
10129
|
fromPubkey: params.authorizedPubkey,
|
|
10108
10130
|
newAccountPubkey: params.splitStakePubkey,
|
|
10109
|
-
lamports:
|
|
10131
|
+
lamports: rentExemptReserve,
|
|
10110
10132
|
space: this.space,
|
|
10111
10133
|
programId: this.programId
|
|
10112
10134
|
}));
|
|
@@ -10117,7 +10139,9 @@ class StakeProgram {
|
|
|
10117
10139
|
* Generate a Transaction that splits Stake tokens into another account
|
|
10118
10140
|
* derived from a base public key and seed
|
|
10119
10141
|
*/
|
|
10120
|
-
static splitWithSeed(params
|
|
10142
|
+
static splitWithSeed(params,
|
|
10143
|
+
// If this stake account is new, compute the cost of allocating it in lamports
|
|
10144
|
+
rentExemptReserve) {
|
|
10121
10145
|
const {
|
|
10122
10146
|
stakePubkey,
|
|
10123
10147
|
authorizedPubkey,
|
|
@@ -10134,6 +10158,13 @@ class StakeProgram {
|
|
|
10134
10158
|
space: this.space,
|
|
10135
10159
|
programId: this.programId
|
|
10136
10160
|
}));
|
|
10161
|
+
if (rentExemptReserve && rentExemptReserve > 0) {
|
|
10162
|
+
transaction.add(SystemProgram.transfer({
|
|
10163
|
+
fromPubkey: params.authorizedPubkey,
|
|
10164
|
+
toPubkey: splitStakePubkey,
|
|
10165
|
+
lamports: rentExemptReserve
|
|
10166
|
+
}));
|
|
10167
|
+
}
|
|
10137
10168
|
return transaction.add(this.splitInstruction({
|
|
10138
10169
|
stakePubkey,
|
|
10139
10170
|
authorizedPubkey,
|
|
@@ -10264,8 +10295,8 @@ StakeProgram.programId = new PublicKey('Stake11111111111111111111111111111111111
|
|
|
10264
10295
|
* Max space of a Stake account
|
|
10265
10296
|
*
|
|
10266
10297
|
* This is generated from the solana-stake-program StakeState struct as
|
|
10267
|
-
* `
|
|
10268
|
-
* https://docs.rs/solana-stake-program/latest/solana_stake_program/stake_state/enum.
|
|
10298
|
+
* `StakeStateV2::size_of()`:
|
|
10299
|
+
* https://docs.rs/solana-stake-program/latest/solana_stake_program/stake_state/enum.StakeStateV2.html
|
|
10269
10300
|
*/
|
|
10270
10301
|
StakeProgram.space = 200;
|
|
10271
10302
|
|
|
@@ -10740,10 +10771,8 @@ class ValidatorInfo {
|
|
|
10740
10771
|
if (configKeyCount !== 2) return null;
|
|
10741
10772
|
const configKeys = [];
|
|
10742
10773
|
for (let i = 0; i < 2; i++) {
|
|
10743
|
-
const publicKey = new PublicKey(byteArray
|
|
10744
|
-
|
|
10745
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
10746
|
-
byteArray = byteArray.slice(1);
|
|
10774
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
10775
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
10747
10776
|
configKeys.push({
|
|
10748
10777
|
publicKey,
|
|
10749
10778
|
isSigner
|