@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.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
|
|
|
@@ -8033,7 +8044,7 @@ class Secp256k1Program {
|
|
|
8033
8044
|
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
8034
8045
|
|
|
8035
8046
|
try {
|
|
8036
|
-
return Buffer.from(
|
|
8047
|
+
return Buffer.from(keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8037
8048
|
} catch (error) {
|
|
8038
8049
|
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
8039
8050
|
}
|
|
@@ -8133,7 +8144,7 @@ class Secp256k1Program {
|
|
|
8133
8144
|
/* isCompressed */
|
|
8134
8145
|
).slice(1); // throw away leading byte
|
|
8135
8146
|
|
|
8136
|
-
const messageHash = Buffer.from(
|
|
8147
|
+
const messageHash = Buffer.from(keccak_256(toBuffer(message)));
|
|
8137
8148
|
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
8138
8149
|
return this.createInstructionWithPublicKey({
|
|
8139
8150
|
publicKey,
|
|
@@ -9027,6 +9038,33 @@ class VoteInstruction {
|
|
|
9027
9038
|
}
|
|
9028
9039
|
};
|
|
9029
9040
|
}
|
|
9041
|
+
/**
|
|
9042
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
9043
|
+
*/
|
|
9044
|
+
|
|
9045
|
+
|
|
9046
|
+
static decodeAuthorizeWithSeed(instruction) {
|
|
9047
|
+
this.checkProgramId(instruction.programId);
|
|
9048
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
9049
|
+
const {
|
|
9050
|
+
voteAuthorizeWithSeedArgs: {
|
|
9051
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9052
|
+
currentAuthorityDerivedKeySeed,
|
|
9053
|
+
newAuthorized,
|
|
9054
|
+
voteAuthorizationType
|
|
9055
|
+
}
|
|
9056
|
+
} = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
|
|
9057
|
+
return {
|
|
9058
|
+
currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
|
|
9059
|
+
currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
|
|
9060
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9061
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
9062
|
+
voteAuthorizationType: {
|
|
9063
|
+
index: voteAuthorizationType
|
|
9064
|
+
},
|
|
9065
|
+
votePubkey: instruction.keys[0].pubkey
|
|
9066
|
+
};
|
|
9067
|
+
}
|
|
9030
9068
|
/**
|
|
9031
9069
|
* Decode a withdraw instruction and retrieve the instruction params.
|
|
9032
9070
|
*/
|
|
@@ -9083,6 +9121,10 @@ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
|
9083
9121
|
Withdraw: {
|
|
9084
9122
|
index: 3,
|
|
9085
9123
|
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
9124
|
+
},
|
|
9125
|
+
AuthorizeWithSeed: {
|
|
9126
|
+
index: 10,
|
|
9127
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteAuthorizeWithSeedArgs()])
|
|
9086
9128
|
}
|
|
9087
9129
|
});
|
|
9088
9130
|
/**
|
|
@@ -9211,6 +9253,49 @@ class VoteProgram {
|
|
|
9211
9253
|
data
|
|
9212
9254
|
});
|
|
9213
9255
|
}
|
|
9256
|
+
/**
|
|
9257
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
|
|
9258
|
+
* where the current Voter or Withdrawer authority is a derived key.
|
|
9259
|
+
*/
|
|
9260
|
+
|
|
9261
|
+
|
|
9262
|
+
static authorizeWithSeed(params) {
|
|
9263
|
+
const {
|
|
9264
|
+
currentAuthorityDerivedKeyBasePubkey,
|
|
9265
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9266
|
+
currentAuthorityDerivedKeySeed,
|
|
9267
|
+
newAuthorizedPubkey,
|
|
9268
|
+
voteAuthorizationType,
|
|
9269
|
+
votePubkey
|
|
9270
|
+
} = params;
|
|
9271
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
9272
|
+
const data = encodeData(type, {
|
|
9273
|
+
voteAuthorizeWithSeedArgs: {
|
|
9274
|
+
currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
|
|
9275
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9276
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
9277
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
9278
|
+
}
|
|
9279
|
+
});
|
|
9280
|
+
const keys = [{
|
|
9281
|
+
pubkey: votePubkey,
|
|
9282
|
+
isSigner: false,
|
|
9283
|
+
isWritable: true
|
|
9284
|
+
}, {
|
|
9285
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
9286
|
+
isSigner: false,
|
|
9287
|
+
isWritable: false
|
|
9288
|
+
}, {
|
|
9289
|
+
pubkey: currentAuthorityDerivedKeyBasePubkey,
|
|
9290
|
+
isSigner: true,
|
|
9291
|
+
isWritable: false
|
|
9292
|
+
}];
|
|
9293
|
+
return new Transaction().add({
|
|
9294
|
+
keys,
|
|
9295
|
+
programId: this.programId,
|
|
9296
|
+
data
|
|
9297
|
+
});
|
|
9298
|
+
}
|
|
9214
9299
|
/**
|
|
9215
9300
|
* Generate a transaction to withdraw from a Vote account.
|
|
9216
9301
|
*/
|