@solana/web3.js 1.30.0 → 1.32.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/module.flow.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.15.0
4
+ * Flowgen v1.16.0
5
5
  */
6
6
 
7
7
  declare module "@solana/web3.js" {
@@ -64,6 +64,7 @@ declare module "@solana/web3.js" {
64
64
  * Return the base-58 representation of the public key
65
65
  */
66
66
  toBase58(): string;
67
+ toJSON(): string;
67
68
 
68
69
  /**
69
70
  * Return the byte array representation of the public key
@@ -1028,6 +1029,7 @@ declare module "@solana/web3.js" {
1028
1029
  declare export type TokenBalance = {
1029
1030
  accountIndex: number,
1030
1031
  mint: string,
1032
+ owner?: string,
1031
1033
  uiTokenAmount: TokenAmount,
1032
1034
  ...
1033
1035
  };
@@ -1817,6 +1819,22 @@ declare module "@solana/web3.js" {
1817
1819
  ...
1818
1820
  };
1819
1821
 
1822
+ /**
1823
+ * Configuration object for getMultipleAccounts
1824
+ */
1825
+ declare export type GetMultipleAccountsConfig = {
1826
+ /**
1827
+ * Optional commitment level
1828
+ */
1829
+ commitment?: Commitment,
1830
+
1831
+ /**
1832
+ * Optional encoding for account data (default base64)
1833
+ */
1834
+ encoding?: "base64" | "jsonParsed",
1835
+ ...
1836
+ };
1837
+
1820
1838
  /**
1821
1839
  * Information describing an account
1822
1840
  */
@@ -1842,7 +1860,7 @@ declare module "@solana/web3.js" {
1842
1860
  data: T,
1843
1861
 
1844
1862
  /**
1845
- * Optional rent epoch infor for account
1863
+ * Optional rent epoch info for account
1846
1864
  */
1847
1865
  rentEpoch?: number,
1848
1866
  ...
@@ -2047,7 +2065,7 @@ declare module "@solana/web3.js" {
2047
2065
  declare export type FetchMiddleware = (
2048
2066
  url: string,
2049
2067
  options: any,
2050
- fetch: Function
2068
+ fetch: (modifiedUrl: string, modifiedOptions: any) => void
2051
2069
  ) => void;
2052
2070
 
2053
2071
  /**
@@ -2246,8 +2264,8 @@ account: AccountInfo<ParsedAccountData>,...
2246
2264
  */
2247
2265
  getMultipleAccountsInfo(
2248
2266
  publicKeys: PublicKey[],
2249
- commitment?: Commitment
2250
- ): Promise<(AccountInfo<Buffer> | null)[]>;
2267
+ configOrCommitment?: GetMultipleAccountsConfig | Commitment
2268
+ ): Promise<(AccountInfo<Buffer | ParsedAccountData> | null)[]>;
2251
2269
 
2252
2270
  /**
2253
2271
  * Returns epoch activation information for a stake account that has been delegated
@@ -2424,6 +2442,14 @@ feeCalculator: FeeCalculator,...
2424
2442
  commitment?: Commitment
2425
2443
  ): Promise<RpcResponseAndContext<FeeCalculator | null>>;
2426
2444
 
2445
+ /**
2446
+ * Fetch the fee for a message from the cluster, return with context
2447
+ */
2448
+ getFeeForMessage(
2449
+ message: Message,
2450
+ commitment?: Commitment
2451
+ ): Promise<RpcResponseAndContext<number>>;
2452
+
2427
2453
  /**
2428
2454
  * Fetch a recent blockhash from the cluster
2429
2455
  * @return {Promise<{
@@ -3935,21 +3961,36 @@ feeCalculator: FeeCalculator,...
3935
3961
  prevCredits: number,
3936
3962
  ...
3937
3963
  };
3964
+ declare export type AuthorizedVoter = {
3965
+ epoch: number,
3966
+ authorizedVoter: PublicKey,
3967
+ ...
3968
+ };
3969
+ declare export type PriorVoter = {
3970
+ authorizedPubkey: PublicKey,
3971
+ epochOfLastAuthorizedSwitch: number,
3972
+ targetEpoch: number,
3973
+ ...
3974
+ };
3975
+ declare export type BlockTimestamp = {
3976
+ slot: number,
3977
+ timetamp: number,
3978
+ ...
3979
+ };
3938
3980
 
3939
3981
  /**
3940
3982
  * VoteAccount class
3941
3983
  */
3942
3984
  declare export class VoteAccount {
3943
3985
  nodePubkey: PublicKey;
3944
- authorizedVoterPubkey: PublicKey;
3945
- authorizedWithdrawerPubkey: PublicKey;
3986
+ authorizedWithdrawer: PublicKey;
3946
3987
  commission: number;
3947
- votes: Array<Lockout>;
3948
3988
  rootSlot: number | null;
3949
- epoch: number;
3950
- credits: number;
3951
- lastEpochCredits: number;
3952
- epochCredits: Array<EpochCredits>;
3989
+ votes: Lockout[];
3990
+ authorizedVoters: AuthorizedVoter[];
3991
+ priorVoters: PriorVoter[];
3992
+ epochCredits: EpochCredits[];
3993
+ lastTimestamp: BlockTimestamp;
3953
3994
 
3954
3995
  /**
3955
3996
  * Deserialize VoteAccount from the account data.
@@ -3961,11 +4002,14 @@ feeCalculator: FeeCalculator,...
3961
4002
  ): VoteAccount;
3962
4003
  }
3963
4004
  declare export var SYSVAR_CLOCK_PUBKEY: PublicKey;
4005
+ declare export var SYSVAR_EPOCH_SCHEDULE_PUBKEY: PublicKey;
4006
+ declare export var SYSVAR_INSTRUCTIONS_PUBKEY: PublicKey;
3964
4007
  declare export var SYSVAR_RECENT_BLOCKHASHES_PUBKEY: PublicKey;
3965
4008
  declare export var SYSVAR_RENT_PUBKEY: PublicKey;
3966
4009
  declare export var SYSVAR_REWARDS_PUBKEY: PublicKey;
4010
+ declare export var SYSVAR_SLOT_HASHES_PUBKEY: PublicKey;
4011
+ declare export var SYSVAR_SLOT_HISTORY_PUBKEY: PublicKey;
3967
4012
  declare export var SYSVAR_STAKE_HISTORY_PUBKEY: PublicKey;
3968
- declare export var SYSVAR_INSTRUCTIONS_PUBKEY: PublicKey;
3969
4013
  declare export class SendTransactionError mixins Error {
3970
4014
  logs: string[] | void;
3971
4015
  constructor(message: string, logs?: string[]): this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.30.0",
3
+ "version": "1.32.0",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
@@ -38,7 +38,6 @@
38
38
  ],
39
39
  "scripts": {
40
40
  "build": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen; npm run flow:gen; npm run flow:check",
41
- "build:browser-test": "rollup -c test/rollup.config.js",
42
41
  "build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
43
42
  "clean": "rimraf ./coverage ./lib",
44
43
  "codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
@@ -55,21 +54,18 @@
55
54
  "re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
56
55
  "test": "mocha -r ts-node/register './test/**/*.test.ts'",
57
56
  "test:cover": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=lcov mocha -r ts-node/register './test/**/*.test.ts'",
58
- "test:browser": "TEST_LIVE=1 npm run build:browser-test && mocha-headless-chrome -f http://localhost:8080/mocha.html --timeout 180000",
59
- "test:browser-with-server": "start-server-and-test 'http-server -p 8080' 8080 test:browser",
60
- "test:browser-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:browser-with-server",
61
57
  "test:live": "TEST_LIVE=1 npm run test",
62
58
  "test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
63
59
  },
64
60
  "dependencies": {
65
61
  "@babel/runtime": "^7.12.5",
62
+ "@ethersproject/sha2": "^5.5.0",
66
63
  "@solana/buffer-layout": "^3.0.0",
67
64
  "bn.js": "^5.0.0",
68
65
  "borsh": "^0.4.0",
69
66
  "bs58": "^4.0.1",
70
67
  "buffer": "6.0.1",
71
68
  "cross-fetch": "^3.1.4",
72
- "ethers": "^5.5.1",
73
69
  "jayson": "^3.4.4",
74
70
  "js-sha3": "^0.8.0",
75
71
  "rpc-websockets": "^7.4.2",
@@ -84,8 +80,8 @@
84
80
  "@babel/preset-env": "^7.12.11",
85
81
  "@babel/preset-typescript": "^7.12.16",
86
82
  "@babel/register": "^7.12.13",
87
- "@commitlint/config-conventional": "^13.1.0",
88
- "@commitlint/travis-cli": "^13.1.0",
83
+ "@commitlint/config-conventional": "^15.0.0",
84
+ "@commitlint/travis-cli": "^15.0.0",
89
85
  "@rollup/plugin-alias": "^3.1.2",
90
86
  "@rollup/plugin-babel": "^5.2.3",
91
87
  "@rollup/plugin-commonjs": "^21.0.0",
@@ -112,7 +108,7 @@
112
108
  "cross-env": "7.0.3",
113
109
  "eslint": "^7.19.0",
114
110
  "eslint-config-prettier": "^8.0.0",
115
- "eslint-plugin-import": "2.25.2",
111
+ "eslint-plugin-import": "2.25.3",
116
112
  "eslint-plugin-mocha": "^9.0.0",
117
113
  "eslint-plugin-prettier": "^4.0.0",
118
114
  "esm": "^3.2.25",
@@ -120,20 +116,19 @@
120
116
  "flowgen": "^1.13.0",
121
117
  "http-server": "^14.0.0",
122
118
  "mocha": "^8.2.1",
123
- "mocha-headless-chrome": "^3.1.0",
124
119
  "mockttp": "^2.0.1",
125
120
  "mz": "^2.7.0",
126
121
  "npm-run-all": "^4.1.5",
127
122
  "nyc": "^15.1.0",
128
123
  "prettier": "^2.3.0",
129
- "puppeteer": "^10.2.0",
124
+ "puppeteer": "^12.0.0",
130
125
  "rimraf": "3.0.2",
131
- "rollup": "2.58.0",
126
+ "rollup": "2.60.2",
132
127
  "rollup-plugin-dts": "^4.0.0",
133
128
  "rollup-plugin-node-polyfills": "^0.2.1",
134
129
  "rollup-plugin-terser": "^7.0.2",
135
130
  "semantic-release": "^18.0.0",
136
- "sinon": "^11.0.0",
131
+ "sinon": "^12.0.0",
137
132
  "start-server-and-test": "^1.12.0",
138
133
  "ts-node": "^10.0.0",
139
134
  "tslib": "^2.1.0",
package/src/account.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as nacl from 'tweetnacl';
1
+ import nacl from 'tweetnacl';
2
2
  import type {SignKeyPair as KeyPair} from 'tweetnacl';
3
3
  import type {Buffer} from 'buffer';
4
4
 
package/src/connection.ts CHANGED
@@ -498,6 +498,7 @@ export type ParsedInnerInstruction = {
498
498
  export type TokenBalance = {
499
499
  accountIndex: number;
500
500
  mint: string;
501
+ owner?: string;
501
502
  uiTokenAmount: TokenAmount;
502
503
  };
503
504
 
@@ -760,19 +761,24 @@ function createRpcClient(
760
761
  agentManager = new AgentManager(useHttps);
761
762
  }
762
763
 
763
- let fetchWithMiddleware: (url: string, options: any) => Promise<Response>;
764
+ let fetchWithMiddleware:
765
+ | ((url: string, options: any) => Promise<Response>)
766
+ | undefined;
764
767
 
765
768
  if (fetchMiddleware) {
766
- fetchWithMiddleware = (url: string, options: any) => {
767
- return new Promise<Response>((resolve, reject) => {
768
- fetchMiddleware(url, options, async (url: string, options: any) => {
769
+ fetchWithMiddleware = async (url: string, options: any) => {
770
+ const modifiedFetchArgs = await new Promise<[string, any]>(
771
+ (resolve, reject) => {
769
772
  try {
770
- resolve(await fetch(url, options));
773
+ fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) =>
774
+ resolve([modifiedUrl, modifiedOptions]),
775
+ );
771
776
  } catch (error) {
772
777
  reject(error);
773
778
  }
774
- });
775
- });
779
+ },
780
+ );
781
+ return await fetch(...modifiedFetchArgs);
776
782
  };
777
783
  }
778
784
 
@@ -1432,6 +1438,7 @@ const ParsedConfirmedTransactionResult = pick({
1432
1438
  const TokenBalanceResult = pick({
1433
1439
  accountIndex: number(),
1434
1440
  mint: string(),
1441
+ owner: optional(string()),
1435
1442
  uiTokenAmount: TokenAmountResult,
1436
1443
  });
1437
1444
 
@@ -1706,6 +1713,16 @@ export type GetParsedProgramAccountsConfig = {
1706
1713
  filters?: GetProgramAccountsFilter[];
1707
1714
  };
1708
1715
 
1716
+ /**
1717
+ * Configuration object for getMultipleAccounts
1718
+ */
1719
+ export type GetMultipleAccountsConfig = {
1720
+ /** Optional commitment level */
1721
+ commitment?: Commitment;
1722
+ /** Optional encoding for account data (default base64) */
1723
+ encoding?: 'base64' | 'jsonParsed';
1724
+ };
1725
+
1709
1726
  /**
1710
1727
  * Information describing an account
1711
1728
  */
@@ -1718,7 +1735,7 @@ export type AccountInfo<T> = {
1718
1735
  lamports: number;
1719
1736
  /** Optional data assigned to the account */
1720
1737
  data: T;
1721
- /** Optional rent epoch infor for account */
1738
+ /** Optional rent epoch info for account */
1722
1739
  rentEpoch?: number;
1723
1740
  };
1724
1741
 
@@ -1972,7 +1989,7 @@ export type HttpHeaders = {[header: string]: string};
1972
1989
  export type FetchMiddleware = (
1973
1990
  url: string,
1974
1991
  options: any,
1975
- fetch: Function,
1992
+ fetch: (modifiedUrl: string, modifiedOptions: any) => void,
1976
1993
  ) => void;
1977
1994
 
1978
1995
  /**
@@ -2474,14 +2491,27 @@ export class Connection {
2474
2491
  */
2475
2492
  async getMultipleAccountsInfo(
2476
2493
  publicKeys: PublicKey[],
2477
- commitment?: Commitment,
2478
- ): Promise<(AccountInfo<Buffer> | null)[]> {
2494
+ configOrCommitment?: GetMultipleAccountsConfig | Commitment,
2495
+ ): Promise<(AccountInfo<Buffer | ParsedAccountData> | null)[]> {
2479
2496
  const keys = publicKeys.map(key => key.toBase58());
2480
- const args = this._buildArgs([keys], commitment, 'base64');
2497
+
2498
+ let commitment;
2499
+ let encoding: 'base64' | 'jsonParsed' = 'base64';
2500
+ if (configOrCommitment) {
2501
+ if (typeof configOrCommitment === 'string') {
2502
+ commitment = configOrCommitment;
2503
+ encoding = 'base64';
2504
+ } else {
2505
+ commitment = configOrCommitment.commitment;
2506
+ encoding = configOrCommitment.encoding || 'base64';
2507
+ }
2508
+ }
2509
+
2510
+ const args = this._buildArgs([keys], commitment, encoding);
2481
2511
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
2482
2512
  const res = create(
2483
2513
  unsafeRes,
2484
- jsonRpcResultAndContext(array(nullable(AccountInfoResult))),
2514
+ jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))),
2485
2515
  );
2486
2516
  if ('error' in res) {
2487
2517
  throw new Error(
@@ -2993,6 +3023,27 @@ export class Connection {
2993
3023
  };
2994
3024
  }
2995
3025
 
3026
+ /**
3027
+ * Fetch the fee for a message from the cluster, return with context
3028
+ */
3029
+ async getFeeForMessage(
3030
+ message: Message,
3031
+ commitment?: Commitment,
3032
+ ): Promise<RpcResponseAndContext<number>> {
3033
+ const wireMessage = message.serialize().toString('base64');
3034
+ const args = this._buildArgs([wireMessage], commitment);
3035
+ const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
3036
+
3037
+ const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
3038
+ if ('error' in res) {
3039
+ throw new Error('failed to get slot: ' + res.error.message);
3040
+ }
3041
+ if (res.result === null) {
3042
+ throw new Error('invalid blockhash');
3043
+ }
3044
+ return res.result as unknown as RpcResponseAndContext<number>;
3045
+ }
3046
+
2996
3047
  /**
2997
3048
  * Fetch a recent blockhash from the cluster
2998
3049
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
package/src/keypair.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as nacl from 'tweetnacl';
1
+ import nacl from 'tweetnacl';
2
2
 
3
3
  import {PublicKey} from './publickey';
4
4
 
package/src/publickey.ts CHANGED
@@ -2,7 +2,7 @@ import BN from 'bn.js';
2
2
  import bs58 from 'bs58';
3
3
  import {Buffer} from 'buffer';
4
4
  import nacl from 'tweetnacl';
5
- import {ethers} from 'ethers';
5
+ import {sha256} from '@ethersproject/sha2';
6
6
 
7
7
  import {Struct, SOLANA_SCHEMA} from './util/borsh-schema';
8
8
  import {toBuffer} from './util/to-buffer';
@@ -87,6 +87,10 @@ export class PublicKey extends Struct {
87
87
  return bs58.encode(this.toBytes());
88
88
  }
89
89
 
90
+ toJSON(): string {
91
+ return this.toBase58();
92
+ }
93
+
90
94
  /**
91
95
  * Return the byte array representation of the public key
92
96
  */
@@ -131,7 +135,7 @@ export class PublicKey extends Struct {
131
135
  Buffer.from(seed),
132
136
  programId.toBuffer(),
133
137
  ]);
134
- const hash = ethers.utils.sha256(new Uint8Array(buffer)).slice(2);
138
+ const hash = sha256(new Uint8Array(buffer)).slice(2);
135
139
  return new PublicKey(Buffer.from(hash, 'hex'));
136
140
  }
137
141
 
@@ -155,7 +159,7 @@ export class PublicKey extends Struct {
155
159
  programId.toBuffer(),
156
160
  Buffer.from('ProgramDerivedAddress'),
157
161
  ]);
158
- let hash = ethers.utils.sha256(new Uint8Array(buffer)).slice(2);
162
+ let hash = sha256(new Uint8Array(buffer)).slice(2);
159
163
  let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
160
164
  if (is_on_curve(publicKeyBytes)) {
161
165
  throw new Error(`Invalid seeds, address must fall off the curve`);
@@ -1,7 +1,7 @@
1
1
  import {Buffer} from 'buffer';
2
2
  import * as BufferLayout from '@solana/buffer-layout';
3
3
  import secp256k1 from 'secp256k1';
4
- import {keccak_256} from 'js-sha3';
4
+ import sha3 from 'js-sha3';
5
5
 
6
6
  import {PublicKey} from './publickey';
7
7
  import {TransactionInstruction} from './transaction';
@@ -86,9 +86,9 @@ export class Secp256k1Program {
86
86
  );
87
87
 
88
88
  try {
89
- return Buffer.from(keccak_256.update(toBuffer(publicKey)).digest()).slice(
90
- -ETHEREUM_ADDRESS_BYTES,
91
- );
89
+ return Buffer.from(
90
+ sha3.keccak_256.update(toBuffer(publicKey)).digest(),
91
+ ).slice(-ETHEREUM_ADDRESS_BYTES);
92
92
  } catch (error) {
93
93
  throw new Error(`Error constructing Ethereum address: ${error}`);
94
94
  }
@@ -197,7 +197,7 @@ export class Secp256k1Program {
197
197
  const privateKey = toBuffer(pkey);
198
198
  const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
199
199
  const messageHash = Buffer.from(
200
- keccak_256.update(toBuffer(message)).digest(),
200
+ sha3.keccak_256.update(toBuffer(message)).digest(),
201
201
  );
202
202
  const {signature, recid: recoveryId} = ecdsaSign(messageHash, privateKey);
203
203
 
package/src/sysvar.ts CHANGED
@@ -4,6 +4,14 @@ export const SYSVAR_CLOCK_PUBKEY = new PublicKey(
4
4
  'SysvarC1ock11111111111111111111111111111111',
5
5
  );
6
6
 
7
+ export const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey(
8
+ 'SysvarEpochSchedu1e111111111111111111111111',
9
+ );
10
+
11
+ export const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey(
12
+ 'Sysvar1nstructions1111111111111111111111111',
13
+ );
14
+
7
15
  export const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey(
8
16
  'SysvarRecentB1ockHashes11111111111111111111',
9
17
  );
@@ -16,10 +24,14 @@ export const SYSVAR_REWARDS_PUBKEY = new PublicKey(
16
24
  'SysvarRewards111111111111111111111111111111',
17
25
  );
18
26
 
19
- export const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey(
20
- 'SysvarStakeHistory1111111111111111111111111',
27
+ export const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey(
28
+ 'SysvarS1otHashes111111111111111111111111111',
21
29
  );
22
30
 
23
- export const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey(
24
- 'Sysvar1nstructions1111111111111111111111111',
31
+ export const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey(
32
+ 'SysvarS1otHistory11111111111111111111111111',
33
+ );
34
+
35
+ export const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey(
36
+ 'SysvarStakeHistory1111111111111111111111111',
25
37
  );
@@ -259,9 +259,12 @@ export class Transaction {
259
259
 
260
260
  // Sort. Prioritizing first by signer, then by writable
261
261
  accountMetas.sort(function (x, y) {
262
+ const pubkeySorting = x.pubkey
263
+ .toBase58()
264
+ .localeCompare(y.pubkey.toBase58());
262
265
  const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
263
266
  const checkWritable =
264
- x.isWritable === y.isWritable ? 0 : x.isWritable ? -1 : 1;
267
+ x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
265
268
  return checkSigner || checkWritable;
266
269
  });
267
270