@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.
- package/lib/index.browser.cjs.js +106 -90
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +71 -51
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +120 -104
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +15 -9
- package/lib/index.esm.js +71 -51
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +3165 -1781
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +12 -5
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +106 -90
- package/lib/index.native.js.map +1 -1
- package/package.json +12 -13
- package/src/connection.ts +30 -8
- package/src/loader.ts +34 -3
- package/src/programs/vote.ts +3 -1
- package/src/utils/ed25519.ts +6 -9
- package/src/utils/secp256k1.ts +7 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/web3.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.77.0",
|
|
4
4
|
"description": "Solana Javascript API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"compile:js": "cross-env NODE_ENV=production rollup -c",
|
|
42
42
|
"compile:typedefs": "./scripts/typegen.sh",
|
|
43
43
|
"build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
|
|
44
|
-
"clean": "rimraf ./
|
|
44
|
+
"clean": "rimraf ./doc ./declarations ./lib",
|
|
45
45
|
"dev": "cross-env NODE_ENV=development rollup -c --watch",
|
|
46
46
|
"publish-packages": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
|
|
47
47
|
"test:lint": "eslint src/ test/ --ext .js,.ts",
|
|
@@ -55,9 +55,8 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@babel/runtime": "^7.12.5",
|
|
58
|
-
"@noble/
|
|
59
|
-
"@noble/hashes": "^1.
|
|
60
|
-
"@noble/secp256k1": "^1.6.3",
|
|
58
|
+
"@noble/curves": "^1.0.0",
|
|
59
|
+
"@noble/hashes": "^1.3.0",
|
|
61
60
|
"@solana/buffer-layout": "^4.0.0",
|
|
62
61
|
"agentkeepalive": "^4.2.1",
|
|
63
62
|
"bigint-buffer": "^1.1.5",
|
|
@@ -84,6 +83,7 @@
|
|
|
84
83
|
"@rollup/plugin-multi-entry": "^6.0.0",
|
|
85
84
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
86
85
|
"@rollup/plugin-replace": "^5.0.2",
|
|
86
|
+
"@rollup/plugin-terser": "^0.4.0",
|
|
87
87
|
"@solana/spl-token": "^0.3.7",
|
|
88
88
|
"@types/bn.js": "^5.1.0",
|
|
89
89
|
"@types/bs58": "^4.0.1",
|
|
@@ -96,12 +96,12 @@
|
|
|
96
96
|
"@types/node-fetch": "2",
|
|
97
97
|
"@types/sinon": "^10.0.0",
|
|
98
98
|
"@types/sinon-chai": "^3.2.8",
|
|
99
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
100
|
-
"@typescript-eslint/parser": "^5.
|
|
99
|
+
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
|
100
|
+
"@typescript-eslint/parser": "^5.57.1",
|
|
101
101
|
"chai": "^4.3.0",
|
|
102
102
|
"chai-as-promised": "^7.1.1",
|
|
103
103
|
"cross-env": "7.0.3",
|
|
104
|
-
"eslint": "^8.
|
|
104
|
+
"eslint": "^8.37.0",
|
|
105
105
|
"eslint-config-prettier": "^8.5.0",
|
|
106
106
|
"eslint-plugin-import": "^2.26.0",
|
|
107
107
|
"eslint-plugin-mocha": "^10.1.0",
|
|
@@ -113,10 +113,9 @@
|
|
|
113
113
|
"node-abort-controller": "^3.0.1",
|
|
114
114
|
"prettier": "^2.3.0",
|
|
115
115
|
"rimraf": "4.1.2",
|
|
116
|
-
"rollup": "
|
|
117
|
-
"rollup-plugin-dts": "^
|
|
116
|
+
"rollup": "^3.20.2",
|
|
117
|
+
"rollup-plugin-dts": "^5.3.0",
|
|
118
118
|
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
119
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
120
119
|
"semantic-release": "^19.0.3",
|
|
121
120
|
"sinon": "^15.0.1",
|
|
122
121
|
"sinon-chai": "^3.7.0",
|
|
@@ -125,7 +124,7 @@
|
|
|
125
124
|
"ts-node": "^10.0.0",
|
|
126
125
|
"tsconfig": "workspace:*",
|
|
127
126
|
"tslib": "^2.1.0",
|
|
128
|
-
"typedoc": "^0.23",
|
|
129
|
-
"typescript": "^
|
|
127
|
+
"typedoc": "^0.23.28",
|
|
128
|
+
"typescript": "^5.0.3"
|
|
130
129
|
}
|
|
131
130
|
}
|
package/src/connection.ts
CHANGED
|
@@ -2685,8 +2685,16 @@ export type GetProgramAccountsConfig = {
|
|
|
2685
2685
|
filters?: GetProgramAccountsFilter[];
|
|
2686
2686
|
/** The minimum slot that the request can be evaluated at */
|
|
2687
2687
|
minContextSlot?: number;
|
|
2688
|
+
/** wrap the result in an RpcResponse JSON object */
|
|
2689
|
+
withContext?: boolean;
|
|
2688
2690
|
};
|
|
2689
2691
|
|
|
2692
|
+
export type GetProgramAccountsResponse = readonly Readonly<{
|
|
2693
|
+
account: AccountInfo<Buffer>;
|
|
2694
|
+
/** the account Pubkey as base-58 encoded string */
|
|
2695
|
+
pubkey: PublicKey;
|
|
2696
|
+
}>[];
|
|
2697
|
+
|
|
2690
2698
|
/**
|
|
2691
2699
|
* Configuration object for getParsedProgramAccounts
|
|
2692
2700
|
*/
|
|
@@ -3336,17 +3344,13 @@ export class Connection {
|
|
|
3336
3344
|
/**
|
|
3337
3345
|
* Fetch all the token accounts owned by the specified account
|
|
3338
3346
|
*
|
|
3339
|
-
* @return {Promise<RpcResponseAndContext<
|
|
3347
|
+
* @return {Promise<RpcResponseAndContext<GetProgramAccountsResponse>}
|
|
3340
3348
|
*/
|
|
3341
3349
|
async getTokenAccountsByOwner(
|
|
3342
3350
|
ownerAddress: PublicKey,
|
|
3343
3351
|
filter: TokenAccountsFilter,
|
|
3344
3352
|
commitmentOrConfig?: Commitment | GetTokenAccountsByOwnerConfig,
|
|
3345
|
-
): Promise<
|
|
3346
|
-
RpcResponseAndContext<
|
|
3347
|
-
Array<{pubkey: PublicKey; account: AccountInfo<Buffer>}>
|
|
3348
|
-
>
|
|
3349
|
-
> {
|
|
3353
|
+
): Promise<RpcResponseAndContext<GetProgramAccountsResponse>> {
|
|
3350
3354
|
const {commitment, config} =
|
|
3351
3355
|
extractCommitmentFromConfig(commitmentOrConfig);
|
|
3352
3356
|
let _args: any[] = [ownerAddress.toBase58()];
|
|
@@ -3621,10 +3625,24 @@ export class Connection {
|
|
|
3621
3625
|
*
|
|
3622
3626
|
* @return {Promise<Array<{pubkey: PublicKey, account: AccountInfo<Buffer>}>>}
|
|
3623
3627
|
*/
|
|
3628
|
+
async getProgramAccounts(
|
|
3629
|
+
programId: PublicKey,
|
|
3630
|
+
configOrCommitment?: GetProgramAccountsConfig &
|
|
3631
|
+
Readonly<{withContext: true}>,
|
|
3632
|
+
): Promise<RpcResponseAndContext<GetProgramAccountsResponse>>;
|
|
3633
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
3624
3634
|
async getProgramAccounts(
|
|
3625
3635
|
programId: PublicKey,
|
|
3626
3636
|
configOrCommitment?: GetProgramAccountsConfig | Commitment,
|
|
3627
|
-
): Promise<
|
|
3637
|
+
): Promise<GetProgramAccountsResponse>;
|
|
3638
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
3639
|
+
async getProgramAccounts(
|
|
3640
|
+
programId: PublicKey,
|
|
3641
|
+
configOrCommitment?: GetProgramAccountsConfig | Commitment,
|
|
3642
|
+
): Promise<
|
|
3643
|
+
| GetProgramAccountsResponse
|
|
3644
|
+
| RpcResponseAndContext<GetProgramAccountsResponse>
|
|
3645
|
+
> {
|
|
3628
3646
|
const {commitment, config} =
|
|
3629
3647
|
extractCommitmentFromConfig(configOrCommitment);
|
|
3630
3648
|
const {encoding, ...configWithoutEncoding} = config || {};
|
|
@@ -3635,7 +3653,11 @@ export class Connection {
|
|
|
3635
3653
|
configWithoutEncoding,
|
|
3636
3654
|
);
|
|
3637
3655
|
const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
|
|
3638
|
-
const
|
|
3656
|
+
const baseSchema = array(KeyedAccountInfoResult);
|
|
3657
|
+
const res =
|
|
3658
|
+
configWithoutEncoding.withContext === true
|
|
3659
|
+
? create(unsafeRes, jsonRpcResultAndContext(baseSchema))
|
|
3660
|
+
: create(unsafeRes, jsonRpcResult(baseSchema));
|
|
3639
3661
|
if ('error' in res) {
|
|
3640
3662
|
throw new SolanaJSONRPCError(
|
|
3641
3663
|
res.error,
|
package/src/loader.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as BufferLayout from '@solana/buffer-layout';
|
|
|
3
3
|
|
|
4
4
|
import {PublicKey} from './publickey';
|
|
5
5
|
import {Transaction, PACKET_DATA_SIZE} from './transaction';
|
|
6
|
+
import {MS_PER_SLOT} from './timing';
|
|
6
7
|
import {SYSVAR_RENT_PUBKEY} from './sysvar';
|
|
7
8
|
import {sendAndConfirmTransaction} from './utils/send-and-confirm-transaction';
|
|
8
9
|
import {sleep} from './utils/sleep';
|
|
@@ -220,14 +221,44 @@ export class Loader {
|
|
|
220
221
|
programId,
|
|
221
222
|
data,
|
|
222
223
|
});
|
|
223
|
-
|
|
224
|
-
|
|
224
|
+
const deployCommitment = 'processed';
|
|
225
|
+
const finalizeSignature = await connection.sendTransaction(
|
|
225
226
|
transaction,
|
|
226
227
|
[payer, program],
|
|
228
|
+
{preflightCommitment: deployCommitment},
|
|
229
|
+
);
|
|
230
|
+
const {context, value} = await connection.confirmTransaction(
|
|
227
231
|
{
|
|
228
|
-
|
|
232
|
+
signature: finalizeSignature,
|
|
233
|
+
lastValidBlockHeight: transaction.lastValidBlockHeight!,
|
|
234
|
+
blockhash: transaction.recentBlockhash!,
|
|
229
235
|
},
|
|
236
|
+
deployCommitment,
|
|
230
237
|
);
|
|
238
|
+
if (value.err) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`Transaction ${finalizeSignature} failed (${JSON.stringify(value)})`,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
// We prevent programs from being usable until the slot after their deployment.
|
|
244
|
+
// See https://github.com/solana-labs/solana/pull/29654
|
|
245
|
+
while (
|
|
246
|
+
true // eslint-disable-line no-constant-condition
|
|
247
|
+
) {
|
|
248
|
+
try {
|
|
249
|
+
const currentSlot = await connection.getSlot({
|
|
250
|
+
commitment: deployCommitment,
|
|
251
|
+
});
|
|
252
|
+
if (currentSlot > context.slot) {
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
} catch {
|
|
256
|
+
/* empty */
|
|
257
|
+
}
|
|
258
|
+
await new Promise(resolve =>
|
|
259
|
+
setTimeout(resolve, Math.round(MS_PER_SLOT / 2)),
|
|
260
|
+
);
|
|
261
|
+
}
|
|
231
262
|
}
|
|
232
263
|
|
|
233
264
|
// success
|
package/src/programs/vote.ts
CHANGED
|
@@ -366,8 +366,10 @@ export class VoteProgram {
|
|
|
366
366
|
* This is generated from the solana-vote-program VoteState struct as
|
|
367
367
|
* `VoteState::size_of()`:
|
|
368
368
|
* https://docs.rs/solana-vote-program/1.9.5/solana_vote_program/vote_state/struct.VoteState.html#method.size_of
|
|
369
|
+
*
|
|
370
|
+
* KEEP IN SYNC WITH `VoteState::size_of()` in https://github.com/solana-labs/solana/blob/a474cb24b9238f5edcc982f65c0b37d4a1046f7e/sdk/program/src/vote/state/mod.rs#L340-L342
|
|
369
371
|
*/
|
|
370
|
-
static space: number = 3731;
|
|
372
|
+
static space: number = process.env.TEST_LIVE ? 3762 : 3731;
|
|
371
373
|
|
|
372
374
|
/**
|
|
373
375
|
* Generate an Initialize instruction.
|
package/src/utils/ed25519.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as ed25519 from '@noble/ed25519';
|
|
1
|
+
import {ed25519} from '@noble/curves/ed25519';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* A 64 byte secret key, the first 32 bytes of which is the
|
|
@@ -16,8 +15,6 @@ export interface Ed25519Keypair {
|
|
|
16
15
|
secretKey: Ed25519SecretKey;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
ed25519.utils.sha512Sync = (...m) => sha512(ed25519.utils.concatBytes(...m));
|
|
20
|
-
|
|
21
18
|
export const generatePrivateKey = ed25519.utils.randomPrivateKey;
|
|
22
19
|
export const generateKeypair = (): Ed25519Keypair => {
|
|
23
20
|
const privateScalar = ed25519.utils.randomPrivateKey();
|
|
@@ -30,17 +27,17 @@ export const generateKeypair = (): Ed25519Keypair => {
|
|
|
30
27
|
secretKey,
|
|
31
28
|
};
|
|
32
29
|
};
|
|
33
|
-
export const getPublicKey = ed25519.
|
|
30
|
+
export const getPublicKey = ed25519.getPublicKey;
|
|
34
31
|
export function isOnCurve(publicKey: Uint8Array): boolean {
|
|
35
32
|
try {
|
|
36
|
-
ed25519.
|
|
33
|
+
ed25519.ExtendedPoint.fromHex(publicKey);
|
|
37
34
|
return true;
|
|
38
35
|
} catch {
|
|
39
36
|
return false;
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
export const sign = (
|
|
43
|
-
message: Parameters<typeof ed25519.
|
|
40
|
+
message: Parameters<typeof ed25519.sign>[0],
|
|
44
41
|
secretKey: Ed25519SecretKey,
|
|
45
|
-
) => ed25519.
|
|
46
|
-
export const verify = ed25519.
|
|
42
|
+
) => ed25519.sign(message, secretKey.slice(0, 32));
|
|
43
|
+
export const verify = ed25519.verify;
|
package/src/utils/secp256k1.ts
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {sha256} from '@noble/hashes/sha256';
|
|
3
|
-
import * as secp256k1 from '@noble/secp256k1';
|
|
4
|
-
|
|
5
|
-
// Supply a synchronous hashing algorithm to make this
|
|
6
|
-
// library interoperable with the synchronous APIs in web3.js.
|
|
7
|
-
secp256k1.utils.hmacSha256Sync = (key: Uint8Array, ...msgs: Uint8Array[]) => {
|
|
8
|
-
const h = hmac.create(sha256, key);
|
|
9
|
-
msgs.forEach(msg => h.update(msg));
|
|
10
|
-
return h.digest();
|
|
11
|
-
};
|
|
1
|
+
import {secp256k1} from '@noble/curves/secp256k1';
|
|
12
2
|
|
|
13
3
|
export const ecdsaSign = (
|
|
14
|
-
msgHash: Parameters<typeof secp256k1.
|
|
15
|
-
privKey: Parameters<typeof secp256k1.
|
|
16
|
-
) =>
|
|
4
|
+
msgHash: Parameters<typeof secp256k1.sign>[0],
|
|
5
|
+
privKey: Parameters<typeof secp256k1.sign>[1],
|
|
6
|
+
) => {
|
|
7
|
+
const signature = secp256k1.sign(msgHash, privKey);
|
|
8
|
+
return [signature.toCompactRawBytes(), signature.recovery!] as const;
|
|
9
|
+
};
|
|
17
10
|
export const isValidPrivateKey = secp256k1.utils.isValidPrivateKey;
|
|
18
11
|
export const publicKeyCreate = secp256k1.getPublicKey;
|