@solana/web3.js 1.58.0 → 1.60.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 +103 -24
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +103 -23
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +103 -24
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +27 -2
- package/lib/index.esm.js +103 -23
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +357 -722
- 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 +103 -24
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -2
- package/src/connection.ts +5 -0
- package/src/keypair.ts +1 -1
- package/src/layout.ts +22 -0
- package/src/programs/secp256k1.ts +5 -7
- package/src/programs/vote.ts +109 -2
- package/src/transaction/message.ts +15 -24
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
|
*/
|
|
@@ -1824,7 +1847,7 @@ declare module '@solana/web3.js' {
|
|
|
1824
1847
|
}
|
|
1825
1848
|
|
|
1826
1849
|
export type TransactionMessageArgs = {
|
|
1827
|
-
|
|
1850
|
+
payerKey: PublicKey;
|
|
1828
1851
|
instructions: Array<TransactionInstruction>;
|
|
1829
1852
|
recentBlockhash: Blockhash;
|
|
1830
1853
|
};
|
|
@@ -1836,7 +1859,7 @@ declare module '@solana/web3.js' {
|
|
|
1836
1859
|
addressLookupTableAccounts: AddressLookupTableAccount[];
|
|
1837
1860
|
};
|
|
1838
1861
|
export class TransactionMessage {
|
|
1839
|
-
|
|
1862
|
+
payerKey: PublicKey;
|
|
1840
1863
|
instructions: Array<TransactionInstruction>;
|
|
1841
1864
|
recentBlockhash: Blockhash;
|
|
1842
1865
|
constructor(args: TransactionMessageArgs);
|
|
@@ -2409,6 +2432,8 @@ declare module '@solana/web3.js' {
|
|
|
2409
2432
|
signer: boolean;
|
|
2410
2433
|
/** Indicates if the account is writable for this transaction */
|
|
2411
2434
|
writable: boolean;
|
|
2435
|
+
/** Indicates if the account key came from the transaction or a lookup table */
|
|
2436
|
+
source?: 'transaction' | 'lookupTable';
|
|
2412
2437
|
};
|
|
2413
2438
|
/**
|
|
2414
2439
|
* A parsed transaction instruction
|
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
|
|
|
@@ -1934,10 +1945,10 @@ class Transaction {
|
|
|
1934
1945
|
|
|
1935
1946
|
class TransactionMessage {
|
|
1936
1947
|
constructor(args) {
|
|
1937
|
-
this.
|
|
1948
|
+
this.payerKey = void 0;
|
|
1938
1949
|
this.instructions = void 0;
|
|
1939
1950
|
this.recentBlockhash = void 0;
|
|
1940
|
-
this.
|
|
1951
|
+
this.payerKey = args.payerKey;
|
|
1941
1952
|
this.instructions = args.instructions;
|
|
1942
1953
|
this.recentBlockhash = args.recentBlockhash;
|
|
1943
1954
|
}
|
|
@@ -1958,6 +1969,12 @@ class TransactionMessage {
|
|
|
1958
1969
|
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
1959
1970
|
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
1960
1971
|
const accountKeys = message.getAccountKeys(args);
|
|
1972
|
+
const payerKey = accountKeys.get(0);
|
|
1973
|
+
|
|
1974
|
+
if (payerKey === undefined) {
|
|
1975
|
+
throw new Error('Failed to decompile message because no account keys were found');
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1961
1978
|
const instructions = [];
|
|
1962
1979
|
|
|
1963
1980
|
for (const compiledIx of compiledInstructions) {
|
|
@@ -2003,35 +2020,23 @@ class TransactionMessage {
|
|
|
2003
2020
|
}
|
|
2004
2021
|
|
|
2005
2022
|
return new TransactionMessage({
|
|
2006
|
-
|
|
2023
|
+
payerKey,
|
|
2007
2024
|
instructions,
|
|
2008
2025
|
recentBlockhash
|
|
2009
2026
|
});
|
|
2010
2027
|
}
|
|
2011
2028
|
|
|
2012
2029
|
compileToLegacyMessage() {
|
|
2013
|
-
const payerKey = this.accountKeys.get(0);
|
|
2014
|
-
|
|
2015
|
-
if (payerKey === undefined) {
|
|
2016
|
-
throw new Error('Failed to compile message because no account keys were found');
|
|
2017
|
-
}
|
|
2018
|
-
|
|
2019
2030
|
return Message.compile({
|
|
2020
|
-
payerKey,
|
|
2031
|
+
payerKey: this.payerKey,
|
|
2021
2032
|
recentBlockhash: this.recentBlockhash,
|
|
2022
2033
|
instructions: this.instructions
|
|
2023
2034
|
});
|
|
2024
2035
|
}
|
|
2025
2036
|
|
|
2026
2037
|
compileToV0Message(addressLookupTableAccounts) {
|
|
2027
|
-
const payerKey = this.accountKeys.get(0);
|
|
2028
|
-
|
|
2029
|
-
if (payerKey === undefined) {
|
|
2030
|
-
throw new Error('Failed to compile message because no account keys were found');
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
2038
|
return MessageV0.compile({
|
|
2034
|
-
payerKey,
|
|
2039
|
+
payerKey: this.payerKey,
|
|
2035
2040
|
recentBlockhash: this.recentBlockhash,
|
|
2036
2041
|
instructions: this.instructions,
|
|
2037
2042
|
addressLookupTableAccounts
|
|
@@ -4327,7 +4332,8 @@ const ParsedConfirmedTransactionResult = type({
|
|
|
4327
4332
|
accountKeys: array(type({
|
|
4328
4333
|
pubkey: PublicKeyFromString,
|
|
4329
4334
|
signer: boolean(),
|
|
4330
|
-
writable: boolean()
|
|
4335
|
+
writable: boolean(),
|
|
4336
|
+
source: optional(union([literal('transaction'), literal('lookupTable')]))
|
|
4331
4337
|
})),
|
|
4332
4338
|
instructions: array(ParsedOrRawInstruction),
|
|
4333
4339
|
recentBlockhash: string(),
|
|
@@ -7503,7 +7509,7 @@ class Keypair {
|
|
|
7503
7509
|
|
|
7504
7510
|
|
|
7505
7511
|
get secretKey() {
|
|
7506
|
-
return this._keypair.secretKey;
|
|
7512
|
+
return new Uint8Array(this._keypair.secretKey);
|
|
7507
7513
|
}
|
|
7508
7514
|
|
|
7509
7515
|
}
|
|
@@ -8096,7 +8102,7 @@ class Secp256k1Program {
|
|
|
8096
8102
|
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
8097
8103
|
|
|
8098
8104
|
try {
|
|
8099
|
-
return Buffer.from(
|
|
8105
|
+
return Buffer.from(keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8100
8106
|
} catch (error) {
|
|
8101
8107
|
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
8102
8108
|
}
|
|
@@ -8196,7 +8202,7 @@ class Secp256k1Program {
|
|
|
8196
8202
|
/* isCompressed */
|
|
8197
8203
|
).slice(1); // throw away leading byte
|
|
8198
8204
|
|
|
8199
|
-
const messageHash = Buffer.from(
|
|
8205
|
+
const messageHash = Buffer.from(keccak_256(toBuffer(message)));
|
|
8200
8206
|
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
8201
8207
|
return this.createInstructionWithPublicKey({
|
|
8202
8208
|
publicKey,
|
|
@@ -9090,6 +9096,33 @@ class VoteInstruction {
|
|
|
9090
9096
|
}
|
|
9091
9097
|
};
|
|
9092
9098
|
}
|
|
9099
|
+
/**
|
|
9100
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
9101
|
+
*/
|
|
9102
|
+
|
|
9103
|
+
|
|
9104
|
+
static decodeAuthorizeWithSeed(instruction) {
|
|
9105
|
+
this.checkProgramId(instruction.programId);
|
|
9106
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
9107
|
+
const {
|
|
9108
|
+
voteAuthorizeWithSeedArgs: {
|
|
9109
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9110
|
+
currentAuthorityDerivedKeySeed,
|
|
9111
|
+
newAuthorized,
|
|
9112
|
+
voteAuthorizationType
|
|
9113
|
+
}
|
|
9114
|
+
} = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
|
|
9115
|
+
return {
|
|
9116
|
+
currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
|
|
9117
|
+
currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
|
|
9118
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9119
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
9120
|
+
voteAuthorizationType: {
|
|
9121
|
+
index: voteAuthorizationType
|
|
9122
|
+
},
|
|
9123
|
+
votePubkey: instruction.keys[0].pubkey
|
|
9124
|
+
};
|
|
9125
|
+
}
|
|
9093
9126
|
/**
|
|
9094
9127
|
* Decode a withdraw instruction and retrieve the instruction params.
|
|
9095
9128
|
*/
|
|
@@ -9146,6 +9179,10 @@ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
|
9146
9179
|
Withdraw: {
|
|
9147
9180
|
index: 3,
|
|
9148
9181
|
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
9182
|
+
},
|
|
9183
|
+
AuthorizeWithSeed: {
|
|
9184
|
+
index: 10,
|
|
9185
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteAuthorizeWithSeedArgs()])
|
|
9149
9186
|
}
|
|
9150
9187
|
});
|
|
9151
9188
|
/**
|
|
@@ -9274,6 +9311,49 @@ class VoteProgram {
|
|
|
9274
9311
|
data
|
|
9275
9312
|
});
|
|
9276
9313
|
}
|
|
9314
|
+
/**
|
|
9315
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
|
|
9316
|
+
* where the current Voter or Withdrawer authority is a derived key.
|
|
9317
|
+
*/
|
|
9318
|
+
|
|
9319
|
+
|
|
9320
|
+
static authorizeWithSeed(params) {
|
|
9321
|
+
const {
|
|
9322
|
+
currentAuthorityDerivedKeyBasePubkey,
|
|
9323
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9324
|
+
currentAuthorityDerivedKeySeed,
|
|
9325
|
+
newAuthorizedPubkey,
|
|
9326
|
+
voteAuthorizationType,
|
|
9327
|
+
votePubkey
|
|
9328
|
+
} = params;
|
|
9329
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
9330
|
+
const data = encodeData(type, {
|
|
9331
|
+
voteAuthorizeWithSeedArgs: {
|
|
9332
|
+
currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
|
|
9333
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9334
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
9335
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
9336
|
+
}
|
|
9337
|
+
});
|
|
9338
|
+
const keys = [{
|
|
9339
|
+
pubkey: votePubkey,
|
|
9340
|
+
isSigner: false,
|
|
9341
|
+
isWritable: true
|
|
9342
|
+
}, {
|
|
9343
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
9344
|
+
isSigner: false,
|
|
9345
|
+
isWritable: false
|
|
9346
|
+
}, {
|
|
9347
|
+
pubkey: currentAuthorityDerivedKeyBasePubkey,
|
|
9348
|
+
isSigner: true,
|
|
9349
|
+
isWritable: false
|
|
9350
|
+
}];
|
|
9351
|
+
return new Transaction().add({
|
|
9352
|
+
keys,
|
|
9353
|
+
programId: this.programId,
|
|
9354
|
+
data
|
|
9355
|
+
});
|
|
9356
|
+
}
|
|
9277
9357
|
/**
|
|
9278
9358
|
* Generate a transaction to withdraw from a Vote account.
|
|
9279
9359
|
*/
|