@solana/web3.js 1.33.0 → 1.34.0

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/module.flow.js CHANGED
@@ -4120,6 +4120,21 @@ lastValidBlockHeight: number,...
4120
4120
  ...
4121
4121
  };
4122
4122
 
4123
+ /**
4124
+ * Authorize instruction params
4125
+ */
4126
+ declare export type AuthorizeVoteParams = {
4127
+ votePubkey: PublicKey,
4128
+
4129
+ /**
4130
+ * Current vote or withdraw authority, depending on `voteAuthorizationType`
4131
+ */
4132
+ authorizedPubkey: PublicKey,
4133
+ newAuthorizedPubkey: PublicKey,
4134
+ voteAuthorizationType: VoteAuthorizationType,
4135
+ ...
4136
+ };
4137
+
4123
4138
  /**
4124
4139
  * Withdraw from vote account transaction params
4125
4140
  */
@@ -4149,6 +4164,13 @@ lastValidBlockHeight: number,...
4149
4164
  instruction: TransactionInstruction
4150
4165
  ): InitializeAccountParams;
4151
4166
 
4167
+ /**
4168
+ * Decode an authorize instruction and retrieve the instruction params.
4169
+ */
4170
+ static decodeAuthorize(
4171
+ instruction: TransactionInstruction
4172
+ ): AuthorizeVoteParams;
4173
+
4152
4174
  /**
4153
4175
  * Decode a withdraw instruction and retrieve the instruction params.
4154
4176
  */
@@ -4160,7 +4182,36 @@ lastValidBlockHeight: number,...
4160
4182
  /**
4161
4183
  * An enumeration of valid VoteInstructionType's
4162
4184
  */
4163
- declare export type VoteInstructionType = "InitializeAccount" | "Withdraw";
4185
+ declare export type VoteInstructionType =
4186
+ | "Authorize"
4187
+ | "InitializeAccount"
4188
+ | "Withdraw";
4189
+
4190
+ /**
4191
+ * VoteAuthorize type
4192
+ */
4193
+ declare export type VoteAuthorizationType = {
4194
+ /**
4195
+ * The VoteAuthorize index (from solana-vote-program)
4196
+ */
4197
+ index: number,
4198
+ ...
4199
+ };
4200
+
4201
+ /**
4202
+ * An enumeration of valid VoteAuthorization layouts.
4203
+ */
4204
+ declare export var VoteAuthorizationLayout: $ReadOnly<{
4205
+ Voter: {
4206
+ index: number,
4207
+ ...
4208
+ },
4209
+ Withdrawer: {
4210
+ index: number,
4211
+ ...
4212
+ },
4213
+ ...
4214
+ }>;
4164
4215
 
4165
4216
  /**
4166
4217
  * Factory class for transactions to interact with the Vote program
@@ -4192,6 +4243,11 @@ lastValidBlockHeight: number,...
4192
4243
  */
4193
4244
  static createAccount(params: CreateVoteAccountParams): Transaction;
4194
4245
 
4246
+ /**
4247
+ * Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account.
4248
+ */
4249
+ static authorize(params: AuthorizeVoteParams): Transaction;
4250
+
4195
4251
  /**
4196
4252
  * Generate a transaction to withdraw from a Vote account.
4197
4253
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.33.0",
3
+ "version": "1.34.0",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
@@ -49,6 +49,17 @@ export type InitializeAccountParams = {
49
49
  voteInit: VoteInit;
50
50
  };
51
51
 
52
+ /**
53
+ * Authorize instruction params
54
+ */
55
+ export type AuthorizeVoteParams = {
56
+ votePubkey: PublicKey;
57
+ /** Current vote or withdraw authority, depending on `voteAuthorizationType` */
58
+ authorizedPubkey: PublicKey;
59
+ newAuthorizedPubkey: PublicKey;
60
+ voteAuthorizationType: VoteAuthorizationType;
61
+ };
62
+
52
63
  /**
53
64
  * Withdraw from vote account transaction params
54
65
  */
@@ -120,6 +131,30 @@ export class VoteInstruction {
120
131
  };
121
132
  }
122
133
 
