@solana/web3.js 1.77.3 → 1.78.1
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 +10978 -6909
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +10964 -6909
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +10963 -6895
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +61 -5
- package/lib/index.esm.js +10949 -6895
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +30704 -25949
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +9 -9
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +10978 -6909
- package/lib/index.native.js.map +1 -1
- package/package.json +27 -26
- package/src/connection.ts +41 -1
- package/src/fetch-impl.ts +14 -11
- package/src/keypair.ts +11 -2
- package/src/transaction/legacy.ts +31 -1
- package/src/utils/cluster.ts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/web3.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.78.1",
|
|
4
4
|
"description": "Solana Javascript API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"test:unit:node": "cross-env NODE_ENV=test TS_NODE_COMPILER_OPTIONS='{ \"module\": \"commonjs\", \"target\": \"es2019\" }' ts-mocha --require esm './test/**/*.test.ts'"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@babel/runtime": "^7.
|
|
57
|
+
"@babel/runtime": "^7.22.6",
|
|
58
58
|
"@noble/curves": "^1.0.0",
|
|
59
59
|
"@noble/hashes": "^1.3.0",
|
|
60
60
|
"@solana/buffer-layout": "^4.0.0",
|
|
@@ -66,65 +66,66 @@
|
|
|
66
66
|
"buffer": "6.0.3",
|
|
67
67
|
"fast-stable-stringify": "^1.0.0",
|
|
68
68
|
"jayson": "^4.1.0",
|
|
69
|
-
"node-fetch": "^2.6.
|
|
69
|
+
"node-fetch": "^2.6.12",
|
|
70
70
|
"rpc-websockets": "^7.5.1",
|
|
71
71
|
"superstruct": "^0.14.2"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@babel/core": "^7.
|
|
74
|
+
"@babel/core": "^7.22.9",
|
|
75
75
|
"@babel/plugin-proposal-class-properties": "^7.12.1",
|
|
76
|
+
"@babel/plugin-proposal-private-methods": "^7.18.6",
|
|
76
77
|
"@babel/plugin-transform-runtime": "^7.12.10",
|
|
77
|
-
"@babel/preset-env": "^7.
|
|
78
|
+
"@babel/preset-env": "^7.22.4",
|
|
78
79
|
"@babel/preset-typescript": "^7.12.16",
|
|
79
80
|
"@rollup/plugin-alias": "^4.0.3",
|
|
80
81
|
"@rollup/plugin-babel": "^6.0.3",
|
|
81
|
-
"@rollup/plugin-commonjs": "^
|
|
82
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
82
83
|
"@rollup/plugin-json": "^6.0.0",
|
|
83
84
|
"@rollup/plugin-multi-entry": "^6.0.0",
|
|
84
|
-
"@rollup/plugin-node-resolve": "^15.0
|
|
85
|
+
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
85
86
|
"@rollup/plugin-replace": "^5.0.2",
|
|
86
|
-
"@rollup/plugin-terser": "^0.4.
|
|
87
|
-
"@solana/spl-token": "^0.3.
|
|
87
|
+
"@rollup/plugin-terser": "^0.4.3",
|
|
88
|
+
"@solana/spl-token": "^0.3.8",
|
|
88
89
|
"@types/bn.js": "^5.1.0",
|
|
89
90
|
"@types/bs58": "^4.0.1",
|
|
90
|
-
"@types/chai": "^4.
|
|
91
|
+
"@types/chai": "^4.3.5",
|
|
91
92
|
"@types/chai-as-promised": "^7.1.3",
|
|
92
93
|
"@types/express-serve-static-core": "^4.17.35",
|
|
93
|
-
"@types/mocha": "^10.0.
|
|
94
|
-
"@types/mz": "^2.7.
|
|
95
|
-
"@types/node": "^
|
|
94
|
+
"@types/mocha": "^10.0.1",
|
|
95
|
+
"@types/mz": "^2.7.4",
|
|
96
|
+
"@types/node": "^20.4.4",
|
|
96
97
|
"@types/node-fetch": "2",
|
|
97
98
|
"@types/sinon": "^10.0.0",
|
|
98
99
|
"@types/sinon-chai": "^3.2.8",
|
|
99
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
100
|
-
"@typescript-eslint/parser": "^
|
|
101
|
-
"chai": "^4.3.
|
|
100
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
101
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
102
|
+
"chai": "^4.3.7",
|
|
102
103
|
"chai-as-promised": "^7.1.1",
|
|
103
104
|
"cross-env": "7.0.3",
|
|
104
|
-
"eslint": "^8.
|
|
105
|
-
"eslint-config-prettier": "^8.
|
|
105
|
+
"eslint": "^8.45.0",
|
|
106
|
+
"eslint-config-prettier": "^8.9.0",
|
|
106
107
|
"eslint-plugin-import": "^2.26.0",
|
|
107
108
|
"eslint-plugin-mocha": "^10.1.0",
|
|
108
109
|
"eslint-plugin-prettier": "^4.2.1",
|
|
109
110
|
"esm": "^3.2.25",
|
|
110
|
-
"mocha": "^10.
|
|
111
|
-
"mockttp": "^3.
|
|
111
|
+
"mocha": "^10.2.0",
|
|
112
|
+
"mockttp": "^3.9.1",
|
|
112
113
|
"mz": "^2.7.0",
|
|
113
114
|
"node-abort-controller": "^3.0.1",
|
|
114
115
|
"prettier": "^2.8.8",
|
|
115
116
|
"rimraf": "5.0.1",
|
|
116
|
-
"rollup": "^3.
|
|
117
|
+
"rollup": "^3.26.2",
|
|
117
118
|
"rollup-plugin-dts": "^5.3.0",
|
|
118
119
|
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
119
|
-
"semantic-release": "^
|
|
120
|
-
"sinon": "^15.0
|
|
120
|
+
"semantic-release": "^21.0.7",
|
|
121
|
+
"sinon": "^15.1.0",
|
|
121
122
|
"sinon-chai": "^3.7.0",
|
|
122
123
|
"start-server-and-test": "^2.0.0",
|
|
123
124
|
"ts-mocha": "^10.0.0",
|
|
124
|
-
"ts-node": "^10.
|
|
125
|
+
"ts-node": "^10.9.1",
|
|
125
126
|
"tsconfig": "workspace:*",
|
|
126
127
|
"tslib": "^2.5.2",
|
|
127
|
-
"typedoc": "^0.
|
|
128
|
-
"typescript": "^5.
|
|
128
|
+
"typedoc": "^0.24.8",
|
|
129
|
+
"typescript": "^5.1.6"
|
|
129
130
|
}
|
|
130
131
|
}
|
package/src/connection.ts
CHANGED
|
@@ -31,7 +31,7 @@ import {JSONRPCError} from 'jayson';
|
|
|
31
31
|
|
|
32
32
|
import {EpochSchedule} from './epoch-schedule';
|
|
33
33
|
import {SendTransactionError, SolanaJSONRPCError} from './errors';
|
|
34
|
-
import fetchImpl
|
|
34
|
+
import fetchImpl from './fetch-impl';
|
|
35
35
|
import {DurableNonce, NonceAccount} from './nonce-account';
|
|
36
36
|
import {PublicKey} from './publickey';
|
|
37
37
|
import {Signer} from './keypair';
|
|
@@ -623,6 +623,16 @@ export type GetLatestBlockhashConfig = {
|
|
|
623
623
|
minContextSlot?: number;
|
|
624
624
|
};
|
|
625
625
|
|
|
626
|
+
/**
|
|
627
|
+
* Configuration object for changing `isBlockhashValid` query behavior
|
|
628
|
+
*/
|
|
629
|
+
export type IsBlockhashValidConfig = {
|
|
630
|
+
/** The level of commitment desired */
|
|
631
|
+
commitment?: Commitment;
|
|
632
|
+
/** The minimum slot that the request can be evaluated at */
|
|
633
|
+
minContextSlot?: number;
|
|
634
|
+
};
|
|
635
|
+
|
|
626
636
|
/**
|
|
627
637
|
* Configuration object for changing `getSlot` query behavior
|
|
628
638
|
*/
|
|
@@ -2561,6 +2571,11 @@ const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(
|
|
|
2561
2571
|
}),
|
|
2562
2572
|
);
|
|
2563
2573
|
|
|
2574
|
+
/**
|
|
2575
|
+
* Expected JSON RPC response for the "isBlockhashValid" message
|
|
2576
|
+
*/
|
|
2577
|
+
const IsBlockhashValidRpcResult = jsonRpcResultAndContext(boolean());
|
|
2578
|
+
|
|
2564
2579
|
const PerfSampleResult = pick({
|
|
2565
2580
|
slot: number(),
|
|
2566
2581
|
numTransactions: number(),
|
|
@@ -4601,6 +4616,31 @@ export class Connection {
|
|
|
4601
4616
|
return res.result;
|
|
4602
4617
|
}
|
|
4603
4618
|
|
|
4619
|
+
/**
|
|
4620
|
+
* Returns whether a blockhash is still valid or not
|
|
4621
|
+
*/
|
|
4622
|
+
async isBlockhashValid(
|
|
4623
|
+
blockhash: Blockhash,
|
|
4624
|
+
rawConfig?: IsBlockhashValidConfig,
|
|
4625
|
+
): Promise<RpcResponseAndContext<boolean>> {
|
|
4626
|
+
const {commitment, config} = extractCommitmentFromConfig(rawConfig);
|
|
4627
|
+
const args = this._buildArgs(
|
|
4628
|
+
[blockhash],
|
|
4629
|
+
commitment,
|
|
4630
|
+
undefined /* encoding */,
|
|
4631
|
+
config,
|
|
4632
|
+
);
|
|
4633
|
+
const unsafeRes = await this._rpcRequest('isBlockhashValid', args);
|
|
4634
|
+
const res = create(unsafeRes, IsBlockhashValidRpcResult);
|
|
4635
|
+
if ('error' in res) {
|
|
4636
|
+
throw new SolanaJSONRPCError(
|
|
4637
|
+
res.error,
|
|
4638
|
+
'failed to determine if the blockhash `' + blockhash + '`is valid',
|
|
4639
|
+
);
|
|
4640
|
+
}
|
|
4641
|
+
return res.result;
|
|
4642
|
+
}
|
|
4643
|
+
|
|
4604
4644
|
/**
|
|
4605
4645
|
* Fetch the node version
|
|
4606
4646
|
*/
|
package/src/fetch-impl.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import * as nodeFetch from 'node-fetch';
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
export default (typeof globalThis.fetch === 'function'
|
|
4
|
+
? // The Fetch API is supported experimentally in Node 17.5+ and natively in Node 18+.
|
|
5
|
+
globalThis.fetch
|
|
6
|
+
: // Otherwise use the polyfill.
|
|
7
|
+
async function (
|
|
8
|
+
input: nodeFetch.RequestInfo,
|
|
9
|
+
init?: nodeFetch.RequestInit,
|
|
10
|
+
): Promise<nodeFetch.Response> {
|
|
11
|
+
const processedInput =
|
|
12
|
+
typeof input === 'string' && input.slice(0, 2) === '//'
|
|
13
|
+
? 'https:' + input
|
|
14
|
+
: input;
|
|
15
|
+
return await nodeFetch.default(processedInput, init);
|
|
16
|
+
}) as typeof globalThis.fetch;
|
package/src/keypair.ts
CHANGED
|
@@ -19,7 +19,7 @@ export class Keypair {
|
|
|
19
19
|
* Create a new keypair instance.
|
|
20
20
|
* Generate random keypair if no {@link Ed25519Keypair} is provided.
|
|
21
21
|
*
|
|
22
|
-
* @param keypair ed25519 keypair
|
|
22
|
+
* @param {Ed25519Keypair} keypair ed25519 keypair
|
|
23
23
|
*/
|
|
24
24
|
constructor(keypair?: Ed25519Keypair) {
|
|
25
25
|
this._keypair = keypair ?? generateKeypair();
|
|
@@ -27,6 +27,8 @@ export class Keypair {
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Generate a new random keypair
|
|
30
|
+
*
|
|
31
|
+
* @returns {Keypair} Keypair
|
|
30
32
|
*/
|
|
31
33
|
static generate(): Keypair {
|
|
32
34
|
return new Keypair(generateKeypair());
|
|
@@ -42,7 +44,9 @@ export class Keypair {
|
|
|
42
44
|
* @throws error if the provided secret key is invalid and validation is not skipped.
|
|
43
45
|
*
|
|
44
46
|
* @param secretKey secret key byte array
|
|
45
|
-
* @param options
|
|
47
|
+
* @param options skip secret key validation
|
|
48
|
+
*
|
|
49
|
+
* @returns {Keypair} Keypair
|
|
46
50
|
*/
|
|
47
51
|
static fromSecretKey(
|
|
48
52
|
secretKey: Uint8Array,
|
|
@@ -68,6 +72,8 @@ export class Keypair {
|
|
|
68
72
|
* Generate a keypair from a 32 byte seed.
|
|
69
73
|
*
|
|
70
74
|
* @param seed seed byte array
|
|
75
|
+
*
|
|
76
|
+
* @returns {Keypair} Keypair
|
|
71
77
|
*/
|
|
72
78
|
static fromSeed(seed: Uint8Array): Keypair {
|
|
73
79
|
const publicKey = getPublicKey(seed);
|
|
@@ -79,6 +85,8 @@ export class Keypair {
|
|
|
79
85
|
|
|
80
86
|
/**
|
|
81
87
|
* The public key for this keypair
|
|
88
|
+
*
|
|
89
|
+
* @returns {PublicKey} PublicKey
|
|
82
90
|
*/
|
|
83
91
|
get publicKey(): PublicKey {
|
|
84
92
|
return new PublicKey(this._keypair.publicKey);
|
|
@@ -86,6 +94,7 @@ export class Keypair {
|
|
|
86
94
|
|
|
87
95
|
/**
|
|
88
96
|
* The raw secret key for this keypair
|
|
97
|
+
* @returns {Uint8Array} Secret key in an array of Uint8 bytes
|
|
89
98
|
*/
|
|
90
99
|
get secretKey(): Uint8Array {
|
|
91
100
|
return new Uint8Array(this._keypair.secretKey);
|
|
@@ -209,6 +209,8 @@ export class Transaction {
|
|
|
209
209
|
|
|
210
210
|
/**
|
|
211
211
|
* The first (payer) Transaction signature
|
|
212
|
+
*
|
|
213
|
+
* @returns {Buffer | null} Buffer of payer's signature
|
|
212
214
|
*/
|
|
213
215
|
get signature(): Buffer | null {
|
|
214
216
|
if (this.signatures.length > 0) {
|
|
@@ -335,6 +337,8 @@ export class Transaction {
|
|
|
335
337
|
|
|
336
338
|
/**
|
|
337
339
|
* Add one or more instructions to this Transaction
|
|
340
|
+
*
|
|
341
|
+
* @param {Array< Transaction | TransactionInstruction | TransactionInstructionCtorFields >} items - Instructions to add to the Transaction
|
|
338
342
|
*/
|
|
339
343
|
add(
|
|
340
344
|
...items: Array<
|
|
@@ -464,7 +468,7 @@ export class Transaction {
|
|
|
464
468
|
ignorePunctuation: false,
|
|
465
469
|
numeric: false,
|
|
466
470
|
caseFirst: 'lower',
|
|
467
|
-
};
|
|
471
|
+
} as Intl.CollatorOptions;
|
|
468
472
|
return x.pubkey
|
|
469
473
|
.toBase58()
|
|
470
474
|
.localeCompare(y.pubkey.toBase58(), 'en', options);
|
|
@@ -594,6 +598,10 @@ export class Transaction {
|
|
|
594
598
|
|
|
595
599
|
/**
|
|
596
600
|
* Get the estimated fee associated with a transaction
|
|
601
|
+
*
|
|
602
|
+
* @param {Connection} connection Connection to RPC Endpoint.
|
|
603
|
+
*
|
|
604
|
+
* @returns {Promise<number | null>} The estimated fee for the transaction
|
|
597
605
|
*/
|
|
598
606
|
async getEstimatedFee(connection: Connection): Promise<number | null> {
|
|
599
607
|
return (await connection.getFeeForMessage(this.compileMessage())).value;
|
|
@@ -641,6 +649,8 @@ export class Transaction {
|
|
|
641
649
|
* rejected.
|
|
642
650
|
*
|
|
643
651
|
* The Transaction must be assigned a valid `recentBlockhash` before invoking this method
|
|
652
|
+
*
|
|
653
|
+
* @param {Array<Signer>} signers Array of signers that will sign the transaction
|
|
644
654
|
*/
|
|
645
655
|
sign(...signers: Array<Signer>) {
|
|
646
656
|
if (signers.length === 0) {
|
|
@@ -675,6 +685,8 @@ export class Transaction {
|
|
|
675
685
|
* instructions.
|
|
676
686
|
*
|
|
677
687
|
* All the caveats from the `sign` method apply to `partialSign`
|
|
688
|
+
*
|
|
689
|
+
* @param {Array<Signer>} signers Array of signers that will sign the transaction
|
|
678
690
|
*/
|
|
679
691
|
partialSign(...signers: Array<Signer>) {
|
|
680
692
|
if (signers.length === 0) {
|
|
@@ -713,6 +725,9 @@ export class Transaction {
|
|
|
713
725
|
* Add an externally created signature to a transaction. The public key
|
|
714
726
|
* must correspond to either the fee payer or a signer account in the transaction
|
|
715
727
|
* instructions.
|
|
728
|
+
*
|
|
729
|
+
* @param {PublicKey} pubkey Public key that will be added to the transaction.
|
|
730
|
+
* @param {Buffer} signature An externally created signature to add to the transaction.
|
|
716
731
|
*/
|
|
717
732
|
addSignature(pubkey: PublicKey, signature: Buffer) {
|
|
718
733
|
this._compile(); // Ensure signatures array is populated
|
|
@@ -739,6 +754,8 @@ export class Transaction {
|
|
|
739
754
|
* Verify signatures of a Transaction
|
|
740
755
|
* Optional parameter specifies if we're expecting a fully signed Transaction or a partially signed one.
|
|
741
756
|
* If no boolean is provided, we expect a fully signed Transaction by default.
|
|
757
|
+
*
|
|
758
|
+
* @param {boolean} [requireAllSignatures=true] Require a fully signed Transaction
|
|
742
759
|
*/
|
|
743
760
|
verifySignatures(requireAllSignatures?: boolean): boolean {
|
|
744
761
|
return this._verifySignatures(
|
|
@@ -770,6 +787,10 @@ export class Transaction {
|
|
|
770
787
|
|
|
771
788
|
/**
|
|
772
789
|
* Serialize the Transaction in the wire format.
|
|
790
|
+
*
|
|
791
|
+
* @param {Buffer} [config] Config of transaction.
|
|
792
|
+
*
|
|
793
|
+
* @returns {Buffer} Signature of transaction in wire format.
|
|
773
794
|
*/
|
|
774
795
|
serialize(config?: SerializeConfig): Buffer {
|
|
775
796
|
const {requireAllSignatures, verifySignatures} = Object.assign(
|
|
@@ -849,6 +870,10 @@ export class Transaction {
|
|
|
849
870
|
|
|
850
871
|
/**
|
|
851
872
|
* Parse a wire transaction into a Transaction object.
|
|
873
|
+
*
|
|
874
|
+
* @param {Buffer | Uint8Array | Array<number>} buffer Signature of wire Transaction
|
|
875
|
+
*
|
|
876
|
+
* @returns {Transaction} Transaction associated with the signature
|
|
852
877
|
*/
|
|
853
878
|
static from(buffer: Buffer | Uint8Array | Array<number>): Transaction {
|
|
854
879
|
// Slice up wire data
|
|
@@ -867,6 +892,11 @@ export class Transaction {
|
|
|
867
892
|
|
|
868
893
|
/**
|
|
869
894
|
* Populate Transaction object from message and signatures
|
|
895
|
+
*
|
|
896
|
+
* @param {Message} message Message of transaction
|
|
897
|
+
* @param {Array<string>} signatures List of signatures to assign to the transaction
|
|
898
|
+
*
|
|
899
|
+
* @returns {Transaction} The populated Transaction
|
|
870
900
|
*/
|
|
871
901
|
static populate(
|
|
872
902
|
message: Message,
|
package/src/utils/cluster.ts
CHANGED
|
@@ -15,6 +15,10 @@ export type Cluster = 'devnet' | 'testnet' | 'mainnet-beta';
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Retrieves the RPC API URL for the specified cluster
|
|
18
|
+
* @param {Cluster} [cluster="devnet"] - The cluster name of the RPC API URL to use. Possible options: 'devnet' | 'testnet' | 'mainnet-beta'
|
|
19
|
+
* @param {boolean} [tls="http"] - Use TLS when connecting to cluster.
|
|
20
|
+
*
|
|
21
|
+
* @returns {string} URL string of the RPC endpoint
|
|
18
22
|
*/
|
|
19
23
|
export function clusterApiUrl(cluster?: Cluster, tls?: boolean): string {
|
|
20
24
|
const key = tls === false ? 'http' : 'https';
|