@vue-solana/core 0.2.0 → 0.3.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/README.md +35 -5
- package/dist/clusters.cjs +35 -0
- package/dist/clusters.d.cts +9 -0
- package/dist/clusters.d.mts +9 -0
- package/dist/clusters.d.ts +9 -0
- package/dist/clusters.mjs +30 -0
- package/dist/index.cjs +33 -301
- package/dist/index.d.cts +9 -78
- package/dist/index.d.mts +9 -78
- package/dist/index.d.ts +9 -78
- package/dist/index.mjs +12 -283
- package/dist/mobile-wallet.cjs +69 -0
- package/dist/mobile-wallet.d.cts +19 -0
- package/dist/mobile-wallet.d.mts +19 -0
- package/dist/mobile-wallet.d.ts +19 -0
- package/dist/mobile-wallet.mjs +65 -0
- package/dist/rpc.cjs +31 -0
- package/dist/rpc.d.cts +7 -0
- package/dist/rpc.d.mts +7 -0
- package/dist/rpc.d.ts +7 -0
- package/dist/rpc.mjs +28 -0
- package/dist/transaction.cjs +17 -0
- package/dist/transaction.d.cts +6 -0
- package/dist/transaction.d.mts +6 -0
- package/dist/transaction.d.ts +6 -0
- package/dist/transaction.mjs +15 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.cts +53 -0
- package/dist/types.d.mts +53 -0
- package/dist/types.d.ts +53 -0
- package/dist/types.mjs +1 -0
- package/dist/wallet-standard.cjs +221 -0
- package/dist/wallet-standard.d.cts +17 -0
- package/dist/wallet-standard.d.mts +17 -0
- package/dist/wallet-standard.d.ts +17 -0
- package/dist/wallet-standard.mjs +211 -0
- package/dist/wallet.cjs +20 -0
- package/dist/wallet.d.cts +10 -0
- package/dist/wallet.d.mts +10 -0
- package/dist/wallet.d.ts +10 -0
- package/dist/wallet.mjs +16 -0
- package/package.json +37 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Framework-agnostic Solana primitives used by the Vue Solana packages.
|
|
4
4
|
|
|
5
|
-
Use this package directly when you want connection helpers, shared wallet types, and transaction helpers without installing the Vue plugin.
|
|
5
|
+
Use this package directly when you want connection helpers, shared wallet types, Android Mobile Wallet Adapter registration helpers, and transaction helpers without installing the Vue plugin.
|
|
6
6
|
|
|
7
7
|
`@vue-solana/core` does not replace `@solana/web3-compat`. Use `@solana/web3-compat` for raw Solana primitives like `Connection`, `PublicKey`, and transactions. Use `@vue-solana/core` for Vue Solana shared configuration, cluster endpoint defaults, wallet interfaces, and transaction helpers.
|
|
8
8
|
|
|
@@ -15,6 +15,7 @@ Official Solana docs:
|
|
|
15
15
|
Full Vue Solana docs:
|
|
16
16
|
|
|
17
17
|
- [`@vue-solana/core`](https://vue-solana-docs.vercel.app/packages/core)
|
|
18
|
+
- [Live demo](https://vue-solana-docs.vercel.app/demo)
|
|
18
19
|
- [Getting Started](https://vue-solana-docs.vercel.app/getting-started)
|
|
19
20
|
- [Troubleshooting](https://vue-solana-docs.vercel.app/troubleshooting)
|
|
20
21
|
|
|
@@ -42,6 +43,13 @@ const { blockhash } = await solana.connection.getLatestBlockhash();
|
|
|
42
43
|
console.log(solana.endpoint, blockhash);
|
|
43
44
|
```
|
|
44
45
|
|
|
46
|
+
The root export remains supported. Direct subpath exports are also available for narrower imports:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { createSolanaContext } from "@vue-solana/core/rpc";
|
|
50
|
+
import type { SolanaConfig } from "@vue-solana/core/types";
|
|
51
|
+
```
|
|
52
|
+
|
|
45
53
|
## Configuration
|
|
46
54
|
|
|
47
55
|
```ts
|
|
@@ -68,6 +76,16 @@ https://faucet.solana.com
|
|
|
68
76
|
|
|
69
77
|
## API
|
|
70
78
|
|
|
79
|
+
Direct subpaths:
|
|
80
|
+
|
|
81
|
+
- `@vue-solana/core/types`
|
|
82
|
+
- `@vue-solana/core/clusters`
|
|
83
|
+
- `@vue-solana/core/rpc`
|
|
84
|
+
- `@vue-solana/core/mobile-wallet`
|
|
85
|
+
- `@vue-solana/core/transaction`
|
|
86
|
+
- `@vue-solana/core/wallet`
|
|
87
|
+
- `@vue-solana/core/wallet-standard`
|
|
88
|
+
|
|
71
89
|
- `DEFAULT_CLUSTER`: default cluster, currently `devnet`.
|
|
72
90
|
- `createSolanaConnection(config?)`: creates a `Connection`.
|
|
73
91
|
- `createSolanaContext(config?)`: creates `{ cluster, endpoint, wsEndpoint, connection }`.
|
|
@@ -93,14 +111,26 @@ const wallet: SolanaWallet = {
|
|
|
93
111
|
};
|
|
94
112
|
```
|
|
95
113
|
|
|
96
|
-
Browser wallets discovered through the Solana Wallet Standard are adapted into `SolanaWallet`. You can also provide a custom object that implements `SolanaWallet` for tests or custom adapters.
|
|
114
|
+
Browser extension wallets discovered through the Solana Wallet Standard are adapted into `SolanaWallet`. Android Mobile Wallet Adapter is registered through `@solana-mobile/wallet-standard-mobile` and then adapted through the same Wallet Standard adapter on supported Android Chrome clients. You can also provide a custom object that implements `SolanaWallet` for tests or custom adapters.
|
|
115
|
+
|
|
116
|
+
Current wallet support:
|
|
117
|
+
|
|
118
|
+
- Browser extension wallets through Wallet Standard packages.
|
|
119
|
+
- Android native mobile wallets through `@solana-mobile/wallet-standard-mobile` on Android Chrome and Chrome PWAs.
|
|
120
|
+
- Manual/custom wallet objects that implement `SolanaWallet`.
|
|
121
|
+
|
|
122
|
+
Planned but not supported yet:
|
|
123
|
+
|
|
124
|
+
- iOS browser wallets through wallet-specific universal link or deep link adapters.
|
|
125
|
+
- Desktop native app wallets through wallet-specific protocol links or future native Wallet Standard registration.
|
|
97
126
|
|
|
98
127
|
## Examples
|
|
99
128
|
|
|
100
129
|
For complete runnable Vue and Nuxt examples that use this package through the framework integrations, see:
|
|
101
130
|
|
|
102
|
-
- [
|
|
103
|
-
-
|
|
131
|
+
- [Live demo](https://vue-solana-docs.vercel.app/demo)
|
|
132
|
+
- <a href="https://vue-solana-docs.vercel.app/examples/vue-vite" target="_blank" rel="noopener noreferrer"><code>examples/vue-vite</code></a>
|
|
133
|
+
- <a href="https://vue-solana-docs.vercel.app/examples/nuxt" target="_blank" rel="noopener noreferrer"><code>examples/nuxt</code></a>
|
|
104
134
|
|
|
105
135
|
## Known TypeScript Issue
|
|
106
136
|
|
|
@@ -127,4 +157,4 @@ Make sure your `tsconfig.json` includes `types/**/*.d.ts` or another pattern tha
|
|
|
127
157
|
|
|
128
158
|
## Status
|
|
129
159
|
|
|
130
|
-
This package is early-stage. RPC helpers, wallet primitives, and transaction helpers are usable.
|
|
160
|
+
This package is early-stage. RPC helpers, browser extension wallet primitives, Android mobile wallet registration, and transaction helpers are usable.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_CLUSTER = "devnet";
|
|
4
|
+
const CLUSTER_ENDPOINTS = {
|
|
5
|
+
"mainnet-beta": "https://api.mainnet-beta.solana.com",
|
|
6
|
+
testnet: "https://api.testnet.solana.com",
|
|
7
|
+
devnet: "https://api.devnet.solana.com",
|
|
8
|
+
localnet: "http://127.0.0.1:8899"
|
|
9
|
+
};
|
|
10
|
+
const CLUSTER_WEBSOCKET_ENDPOINTS = {
|
|
11
|
+
"mainnet-beta": "wss://api.mainnet-beta.solana.com",
|
|
12
|
+
testnet: "wss://api.testnet.solana.com",
|
|
13
|
+
devnet: "wss://api.devnet.solana.com",
|
|
14
|
+
localnet: "ws://127.0.0.1:8900"
|
|
15
|
+
};
|
|
16
|
+
function getClusterEndpoint(cluster = DEFAULT_CLUSTER) {
|
|
17
|
+
return CLUSTER_ENDPOINTS[cluster];
|
|
18
|
+
}
|
|
19
|
+
function getClusterWebSocketEndpoint(cluster = DEFAULT_CLUSTER) {
|
|
20
|
+
return CLUSTER_WEBSOCKET_ENDPOINTS[cluster];
|
|
21
|
+
}
|
|
22
|
+
function getWebSocketEndpoint(endpoint) {
|
|
23
|
+
const url = new URL(endpoint);
|
|
24
|
+
if (url.protocol === "https:") {
|
|
25
|
+
url.protocol = "wss:";
|
|
26
|
+
} else if (url.protocol === "http:") {
|
|
27
|
+
url.protocol = "ws:";
|
|
28
|
+
}
|
|
29
|
+
return url.toString();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.DEFAULT_CLUSTER = DEFAULT_CLUSTER;
|
|
33
|
+
exports.getClusterEndpoint = getClusterEndpoint;
|
|
34
|
+
exports.getClusterWebSocketEndpoint = getClusterWebSocketEndpoint;
|
|
35
|
+
exports.getWebSocketEndpoint = getWebSocketEndpoint;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SolanaCluster } from './types.cjs';
|
|
2
|
+
import '@solana/web3-compat';
|
|
3
|
+
|
|
4
|
+
declare const DEFAULT_CLUSTER: SolanaCluster;
|
|
5
|
+
declare function getClusterEndpoint(cluster?: SolanaCluster): string;
|
|
6
|
+
declare function getClusterWebSocketEndpoint(cluster?: SolanaCluster): string;
|
|
7
|
+
declare function getWebSocketEndpoint(endpoint: string): string;
|
|
8
|
+
|
|
9
|
+
export { DEFAULT_CLUSTER, getClusterEndpoint, getClusterWebSocketEndpoint, getWebSocketEndpoint };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SolanaCluster } from './types.mjs';
|
|
2
|
+
import '@solana/web3-compat';
|
|
3
|
+
|
|
4
|
+
declare const DEFAULT_CLUSTER: SolanaCluster;
|
|
5
|
+
declare function getClusterEndpoint(cluster?: SolanaCluster): string;
|
|
6
|
+
declare function getClusterWebSocketEndpoint(cluster?: SolanaCluster): string;
|
|
7
|
+
declare function getWebSocketEndpoint(endpoint: string): string;
|
|
8
|
+
|
|
9
|
+
export { DEFAULT_CLUSTER, getClusterEndpoint, getClusterWebSocketEndpoint, getWebSocketEndpoint };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SolanaCluster } from './types.js';
|
|
2
|
+
import '@solana/web3-compat';
|
|
3
|
+
|
|
4
|
+
declare const DEFAULT_CLUSTER: SolanaCluster;
|
|
5
|
+
declare function getClusterEndpoint(cluster?: SolanaCluster): string;
|
|
6
|
+
declare function getClusterWebSocketEndpoint(cluster?: SolanaCluster): string;
|
|
7
|
+
declare function getWebSocketEndpoint(endpoint: string): string;
|
|
8
|
+
|
|
9
|
+
export { DEFAULT_CLUSTER, getClusterEndpoint, getClusterWebSocketEndpoint, getWebSocketEndpoint };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const DEFAULT_CLUSTER = "devnet";
|
|
2
|
+
const CLUSTER_ENDPOINTS = {
|
|
3
|
+
"mainnet-beta": "https://api.mainnet-beta.solana.com",
|
|
4
|
+
testnet: "https://api.testnet.solana.com",
|
|
5
|
+
devnet: "https://api.devnet.solana.com",
|
|
6
|
+
localnet: "http://127.0.0.1:8899"
|
|
7
|
+
};
|
|
8
|
+
const CLUSTER_WEBSOCKET_ENDPOINTS = {
|
|
9
|
+
"mainnet-beta": "wss://api.mainnet-beta.solana.com",
|
|
10
|
+
testnet: "wss://api.testnet.solana.com",
|
|
11
|
+
devnet: "wss://api.devnet.solana.com",
|
|
12
|
+
localnet: "ws://127.0.0.1:8900"
|
|
13
|
+
};
|
|
14
|
+
function getClusterEndpoint(cluster = DEFAULT_CLUSTER) {
|
|
15
|
+
return CLUSTER_ENDPOINTS[cluster];
|
|
16
|
+
}
|
|
17
|
+
function getClusterWebSocketEndpoint(cluster = DEFAULT_CLUSTER) {
|
|
18
|
+
return CLUSTER_WEBSOCKET_ENDPOINTS[cluster];
|
|
19
|
+
}
|
|
20
|
+
function getWebSocketEndpoint(endpoint) {
|
|
21
|
+
const url = new URL(endpoint);
|
|
22
|
+
if (url.protocol === "https:") {
|
|
23
|
+
url.protocol = "wss:";
|
|
24
|
+
} else if (url.protocol === "http:") {
|
|
25
|
+
url.protocol = "ws:";
|
|
26
|
+
}
|
|
27
|
+
return url.toString();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { DEFAULT_CLUSTER, getClusterEndpoint, getClusterWebSocketEndpoint, getWebSocketEndpoint };
|
package/dist/index.cjs
CHANGED
|
@@ -1,303 +1,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} else if (url.protocol === "http:") {
|
|
37
|
-
url.protocol = "ws:";
|
|
38
|
-
}
|
|
39
|
-
return url.toString();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function createSolanaConnection(config = {}) {
|
|
43
|
-
const cluster = config.cluster ?? DEFAULT_CLUSTER;
|
|
44
|
-
const endpoint = config.endpoint ?? getClusterEndpoint(cluster);
|
|
45
|
-
const wsEndpoint = config.wsEndpoint ?? (config.endpoint ? getWebSocketEndpoint(endpoint) : getClusterWebSocketEndpoint(cluster));
|
|
46
|
-
return new web3Compat.Connection(endpoint, {
|
|
47
|
-
commitment: config.commitment,
|
|
48
|
-
wsEndpoint
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function createSolanaContext(config = {}) {
|
|
52
|
-
const cluster = config.cluster ?? DEFAULT_CLUSTER;
|
|
53
|
-
const endpoint = config.endpoint ?? getClusterEndpoint(cluster);
|
|
54
|
-
const wsEndpoint = config.wsEndpoint ?? (config.endpoint ? getWebSocketEndpoint(endpoint) : getClusterWebSocketEndpoint(cluster));
|
|
55
|
-
return {
|
|
56
|
-
cluster,
|
|
57
|
-
endpoint,
|
|
58
|
-
wsEndpoint,
|
|
59
|
-
connection: new web3Compat.Connection(endpoint, {
|
|
60
|
-
commitment: config.commitment,
|
|
61
|
-
wsEndpoint
|
|
62
|
-
})
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function isWalletConnected(wallet) {
|
|
67
|
-
return Boolean(wallet?.connected && wallet.publicKey);
|
|
68
|
-
}
|
|
69
|
-
function assertWalletConnected(wallet) {
|
|
70
|
-
if (!isWalletConnected(wallet)) {
|
|
71
|
-
throw new Error("Solana wallet is not connected");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function assertWalletCanSign(wallet) {
|
|
75
|
-
assertWalletConnected(wallet);
|
|
76
|
-
if (!wallet.signTransaction) {
|
|
77
|
-
throw new Error("Solana wallet does not support signTransaction");
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async function signAndSendTransaction(connection, wallet, transaction, options) {
|
|
82
|
-
assertWalletConnected(wallet);
|
|
83
|
-
if (wallet.signAndSendTransaction) {
|
|
84
|
-
const result = await wallet.signAndSendTransaction(transaction, options);
|
|
85
|
-
return result.signature;
|
|
86
|
-
}
|
|
87
|
-
assertWalletCanSign(wallet);
|
|
88
|
-
const signedTransaction = await wallet.signTransaction(transaction);
|
|
89
|
-
const rawTransaction = signedTransaction.serialize();
|
|
90
|
-
return connection.sendRawTransaction(rawTransaction, options);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const SOLANA_CHAINS = [
|
|
94
|
-
"solana:mainnet",
|
|
95
|
-
"solana:testnet",
|
|
96
|
-
"solana:devnet",
|
|
97
|
-
"solana:localnet"
|
|
98
|
-
];
|
|
99
|
-
function getSolanaChain(cluster) {
|
|
100
|
-
if (cluster === "mainnet-beta") {
|
|
101
|
-
return "solana:mainnet";
|
|
102
|
-
}
|
|
103
|
-
return `solana:${cluster}`;
|
|
104
|
-
}
|
|
105
|
-
function isSolanaStandardWallet(wallet) {
|
|
106
|
-
return features.StandardConnect in wallet.features && features.StandardDisconnect in wallet.features && wallet.chains.some((chain) => SOLANA_CHAINS.includes(chain));
|
|
107
|
-
}
|
|
108
|
-
function getRegisteredSolanaWallets() {
|
|
109
|
-
if (typeof window === "undefined") {
|
|
110
|
-
return [];
|
|
111
|
-
}
|
|
112
|
-
return app.getWallets().get().filter(isSolanaStandardWallet).map(createSolanaWalletInfo);
|
|
113
|
-
}
|
|
114
|
-
function subscribeSolanaWallets(listener) {
|
|
115
|
-
if (typeof window === "undefined") {
|
|
116
|
-
return () => {
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
const wallets = app.getWallets();
|
|
120
|
-
const offRegister = wallets.on("register", listener);
|
|
121
|
-
const offUnregister = wallets.on("unregister", listener);
|
|
122
|
-
return () => {
|
|
123
|
-
offRegister();
|
|
124
|
-
offUnregister();
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
128
|
-
const wallet = walletInfo.wallet;
|
|
129
|
-
let accounts = wallet.accounts;
|
|
130
|
-
let account = options.account;
|
|
131
|
-
let allowAccountUpdates = Boolean(options.account);
|
|
132
|
-
let connecting = false;
|
|
133
|
-
let disconnecting = false;
|
|
134
|
-
let manuallyDisconnected = false;
|
|
135
|
-
const eventsFeature = wallet.features[features.StandardEvents];
|
|
136
|
-
eventsFeature?.on("change", (properties) => {
|
|
137
|
-
if (properties.accounts) {
|
|
138
|
-
accounts = properties.accounts;
|
|
139
|
-
account = allowAccountUpdates && !manuallyDisconnected ? getSolanaAccount(accounts, options.chain) : void 0;
|
|
140
|
-
options.onChange?.();
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
return {
|
|
144
|
-
get publicKey() {
|
|
145
|
-
return account ? new web3Compat.PublicKey(account.publicKey) : null;
|
|
146
|
-
},
|
|
147
|
-
get connected() {
|
|
148
|
-
return Boolean(account);
|
|
149
|
-
},
|
|
150
|
-
get connecting() {
|
|
151
|
-
return connecting;
|
|
152
|
-
},
|
|
153
|
-
get disconnecting() {
|
|
154
|
-
return disconnecting;
|
|
155
|
-
},
|
|
156
|
-
async connect() {
|
|
157
|
-
connecting = true;
|
|
158
|
-
manuallyDisconnected = false;
|
|
159
|
-
options.onChange?.();
|
|
160
|
-
try {
|
|
161
|
-
const feature = wallet.features[features.StandardConnect];
|
|
162
|
-
const result = await feature.connect();
|
|
163
|
-
accounts = result.accounts;
|
|
164
|
-
allowAccountUpdates = true;
|
|
165
|
-
account = getSolanaAccount(accounts, options.chain);
|
|
166
|
-
if (!account) {
|
|
167
|
-
throw new Error("Solana wallet did not authorize a Solana account");
|
|
168
|
-
}
|
|
169
|
-
} finally {
|
|
170
|
-
connecting = false;
|
|
171
|
-
options.onChange?.();
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
async disconnect() {
|
|
175
|
-
const feature = wallet.features[features.StandardDisconnect];
|
|
176
|
-
disconnecting = true;
|
|
177
|
-
manuallyDisconnected = true;
|
|
178
|
-
allowAccountUpdates = false;
|
|
179
|
-
account = void 0;
|
|
180
|
-
options.onChange?.();
|
|
181
|
-
try {
|
|
182
|
-
await feature.disconnect();
|
|
183
|
-
accounts = [];
|
|
184
|
-
account = void 0;
|
|
185
|
-
} catch (error) {
|
|
186
|
-
manuallyDisconnected = false;
|
|
187
|
-
allowAccountUpdates = true;
|
|
188
|
-
account = getSolanaAccount(accounts, options.chain);
|
|
189
|
-
throw error;
|
|
190
|
-
} finally {
|
|
191
|
-
disconnecting = false;
|
|
192
|
-
options.onChange?.();
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
signTransaction: hasSignTransaction(wallet) ? async (transaction) => {
|
|
196
|
-
const activeAccount = getActiveAccount(account);
|
|
197
|
-
const [result] = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction({
|
|
198
|
-
account: activeAccount,
|
|
199
|
-
transaction: serializeTransaction(transaction),
|
|
200
|
-
chain: options.chain
|
|
201
|
-
});
|
|
202
|
-
if (!result) {
|
|
203
|
-
throw new Error("Solana wallet did not return a signed transaction");
|
|
204
|
-
}
|
|
205
|
-
return deserializeTransaction(transaction, result.signedTransaction);
|
|
206
|
-
} : void 0,
|
|
207
|
-
signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => {
|
|
208
|
-
const activeAccount = getActiveAccount(account);
|
|
209
|
-
const results = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction(
|
|
210
|
-
...transactions.map((transaction) => ({
|
|
211
|
-
account: activeAccount,
|
|
212
|
-
transaction: serializeTransaction(transaction),
|
|
213
|
-
chain: options.chain
|
|
214
|
-
}))
|
|
215
|
-
);
|
|
216
|
-
return results.map(
|
|
217
|
-
(result, index) => deserializeTransaction(transactions[index], result.signedTransaction)
|
|
218
|
-
);
|
|
219
|
-
} : void 0,
|
|
220
|
-
signAndSendTransaction: hasSignAndSendTransaction(wallet) ? async (transaction, sendOptions) => {
|
|
221
|
-
const activeAccount = getActiveAccount(account);
|
|
222
|
-
const [result] = await wallet.features[walletStandardFeatures.SolanaSignAndSendTransaction].signAndSendTransaction({
|
|
223
|
-
account: activeAccount,
|
|
224
|
-
transaction: serializeTransaction(transaction),
|
|
225
|
-
chain: options.chain ?? getSolanaAccountChain(activeAccount),
|
|
226
|
-
options: sendOptions
|
|
227
|
-
});
|
|
228
|
-
if (!result) {
|
|
229
|
-
throw new Error("Solana wallet did not return a transaction signature");
|
|
230
|
-
}
|
|
231
|
-
return { signature: bs58__default.encode(result.signature) };
|
|
232
|
-
} : void 0
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
function createSolanaWalletInfo(wallet) {
|
|
236
|
-
return {
|
|
237
|
-
name: wallet.name,
|
|
238
|
-
icon: wallet.icon,
|
|
239
|
-
chains: wallet.chains,
|
|
240
|
-
accounts: wallet.accounts.map((account) => ({
|
|
241
|
-
address: account.address,
|
|
242
|
-
publicKey: Uint8Array.from(account.publicKey),
|
|
243
|
-
chains: account.chains,
|
|
244
|
-
label: account.label,
|
|
245
|
-
icon: account.icon
|
|
246
|
-
})),
|
|
247
|
-
wallet
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
function getSolanaAccount(accounts, chain) {
|
|
251
|
-
return accounts.find((account) => account.chains.some((accountChain) => accountChain === chain)) ?? accounts.find(
|
|
252
|
-
(account) => account.chains.some((accountChain) => SOLANA_CHAINS.includes(accountChain))
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
function getActiveAccount(account) {
|
|
256
|
-
if (!account) {
|
|
257
|
-
throw new Error("Solana wallet is not connected");
|
|
258
|
-
}
|
|
259
|
-
return account;
|
|
260
|
-
}
|
|
261
|
-
function getSolanaAccountChain(account) {
|
|
262
|
-
const chain = account.chains.find(
|
|
263
|
-
(accountChain) => SOLANA_CHAINS.includes(accountChain)
|
|
264
|
-
);
|
|
265
|
-
if (!chain) {
|
|
266
|
-
throw new Error("Solana wallet account does not support a Solana chain");
|
|
267
|
-
}
|
|
268
|
-
return chain;
|
|
269
|
-
}
|
|
270
|
-
function hasSignTransaction(wallet) {
|
|
271
|
-
return walletStandardFeatures.SolanaSignTransaction in wallet.features;
|
|
272
|
-
}
|
|
273
|
-
function hasSignAndSendTransaction(wallet) {
|
|
274
|
-
return walletStandardFeatures.SolanaSignAndSendTransaction in wallet.features;
|
|
275
|
-
}
|
|
276
|
-
function serializeTransaction(transaction) {
|
|
277
|
-
if (transaction instanceof web3Compat.Transaction) {
|
|
278
|
-
return transaction.serialize({ requireAllSignatures: false, verifySignatures: false });
|
|
279
|
-
}
|
|
280
|
-
return transaction.serialize();
|
|
281
|
-
}
|
|
282
|
-
function deserializeTransaction(source, bytes) {
|
|
283
|
-
if (source instanceof web3Compat.Transaction) {
|
|
284
|
-
return web3Compat.Transaction.from(bytes);
|
|
285
|
-
}
|
|
286
|
-
return web3Compat.VersionedTransaction.deserialize(bytes);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
exports.DEFAULT_CLUSTER = DEFAULT_CLUSTER;
|
|
290
|
-
exports.adaptSolanaStandardWallet = adaptSolanaStandardWallet;
|
|
291
|
-
exports.assertWalletCanSign = assertWalletCanSign;
|
|
292
|
-
exports.assertWalletConnected = assertWalletConnected;
|
|
293
|
-
exports.createSolanaConnection = createSolanaConnection;
|
|
294
|
-
exports.createSolanaContext = createSolanaContext;
|
|
295
|
-
exports.getClusterEndpoint = getClusterEndpoint;
|
|
296
|
-
exports.getClusterWebSocketEndpoint = getClusterWebSocketEndpoint;
|
|
297
|
-
exports.getRegisteredSolanaWallets = getRegisteredSolanaWallets;
|
|
298
|
-
exports.getSolanaChain = getSolanaChain;
|
|
299
|
-
exports.getWebSocketEndpoint = getWebSocketEndpoint;
|
|
300
|
-
exports.isSolanaStandardWallet = isSolanaStandardWallet;
|
|
301
|
-
exports.isWalletConnected = isWalletConnected;
|
|
302
|
-
exports.signAndSendTransaction = signAndSendTransaction;
|
|
303
|
-
exports.subscribeSolanaWallets = subscribeSolanaWallets;
|
|
3
|
+
const clusters = require('./clusters.cjs');
|
|
4
|
+
const mobileWallet = require('./mobile-wallet.cjs');
|
|
5
|
+
const rpc = require('./rpc.cjs');
|
|
6
|
+
const transaction = require('./transaction.cjs');
|
|
7
|
+
const wallet = require('./wallet.cjs');
|
|
8
|
+
const walletStandard = require('./wallet-standard.cjs');
|
|
9
|
+
require('@solana-mobile/wallet-standard-mobile');
|
|
10
|
+
require('@solana/web3-compat');
|
|
11
|
+
require('@wallet-standard/app');
|
|
12
|
+
require('@wallet-standard/features');
|
|
13
|
+
require('@solana/wallet-standard-features');
|
|
14
|
+
require('bs58');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
exports.DEFAULT_CLUSTER = clusters.DEFAULT_CLUSTER;
|
|
19
|
+
exports.getClusterEndpoint = clusters.getClusterEndpoint;
|
|
20
|
+
exports.getClusterWebSocketEndpoint = clusters.getClusterWebSocketEndpoint;
|
|
21
|
+
exports.getWebSocketEndpoint = clusters.getWebSocketEndpoint;
|
|
22
|
+
exports.getDefaultMobileWalletAppIdentity = mobileWallet.getDefaultMobileWalletAppIdentity;
|
|
23
|
+
exports.isSolanaMobileWalletSupported = mobileWallet.isSolanaMobileWalletSupported;
|
|
24
|
+
exports.registerSolanaMobileWallet = mobileWallet.registerSolanaMobileWallet;
|
|
25
|
+
exports.createSolanaConnection = rpc.createSolanaConnection;
|
|
26
|
+
exports.createSolanaContext = rpc.createSolanaContext;
|
|
27
|
+
exports.signAndSendTransaction = transaction.signAndSendTransaction;
|
|
28
|
+
exports.assertWalletCanSign = wallet.assertWalletCanSign;
|
|
29
|
+
exports.assertWalletConnected = wallet.assertWalletConnected;
|
|
30
|
+
exports.isWalletConnected = wallet.isWalletConnected;
|
|
31
|
+
exports.adaptSolanaStandardWallet = walletStandard.adaptSolanaStandardWallet;
|
|
32
|
+
exports.getRegisteredSolanaWallets = walletStandard.getRegisteredSolanaWallets;
|
|
33
|
+
exports.getSolanaChain = walletStandard.getSolanaChain;
|
|
34
|
+
exports.isSolanaStandardWallet = walletStandard.isSolanaStandardWallet;
|
|
35
|
+
exports.subscribeSolanaWallets = walletStandard.subscribeSolanaWallets;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,78 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
commitment?: Commitment;
|
|
11
|
-
autoConnect?: boolean;
|
|
12
|
-
}
|
|
13
|
-
interface SolanaContext {
|
|
14
|
-
cluster: SolanaCluster;
|
|
15
|
-
endpoint: string;
|
|
16
|
-
wsEndpoint: string;
|
|
17
|
-
connection: Connection;
|
|
18
|
-
}
|
|
19
|
-
type SolanaTransaction = Transaction | VersionedTransaction;
|
|
20
|
-
interface SolanaWallet {
|
|
21
|
-
publicKey: PublicKey | null;
|
|
22
|
-
connected: boolean;
|
|
23
|
-
connecting?: boolean;
|
|
24
|
-
disconnecting?: boolean;
|
|
25
|
-
connect: () => Promise<void>;
|
|
26
|
-
disconnect: () => Promise<void>;
|
|
27
|
-
signTransaction?: <T extends SolanaTransaction>(transaction: T) => Promise<T>;
|
|
28
|
-
signAllTransactions?: <T extends SolanaTransaction>(transactions: T[]) => Promise<T[]>;
|
|
29
|
-
signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendOptions) => Promise<{
|
|
30
|
-
signature: TransactionSignature;
|
|
31
|
-
}>;
|
|
32
|
-
}
|
|
33
|
-
interface SolanaWalletInfo {
|
|
34
|
-
name: string;
|
|
35
|
-
icon: string;
|
|
36
|
-
chains: readonly string[];
|
|
37
|
-
accounts: readonly {
|
|
38
|
-
address: string;
|
|
39
|
-
publicKey: Uint8Array;
|
|
40
|
-
chains: readonly string[];
|
|
41
|
-
label?: string;
|
|
42
|
-
icon?: string;
|
|
43
|
-
}[];
|
|
44
|
-
wallet: unknown;
|
|
45
|
-
}
|
|
46
|
-
interface SendTransactionOptions extends SendOptions {
|
|
47
|
-
skipPreflight?: boolean;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
declare const DEFAULT_CLUSTER: SolanaCluster;
|
|
51
|
-
declare function getClusterEndpoint(cluster?: SolanaCluster): string;
|
|
52
|
-
declare function getClusterWebSocketEndpoint(cluster?: SolanaCluster): string;
|
|
53
|
-
declare function getWebSocketEndpoint(endpoint: string): string;
|
|
54
|
-
|
|
55
|
-
declare function createSolanaConnection(config?: SolanaConfig): Connection;
|
|
56
|
-
declare function createSolanaContext(config?: SolanaConfig): SolanaContext;
|
|
57
|
-
|
|
58
|
-
declare function signAndSendTransaction(connection: Connection, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<TransactionSignature>;
|
|
59
|
-
|
|
60
|
-
declare function isWalletConnected(wallet: Pick<SolanaWallet, "connected" | "publicKey"> | null | undefined): boolean;
|
|
61
|
-
declare function assertWalletConnected(wallet: SolanaWallet | null | undefined): asserts wallet is SolanaWallet & {
|
|
62
|
-
publicKey: NonNullable<SolanaWallet["publicKey"]>;
|
|
63
|
-
};
|
|
64
|
-
declare function assertWalletCanSign(wallet: SolanaWallet | null | undefined): asserts wallet is SolanaWallet & Required<Pick<SolanaWallet, "signTransaction">>;
|
|
65
|
-
|
|
66
|
-
interface AdaptSolanaWalletOptions {
|
|
67
|
-
chain?: SolanaChain;
|
|
68
|
-
account?: WalletAccount;
|
|
69
|
-
onChange?: () => void;
|
|
70
|
-
}
|
|
71
|
-
declare function getSolanaChain(cluster: SolanaCluster): SolanaChain;
|
|
72
|
-
declare function isSolanaStandardWallet(wallet: Wallet): boolean;
|
|
73
|
-
declare function getRegisteredSolanaWallets(): SolanaWalletInfo[];
|
|
74
|
-
declare function subscribeSolanaWallets(listener: () => void): () => void;
|
|
75
|
-
declare function adaptSolanaStandardWallet(walletInfo: SolanaWalletInfo, options?: AdaptSolanaWalletOptions): SolanaWallet;
|
|
76
|
-
|
|
77
|
-
export { DEFAULT_CLUSTER, adaptSolanaStandardWallet, assertWalletCanSign, assertWalletConnected, createSolanaConnection, createSolanaContext, getClusterEndpoint, getClusterWebSocketEndpoint, getRegisteredSolanaWallets, getSolanaChain, getWebSocketEndpoint, isSolanaStandardWallet, isWalletConnected, signAndSendTransaction, subscribeSolanaWallets };
|
|
78
|
-
export type { AdaptSolanaWalletOptions, SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaTransaction, SolanaWallet, SolanaWalletInfo };
|
|
1
|
+
export { DEFAULT_CLUSTER, getClusterEndpoint, getClusterWebSocketEndpoint, getWebSocketEndpoint } from './clusters.cjs';
|
|
2
|
+
export { RegisterSolanaMobileWalletOptions, SolanaMobileWalletAppIdentity, getDefaultMobileWalletAppIdentity, isSolanaMobileWalletSupported, registerSolanaMobileWallet } from './mobile-wallet.cjs';
|
|
3
|
+
export { createSolanaConnection, createSolanaContext } from './rpc.cjs';
|
|
4
|
+
export { signAndSendTransaction } from './transaction.cjs';
|
|
5
|
+
export { SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaTransaction, SolanaWallet, SolanaWalletInfo } from './types.cjs';
|
|
6
|
+
export { assertWalletCanSign, assertWalletConnected, isWalletConnected } from './wallet.cjs';
|
|
7
|
+
export { AdaptSolanaWalletOptions, adaptSolanaStandardWallet, getRegisteredSolanaWallets, getSolanaChain, isSolanaStandardWallet, subscribeSolanaWallets } from './wallet-standard.cjs';
|
|
8
|
+
import '@solana/web3-compat';
|
|
9
|
+
import '@wallet-standard/base';
|