@solana/client 0.1.4 → 0.2.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/dist/index.browser.cjs +141 -35
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +130 -36
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +130 -36
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +141 -35
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +130 -36
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/actions.d.ts +9 -0
- package/dist/types/actions.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +42 -10
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/wallet/connectors.d.ts +29 -0
- package/dist/types/wallet/connectors.d.ts.map +1 -0
- package/package.json +7 -1
package/dist/index.browser.cjs
CHANGED
|
@@ -7,14 +7,44 @@ var system = require('@solana-program/system');
|
|
|
7
7
|
var token = require('@solana-program/token');
|
|
8
8
|
var computeBudget = require('@solana-program/compute-budget');
|
|
9
9
|
var vanilla = require('zustand/vanilla');
|
|
10
|
-
var transactions = require('@solana/transactions');
|
|
11
|
-
var walletStandardFeatures = require('@solana/wallet-standard-features');
|
|
12
10
|
var app = require('@wallet-standard/app');
|
|
13
11
|
var features = require('@wallet-standard/features');
|
|
12
|
+
var transactions = require('@solana/transactions');
|
|
13
|
+
var walletStandardFeatures = require('@solana/wallet-standard-features');
|
|
14
14
|
|
|
15
15
|
var __defProp = Object.defineProperty;
|
|
16
16
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
17
|
|
|
18
|
+
// src/actions.ts
|
|
19
|
+
function connectWallet(client, params) {
|
|
20
|
+
return client.actions.connectWallet(params.connectorId, params.options);
|
|
21
|
+
}
|
|
22
|
+
__name(connectWallet, "connectWallet");
|
|
23
|
+
function disconnectWallet(client, _params) {
|
|
24
|
+
return client.actions.disconnectWallet();
|
|
25
|
+
}
|
|
26
|
+
__name(disconnectWallet, "disconnectWallet");
|
|
27
|
+
function fetchAccount(client, params) {
|
|
28
|
+
return client.actions.fetchAccount(params.address, params.commitment);
|
|
29
|
+
}
|
|
30
|
+
__name(fetchAccount, "fetchAccount");
|
|
31
|
+
function fetchBalance(client, params) {
|
|
32
|
+
return client.actions.fetchBalance(params.address, params.commitment);
|
|
33
|
+
}
|
|
34
|
+
__name(fetchBalance, "fetchBalance");
|
|
35
|
+
function requestAirdrop(client, params) {
|
|
36
|
+
return client.actions.requestAirdrop(params.address, params.lamports);
|
|
37
|
+
}
|
|
38
|
+
__name(requestAirdrop, "requestAirdrop");
|
|
39
|
+
function sendTransaction(client, params) {
|
|
40
|
+
return client.actions.sendTransaction(params.transaction, params.commitment);
|
|
41
|
+
}
|
|
42
|
+
__name(sendTransaction, "sendTransaction");
|
|
43
|
+
function setCluster(client, params) {
|
|
44
|
+
return client.actions.setCluster(params.endpoint, params.config);
|
|
45
|
+
}
|
|
46
|
+
__name(setCluster, "setCluster");
|
|
47
|
+
|
|
18
48
|
// src/utils.ts
|
|
19
49
|
function deepFreeze(value) {
|
|
20
50
|
if (typeof value !== "object" || value === null) {
|
|
@@ -227,7 +257,7 @@ function getSerializableStateSnapshot(client) {
|
|
|
227
257
|
}
|
|
228
258
|
}
|
|
229
259
|
return {
|
|
230
|
-
autoconnect:
|
|
260
|
+
autoconnect: Boolean(lastConnectorId),
|
|
231
261
|
commitment: state.cluster.commitment,
|
|
232
262
|
endpoint: state.cluster.endpoint,
|
|
233
263
|
lastConnectorId,
|
|
@@ -304,7 +334,7 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
304
334
|
}
|
|
305
335
|
}
|
|
306
336
|
__name(warmupCluster, "warmupCluster");
|
|
307
|
-
async function
|
|
337
|
+
async function setCluster2(endpoint, config) {
|
|
308
338
|
const nextCommitment = config?.commitment ?? store.getState().cluster.commitment;
|
|
309
339
|
const websocketEndpoint = config?.websocketEndpoint ?? endpoint;
|
|
310
340
|
store.setState((state) => ({
|
|
@@ -355,8 +385,8 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
355
385
|
throw error;
|
|
356
386
|
}
|
|
357
387
|
}
|
|
358
|
-
__name(
|
|
359
|
-
async function
|
|
388
|
+
__name(setCluster2, "setCluster");
|
|
389
|
+
async function connectWallet2(connectorId, options = {}) {
|
|
360
390
|
const connector = connectors.get(connectorId);
|
|
361
391
|
if (!connector) {
|
|
362
392
|
throw new Error(`No wallet connector registered for id "${connectorId}".`);
|
|
@@ -395,8 +425,8 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
395
425
|
throw error;
|
|
396
426
|
}
|
|
397
427
|
}
|
|
398
|
-
__name(
|
|
399
|
-
async function
|
|
428
|
+
__name(connectWallet2, "connectWallet");
|
|
429
|
+
async function disconnectWallet3() {
|
|
400
430
|
const wallet = store.getState().wallet;
|
|
401
431
|
if (wallet.status === "disconnected") {
|
|
402
432
|
return;
|
|
@@ -418,8 +448,8 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
418
448
|
updateState(store, { wallet: { status: "disconnected" } });
|
|
419
449
|
}
|
|
420
450
|
}
|
|
421
|
-
__name(
|
|
422
|
-
async function
|
|
451
|
+
__name(disconnectWallet3, "disconnectWallet");
|
|
452
|
+
async function fetchBalance2(address4, commitment) {
|
|
423
453
|
const key = address4.toString();
|
|
424
454
|
store.setState((state) => ({
|
|
425
455
|
...state,
|
|
@@ -482,8 +512,8 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
482
512
|
throw error;
|
|
483
513
|
}
|
|
484
514
|
}
|
|
485
|
-
__name(
|
|
486
|
-
async function
|
|
515
|
+
__name(fetchBalance2, "fetchBalance");
|
|
516
|
+
async function fetchAccount2(address4, commitment) {
|
|
487
517
|
const key = address4.toString();
|
|
488
518
|
store.setState((state) => ({
|
|
489
519
|
...state,
|
|
@@ -547,8 +577,8 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
547
577
|
throw error;
|
|
548
578
|
}
|
|
549
579
|
}
|
|
550
|
-
__name(
|
|
551
|
-
async function
|
|
580
|
+
__name(fetchAccount2, "fetchAccount");
|
|
581
|
+
async function sendTransaction2(transaction, commitment) {
|
|
552
582
|
const targetCommitment = getCommitment(commitment);
|
|
553
583
|
const abortController = new AbortController();
|
|
554
584
|
const signature4 = await runtime.rpc.sendTransaction(kit.getBase64EncodedWireTransaction(transaction), {
|
|
@@ -619,8 +649,8 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
619
649
|
throw error;
|
|
620
650
|
}
|
|
621
651
|
}
|
|
622
|
-
__name(
|
|
623
|
-
async function
|
|
652
|
+
__name(sendTransaction2, "sendTransaction");
|
|
653
|
+
async function requestAirdrop2(address4, lamports2) {
|
|
624
654
|
try {
|
|
625
655
|
const factory = kit.airdropFactory({
|
|
626
656
|
rpc: runtime.rpc,
|
|
@@ -646,15 +676,15 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
646
676
|
throw error;
|
|
647
677
|
}
|
|
648
678
|
}
|
|
649
|
-
__name(
|
|
679
|
+
__name(requestAirdrop2, "requestAirdrop");
|
|
650
680
|
return {
|
|
651
|
-
connectWallet,
|
|
652
|
-
disconnectWallet:
|
|
653
|
-
fetchAccount,
|
|
654
|
-
fetchBalance,
|
|
655
|
-
requestAirdrop,
|
|
656
|
-
sendTransaction,
|
|
657
|
-
setCluster
|
|
681
|
+
connectWallet: connectWallet2,
|
|
682
|
+
disconnectWallet: disconnectWallet3,
|
|
683
|
+
fetchAccount: fetchAccount2,
|
|
684
|
+
fetchBalance: fetchBalance2,
|
|
685
|
+
requestAirdrop: requestAirdrop2,
|
|
686
|
+
sendTransaction: sendTransaction2,
|
|
687
|
+
setCluster: setCluster2
|
|
658
688
|
};
|
|
659
689
|
}
|
|
660
690
|
__name(createActions, "createActions");
|
|
@@ -1088,13 +1118,13 @@ function createWalletTransactionSigner(session, config = {}) {
|
|
|
1088
1118
|
}
|
|
1089
1119
|
if (session.sendTransaction) {
|
|
1090
1120
|
const base58Encoder = codecsStrings.getBase58Encoder();
|
|
1091
|
-
const
|
|
1121
|
+
const sendTransaction2 = session.sendTransaction.bind(session);
|
|
1092
1122
|
const sendingSigner = Object.freeze({
|
|
1093
1123
|
address: address4,
|
|
1094
1124
|
async signAndSendTransactions(transactions) {
|
|
1095
1125
|
const signatures = [];
|
|
1096
1126
|
for (const transaction of transactions) {
|
|
1097
|
-
const signatureString = await
|
|
1127
|
+
const signatureString = await sendTransaction2(
|
|
1098
1128
|
transaction,
|
|
1099
1129
|
commitment ? { commitment } : void 0
|
|
1100
1130
|
);
|
|
@@ -1280,7 +1310,7 @@ function createSplTokenHelper(runtime, config) {
|
|
|
1280
1310
|
return ata;
|
|
1281
1311
|
}
|
|
1282
1312
|
__name(deriveAssociatedTokenAddress, "deriveAssociatedTokenAddress");
|
|
1283
|
-
async function
|
|
1313
|
+
async function fetchBalance2(owner, commitment) {
|
|
1284
1314
|
const ataAddress = await deriveAssociatedTokenAddress(owner);
|
|
1285
1315
|
const decimals = await resolveDecimals(commitment);
|
|
1286
1316
|
try {
|
|
@@ -1305,7 +1335,7 @@ function createSplTokenHelper(runtime, config) {
|
|
|
1305
1335
|
};
|
|
1306
1336
|
}
|
|
1307
1337
|
}
|
|
1308
|
-
__name(
|
|
1338
|
+
__name(fetchBalance2, "fetchBalance");
|
|
1309
1339
|
async function prepareTransfer(config2) {
|
|
1310
1340
|
const commitment = config2.commitment;
|
|
1311
1341
|
const lifetime = await resolveLifetime2(runtime, commitment, config2.lifetime);
|
|
@@ -1422,7 +1452,7 @@ function createSplTokenHelper(runtime, config) {
|
|
|
1422
1452
|
__name(sendTransfer, "sendTransfer");
|
|
1423
1453
|
return {
|
|
1424
1454
|
deriveAssociatedTokenAddress,
|
|
1425
|
-
fetchBalance,
|
|
1455
|
+
fetchBalance: fetchBalance2,
|
|
1426
1456
|
prepareTransfer,
|
|
1427
1457
|
sendPreparedTransfer,
|
|
1428
1458
|
sendTransfer
|
|
@@ -2747,13 +2777,13 @@ function getChain(account) {
|
|
|
2747
2777
|
return preferred;
|
|
2748
2778
|
}
|
|
2749
2779
|
__name(getChain, "getChain");
|
|
2750
|
-
async function
|
|
2780
|
+
async function disconnectWallet2(wallet) {
|
|
2751
2781
|
const disconnectFeature = wallet.features[features.StandardDisconnect];
|
|
2752
2782
|
if (disconnectFeature) {
|
|
2753
2783
|
await disconnectFeature.disconnect();
|
|
2754
2784
|
}
|
|
2755
2785
|
}
|
|
2756
|
-
__name(
|
|
2786
|
+
__name(disconnectWallet2, "disconnectWallet");
|
|
2757
2787
|
function createWalletStandardConnector(wallet, options = {}) {
|
|
2758
2788
|
const metadata = {
|
|
2759
2789
|
canAutoConnect: options.canAutoConnect ?? Boolean(wallet.features[features.StandardConnect]),
|
|
@@ -2801,7 +2831,7 @@ function createWalletStandardConnector(wallet, options = {}) {
|
|
|
2801
2831
|
const [output] = await signTransactionFeature.signTransaction(request);
|
|
2802
2832
|
return transactionDecoder.decode(output.signedTransaction);
|
|
2803
2833
|
} : void 0;
|
|
2804
|
-
const
|
|
2834
|
+
const sendTransaction2 = signAndSendFeature ? async (transaction, config) => {
|
|
2805
2835
|
const wireBytes = new Uint8Array(transactionEncoder.encode(transaction));
|
|
2806
2836
|
const chain = options.defaultChain ?? getChain(primaryAccount) ?? "solana:mainnet-beta";
|
|
2807
2837
|
const [output] = await signAndSendFeature.signAndSendTransaction({
|
|
@@ -2815,21 +2845,21 @@ function createWalletStandardConnector(wallet, options = {}) {
|
|
|
2815
2845
|
return base58Decoder.decode(output.signature);
|
|
2816
2846
|
} : void 0;
|
|
2817
2847
|
async function disconnectSession() {
|
|
2818
|
-
await
|
|
2848
|
+
await disconnectWallet2(wallet);
|
|
2819
2849
|
}
|
|
2820
2850
|
__name(disconnectSession, "disconnectSession");
|
|
2821
2851
|
return {
|
|
2822
2852
|
account: sessionAccount,
|
|
2823
2853
|
connector: metadata,
|
|
2824
2854
|
disconnect: disconnectSession,
|
|
2825
|
-
sendTransaction,
|
|
2855
|
+
sendTransaction: sendTransaction2,
|
|
2826
2856
|
signMessage,
|
|
2827
2857
|
signTransaction
|
|
2828
2858
|
};
|
|
2829
2859
|
}
|
|
2830
2860
|
__name(connect, "connect");
|
|
2831
2861
|
async function disconnect() {
|
|
2832
|
-
await
|
|
2862
|
+
await disconnectWallet2(wallet);
|
|
2833
2863
|
}
|
|
2834
2864
|
__name(disconnect, "disconnect");
|
|
2835
2865
|
function isSupported() {
|
|
@@ -2885,12 +2915,78 @@ function watchWalletStandardConnectors(onChange, options = {}) {
|
|
|
2885
2915
|
}
|
|
2886
2916
|
__name(watchWalletStandardConnectors, "watchWalletStandardConnectors");
|
|
2887
2917
|
|
|
2918
|
+
// src/wallet/connectors.ts
|
|
2919
|
+
function autoDiscover(options = {}) {
|
|
2920
|
+
const { get } = app.getWallets();
|
|
2921
|
+
const wallets = get().filter((wallet) => options.filter ? options.filter(wallet) : true);
|
|
2922
|
+
const connectors = wallets.map((wallet) => createWalletStandardConnector(wallet, options.overrides?.(wallet)));
|
|
2923
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2924
|
+
return connectors.filter((connector) => {
|
|
2925
|
+
if (seen.has(connector.id)) return false;
|
|
2926
|
+
seen.add(connector.id);
|
|
2927
|
+
return true;
|
|
2928
|
+
});
|
|
2929
|
+
}
|
|
2930
|
+
__name(autoDiscover, "autoDiscover");
|
|
2931
|
+
function injected(options) {
|
|
2932
|
+
const connector = {
|
|
2933
|
+
canAutoConnect: true,
|
|
2934
|
+
id: "wallet-standard:injected",
|
|
2935
|
+
kind: "wallet-standard",
|
|
2936
|
+
name: "Injected Wallet",
|
|
2937
|
+
ready: typeof window !== "undefined",
|
|
2938
|
+
async connect() {
|
|
2939
|
+
const wallets = app.getWallets().get();
|
|
2940
|
+
const first = wallets.find((wallet) => features.StandardConnect in wallet.features);
|
|
2941
|
+
if (!first) {
|
|
2942
|
+
throw new Error("No Wallet Standard wallets available.");
|
|
2943
|
+
}
|
|
2944
|
+
return createWalletStandardConnector(first, options).connect();
|
|
2945
|
+
},
|
|
2946
|
+
async disconnect() {
|
|
2947
|
+
},
|
|
2948
|
+
isSupported() {
|
|
2949
|
+
return typeof window !== "undefined";
|
|
2950
|
+
}
|
|
2951
|
+
};
|
|
2952
|
+
return connector;
|
|
2953
|
+
}
|
|
2954
|
+
__name(injected, "injected");
|
|
2955
|
+
function filterByName(name) {
|
|
2956
|
+
const lower = name.toLowerCase();
|
|
2957
|
+
return (wallet) => wallet.name.toLowerCase().includes(lower);
|
|
2958
|
+
}
|
|
2959
|
+
__name(filterByName, "filterByName");
|
|
2960
|
+
function phantom(options) {
|
|
2961
|
+
return autoDiscover({
|
|
2962
|
+
filter: filterByName("phantom"),
|
|
2963
|
+
overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:phantom" }), "overrides")
|
|
2964
|
+
});
|
|
2965
|
+
}
|
|
2966
|
+
__name(phantom, "phantom");
|
|
2967
|
+
function solflare(options) {
|
|
2968
|
+
return autoDiscover({
|
|
2969
|
+
filter: filterByName("solflare"),
|
|
2970
|
+
overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:solflare" }), "overrides")
|
|
2971
|
+
});
|
|
2972
|
+
}
|
|
2973
|
+
__name(solflare, "solflare");
|
|
2974
|
+
function backpack(options) {
|
|
2975
|
+
return autoDiscover({
|
|
2976
|
+
filter: filterByName("backpack"),
|
|
2977
|
+
overrides: /* @__PURE__ */ __name(() => ({ ...options, id: "wallet-standard:backpack" }), "overrides")
|
|
2978
|
+
});
|
|
2979
|
+
}
|
|
2980
|
+
__name(backpack, "backpack");
|
|
2981
|
+
|
|
2888
2982
|
exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
|
|
2889
2983
|
exports.SIGNATURE_STATUS_TIMEOUT_MS = SIGNATURE_STATUS_TIMEOUT_MS;
|
|
2890
2984
|
exports.applyRatio = applyRatio;
|
|
2891
2985
|
exports.applySerializableState = applySerializableState;
|
|
2892
2986
|
exports.assertDecimals = assertDecimals;
|
|
2893
2987
|
exports.assertNonNegative = assertNonNegative;
|
|
2988
|
+
exports.autoDiscover = autoDiscover;
|
|
2989
|
+
exports.backpack = backpack;
|
|
2894
2990
|
exports.bigintFromJson = bigintFromJson;
|
|
2895
2991
|
exports.bigintToJson = bigintToJson;
|
|
2896
2992
|
exports.checkedAdd = checkedAdd;
|
|
@@ -2898,6 +2994,7 @@ exports.checkedDivide = checkedDivide;
|
|
|
2898
2994
|
exports.checkedMultiply = checkedMultiply;
|
|
2899
2995
|
exports.checkedSubtract = checkedSubtract;
|
|
2900
2996
|
exports.confirmationMeetsCommitment = confirmationMeetsCommitment;
|
|
2997
|
+
exports.connectWallet = connectWallet;
|
|
2901
2998
|
exports.createAsyncState = createAsyncState;
|
|
2902
2999
|
exports.createClient = createClient;
|
|
2903
3000
|
exports.createClientStore = createClientStore;
|
|
@@ -2918,8 +3015,12 @@ exports.createWalletRegistry = createWalletRegistry;
|
|
|
2918
3015
|
exports.createWalletStandardConnector = createWalletStandardConnector;
|
|
2919
3016
|
exports.deriveConfirmationStatus = deriveConfirmationStatus;
|
|
2920
3017
|
exports.deserializeSolanaState = deserializeSolanaState;
|
|
3018
|
+
exports.disconnectWallet = disconnectWallet;
|
|
3019
|
+
exports.fetchAccount = fetchAccount;
|
|
3020
|
+
exports.fetchBalance = fetchBalance;
|
|
2921
3021
|
exports.getInitialSerializableState = getInitialSerializableState;
|
|
2922
3022
|
exports.getWalletStandardConnectors = getWalletStandardConnectors;
|
|
3023
|
+
exports.injected = injected;
|
|
2923
3024
|
exports.insertReferenceKey = insertReferenceKey;
|
|
2924
3025
|
exports.insertReferenceKeys = insertReferenceKeys;
|
|
2925
3026
|
exports.lamports = lamports;
|
|
@@ -2929,10 +3030,15 @@ exports.lamportsMath = lamportsMath;
|
|
|
2929
3030
|
exports.lamportsToJson = lamportsToJson;
|
|
2930
3031
|
exports.lamportsToSolString = lamportsToSolString;
|
|
2931
3032
|
exports.normalizeSignature = normalizeSignature;
|
|
3033
|
+
exports.phantom = phantom;
|
|
2932
3034
|
exports.pow10 = pow10;
|
|
2933
3035
|
exports.prepareTransaction = prepareTransaction;
|
|
3036
|
+
exports.requestAirdrop = requestAirdrop;
|
|
2934
3037
|
exports.resolveCluster = resolveCluster;
|
|
3038
|
+
exports.sendTransaction = sendTransaction;
|
|
2935
3039
|
exports.serializeSolanaState = serializeSolanaState;
|
|
3040
|
+
exports.setCluster = setCluster;
|
|
3041
|
+
exports.solflare = solflare;
|
|
2936
3042
|
exports.stableStringify = stableStringify;
|
|
2937
3043
|
exports.subscribeSolanaState = subscribeSolanaState;
|
|
2938
3044
|
exports.toAddress = toAddress2;
|