@solana/web3.js 1.58.0 → 1.59.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/lib/index.browser.cjs.js +89 -5
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +89 -4
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +89 -5
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +23 -0
- package/lib/index.esm.js +89 -4
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +343 -703
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +5 -13
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +89 -5
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -2
- package/src/layout.ts +22 -0
- package/src/programs/secp256k1.ts +5 -7
- package/src/programs/vote.ts +109 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/web3.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.59.0",
|
|
4
4
|
"description": "Solana Javascript API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -69,7 +69,6 @@
|
|
|
69
69
|
"buffer": "6.0.1",
|
|
70
70
|
"fast-stable-stringify": "^1.0.0",
|
|
71
71
|
"jayson": "^3.4.4",
|
|
72
|
-
"js-sha3": "^0.8.0",
|
|
73
72
|
"node-fetch": "2",
|
|
74
73
|
"rpc-websockets": "^7.5.0",
|
|
75
74
|
"superstruct": "^0.14.2"
|
package/src/layout.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {Buffer} from 'buffer';
|
|
2
2
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
3
3
|
|
|
4
|
+
import {VoteAuthorizeWithSeedArgs} from './programs/vote';
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Layout for a public key
|
|
6
8
|
*/
|
|
@@ -141,6 +143,23 @@ export const voteInit = (property: string = 'voteInit') => {
|
|
|
141
143
|
);
|
|
142
144
|
};
|
|
143
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Layout for a VoteAuthorizeWithSeedArgs object
|
|
148
|
+
*/
|
|
149
|
+
export const voteAuthorizeWithSeedArgs = (
|
|
150
|
+
property: string = 'voteAuthorizeWithSeedArgs',
|
|
151
|
+
) => {
|
|
152
|
+
return BufferLayout.struct<VoteAuthorizeWithSeedArgs>(
|
|
153
|
+
[
|
|
154
|
+
BufferLayout.u32('voteAuthorizationType'),
|
|
155
|
+
publicKey('currentAuthorityDerivedKeyOwnerPubkey'),
|
|
156
|
+
rustString('currentAuthorityDerivedKeySeed'),
|
|
157
|
+
publicKey('newAuthorized'),
|
|
158
|
+
],
|
|
159
|
+
property,
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
|
|
144
163
|
export function getAlloc(type: any, fields: any): number {
|
|
145
164
|
const getItemAlloc = (item: any): number => {
|
|
146
165
|
if (item.span >= 0) {
|
|
@@ -152,6 +171,9 @@ export function getAlloc(type: any, fields: any): number {
|
|
|
152
171
|
if (Array.isArray(field)) {
|
|
153
172
|
return field.length * getItemAlloc(item.elementLayout);
|
|
154
173
|
}
|
|
174
|
+
} else if ('fields' in item) {
|
|
175
|
+
// This is a `Structure` whose size needs to be recursively measured.
|
|
176
|
+
return getAlloc({layout: item}, fields[item.property]);
|
|
155
177
|
}
|
|
156
178
|
// Couldn't determine allocated size of layout
|
|
157
179
|
return 0;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Buffer} from 'buffer';
|
|
2
2
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
3
|
-
import
|
|
3
|
+
import {keccak_256} from '@noble/hashes/sha3';
|
|
4
4
|
|
|
5
5
|
import {PublicKey} from '../publickey';
|
|
6
6
|
import {TransactionInstruction} from '../transaction';
|
|
@@ -98,9 +98,9 @@ export class Secp256k1Program {
|
|
|
98
98
|
);
|
|
99
99
|
|
|
100
100
|
try {
|
|
101
|
-
return Buffer.from(
|
|
102
|
-
|
|
103
|
-
)
|
|
101
|
+
return Buffer.from(keccak_256(toBuffer(publicKey))).slice(
|
|
102
|
+
-ETHEREUM_ADDRESS_BYTES,
|
|
103
|
+
);
|
|
104
104
|
} catch (error) {
|
|
105
105
|
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
106
106
|
}
|
|
@@ -211,9 +211,7 @@ export class Secp256k1Program {
|
|
|
211
211
|
privateKey,
|
|
212
212
|
false /* isCompressed */,
|
|
213
213
|
).slice(1); // throw away leading byte
|
|
214
|
-
const messageHash = Buffer.from(
|
|
215
|
-
sha3.keccak_256.update(toBuffer(message)).digest(),
|
|
216
|
-
);
|
|
214
|
+
const messageHash = Buffer.from(keccak_256(toBuffer(message)));
|
|
217
215
|
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
218
216
|
|
|
219
217
|
return this.createInstructionWithPublicKey({
|
package/src/programs/vote.ts
CHANGED
|
@@ -65,6 +65,18 @@ export type AuthorizeVoteParams = {
|
|
|
65
65
|
voteAuthorizationType: VoteAuthorizationType;
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* AuthorizeWithSeed instruction params
|
|
70
|
+
*/
|
|
71
|
+
export type AuthorizeVoteWithSeedParams = {
|
|
72
|
+
currentAuthorityDerivedKeyBasePubkey: PublicKey;
|
|
73
|
+
currentAuthorityDerivedKeyOwnerPubkey: PublicKey;
|
|
74
|
+
currentAuthorityDerivedKeySeed: string;
|
|
75
|
+
newAuthorizedPubkey: PublicKey;
|
|
76
|
+
voteAuthorizationType: VoteAuthorizationType;
|
|
77
|
+
votePubkey: PublicKey;
|
|
78
|
+
};
|
|
79
|
+
|
|
68
80
|
/**
|
|
69
81
|
* Withdraw from vote account transaction params
|
|
70
82
|
*/
|
|
@@ -160,6 +172,41 @@ export class VoteInstruction {
|
|
|
160
172
|
};
|
|
161
173
|
}
|
|
162
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
177
|
+
*/
|
|
178
|
+
static decodeAuthorizeWithSeed(
|
|
179
|
+
instruction: TransactionInstruction,
|
|
180
|
+
): AuthorizeVoteWithSeedParams {
|
|
181
|
+
this.checkProgramId(instruction.programId);
|
|
182
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
183
|
+
|
|
184
|
+
const {
|
|
185
|
+
voteAuthorizeWithSeedArgs: {
|
|
186
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
187
|
+
currentAuthorityDerivedKeySeed,
|
|
188
|
+
newAuthorized,
|
|
189
|
+
voteAuthorizationType,
|
|
190
|
+
},
|
|
191
|
+
} = decodeData(
|
|
192
|
+
VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed,
|
|
193
|
+
instruction.data,
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
|
|
198
|
+
currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(
|
|
199
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
200
|
+
),
|
|
201
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
202
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
203
|
+
voteAuthorizationType: {
|
|
204
|
+
index: voteAuthorizationType,
|
|
205
|
+
},
|
|
206
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
163
210
|
/**
|
|
164
211
|
* Decode a withdraw instruction and retrieve the instruction params.
|
|
165
212
|
*/
|
|
@@ -211,13 +258,23 @@ export type VoteInstructionType =
|
|
|
211
258
|
// It would be preferable for this type to be `keyof VoteInstructionInputData`
|
|
212
259
|
// but Typedoc does not transpile `keyof` expressions.
|
|
213
260
|
// See https://github.com/TypeStrong/typedoc/issues/1894
|
|
214
|
-
'Authorize' | 'InitializeAccount' | 'Withdraw';
|
|
215
|
-
|
|
261
|
+
'Authorize' | 'AuthorizeWithSeed' | 'InitializeAccount' | 'Withdraw';
|
|
262
|
+
|
|
263
|
+
/** @internal */
|
|
264
|
+
export type VoteAuthorizeWithSeedArgs = Readonly<{
|
|
265
|
+
currentAuthorityDerivedKeyOwnerPubkey: Uint8Array;
|
|
266
|
+
currentAuthorityDerivedKeySeed: string;
|
|
267
|
+
newAuthorized: Uint8Array;
|
|
268
|
+
voteAuthorizationType: number;
|
|
269
|
+
}>;
|
|
216
270
|
type VoteInstructionInputData = {
|
|
217
271
|
Authorize: IInstructionInputData & {
|
|
218
272
|
newAuthorized: Uint8Array;
|
|
219
273
|
voteAuthorizationType: number;
|
|
220
274
|
};
|
|
275
|
+
AuthorizeWithSeed: IInstructionInputData & {
|
|
276
|
+
voteAuthorizeWithSeedArgs: VoteAuthorizeWithSeedArgs;
|
|
277
|
+
};
|
|
221
278
|
InitializeAccount: IInstructionInputData & {
|
|
222
279
|
voteInit: Readonly<{
|
|
223
280
|
authorizedVoter: Uint8Array;
|
|
@@ -258,6 +315,13 @@ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze<{
|
|
|
258
315
|
BufferLayout.ns64('lamports'),
|
|
259
316
|
]),
|
|
260
317
|
},
|
|
318
|
+
AuthorizeWithSeed: {
|
|
319
|
+
index: 10,
|
|
320
|
+
layout: BufferLayout.struct<VoteInstructionInputData['AuthorizeWithSeed']>([
|
|
321
|
+
BufferLayout.u32('instruction'),
|
|
322
|
+
Layout.voteAuthorizeWithSeedArgs(),
|
|
323
|
+
]),
|
|
324
|
+
},
|
|
261
325
|
});
|
|
262
326
|
|
|
263
327
|
/**
|
|
@@ -390,6 +454,49 @@ export class VoteProgram {
|
|
|
390
454
|
});
|
|
391
455
|
}
|
|
392
456
|
|
|
457
|
+
/**
|
|
458
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
|
|
459
|
+
* where the current Voter or Withdrawer authority is a derived key.
|
|
460
|
+
*/
|
|
461
|
+
static authorizeWithSeed(params: AuthorizeVoteWithSeedParams): Transaction {
|
|
462
|
+
const {
|
|
463
|
+
currentAuthorityDerivedKeyBasePubkey,
|
|
464
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
465
|
+
currentAuthorityDerivedKeySeed,
|
|
466
|
+
newAuthorizedPubkey,
|
|
467
|
+
voteAuthorizationType,
|
|
468
|
+
votePubkey,
|
|
469
|
+
} = params;
|
|
470
|
+
|
|
471
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
472
|
+
const data = encodeData(type, {
|
|
473
|
+
voteAuthorizeWithSeedArgs: {
|
|
474
|
+
currentAuthorityDerivedKeyOwnerPubkey: toBuffer(
|
|
475
|
+
currentAuthorityDerivedKeyOwnerPubkey.toBuffer(),
|
|
476
|
+
),
|
|
477
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
478
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
479
|
+
voteAuthorizationType: voteAuthorizationType.index,
|
|
480
|
+
},
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
const keys = [
|
|
484
|
+
{pubkey: votePubkey, isSigner: false, isWritable: true},
|
|
485
|
+
{pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false},
|
|
486
|
+
{
|
|
487
|
+
pubkey: currentAuthorityDerivedKeyBasePubkey,
|
|
488
|
+
isSigner: true,
|
|
489
|
+
isWritable: false,
|
|
490
|
+
},
|
|
491
|
+
];
|
|
492
|
+
|
|
493
|
+
return new Transaction().add({
|
|
494
|
+
keys,
|
|
495
|
+
programId: this.programId,
|
|
496
|
+
data,
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
|
|
393
500
|
/**
|
|
394
501
|
* Generate a transaction to withdraw from a Vote account.
|
|
395
502
|
*/
|