@solana/web3.js 1.75.0 → 1.77.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.
@@ -1,6 +1,5 @@
1
1
  import { Buffer } from 'buffer';
2
- import { sha512 } from '@noble/hashes/sha512';
3
- import * as ed25519 from '@noble/ed25519';
2
+ import { ed25519 } from '@noble/curves/ed25519';
4
3
  import BN from 'bn.js';
5
4
  import bs58 from 'bs58';
6
5
  import { sha256 } from '@noble/hashes/sha256';
@@ -13,8 +12,7 @@ import RpcClient from 'jayson/lib/client/browser';
13
12
  import RpcWebSocketCommonClient from 'rpc-websockets/dist/lib/client';
14
13
  import createRpc from 'rpc-websockets/dist/lib/client/websocket.browser';
15
14
  import { keccak_256 } from '@noble/hashes/sha3';
16
- import { hmac } from '@noble/hashes/hmac';
17
- import * as secp256k1 from '@noble/secp256k1';
15
+ import { secp256k1 } from '@noble/curves/secp256k1';
18
16
 
19
17
  /**
20
18
  * A 64 byte secret key, the first 32 bytes of which is the
@@ -22,7 +20,6 @@ import * as secp256k1 from '@noble/secp256k1';
22
20
  * Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
23
21
  */
24
22
 
25
- ed25519.utils.sha512Sync = (...m) => sha512(ed25519.utils.concatBytes(...m));
26
23
  const generatePrivateKey = ed25519.utils.randomPrivateKey;
27
24
  const generateKeypair = () => {
28
25
  const privateScalar = ed25519.utils.randomPrivateKey();
@@ -35,17 +32,17 @@ const generateKeypair = () => {
35
32
  secretKey
36
33
  };
37
34
  };
38
- const getPublicKey = ed25519.sync.getPublicKey;
35
+ const getPublicKey = ed25519.getPublicKey;
39
36
  function isOnCurve(publicKey) {
40
37
  try {
41
- ed25519.Point.fromHex(publicKey, true /* strict */);
38
+ ed25519.ExtendedPoint.fromHex(publicKey);
42
39
  return true;
43
40
  } catch {
44
41
  return false;
45
42
  }
46
43
  }
47
- const sign = (message, secretKey) => ed25519.sync.sign(message, secretKey.slice(0, 32));
48
- const verify = ed25519.sync.verify;
44
+ const sign = (message, secretKey) => ed25519.sign(message, secretKey.slice(0, 32));
45
+ const verify = ed25519.verify;
49
46
 
50
47
  const toBuffer = arr => {
51
48
  if (Buffer.isBuffer(arr)) {
@@ -602,8 +599,8 @@ class CompiledKeys {
602
599
  getOrInsertDefault(ix.programId).isInvoked = true;
603
600
  for (const accountMeta of ix.keys) {
604
601
  const keyMeta = getOrInsertDefault(accountMeta.pubkey);
605
- keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
606
- keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
602
+ keyMeta.isSigner ||= accountMeta.isSigner;
603
+ keyMeta.isWritable ||= accountMeta.isWritable;
607
604
  }
608
605
  }
609
606
  return new CompiledKeys(payer, keyMetaMap);
@@ -1941,6 +1938,29 @@ class VersionedTransaction {
1941
1938
  }
1942
1939
  }
1943
1940
 
1941
+ // TODO: These constants should be removed in favor of reading them out of a
1942
+ // Syscall account
1943
+
1944
+ /**
1945
+ * @internal
1946
+ */
1947
+ const NUM_TICKS_PER_SECOND = 160;
1948
+
1949
+ /**
1950
+ * @internal
1951
+ */
1952
+ const DEFAULT_TICKS_PER_SLOT = 64;
1953
+
1954
+ /**
1955
+ * @internal
1956
+ */
1957
+ const NUM_SLOTS_PER_SECOND = NUM_TICKS_PER_SECOND / DEFAULT_TICKS_PER_SLOT;
1958
+
1959
+ /**
1960
+ * @internal
1961
+ */
1962
+ const MS_PER_SLOT = 1000 / NUM_SLOTS_PER_SECOND;
1963
+
1944
1964
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
1945
1965
  const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
1946
1966
  const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
@@ -2955,9 +2975,37 @@ class Loader {
2955
2975
  programId,
2956
2976
  data
2957
2977
  });
2958
- await sendAndConfirmTransaction(connection, transaction, [payer, program], {
2959
- commitment: 'confirmed'
2978
+ const deployCommitment = 'processed';
2979
+ const finalizeSignature = await connection.sendTransaction(transaction, [payer, program], {
2980
+ preflightCommitment: deployCommitment
2960
2981
  });
2982
+ const {
2983
+ context,
2984
+ value
2985
+ } = await connection.confirmTransaction({
2986
+ signature: finalizeSignature,
2987
+ lastValidBlockHeight: transaction.lastValidBlockHeight,
2988
+ blockhash: transaction.recentBlockhash
2989
+ }, deployCommitment);
2990
+ if (value.err) {
2991
+ throw new Error(`Transaction ${finalizeSignature} failed (${JSON.stringify(value)})`);
2992
+ }
2993
+ // We prevent programs from being usable until the slot after their deployment.
2994
+ // See https://github.com/solana-labs/solana/pull/29654
2995
+ while (true // eslint-disable-line no-constant-condition
2996
+ ) {
2997
+ try {
2998
+ const currentSlot = await connection.getSlot({
2999
+ commitment: deployCommitment
3000
+ });
3001
+ if (currentSlot > context.slot) {
3002
+ break;
3003
+ }
3004
+ } catch {
3005
+ /* empty */
3006
+ }
3007
+ await new Promise(resolve => setTimeout(resolve, Math.round(MS_PER_SLOT / 2)));
3008
+ }
2961
3009
  }
2962
3010
 
2963
3011
  // success
@@ -3243,29 +3291,6 @@ class RpcWebSocketClient extends RpcWebSocketCommonClient {
3243
3291
  }
3244
3292
  }