134
+ /**
135
+ * Decode an authorize instruction and retrieve the instruction params.
136
+ */
137
+ static decodeAuthorize(
138
+ instruction: TransactionInstruction,
139
+ ): AuthorizeVoteParams {
140
+ this.checkProgramId(instruction.programId);
141
+ this.checkKeyLength(instruction.keys, 3);
142
+
143
+ const {newAuthorized, voteAuthorizationType} = decodeData(
144
+ VOTE_INSTRUCTION_LAYOUTS.Authorize,
145
+ instruction.data,
146
+ );
147
+
148
+ return {
149
+ votePubkey: instruction.keys[0].pubkey,
150
+ authorizedPubkey: instruction.keys[2].pubkey,
151
+ newAuthorizedPubkey: new PublicKey(newAuthorized),
152
+ voteAuthorizationType: {
153
+ index: voteAuthorizationType,
154
+ },
155
+ };
156
+ }
157
+
123
158
  /**
124
159
  * Decode a withdraw instruction and retrieve the instruction params.
125
160
  */
@@ -166,7 +201,10 @@ export class VoteInstruction {
166
201
  /**
167
202
  * An enumeration of valid VoteInstructionType's
168
203
  */
169
- export type VoteInstructionType = 'InitializeAccount' | 'Withdraw';
204
+ export type VoteInstructionType =
205
+ | 'Authorize'
206
+ | 'InitializeAccount'
207
+ | 'Withdraw';
170
208
 
171
209
  const VOTE_INSTRUCTION_LAYOUTS: {
172
210
  [type in VoteInstructionType]: InstructionType;
@@ -178,6 +216,14 @@ const VOTE_INSTRUCTION_LAYOUTS: {
178
216
  Layout.voteInit(),
179
217
  ]),
180
218
  },
219
+ Authorize: {
220
+ index: 1,
221
+ layout: BufferLayout.struct([
222
+ BufferLayout.u32('instruction'),
223
+ Layout.publicKey('newAuthorized'),
224
+ BufferLayout.u32('voteAuthorizationType'),
225
+ ]),
226
+ },
181
227
  Withdraw: {
182
228
  index: 3,
183
229
  layout: BufferLayout.struct([
@@ -187,6 +233,26 @@ const VOTE_INSTRUCTION_LAYOUTS: {
187
233
  },
188
234
  });
189
235
 
236
+ /**
237
+ * VoteAuthorize type
238
+ */
239
+ export type VoteAuthorizationType = {
240
+ /** The VoteAuthorize index (from solana-vote-program) */
241
+ index: number;
242
+ };
243
+
244
+ /**
245
+ * An enumeration of valid VoteAuthorization layouts.
246
+ */
247
+ export const VoteAuthorizationLayout = Object.freeze({
248
+ Voter: {
249
+ index: 0,
250
+ },
251
+ Withdrawer: {
252
+ index: 1,
253
+ },
254
+ });
255
+
190
256
  /**
191
257
  * Factory class for transactions to interact with the Vote program
192
258
  */
@@ -267,6 +333,36 @@ export class VoteProgram {
267
333
  );
268
334
  }
269
335
 
336
+ /**
337
+ * Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account.
338
+ */
339
+ static authorize(params: AuthorizeVoteParams): Transaction {
340
+ const {
341
+ votePubkey,
342
+ authorizedPubkey,
343
+ newAuthorizedPubkey,
344
+ voteAuthorizationType,
345
+ } = params;
346
+
347
+ const type = VOTE_INSTRUCTION_LAYOUTS.Authorize;
348
+ const data = encodeData(type, {
349
+ newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
350
+ voteAuthorizationType: voteAuthorizationType.index,
351
+ });
352
+
353
+ const keys = [
354
+ {pubkey: votePubkey, isSigner: false, isWritable: true},
355
+ {pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false},
356
+ {pubkey: authorizedPubkey, isSigner: true, isWritable: false},
357
+ ];
358
+
359
+ return new Transaction().add({
360
+ keys,
361
+ programId: this.programId,
362
+ data,
363
+ });
364
+ }
365
+
270
366
  /**
271
367
  * Generate a transaction to withdraw from a Vote account.
272
368
  */