@solana/web3.js 1.74.0 → 1.76.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 +72 -62
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +37 -23
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +86 -76
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +20 -0
- package/lib/index.esm.js +37 -23
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +3132 -1754
- 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 +72 -62
- package/lib/index.native.js.map +1 -1
- package/package.json +15 -16
- package/src/connection.ts +56 -0
- package/src/utils/ed25519.ts +6 -9
- package/src/utils/secp256k1.ts +7 -14
package/lib/index.d.ts
CHANGED
|
@@ -2101,6 +2101,22 @@ type InflationReward = {
|
|
|
2101
2101
|
/** vote account commission when the reward was credited */
|
|
2102
2102
|
commission?: number | null;
|
|
2103
2103
|
};
|
|
2104
|
+
type RecentPrioritizationFees = {
|
|
2105
|
+
/** slot in which the fee was observed */
|
|
2106
|
+
slot: number;
|
|
2107
|
+
/** the per-compute-unit fee paid by at least one successfully landed transaction, specified in increments of 0.000001 lamports*/
|
|
2108
|
+
prioritizationFee: number;
|
|
2109
|
+
};
|
|
2110
|
+
/**
|
|
2111
|
+
* Configuration object for changing `getRecentPrioritizationFees` query behavior
|
|
2112
|
+
*/
|
|
2113
|
+
type GetRecentPrioritizationFeesConfig = {
|
|
2114
|
+
/**
|
|
2115
|
+
* If this parameter is provided, the response will reflect a fee to land a transaction locking
|
|
2116
|
+
* all of the provided accounts as writable.
|
|
2117
|
+
*/
|
|
2118
|
+
lockedWritableAccounts?: PublicKey[];
|
|
2119
|
+
};
|
|
2104
2120
|
type InflationRate = {
|
|
2105
2121
|
/** total inflation */
|
|
2106
2122
|
total: number;
|
|
@@ -3286,6 +3302,10 @@ export class Connection {
|
|
|
3286
3302
|
* Fetch the fee for a message from the cluster, return with context
|
|
3287
3303
|
*/
|
|
3288
3304
|
getFeeForMessage(message: VersionedMessage, commitment?: Commitment): Promise<RpcResponseAndContext<number | null>>;
|
|
3305
|
+
/**
|
|
3306
|
+
* Fetch a list of prioritization fees from recent blocks.
|
|
3307
|
+
*/
|
|
3308
|
+
getRecentPrioritizationFees(config?: GetRecentPrioritizationFeesConfig): Promise<RecentPrioritizationFees[]>;
|
|
3289
3309
|
/**
|
|
3290
3310
|
* Fetch a recent blockhash from the cluster
|
|
3291
3311
|
* @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
|
package/lib/index.esm.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import {
|
|
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';
|
|
@@ -20,8 +19,7 @@ import * as nodeFetch from 'node-fetch';
|
|
|
20
19
|
import RpcWebSocketCommonClient from 'rpc-websockets/dist/lib/client';
|
|
21
20
|
import WebsocketFactory from 'rpc-websockets/dist/lib/client/websocket';
|
|
22
21
|
import { keccak_256 } from '@noble/hashes/sha3';
|
|
23
|
-
import {
|
|
24
|
-
import * as secp256k1 from '@noble/secp256k1';
|
|
22
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
25
23
|
|
|
26
24
|
/**
|
|
27
25
|
* A 64 byte secret key, the first 32 bytes of which is the
|
|
@@ -29,7 +27,6 @@ import * as secp256k1 from '@noble/secp256k1';
|
|
|
29
27
|
* Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
|
|
30
28
|
*/
|
|
31
29
|
|
|
32
|
-
ed25519.utils.sha512Sync = (...m) => sha512(ed25519.utils.concatBytes(...m));
|
|
33
30
|
const generatePrivateKey = ed25519.utils.randomPrivateKey;
|
|
34
31
|
const generateKeypair = () => {
|
|
35
32
|
const privateScalar = ed25519.utils.randomPrivateKey();
|
|
@@ -42,17 +39,17 @@ const generateKeypair = () => {
|
|
|
42
39
|
secretKey
|
|
43
40
|
};
|
|
44
41
|
};
|
|
45
|
-
const getPublicKey = ed25519.
|
|
42
|
+
const getPublicKey = ed25519.getPublicKey;
|
|
46
43
|
function isOnCurve(publicKey) {
|
|
47
44
|
try {
|
|
48
|
-
ed25519.
|
|
45
|
+
ed25519.ExtendedPoint.fromHex(publicKey);
|
|
49
46
|
return true;
|
|
50
47
|
} catch {
|
|
51
48
|
return false;
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
|
-
const sign = (message, secretKey) => ed25519.
|
|
55
|
-
const verify = ed25519.
|
|
51
|
+
const sign = (message, secretKey) => ed25519.sign(message, secretKey.slice(0, 32));
|
|
52
|
+
const verify = ed25519.verify;
|
|
56
53
|
|
|
57
54
|
const toBuffer = arr => {
|
|
58
55
|
if (Buffer.isBuffer(arr)) {
|
|
@@ -609,8 +606,8 @@ class CompiledKeys {
|
|
|
609
606
|
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
610
607
|
for (const accountMeta of ix.keys) {
|
|
611
608
|
const keyMeta = getOrInsertDefault(accountMeta.pubkey);
|
|
612
|
-
keyMeta.isSigner
|
|
613
|
-
keyMeta.isWritable
|
|
609
|
+
keyMeta.isSigner ||= accountMeta.isSigner;
|
|
610
|
+
keyMeta.isWritable ||= accountMeta.isWritable;
|
|
614
611
|
}
|
|
615
612
|
}
|
|
616
613
|
return new CompiledKeys(payer, keyMetaMap);
|
|
@@ -5998,6 +5995,13 @@ const GetInflationRewardResult = jsonRpcResult(array(nullable(type({
|
|
|
5998
5995
|
postBalance: number(),
|
|
5999
5996
|
commission: optional(nullable(number()))
|
|
6000
5997
|
}))));
|
|
5998
|
+
/**
|
|
5999
|
+
* Expected JSON RPC response for the "getRecentPrioritizationFees" message
|
|
6000
|
+
*/
|
|
6001
|
+
const GetRecentPrioritizationFeesResult = array(type({
|
|
6002
|
+
slot: number(),
|
|
6003
|
+
prioritizationFee: number()
|
|
6004
|
+
}));
|
|
6001
6005
|
/**
|
|
6002
6006
|
* Expected JSON RPC response for the "getInflationRate" message
|
|
6003
6007
|
*/
|
|
@@ -6222,6 +6226,11 @@ const GetInflationGovernorRpcResult = jsonRpcResult(GetInflationGovernorResult);
|
|
|
6222
6226
|
*/
|
|
6223
6227
|
const GetInflationRateRpcResult = jsonRpcResult(GetInflationRateResult);
|
|
6224
6228
|
|
|
6229
|
+
/**
|
|
6230
|
+
* Expected JSON RPC response for the "getRecentPrioritizationFees" message
|
|
6231
|
+
*/
|
|
6232
|
+
const GetRecentPrioritizationFeesRpcResult = jsonRpcResult(GetRecentPrioritizationFeesResult);
|
|
6233
|
+
|
|
6225
6234
|
/**
|
|
6226
6235
|
* Expected JSON RPC response for the "getEpochInfo" message
|
|
6227
6236
|
*/
|
|
@@ -8119,6 +8128,19 @@ class Connection {
|
|
|
8119
8128
|
return res.result;
|
|
8120
8129
|
}
|
|
8121
8130
|
|
|
8131
|
+
/**
|
|
8132
|
+
* Fetch a list of prioritization fees from recent blocks.
|
|
8133
|
+
*/
|
|
8134
|
+
async getRecentPrioritizationFees(config) {
|
|
8135
|
+
const accounts = config?.lockedWritableAccounts?.map(key => key.toBase58());
|
|
8136
|
+
const args = this._buildArgs(accounts?.length ? [accounts] : []);
|
|
8137
|
+
const unsafeRes = await this._rpcRequest('getRecentPrioritizationFees', args);
|
|
8138
|
+
const res = create(unsafeRes, GetRecentPrioritizationFeesRpcResult);
|
|
8139
|
+
if ('error' in res) {
|
|
8140
|
+
throw new SolanaJSONRPCError(res.error, 'failed to get recent prioritization fees');
|
|
8141
|
+
}
|
|
8142
|
+
return res.result;
|
|
8143
|
+
}
|
|
8122
8144
|
/**
|
|
8123
8145
|
* Fetch a recent blockhash from the cluster
|
|
8124
8146
|
* @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
|
|
@@ -9129,12 +9151,11 @@ class Connection {
|
|
|
9129
9151
|
* @internal
|
|
9130
9152
|
*/
|
|
9131
9153
|
_onSubscriptionStateChange(clientSubscriptionId, callback) {
|
|
9132
|
-
var _this$_subscriptionSt;
|
|
9133
9154
|
const hash = this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
|
|
9134
9155
|
if (hash == null) {
|
|
9135
9156
|
return () => {};
|
|
9136
9157
|
}
|
|
9137
|
-
const stateChangeCallbacks =
|
|
9158
|
+
const stateChangeCallbacks = this._subscriptionStateChangeCallbacksByHash[hash] ||= new Set();
|
|
9138
9159
|
stateChangeCallbacks.add(callback);
|
|
9139
9160
|
return () => {
|
|
9140
9161
|
stateChangeCallbacks.delete(callback);
|
|
@@ -10362,17 +10383,10 @@ class Ed25519Program {
|
|
|
10362
10383
|
}
|
|
10363
10384
|
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
10364
10385
|
|
|
10365
|
-
|
|
10366
|
-
|
|
10367
|
-
|
|
10368
|
-
const h = hmac.create(sha256, key);
|
|
10369
|
-
msgs.forEach(msg => h.update(msg));
|
|
10370
|
-
return h.digest();
|
|
10386
|
+
const ecdsaSign = (msgHash, privKey) => {
|
|
10387
|
+
const signature = secp256k1.sign(msgHash, privKey);
|
|
10388
|
+
return [signature.toCompactRawBytes(), signature.recovery];
|
|
10371
10389
|
};
|
|
10372
|
-
const ecdsaSign = (msgHash, privKey) => secp256k1.signSync(msgHash, privKey, {
|
|
10373
|
-
der: false,
|
|
10374
|
-
recovered: true
|
|
10375
|
-
});
|
|
10376
10390
|
secp256k1.utils.isValidPrivateKey;
|
|
10377
10391
|
const publicKeyCreate = secp256k1.getPublicKey;
|
|
10378
10392
|
|