@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.cjs.js CHANGED
@@ -17,7 +17,7 @@ var RpcClient = require('jayson/lib/client/browser');
17
17
  var http = require('http');
18
18
  var https = require('https');
19
19
  var nodeFetch = require('node-fetch');
20
- var sha3 = require('js-sha3');
20
+ var sha3 = require('@noble/hashes/sha3');
21
21
  var hmac = require('@noble/hashes/hmac');
22
22
  var secp256k1 = require('@noble/secp256k1');
23
23
 
@@ -49,7 +49,6 @@ var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
49
49
  var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
50
50
  var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
51
51
  var nodeFetch__namespace = /*#__PURE__*/_interopNamespace(nodeFetch);
52
- var sha3__default = /*#__PURE__*/_interopDefaultLegacy(sha3);
53
52
  var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
54
53
 
55
54
  /**
@@ -523,7 +522,6 @@ class MessageAccountKeys {
523
522
  /**
524
523
  * Layout for a public key
525
524
  */
526
-
527
525
  const publicKey = (property = 'publicKey') => {
528
526
  return BufferLayout__namespace.blob(32, property);
529
527
  };
@@ -587,6 +585,13 @@ const lockup = (property = 'lockup') => {
587
585
  const voteInit = (property = 'voteInit') => {
588
586
  return BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission')], property);
589
587
  };
588
+ /**
589
+ * Layout for a VoteAuthorizeWithSeedArgs object
590
+ */
591
+
592
+ const voteAuthorizeWithSeedArgs = (property = 'voteAuthorizeWithSeedArgs') => {
593
+ return BufferLayout__namespace.struct([BufferLayout__namespace.u32('voteAuthorizationType'), publicKey('currentAuthorityDerivedKeyOwnerPubkey'), rustString('currentAuthorityDerivedKeySeed'), publicKey('newAuthorized')], property);
594
+ };
590
595
  function getAlloc(type, fields) {
591
596
  const getItemAlloc = item => {
592
597
  if (item.span >= 0) {
@@ -599,6 +604,11 @@ function getAlloc(type, fields) {
599
604
  if (Array.isArray(field)) {
600
605
  return field.length * getItemAlloc(item.elementLayout);
601
606
  }
607
+ } else if ('fields' in item) {
608
+ // This is a `Structure` whose size needs to be recursively measured.
609
+ return getAlloc({
610
+ layout: item
611
+ }, fields[item.property]);
602
612
  } // Couldn't determine allocated size of layout
603
613
 
604
614
 
@@ -1968,10 +1978,10 @@ class Transaction {
1968
1978
 
1969
1979
  class TransactionMessage {
1970
1980
  constructor(args) {
1971
- this.accountKeys = void 0;
1981
+ this.payerKey = void 0;
1972
1982
  this.instructions = void 0;
1973
1983
  this.recentBlockhash = void 0;
1974
- this.accountKeys = args.accountKeys;
1984
+ this.payerKey = args.payerKey;
1975
1985
  this.instructions = args.instructions;
1976
1986
  this.recentBlockhash = args.recentBlockhash;
1977
1987
  }
@@ -1992,6 +2002,12 @@ class TransactionMessage {
1992
2002
  const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
1993
2003
  assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
1994
2004
  const accountKeys = message.getAccountKeys(args);
2005
+ const payerKey = accountKeys.get(0);
2006
+
2007
+ if (payerKey === undefined) {
2008
+ throw new Error('Failed to decompile message because no account keys were found');
2009
+ }
2010
+
1995
2011
  const instructions = [];
1996
2012
 
1997
2013
  for (const compiledIx of compiledInstructions) {
@@ -2037,35 +2053,23 @@ class TransactionMessage {
2037
2053
  }
2038
2054
 
2039
2055
  return new TransactionMessage({
2040
- accountKeys,
2056
+ payerKey,
2041
2057
  instructions,
2042
2058
  recentBlockhash
2043
2059
  });
2044
2060
  }
2045
2061
 
2046
2062
  compileToLegacyMessage() {
2047
- const payerKey = this.accountKeys.get(0);
2048
-
2049
- if (payerKey === undefined) {
2050
- throw new Error('Failed to compile message because no account keys were found');
2051
- }
2052
-
2053
2063
  return Message.compile({
2054
- payerKey,
2064
+ payerKey: this.payerKey,
2055
2065
  recentBlockhash: this.recentBlockhash,
2056
2066
  instructions: this.instructions
2057
2067
  });
2058
2068
  }
2059
2069
 
2060
2070
  compileToV0Message(addressLookupTableAccounts) {
2061
- const payerKey = this.accountKeys.get(0);
2062
-
2063
- if (payerKey === undefined) {
2064
- throw new Error('Failed to compile message because no account keys were found');
2065
- }
2066
-
2067
2071
  return MessageV0.compile({
2068
- payerKey,
2072
+ payerKey: this.payerKey,
2069
2073
  recentBlockhash: this.recentBlockhash,
2070
2074
  instructions: this.instructions,
2071
2075
  addressLookupTableAccounts
@@ -4361,7 +4365,8 @@ const ParsedConfirmedTransactionResult = superstruct.type({
4361
4365
  accountKeys: superstruct.array(superstruct.type({
4362
4366
  pubkey: PublicKeyFromString,
4363
4367
  signer: superstruct.boolean(),
4364
- writable: superstruct.boolean()
4368
+ writable: superstruct.boolean(),
4369
+ source: superstruct.optional(superstruct.union([superstruct.literal('transaction'), superstruct.literal('lookupTable')]))
4365
4370
  })),
4366
4371
  instructions: superstruct.array(ParsedOrRawInstruction),
4367
4372
  recentBlockhash: superstruct.string(),
@@ -7537,7 +7542,7 @@ class Keypair {
7537
7542
 
7538
7543
 
7539
7544
  get secretKey() {
7540
- return this._keypair.secretKey;
7545
+ return new Uint8Array(this._keypair.secretKey);
7541
7546
  }
7542
7547
 
7543
7548
  }
@@ -8130,7 +8135,7 @@ class Secp256k1Program {
8130
8135
  assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
8131
8136
 
8132
8137
  try {
8133
- return buffer.Buffer.from(sha3__default["default"].keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
8138
+ return buffer.Buffer.from(sha3.keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
8134
8139
  } catch (error) {
8135
8140
  throw new Error(`Error constructing Ethereum address: ${error}`);
8136
8141
  }
@@ -8230,7 +8235,7 @@ class Secp256k1Program {
8230
8235
  /* isCompressed */
8231
8236
  ).slice(1); // throw away leading byte
8232
8237
 
8233
- const messageHash = buffer.Buffer.from(sha3__default["default"].keccak_256.update(toBuffer(message)).digest());
8238
+ const messageHash = buffer.Buffer.from(sha3.keccak_256(toBuffer(message)));
8234
8239
  const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
8235
8240
  return this.createInstructionWithPublicKey({
8236
8241
  publicKey,
@@ -9124,6 +9129,33 @@ class VoteInstruction {
9124
9129
  }
9125
9130
  };
9126
9131
  }
9132
+ /**
9133
+ * Decode an authorize instruction and retrieve the instruction params.
9134
+ */
9135
+
9136
+
9137
+ static decodeAuthorizeWithSeed(instruction) {
9138
+ this.checkProgramId(instruction.programId);
9139
+ this.checkKeyLength(instruction.keys, 3);
9140
+ const {
9141
+ voteAuthorizeWithSeedArgs: {
9142
+ currentAuthorityDerivedKeyOwnerPubkey,
9143
+ currentAuthorityDerivedKeySeed,
9144
+ newAuthorized,
9145
+ voteAuthorizationType
9146
+ }
9147
+ } = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
9148
+ return {
9149
+ currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
9150
+ currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
9151
+ currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
9152
+ newAuthorizedPubkey: new PublicKey(newAuthorized),
9153
+ voteAuthorizationType: {
9154
+ index: voteAuthorizationType
9155
+ },
9156
+ votePubkey: instruction.keys[0].pubkey
9157
+ };
9158
+ }
9127
9159
  /**
9128
9160
  * Decode a withdraw instruction and retrieve the instruction params.
9129
9161
  */
@@ -9180,6 +9212,10 @@ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
9180
9212
  Withdraw: {
9181
9213
  index: 3,
9182
9214
  layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), BufferLayout__namespace.ns64('lamports')])
9215
+ },
9216
+ AuthorizeWithSeed: {
9217
+ index: 10,
9218
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), voteAuthorizeWithSeedArgs()])
9183
9219
  }
9184
9220
  });
9185
9221
  /**
@@ -9308,6 +9344,49 @@ class VoteProgram {
9308
9344
  data
9309
9345
  });
9310
9346
  }
9347
+ /**
9348
+ * Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
9349
+ * where the current Voter or Withdrawer authority is a derived key.
9350
+ */
9351
+
9352
+
9353
+ static authorizeWithSeed(params) {
9354
+ const {
9355
+ currentAuthorityDerivedKeyBasePubkey,
9356
+ currentAuthorityDerivedKeyOwnerPubkey,
9357
+ currentAuthorityDerivedKeySeed,
9358
+ newAuthorizedPubkey,
9359
+ voteAuthorizationType,
9360
+ votePubkey
9361
+ } = params;
9362
+ const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
9363
+ const data = encodeData(type, {
9364
+ voteAuthorizeWithSeedArgs: {
9365
+ currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
9366
+ currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
9367
+ newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
9368
+ voteAuthorizationType: voteAuthorizationType.index
9369
+ }
9370
+ });
9371
+ const keys = [{
9372
+ pubkey: votePubkey,
9373
+ isSigner: false,
9374
+ isWritable: true
9375
+ }, {
9376
+ pubkey: SYSVAR_CLOCK_PUBKEY,
9377
+ isSigner: false,
9378
+ isWritable: false
9379
+ }, {
9380
+ pubkey: currentAuthorityDerivedKeyBasePubkey,
9381
+ isSigner: true,
9382
+ isWritable: false
9383
+ }];
9384
+ return new Transaction().add({
9385
+ keys,
9386
+ programId: this.programId,
9387
+ data
9388
+ });
9389
+ }
9311
9390
  /**
9312
9391
  * Generate a transaction to withdraw from a Vote account.
9313
9392
  */