3245
3293
 
3246
- // TODO: These constants should be removed in favor of reading them out of a
3247
- // Syscall account
3248
-
3249
- /**
3250
- * @internal
3251
- */
3252
- const NUM_TICKS_PER_SECOND = 160;
3253
-
3254
- /**
3255
- * @internal
3256
- */
3257
- const DEFAULT_TICKS_PER_SLOT = 64;
3258
-
3259
- /**
3260
- * @internal
3261
- */
3262
- const NUM_SLOTS_PER_SECOND = NUM_TICKS_PER_SECOND / DEFAULT_TICKS_PER_SLOT;
3263
-
3264
- /**
3265
- * @internal
3266
- */
3267
- const MS_PER_SLOT = 1000 / NUM_SLOTS_PER_SECOND;
3268
-
3269
3294
  /**
3270
3295
  * @internal
3271
3296
  */
@@ -4697,7 +4722,7 @@ class Connection {
4697
4722
  /**
4698
4723
  * Fetch all the token accounts owned by the specified account
4699
4724
  *
4700
- * @return {Promise<RpcResponseAndContext<Array<{pubkey: PublicKey, account: AccountInfo<Buffer>}>>>}
4725
+ * @return {Promise<RpcResponseAndContext<GetProgramAccountsResponse>}
4701
4726
  */
4702
4727
  async getTokenAccountsByOwner(ownerAddress, filter, commitmentOrConfig) {
4703
4728
  const {
@@ -4894,6 +4919,8 @@ class Connection {
4894
4919
  *
4895
4920
  * @return {Promise<Array<{pubkey: PublicKey, account: AccountInfo<Buffer>}>>}
4896
4921
  */
4922
+
4923
+ // eslint-disable-next-line no-dupe-class-members
4897
4924
  async getProgramAccounts(programId, configOrCommitment) {
4898
4925
  const {
4899
4926
  commitment,
@@ -4905,7 +4932,8 @@ class Connection {
4905
4932
  } = config || {};
4906
4933
  const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', configWithoutEncoding);
4907
4934
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
4908
- const res = create(unsafeRes, jsonRpcResult(array(KeyedAccountInfoResult)));
4935
+ const baseSchema = array(KeyedAccountInfoResult);
4936
+ const res = configWithoutEncoding.withContext === true ? create(unsafeRes, jsonRpcResultAndContext(baseSchema)) : create(unsafeRes, jsonRpcResult(baseSchema));
4909
4937
  if ('error' in res) {
4910
4938
  throw new SolanaJSONRPCError(res.error, `failed to get accounts owned by program ${programId.toBase58()}`);
4911
4939
  }
@@ -6637,12 +6665,11 @@ class Connection {
6637
6665
  * @internal
6638
6666
  */
6639
6667
  _onSubscriptionStateChange(clientSubscriptionId, callback) {
6640
- var _this$_subscriptionSt;
6641
6668
  const hash = this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
6642
6669
  if (hash == null) {
6643
6670
  return () => {};
6644
6671
  }
6645
- const stateChangeCallbacks = (_this$_subscriptionSt = this._subscriptionStateChangeCallbacksByHash)[hash] || (_this$_subscriptionSt[hash] = new Set());
6672
+ const stateChangeCallbacks = this._subscriptionStateChangeCallbacksByHash[hash] ||= new Set();
6646
6673
  stateChangeCallbacks.add(callback);
6647
6674
  return () => {
6648
6675
  stateChangeCallbacks.delete(callback);
@@ -7870,17 +7897,10 @@ class Ed25519Program {
7870
7897
  }
7871
7898
  Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
7872
7899
 
7873
- // Supply a synchronous hashing algorithm to make this
7874
- // library interoperable with the synchronous APIs in web3.js.
7875
- secp256k1.utils.hmacSha256Sync = (key, ...msgs) => {
7876
- const h = hmac.create(sha256, key);
7877
- msgs.forEach(msg => h.update(msg));
7878
- return h.digest();
7900
+ const ecdsaSign = (msgHash, privKey) => {
7901
+ const signature = secp256k1.sign(msgHash, privKey);
7902
+ return [signature.toCompactRawBytes(), signature.recovery];
7879
7903
  };
7880
- const ecdsaSign = (msgHash, privKey) => secp256k1.signSync(msgHash, privKey, {
7881
- der: false,
7882
- recovered: true
7883
- });
7884
7904
  secp256k1.utils.isValidPrivateKey;
7885
7905
  const publicKeyCreate = secp256k1.getPublicKey;
7886
7906
 
@@ -9150,7 +9170,7 @@ class VoteProgram {
9150
9170
  }
9151
9171
  }
9152
9172
  VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
9153
- VoteProgram.space = 3731;
9173
+ VoteProgram.space = process.env.TEST_LIVE ? 3762 : 3731;
9154
9174
 
9155
9175
  const VALIDATOR_INFO_KEY = new PublicKey('Va1idator1nfo111111111111111111111111111111');
9156
9176