@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.browser.esm.js
CHANGED
|
@@ -11,7 +11,7 @@ import { toBigIntLE, toBufferLE } from 'bigint-buffer';
|
|
|
11
11
|
import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$1 } from 'superstruct';
|
|
12
12
|
import { Client } from 'rpc-websockets';
|
|
13
13
|
import RpcClient from 'jayson/lib/client/browser';
|
|
14
|
-
import
|
|
14
|
+
import { keccak_256 } from '@noble/hashes/sha3';
|
|
15
15
|
import { hmac } from '@noble/hashes/hmac';
|
|
16
16
|
import * as secp256k1 from '@noble/secp256k1';
|
|
17
17
|
|
|
@@ -486,7 +486,6 @@ class MessageAccountKeys {
|
|
|
486
486
|
/**
|
|
487
487
|
* Layout for a public key
|
|
488
488
|
*/
|
|
489
|
-
|
|
490
489
|
const publicKey = (property = 'publicKey') => {
|
|
491
490
|
return BufferLayout.blob(32, property);
|
|
492
491
|
};
|
|
@@ -550,6 +549,13 @@ const lockup = (property = 'lockup') => {
|
|
|
550
549
|
const voteInit = (property = 'voteInit') => {
|
|
551
550
|
return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
|
|
552
551
|
};
|
|
552
|
+
/**
|
|
553
|
+
* Layout for a VoteAuthorizeWithSeedArgs object
|
|
554
|
+
*/
|
|
555
|
+
|
|
556
|
+
const voteAuthorizeWithSeedArgs = (property = 'voteAuthorizeWithSeedArgs') => {
|
|
557
|
+
return BufferLayout.struct([BufferLayout.u32('voteAuthorizationType'), publicKey('currentAuthorityDerivedKeyOwnerPubkey'), rustString('currentAuthorityDerivedKeySeed'), publicKey('newAuthorized')], property);
|
|
558
|
+
};
|
|
553
559
|
function getAlloc(type, fields) {
|
|
554
560
|
const getItemAlloc = item => {
|
|
555
561
|
if (item.span >= 0) {
|
|
@@ -562,6 +568,11 @@ function getAlloc(type, fields) {
|
|
|
562
568
|
if (Array.isArray(field)) {
|
|
563
569
|
return field.length * getItemAlloc(item.elementLayout);
|
|
564
570
|
}
|
|
571
|
+
} else if ('fields' in item) {
|
|
572
|
+
// This is a `Structure` whose size needs to be recursively measured.
|
|
573
|
+
return getAlloc({
|
|
574
|
+
layout: item
|
|
575
|
+
}, fields[item.property]);
|
|
565
576
|
} // Couldn't determine allocated size of layout
|
|
566
577
|
|
|
567
578
|
|
|
@@ -1931,10 +1942,10 @@ class Transaction {
|
|
|
1931
1942
|
|
|
1932
1943
|
class TransactionMessage {
|
|
1933
1944
|
constructor(args) {
|
|
1934
|
-
this.
|
|
1945
|
+
this.payerKey = void 0;
|
|
1935
1946
|
this.instructions = void 0;
|
|
1936
1947
|
this.recentBlockhash = void 0;
|
|
1937
|
-
this.
|
|
1948
|
+
this.payerKey = args.payerKey;
|
|
1938
1949
|
this.instructions = args.instructions;
|
|
1939
1950
|
this.recentBlockhash = args.recentBlockhash;
|
|
1940
1951
|
}
|
|
@@ -1955,6 +1966,12 @@ class TransactionMessage {
|
|
|
1955
1966
|
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
1956
1967
|
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
1957
1968
|
const accountKeys = message.getAccountKeys(args);
|
|
1969
|
+
const payerKey = accountKeys.get(0);
|
|
1970
|
+
|
|
1971
|
+
if (payerKey === undefined) {
|
|
1972
|
+
throw new Error('Failed to decompile message because no account keys were found');
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1958
1975
|
const instructions = [];
|
|
1959
1976
|
|
|
1960
1977
|
for (const compiledIx of compiledInstructions) {
|
|
@@ -2000,35 +2017,23 @@ class TransactionMessage {
|
|
|
2000
2017
|
}
|
|
2001
2018
|
|
|
2002
2019
|
return new TransactionMessage({
|
|
2003
|
-
|
|
2020
|
+
payerKey,
|
|
2004
2021
|
instructions,
|
|
2005
2022
|
recentBlockhash
|
|
2006
2023
|
});
|
|
2007
2024
|
}
|
|
2008
2025
|
|
|
2009
2026
|
compileToLegacyMessage() {
|
|
2010
|
-
const payerKey = this.accountKeys.get(0);
|
|
2011
|
-
|
|
2012
|
-
if (payerKey === undefined) {
|
|
2013
|
-
throw new Error('Failed to compile message because no account keys were found');
|
|
2014
|
-
}
|
|
2015
|
-
|
|
2016
2027
|
return Message.compile({
|
|
2017
|
-
payerKey,
|
|
2028
|
+
payerKey: this.payerKey,
|
|
2018
2029
|
recentBlockhash: this.recentBlockhash,
|
|
2019
2030
|
instructions: this.instructions
|
|
2020
2031
|
});
|
|
2021
2032
|
}
|
|
2022
2033
|
|
|
2023
2034
|
compileToV0Message(addressLookupTableAccounts) {
|
|
2024
|
-
const payerKey = this.accountKeys.get(0);
|
|
2025
|
-
|
|
2026
|
-
if (payerKey === undefined) {
|
|
2027
|
-
throw new Error('Failed to compile message because no account keys were found');
|
|
2028
|
-
}
|
|
2029
|
-
|
|
2030
2035
|
return MessageV0.compile({
|
|
2031
|
-
payerKey,
|
|
2036
|
+
payerKey: this.payerKey,
|
|
2032
2037
|
recentBlockhash: this.recentBlockhash,
|
|
2033
2038
|
instructions: this.instructions,
|
|
2034
2039
|
addressLookupTableAccounts
|
|
@@ -4264,7 +4269,8 @@ const ParsedConfirmedTransactionResult = type({
|
|
|
4264
4269
|
accountKeys: array(type({
|
|
4265
4270
|
pubkey: PublicKeyFromString,
|
|
4266
4271
|
signer: boolean(),
|
|
4267
|
-
writable: boolean()
|
|
4272
|
+
writable: boolean(),
|
|
4273
|
+
source: optional(union([literal('transaction'), literal('lookupTable')]))
|
|
4268
4274
|
})),
|
|
4269
4275
|
instructions: array(ParsedOrRawInstruction),
|
|
4270
4276
|
recentBlockhash: string(),
|
|
@@ -7440,7 +7446,7 @@ class Keypair {
|
|
|
7440
7446
|
|
|
7441
7447
|
|
|
7442
7448
|
get secretKey() {
|
|
7443
|
-
return this._keypair.secretKey;
|
|
7449
|
+
return new Uint8Array(this._keypair.secretKey);
|
|
7444
7450
|
}
|
|
7445
7451
|
|
|
7446
7452
|
}
|
|
@@ -8033,7 +8039,7 @@ class Secp256k1Program {
|
|
|
8033
8039
|
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
8034
8040
|
|
|
8035
8041
|
try {
|
|
8036
|
-
return Buffer.from(
|
|
8042
|
+
return Buffer.from(keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8037
8043
|
} catch (error) {
|
|
8038
8044
|
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
8039
8045
|
}
|
|
@@ -8133,7 +8139,7 @@ class Secp256k1Program {
|
|
|
8133
8139
|
/* isCompressed */
|
|
8134
8140
|
).slice(1); // throw away leading byte
|
|
8135
8141
|
|
|
8136
|
-
const messageHash = Buffer.from(
|
|
8142
|
+
const messageHash = Buffer.from(keccak_256(toBuffer(message)));
|
|
8137
8143
|
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
8138
8144
|
return this.createInstructionWithPublicKey({
|
|
8139
8145
|
publicKey,
|
|
@@ -9027,6 +9033,33 @@ class VoteInstruction {
|
|
|
9027
9033
|
}
|
|
9028
9034
|
};
|
|
9029
9035
|
}
|
|
9036
|
+
/**
|
|
9037
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
9038
|
+
*/
|
|
9039
|
+
|
|
9040
|
+
|
|
9041
|
+
static decodeAuthorizeWithSeed(instruction) {
|
|
9042
|
+
this.checkProgramId(instruction.programId);
|
|
9043
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
9044
|
+
const {
|
|
9045
|
+
voteAuthorizeWithSeedArgs: {
|
|
9046
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9047
|
+
currentAuthorityDerivedKeySeed,
|
|
9048
|
+
newAuthorized,
|
|
9049
|
+
voteAuthorizationType
|
|
9050
|
+
}
|
|
9051
|
+
} = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
|
|
9052
|
+
return {
|
|
9053
|
+
currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
|
|
9054
|
+
currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
|
|
9055
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9056
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
9057
|
+
voteAuthorizationType: {
|
|
9058
|
+
index: voteAuthorizationType
|
|
9059
|
+
},
|
|
9060
|
+
votePubkey: instruction.keys[0].pubkey
|
|
9061
|
+
};
|
|
9062
|
+
}
|
|
9030
9063
|
/**
|
|
9031
9064
|
* Decode a withdraw instruction and retrieve the instruction params.
|
|
9032
9065
|
*/
|
|
@@ -9083,6 +9116,10 @@ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
|
9083
9116
|
Withdraw: {
|
|
9084
9117
|
index: 3,
|
|
9085
9118
|
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
9119
|
+
},
|
|
9120
|
+
AuthorizeWithSeed: {
|
|
9121
|
+
index: 10,
|
|
9122
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteAuthorizeWithSeedArgs()])
|
|
9086
9123
|
}
|
|
9087
9124
|
});
|
|
9088
9125
|
/**
|
|
@@ -9211,6 +9248,49 @@ class VoteProgram {
|
|
|
9211
9248
|
data
|
|
9212
9249
|
});
|
|
9213
9250
|
}
|
|
9251
|
+
/**
|
|
9252
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
|
|
9253
|
+
* where the current Voter or Withdrawer authority is a derived key.
|
|
9254
|
+
*/
|
|
9255
|
+
|
|
9256
|
+
|
|
9257
|
+
static authorizeWithSeed(params) {
|
|
9258
|
+
const {
|
|
9259
|
+
currentAuthorityDerivedKeyBasePubkey,
|
|
9260
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9261
|
+
currentAuthorityDerivedKeySeed,
|
|
9262
|
+
newAuthorizedPubkey,
|
|
9263
|
+
voteAuthorizationType,
|
|
9264
|
+
votePubkey
|
|
9265
|
+
} = params;
|
|
9266
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
9267
|
+
const data = encodeData(type, {
|
|
9268
|
+
voteAuthorizeWithSeedArgs: {
|
|
9269
|
+
currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
|
|
9270
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9271
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
9272
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
9273
|
+
}
|
|
9274
|
+
});
|
|
9275
|
+
const keys = [{
|
|
9276
|
+
pubkey: votePubkey,
|
|
9277
|
+
isSigner: false,
|
|
9278
|
+
isWritable: true
|
|
9279
|
+
}, {
|
|
9280
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
9281
|
+
isSigner: false,
|
|
9282
|
+
isWritable: false
|
|
9283
|
+
}, {
|
|
9284
|
+
pubkey: currentAuthorityDerivedKeyBasePubkey,
|
|
9285
|
+
isSigner: true,
|
|
9286
|
+
isWritable: false
|
|
9287
|
+
}];
|
|
9288
|
+
return new Transaction().add({
|
|
9289
|
+
keys,
|
|
9290
|
+
programId: this.programId,
|
|
9291
|
+
data
|
|
9292
|
+
});
|
|
9293
|
+
}
|
|
9214
9294
|
/**
|
|
9215
9295
|
* Generate a transaction to withdraw from a Vote account.
|
|
9216
9296
|
*/
|