@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.
@@ -14,7 +14,7 @@ var bigintBuffer = require('bigint-buffer');
14
14
  var superstruct = require('superstruct');
15
15
  var rpcWebsockets = require('rpc-websockets');
16
16
  var RpcClient = require('jayson/lib/client/browser');
17
- var sha3 = require('js-sha3');
17
+ var sha3 = require('@noble/hashes/sha3');
18
18
  var hmac = require('@noble/hashes/hmac');
19
19
  var secp256k1 = require('@noble/secp256k1');
20
20
 
@@ -43,7 +43,6 @@ var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
43
43
  var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
44
44
  var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
45
45
  var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
46
- var sha3__default = /*#__PURE__*/_interopDefaultLegacy(sha3);
47
46
  var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
48
47
 
49
48
  /**
@@ -517,7 +516,6 @@ class MessageAccountKeys {
517
516
  /**
518
517
  * Layout for a public key
519
518
  */
520
-
521
519
  const publicKey = (property = 'publicKey') => {
522
520
  return BufferLayout__namespace.blob(32, property);
523
521
  };
@@ -581,6 +579,13 @@ const lockup = (property = 'lockup') => {
581
579
  const voteInit = (property = 'voteInit') => {
582
580
  return BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission')], property);
583
581
  };
582
+ /**
583
+ * Layout for a VoteAuthorizeWithSeedArgs object
584
+ */
585
+
586
+ const voteAuthorizeWithSeedArgs = (property = 'voteAuthorizeWithSeedArgs') => {
587
+ return BufferLayout__namespace.struct([BufferLayout__namespace.u32('voteAuthorizationType'), publicKey('currentAuthorityDerivedKeyOwnerPubkey'), rustString('currentAuthorityDerivedKeySeed'), publicKey('newAuthorized')], property);
588
+ };
584
589
  function getAlloc(type, fields) {
585
590
  const getItemAlloc = item => {
586
591
  if (item.span >= 0) {
@@ -593,6 +598,11 @@ function getAlloc(type, fields) {
593
598
  if (Array.isArray(field)) {
594
599
  return field.length * getItemAlloc(item.elementLayout);
595
600
  }
601
+ } else if ('fields' in item) {
602
+ // This is a `Structure` whose size needs to be recursively measured.
603
+ return getAlloc({
604
+ layout: item
605
+ }, fields[item.property]);
596
606
  } // Couldn't determine allocated size of layout
597
607
 
598
608
 
@@ -8064,7 +8074,7 @@ class Secp256k1Program {
8064
8074
  assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
8065
8075
 
8066
8076
  try {
8067
- return buffer.Buffer.from(sha3__default["default"].keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
8077
+ return buffer.Buffer.from(sha3.keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
8068
8078
  } catch (error) {
8069
8079
  throw new Error(`Error constructing Ethereum address: ${error}`);
8070
8080
  }
@@ -8164,7 +8174,7 @@ class Secp256k1Program {
8164
8174
  /* isCompressed */
8165
8175
  ).slice(1); // throw away leading byte
8166
8176
 
8167
- const messageHash = buffer.Buffer.from(sha3__default["default"].keccak_256.update(toBuffer(message)).digest());
8177
+ const messageHash = buffer.Buffer.from(sha3.keccak_256(toBuffer(message)));
8168
8178
  const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
8169
8179
  return this.createInstructionWithPublicKey({
8170
8180
  publicKey,
@@ -9058,6 +9068,33 @@ class VoteInstruction {
9058
9068
  }
9059
9069
  };
9060
9070
  }
9071
+ /**
9072
+ * Decode an authorize instruction and retrieve the instruction params.
9073
+ */
9074
+
9075
+
9076
+ static decodeAuthorizeWithSeed(instruction) {
9077
+ this.checkProgramId(instruction.programId);
9078
+ this.checkKeyLength(instruction.keys, 3);
9079
+ const {
9080
+ voteAuthorizeWithSeedArgs: {
9081
+ currentAuthorityDerivedKeyOwnerPubkey,
9082
+ currentAuthorityDerivedKeySeed,
9083
+ newAuthorized,
9084
+ voteAuthorizationType
9085
+ }
9086
+ } = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
9087
+ return {
9088
+ currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
9089
+ currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
9090
+ currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
9091
+ newAuthorizedPubkey: new PublicKey(newAuthorized),
9092
+ voteAuthorizationType: {
9093
+ index: voteAuthorizationType
9094
+ },
9095
+ votePubkey: instruction.keys[0].pubkey
9096
+ };
9097
+ }
9061
9098
  /**
9062
9099
  * Decode a withdraw instruction and retrieve the instruction params.
9063
9100
  */
@@ -9114,6 +9151,10 @@ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
9114
9151
  Withdraw: {
9115
9152
  index: 3,
9116
9153
  layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), BufferLayout__namespace.ns64('lamports')])
9154
+ },
9155
+ AuthorizeWithSeed: {
9156
+ index: 10,
9157
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), voteAuthorizeWithSeedArgs()])
9117
9158
  }
9118
9159
  });
9119
9160
  /**
@@ -9242,6 +9283,49 @@ class VoteProgram {
9242
9283
  data
9243
9284
  });
9244
9285
  }
9286
+ /**
9287
+ * Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
9288
+ * where the current Voter or Withdrawer authority is a derived key.
9289
+ */
9290
+
9291
+
9292
+ static authorizeWithSeed(params) {
9293
+ const {
9294
+ currentAuthorityDerivedKeyBasePubkey,
9295
+ currentAuthorityDerivedKeyOwnerPubkey,
9296
+ currentAuthorityDerivedKeySeed,
9297
+ newAuthorizedPubkey,
9298
+ voteAuthorizationType,
9299
+ votePubkey
9300
+ } = params;
9301
+ const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
9302
+ const data = encodeData(type, {
9303
+ voteAuthorizeWithSeedArgs: {
9304
+ currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
9305
+ currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
9306
+ newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
9307
+ voteAuthorizationType: voteAuthorizationType.index
9308
+ }
9309
+ });
9310
+ const keys = [{
9311
+ pubkey: votePubkey,
9312
+ isSigner: false,
9313
+ isWritable: true
9314
+ }, {
9315
+ pubkey: SYSVAR_CLOCK_PUBKEY,
9316
+ isSigner: false,
9317
+ isWritable: false
9318
+ }, {
9319
+ pubkey: currentAuthorityDerivedKeyBasePubkey,
9320
+ isSigner: true,
9321
+ isWritable: false
9322
+ }];
9323
+ return new Transaction().add({
9324
+ keys,
9325
+ programId: this.programId,
9326
+ data
9327
+ });
9328
+ }
9245
9329
  /**
9246
9330
  * Generate a transaction to withdraw from a Vote account.
9247
9331
  */