@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/lib/index.d.ts
CHANGED
|
@@ -1402,6 +1402,17 @@ declare module '@solana/web3.js' {
|
|
|
1402
1402
|
newAuthorizedPubkey: PublicKey;
|
|
1403
1403
|
voteAuthorizationType: VoteAuthorizationType;
|
|
1404
1404
|
};
|
|
1405
|
+
/**
|
|
1406
|
+
* AuthorizeWithSeed instruction params
|
|
1407
|
+
*/
|
|
1408
|
+
export type AuthorizeVoteWithSeedParams = {
|
|
1409
|
+
currentAuthorityDerivedKeyBasePubkey: PublicKey;
|
|
1410
|
+
currentAuthorityDerivedKeyOwnerPubkey: PublicKey;
|
|
1411
|
+
currentAuthorityDerivedKeySeed: string;
|
|
1412
|
+
newAuthorizedPubkey: PublicKey;
|
|
1413
|
+
voteAuthorizationType: VoteAuthorizationType;
|
|
1414
|
+
votePubkey: PublicKey;
|
|
1415
|
+
};
|
|
1405
1416
|
/**
|
|
1406
1417
|
* Withdraw from vote account transaction params
|
|
1407
1418
|
*/
|
|
@@ -1433,6 +1444,12 @@ declare module '@solana/web3.js' {
|
|
|
1433
1444
|
static decodeAuthorize(
|
|
1434
1445
|
instruction: TransactionInstruction,
|
|
1435
1446
|
): AuthorizeVoteParams;
|
|
1447
|
+
/**
|
|
1448
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
1449
|
+
*/
|
|
1450
|
+
static decodeAuthorizeWithSeed(
|
|
1451
|
+
instruction: TransactionInstruction,
|
|
1452
|
+
): AuthorizeVoteWithSeedParams;
|
|
1436
1453
|
/**
|
|
1437
1454
|
* Decode a withdraw instruction and retrieve the instruction params.
|
|
1438
1455
|
*/
|
|
@@ -1445,6 +1462,7 @@ declare module '@solana/web3.js' {
|
|
|
1445
1462
|
*/
|
|
1446
1463
|
export type VoteInstructionType =
|
|
1447
1464
|
| 'Authorize'
|
|
1465
|
+
| 'AuthorizeWithSeed'
|
|
1448
1466
|
| 'InitializeAccount'
|
|
1449
1467
|
| 'Withdraw';
|
|
1450
1468
|
/**
|
|
@@ -1495,6 +1513,11 @@ declare module '@solana/web3.js' {
|
|
|
1495
1513
|
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account.
|
|
1496
1514
|
*/
|
|
1497
1515
|
static authorize(params: AuthorizeVoteParams): Transaction;
|
|
1516
|
+
/**
|
|
1517
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
|
|
1518
|
+
* where the current Voter or Withdrawer authority is a derived key.
|
|
1519
|
+
*/
|
|
1520
|
+
static authorizeWithSeed(params: AuthorizeVoteWithSeedParams): Transaction;
|
|
1498
1521
|
/**
|
|
1499
1522
|
* Generate a transaction to withdraw from a Vote account.
|
|
1500
1523
|
*/
|
package/lib/index.esm.js
CHANGED
|
@@ -14,7 +14,7 @@ import RpcClient from 'jayson/lib/client/browser';
|
|
|
14
14
|
import http from 'http';
|
|
15
15
|
import https from 'https';
|
|
16
16
|
import * as nodeFetch from 'node-fetch';
|
|
17
|
-
import
|
|
17
|
+
import { keccak_256 } from '@noble/hashes/sha3';
|
|
18
18
|
import { hmac } from '@noble/hashes/hmac';
|
|
19
19
|
import * as secp256k1 from '@noble/secp256k1';
|
|
20
20
|
|
|
@@ -489,7 +489,6 @@ class MessageAccountKeys {
|
|
|
489
489
|
/**
|
|
490
490
|
* Layout for a public key
|
|
491
491
|
*/
|
|
492
|
-
|
|
493
492
|
const publicKey = (property = 'publicKey') => {
|
|
494
493
|
return BufferLayout.blob(32, property);
|
|
495
494
|
};
|
|
@@ -553,6 +552,13 @@ const lockup = (property = 'lockup') => {
|
|
|
553
552
|
const voteInit = (property = 'voteInit') => {
|
|
554
553
|
return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
|
|
555
554
|
};
|
|
555
|
+
/**
|
|
556
|
+
* Layout for a VoteAuthorizeWithSeedArgs object
|
|
557
|
+
*/
|
|
558
|
+
|
|
559
|
+
const voteAuthorizeWithSeedArgs = (property = 'voteAuthorizeWithSeedArgs') => {
|
|
560
|
+
return BufferLayout.struct([BufferLayout.u32('voteAuthorizationType'), publicKey('currentAuthorityDerivedKeyOwnerPubkey'), rustString('currentAuthorityDerivedKeySeed'), publicKey('newAuthorized')], property);
|
|
561
|
+
};
|
|
556
562
|
function getAlloc(type, fields) {
|
|
557
563
|
const getItemAlloc = item => {
|
|
558
564
|
if (item.span >= 0) {
|
|
@@ -565,6 +571,11 @@ function getAlloc(type, fields) {
|
|
|
565
571
|
if (Array.isArray(field)) {
|
|
566
572
|
return field.length * getItemAlloc(item.elementLayout);
|
|
567
573
|
}
|
|
574
|
+
} else if ('fields' in item) {
|
|
575
|
+
// This is a `Structure` whose size needs to be recursively measured.
|
|
576
|
+
return getAlloc({
|
|
577
|
+
layout: item
|
|
578
|
+
}, fields[item.property]);
|
|
568
579
|
} // Couldn't determine allocated size of layout
|
|
569
580
|
|
|
570
581
|
|
|
@@ -8096,7 +8107,7 @@ class Secp256k1Program {
|
|
|
8096
8107
|
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
8097
8108
|
|
|
8098
8109
|
try {
|
|
8099
|
-
return Buffer.from(
|
|
8110
|
+
return Buffer.from(keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8100
8111
|
} catch (error) {
|
|
8101
8112
|
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
8102
8113
|
}
|
|
@@ -8196,7 +8207,7 @@ class Secp256k1Program {
|
|
|
8196
8207
|
/* isCompressed */
|
|
8197
8208
|
).slice(1); // throw away leading byte
|
|
8198
8209
|
|
|
8199
|
-
const messageHash = Buffer.from(
|
|
8210
|
+
const messageHash = Buffer.from(keccak_256(toBuffer(message)));
|
|
8200
8211
|
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
8201
8212
|
return this.createInstructionWithPublicKey({
|
|
8202
8213
|
publicKey,
|
|
@@ -9090,6 +9101,33 @@ class VoteInstruction {
|
|
|
9090
9101
|
}
|
|
9091
9102
|
};
|
|
9092
9103
|
}
|
|
9104
|
+
/**
|
|
9105
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
9106
|
+
*/
|
|
9107
|
+
|
|
9108
|
+
|
|
9109
|
+
static decodeAuthorizeWithSeed(instruction) {
|
|
9110
|
+
this.checkProgramId(instruction.programId);
|
|
9111
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
9112
|
+
const {
|
|
9113
|
+
voteAuthorizeWithSeedArgs: {
|
|
9114
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9115
|
+
currentAuthorityDerivedKeySeed,
|
|
9116
|
+
newAuthorized,
|
|
9117
|
+
voteAuthorizationType
|
|
9118
|
+
}
|
|
9119
|
+
} = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
|
|
9120
|
+
return {
|
|
9121
|
+
currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
|
|
9122
|
+
currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
|
|
9123
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9124
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
9125
|
+
voteAuthorizationType: {
|
|
9126
|
+
index: voteAuthorizationType
|
|
9127
|
+
},
|
|
9128
|
+
votePubkey: instruction.keys[0].pubkey
|
|
9129
|
+
};
|
|
9130
|
+
}
|
|
9093
9131
|
/**
|
|
9094
9132
|
* Decode a withdraw instruction and retrieve the instruction params.
|
|
9095
9133
|
*/
|
|
@@ -9146,6 +9184,10 @@ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
|
9146
9184
|
Withdraw: {
|
|
9147
9185
|
index: 3,
|
|
9148
9186
|
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
9187
|
+
},
|
|
9188
|
+
AuthorizeWithSeed: {
|
|
9189
|
+
index: 10,
|
|
9190
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteAuthorizeWithSeedArgs()])
|
|
9149
9191
|
}
|
|
9150
9192
|
});
|
|
9151
9193
|
/**
|
|
@@ -9274,6 +9316,49 @@ class VoteProgram {
|
|
|
9274
9316
|
data
|
|
9275
9317
|
});
|
|
9276
9318
|
}
|
|
9319
|
+
/**
|
|
9320
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
|
|
9321
|
+
* where the current Voter or Withdrawer authority is a derived key.
|
|
9322
|
+
*/
|
|
9323
|
+
|
|
9324
|
+
|
|
9325
|
+
static authorizeWithSeed(params) {
|
|
9326
|
+
const {
|
|
9327
|
+
currentAuthorityDerivedKeyBasePubkey,
|
|
9328
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9329
|
+
currentAuthorityDerivedKeySeed,
|
|
9330
|
+
newAuthorizedPubkey,
|
|
9331
|
+
voteAuthorizationType,
|
|
9332
|
+
votePubkey
|
|
9333
|
+
} = params;
|
|
9334
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
9335
|
+
const data = encodeData(type, {
|
|
9336
|
+
voteAuthorizeWithSeedArgs: {
|
|
9337
|
+
currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
|
|
9338
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9339
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
9340
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
9341
|
+
}
|
|
9342
|
+
});
|
|
9343
|
+
const keys = [{
|
|
9344
|
+
pubkey: votePubkey,
|
|
9345
|
+
isSigner: false,
|
|
9346
|
+
isWritable: true
|
|
9347
|
+
}, {
|
|
9348
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
9349
|
+
isSigner: false,
|
|
9350
|
+
isWritable: false
|
|
9351
|
+
}, {
|
|
9352
|
+
pubkey: currentAuthorityDerivedKeyBasePubkey,
|
|
9353
|
+
isSigner: true,
|
|
9354
|
+
isWritable: false
|
|
9355
|
+
}];
|
|
9356
|
+
return new Transaction().add({
|
|
9357
|
+
keys,
|
|
9358
|
+
programId: this.programId,
|
|
9359
|
+
data
|
|
9360
|
+
});
|
|
9361
|
+
}
|
|
9277
9362
|
/**
|
|
9278
9363
|
* Generate a transaction to withdraw from a Vote account.
|
|
9279
9364
|
*/
|