@vue-solana/core 0.2.1 → 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 +31 -3
- 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/dist/rpc.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const web3Compat = require('@solana/web3-compat');
|
|
4
|
+
const clusters = require('./clusters.cjs');
|
|
5
|
+
|
|
6
|
+
function createSolanaConnection(config = {}) {
|
|
7
|
+
const cluster = config.cluster ?? clusters.DEFAULT_CLUSTER;
|
|
8
|
+
const endpoint = config.endpoint ?? clusters.getClusterEndpoint(cluster);
|
|
9
|
+
const wsEndpoint = config.wsEndpoint ?? (config.endpoint ? clusters.getWebSocketEndpoint(endpoint) : clusters.getClusterWebSocketEndpoint(cluster));
|
|
10
|
+
return new web3Compat.Connection(endpoint, {
|
|
11
|
+
commitment: config.commitment,
|
|
12
|
+
wsEndpoint
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function createSolanaContext(config = {}) {
|
|
16
|
+
const cluster = config.cluster ?? clusters.DEFAULT_CLUSTER;
|
|
17
|
+
const endpoint = config.endpoint ?? clusters.getClusterEndpoint(cluster);
|
|
18
|
+
const wsEndpoint = config.wsEndpoint ?? (config.endpoint ? clusters.getWebSocketEndpoint(endpoint) : clusters.getClusterWebSocketEndpoint(cluster));
|
|
19
|
+
return {
|
|
20
|
+
cluster,
|
|
21
|
+
endpoint,
|
|
22
|
+
wsEndpoint,
|
|
23
|
+
connection: new web3Compat.Connection(endpoint, {
|
|
24
|
+
commitment: config.commitment,
|
|
25
|
+
wsEndpoint
|
|
26
|
+
})
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.createSolanaConnection = createSolanaConnection;
|
|
31
|
+
exports.createSolanaContext = createSolanaContext;
|
package/dist/rpc.d.cts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Connection } from '@solana/web3-compat';
|
|
2
|
+
import { SolanaConfig, SolanaContext } from './types.cjs';
|
|
3
|
+
|
|
4
|
+
declare function createSolanaConnection(config?: SolanaConfig): Connection;
|
|
5
|
+
declare function createSolanaContext(config?: SolanaConfig): SolanaContext;
|
|
6
|
+
|
|
7
|
+
export { createSolanaConnection, createSolanaContext };
|
package/dist/rpc.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Connection } from '@solana/web3-compat';
|
|
2
|
+
import { SolanaConfig, SolanaContext } from './types.mjs';
|
|
3
|
+
|
|
4
|
+
declare function createSolanaConnection(config?: SolanaConfig): Connection;
|
|
5
|
+
declare function createSolanaContext(config?: SolanaConfig): SolanaContext;
|
|
6
|
+
|
|
7
|
+
export { createSolanaConnection, createSolanaContext };
|
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Connection } from '@solana/web3-compat';
|
|
2
|
+
import { SolanaConfig, SolanaContext } from './types.js';
|
|
3
|
+
|
|
4
|
+
declare function createSolanaConnection(config?: SolanaConfig): Connection;
|
|
5
|
+
declare function createSolanaContext(config?: SolanaConfig): SolanaContext;
|
|
6
|
+
|
|
7
|
+
export { createSolanaConnection, createSolanaContext };
|
package/dist/rpc.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Connection } from '@solana/web3-compat';
|
|
2
|
+
import { DEFAULT_CLUSTER, getClusterEndpoint, getWebSocketEndpoint, getClusterWebSocketEndpoint } from './clusters.mjs';
|
|
3
|
+
|
|
4
|
+
function createSolanaConnection(config = {}) {
|
|
5
|
+
const cluster = config.cluster ?? DEFAULT_CLUSTER;
|
|
6
|
+
const endpoint = config.endpoint ?? getClusterEndpoint(cluster);
|
|
7
|
+
const wsEndpoint = config.wsEndpoint ?? (config.endpoint ? getWebSocketEndpoint(endpoint) : getClusterWebSocketEndpoint(cluster));
|
|
8
|
+
return new Connection(endpoint, {
|
|
9
|
+
commitment: config.commitment,
|
|
10
|
+
wsEndpoint
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function createSolanaContext(config = {}) {
|
|
14
|
+
const cluster = config.cluster ?? DEFAULT_CLUSTER;
|
|
15
|
+
const endpoint = config.endpoint ?? getClusterEndpoint(cluster);
|
|
16
|
+
const wsEndpoint = config.wsEndpoint ?? (config.endpoint ? getWebSocketEndpoint(endpoint) : getClusterWebSocketEndpoint(cluster));
|
|
17
|
+
return {
|
|
18
|
+
cluster,
|
|
19
|
+
endpoint,
|
|
20
|
+
wsEndpoint,
|
|
21
|
+
connection: new Connection(endpoint, {
|
|
22
|
+
commitment: config.commitment,
|
|
23
|
+
wsEndpoint
|
|
24
|
+
})
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { createSolanaConnection, createSolanaContext };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const wallet = require('./wallet.cjs');
|
|
4
|
+
|
|
5
|
+
async function signAndSendTransaction(connection, wallet$1, transaction, options) {
|
|
6
|
+
wallet.assertWalletConnected(wallet$1);
|
|
7
|
+
if (wallet$1.signAndSendTransaction) {
|
|
8
|
+
const result = await wallet$1.signAndSendTransaction(transaction, options);
|
|
9
|
+
return result.signature;
|
|
10
|
+
}
|
|
11
|
+
wallet.assertWalletCanSign(wallet$1);
|
|
12
|
+
const signedTransaction = await wallet$1.signTransaction(transaction);
|
|
13
|
+
const rawTransaction = signedTransaction.serialize();
|
|
14
|
+
return connection.sendRawTransaction(rawTransaction, options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.signAndSendTransaction = signAndSendTransaction;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Connection, TransactionSignature } from '@solana/web3-compat';
|
|
2
|
+
import { SolanaWallet, SolanaTransaction, SendTransactionOptions } from './types.cjs';
|
|
3
|
+
|
|
4
|
+
declare function signAndSendTransaction(connection: Connection, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<TransactionSignature>;
|
|
5
|
+
|
|
6
|
+
export { signAndSendTransaction };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Connection, TransactionSignature } from '@solana/web3-compat';
|
|
2
|
+
import { SolanaWallet, SolanaTransaction, SendTransactionOptions } from './types.mjs';
|
|
3
|
+
|
|
4
|
+
declare function signAndSendTransaction(connection: Connection, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<TransactionSignature>;
|
|
5
|
+
|
|
6
|
+
export { signAndSendTransaction };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Connection, TransactionSignature } from '@solana/web3-compat';
|
|
2
|
+
import { SolanaWallet, SolanaTransaction, SendTransactionOptions } from './types.js';
|
|
3
|
+
|
|
4
|
+
declare function signAndSendTransaction(connection: Connection, wallet: SolanaWallet, transaction: SolanaTransaction, options?: SendTransactionOptions): Promise<TransactionSignature>;
|
|
5
|
+
|
|
6
|
+
export { signAndSendTransaction };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { assertWalletConnected, assertWalletCanSign } from './wallet.mjs';
|
|
2
|
+
|
|
3
|
+
async function signAndSendTransaction(connection, wallet, transaction, options) {
|
|
4
|
+
assertWalletConnected(wallet);
|
|
5
|
+
if (wallet.signAndSendTransaction) {
|
|
6
|
+
const result = await wallet.signAndSendTransaction(transaction, options);
|
|
7
|
+
return result.signature;
|
|
8
|
+
}
|
|
9
|
+
assertWalletCanSign(wallet);
|
|
10
|
+
const signedTransaction = await wallet.signTransaction(transaction);
|
|
11
|
+
const rawTransaction = signedTransaction.serialize();
|
|
12
|
+
return connection.sendRawTransaction(rawTransaction, options);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { signAndSendTransaction };
|
package/dist/types.cjs
ADDED
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SendOptions, Commitment, Connection, Transaction, VersionedTransaction, PublicKey, TransactionSignature } from '@solana/web3-compat';
|
|
2
|
+
|
|
3
|
+
type SolanaCluster = "mainnet-beta" | "testnet" | "devnet" | "localnet";
|
|
4
|
+
type SolanaChain = "solana:mainnet" | "solana:testnet" | "solana:devnet" | "solana:localnet";
|
|
5
|
+
interface SolanaConfig {
|
|
6
|
+
cluster?: SolanaCluster;
|
|
7
|
+
endpoint?: string;
|
|
8
|
+
wsEndpoint?: string;
|
|
9
|
+
commitment?: Commitment;
|
|
10
|
+
autoConnect?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface SolanaContext {
|
|
13
|
+
cluster: SolanaCluster;
|
|
14
|
+
endpoint: string;
|
|
15
|
+
wsEndpoint: string;
|
|
16
|
+
connection: Connection;
|
|
17
|
+
}
|
|
18
|
+
type SolanaTransaction = Transaction | VersionedTransaction;
|
|
19
|
+
interface SolanaWallet {
|
|
20
|
+
publicKey: PublicKey | null;
|
|
21
|
+
connected: boolean;
|
|
22
|
+
connecting?: boolean;
|
|
23
|
+
disconnecting?: boolean;
|
|
24
|
+
connect: () => Promise<void>;
|
|
25
|
+
disconnect: () => Promise<void>;
|
|
26
|
+
signTransaction?: <T extends SolanaTransaction>(transaction: T) => Promise<T>;
|
|
27
|
+
signAllTransactions?: <T extends SolanaTransaction>(transactions: T[]) => Promise<T[]>;
|
|
28
|
+
signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendOptions) => Promise<{
|
|
29
|
+
signature: TransactionSignature;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
interface SolanaWalletInfo {
|
|
33
|
+
name: string;
|
|
34
|
+
icon: string;
|
|
35
|
+
chains: readonly string[];
|
|
36
|
+
platform?: "browser" | "mobile" | "desktop";
|
|
37
|
+
source?: "wallet-standard" | "mobile-wallet-adapter" | "deep-link" | "protocol-link";
|
|
38
|
+
appUrl?: string;
|
|
39
|
+
installUrl?: string;
|
|
40
|
+
accounts: readonly {
|
|
41
|
+
address: string;
|
|
42
|
+
publicKey: Uint8Array;
|
|
43
|
+
chains: readonly string[];
|
|
44
|
+
label?: string;
|
|
45
|
+
icon?: string;
|
|
46
|
+
}[];
|
|
47
|
+
wallet: unknown;
|
|
48
|
+
}
|
|
49
|
+
interface SendTransactionOptions extends SendOptions {
|
|
50
|
+
skipPreflight?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type { SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaTransaction, SolanaWallet, SolanaWalletInfo };
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SendOptions, Commitment, Connection, Transaction, VersionedTransaction, PublicKey, TransactionSignature } from '@solana/web3-compat';
|
|
2
|
+
|
|
3
|
+
type SolanaCluster = "mainnet-beta" | "testnet" | "devnet" | "localnet";
|
|
4
|
+
type SolanaChain = "solana:mainnet" | "solana:testnet" | "solana:devnet" | "solana:localnet";
|
|
5
|
+
interface SolanaConfig {
|
|
6
|
+
cluster?: SolanaCluster;
|
|
7
|
+
endpoint?: string;
|
|
8
|
+
wsEndpoint?: string;
|
|
9
|
+
commitment?: Commitment;
|
|
10
|
+
autoConnect?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface SolanaContext {
|
|
13
|
+
cluster: SolanaCluster;
|
|
14
|
+
endpoint: string;
|
|
15
|
+
wsEndpoint: string;
|
|
16
|
+
connection: Connection;
|
|
17
|
+
}
|
|
18
|
+
type SolanaTransaction = Transaction | VersionedTransaction;
|
|
19
|
+
interface SolanaWallet {
|
|
20
|
+
publicKey: PublicKey | null;
|
|
21
|
+
connected: boolean;
|
|
22
|
+
connecting?: boolean;
|
|
23
|
+
disconnecting?: boolean;
|
|
24
|
+
connect: () => Promise<void>;
|
|
25
|
+
disconnect: () => Promise<void>;
|
|
26
|
+
signTransaction?: <T extends SolanaTransaction>(transaction: T) => Promise<T>;
|
|
27
|
+
signAllTransactions?: <T extends SolanaTransaction>(transactions: T[]) => Promise<T[]>;
|
|
28
|
+
signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendOptions) => Promise<{
|
|
29
|
+
signature: TransactionSignature;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
interface SolanaWalletInfo {
|
|
33
|
+
name: string;
|
|
34
|
+
icon: string;
|
|
35
|
+
chains: readonly string[];
|
|
36
|
+
platform?: "browser" | "mobile" | "desktop";
|
|
37
|
+
source?: "wallet-standard" | "mobile-wallet-adapter" | "deep-link" | "protocol-link";
|
|
38
|
+
appUrl?: string;
|
|
39
|
+
installUrl?: string;
|
|
40
|
+
accounts: readonly {
|
|
41
|
+
address: string;
|
|
42
|
+
publicKey: Uint8Array;
|
|
43
|
+
chains: readonly string[];
|
|
44
|
+
label?: string;
|
|
45
|
+
icon?: string;
|
|
46
|
+
}[];
|
|
47
|
+
wallet: unknown;
|
|
48
|
+
}
|
|
49
|
+
interface SendTransactionOptions extends SendOptions {
|
|
50
|
+
skipPreflight?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type { SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaTransaction, SolanaWallet, SolanaWalletInfo };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SendOptions, Commitment, Connection, Transaction, VersionedTransaction, PublicKey, TransactionSignature } from '@solana/web3-compat';
|
|
2
|
+
|
|
3
|
+
type SolanaCluster = "mainnet-beta" | "testnet" | "devnet" | "localnet";
|
|
4
|
+
type SolanaChain = "solana:mainnet" | "solana:testnet" | "solana:devnet" | "solana:localnet";
|
|
5
|
+
interface SolanaConfig {
|
|
6
|
+
cluster?: SolanaCluster;
|
|
7
|
+
endpoint?: string;
|
|
8
|
+
wsEndpoint?: string;
|
|
9
|
+
commitment?: Commitment;
|
|
10
|
+
autoConnect?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface SolanaContext {
|
|
13
|
+
cluster: SolanaCluster;
|
|
14
|
+
endpoint: string;
|
|
15
|
+
wsEndpoint: string;
|
|
16
|
+
connection: Connection;
|
|
17
|
+
}
|
|
18
|
+
type SolanaTransaction = Transaction | VersionedTransaction;
|
|
19
|
+
interface SolanaWallet {
|
|
20
|
+
publicKey: PublicKey | null;
|
|
21
|
+
connected: boolean;
|
|
22
|
+
connecting?: boolean;
|
|
23
|
+
disconnecting?: boolean;
|
|
24
|
+
connect: () => Promise<void>;
|
|
25
|
+
disconnect: () => Promise<void>;
|
|
26
|
+
signTransaction?: <T extends SolanaTransaction>(transaction: T) => Promise<T>;
|
|
27
|
+
signAllTransactions?: <T extends SolanaTransaction>(transactions: T[]) => Promise<T[]>;
|
|
28
|
+
signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendOptions) => Promise<{
|
|
29
|
+
signature: TransactionSignature;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
interface SolanaWalletInfo {
|
|
33
|
+
name: string;
|
|
34
|
+
icon: string;
|
|
35
|
+
chains: readonly string[];
|
|
36
|
+
platform?: "browser" | "mobile" | "desktop";
|
|
37
|
+
source?: "wallet-standard" | "mobile-wallet-adapter" | "deep-link" | "protocol-link";
|
|
38
|
+
appUrl?: string;
|
|
39
|
+
installUrl?: string;
|
|
40
|
+
accounts: readonly {
|
|
41
|
+
address: string;
|
|
42
|
+
publicKey: Uint8Array;
|
|
43
|
+
chains: readonly string[];
|
|
44
|
+
label?: string;
|
|
45
|
+
icon?: string;
|
|
46
|
+
}[];
|
|
47
|
+
wallet: unknown;
|
|
48
|
+
}
|
|
49
|
+
interface SendTransactionOptions extends SendOptions {
|
|
50
|
+
skipPreflight?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type { SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaTransaction, SolanaWallet, SolanaWalletInfo };
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const app = require('@wallet-standard/app');
|
|
4
|
+
const walletStandardMobile = require('@solana-mobile/wallet-standard-mobile');
|
|
5
|
+
const features = require('@wallet-standard/features');
|
|
6
|
+
const walletStandardFeatures = require('@solana/wallet-standard-features');
|
|
7
|
+
const web3Compat = require('@solana/web3-compat');
|
|
8
|
+
const bs58 = require('bs58');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
11
|
+
|
|
12
|
+
const bs58__default = /*#__PURE__*/_interopDefaultCompat(bs58);
|
|
13
|
+
|
|
14
|
+
const SOLANA_CHAINS = [
|
|
15
|
+
"solana:mainnet",
|
|
16
|
+
"solana:testnet",
|
|
17
|
+
"solana:devnet",
|
|
18
|
+
"solana:localnet"
|
|
19
|
+
];
|
|
20
|
+
function getSolanaChain(cluster) {
|
|
21
|
+
if (cluster === "mainnet-beta") {
|
|
22
|
+
return "solana:mainnet";
|
|
23
|
+
}
|
|
24
|
+
return `solana:${cluster}`;
|
|
25
|
+
}
|
|
26
|
+
function isSolanaStandardWallet(wallet) {
|
|
27
|
+
return features.StandardConnect in wallet.features && features.StandardDisconnect in wallet.features && wallet.chains.some((chain) => SOLANA_CHAINS.includes(chain));
|
|
28
|
+
}
|
|
29
|
+
function getRegisteredSolanaWallets() {
|
|
30
|
+
if (typeof window === "undefined") {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
return app.getWallets().get().filter(isSolanaStandardWallet).map(createSolanaWalletInfo);
|
|
34
|
+
}
|
|
35
|
+
function subscribeSolanaWallets(listener) {
|
|
36
|
+
if (typeof window === "undefined") {
|
|
37
|
+
return () => {
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const wallets = app.getWallets();
|
|
41
|
+
const offRegister = wallets.on("register", listener);
|
|
42
|
+
const offUnregister = wallets.on("unregister", listener);
|
|
43
|
+
return () => {
|
|
44
|
+
offRegister();
|
|
45
|
+
offUnregister();
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
49
|
+
const wallet = walletInfo.wallet;
|
|
50
|
+
let accounts = wallet.accounts;
|
|
51
|
+
let account = options.account;
|
|
52
|
+
let allowAccountUpdates = Boolean(options.account);
|
|
53
|
+
let connecting = false;
|
|
54
|
+
let disconnecting = false;
|
|
55
|
+
let manuallyDisconnected = false;
|
|
56
|
+
const eventsFeature = wallet.features[features.StandardEvents];
|
|
57
|
+
eventsFeature?.on("change", (properties) => {
|
|
58
|
+
if (properties.accounts) {
|
|
59
|
+
accounts = properties.accounts;
|
|
60
|
+
account = allowAccountUpdates && !manuallyDisconnected ? getSolanaAccount(accounts, options.chain) : void 0;
|
|
61
|
+
options.onChange?.();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
get publicKey() {
|
|
66
|
+
return account ? new web3Compat.PublicKey(account.publicKey) : null;
|
|
67
|
+
},
|
|
68
|
+
get connected() {
|
|
69
|
+
return Boolean(account);
|
|
70
|
+
},
|
|
71
|
+
get connecting() {
|
|
72
|
+
return connecting;
|
|
73
|
+
},
|
|
74
|
+
get disconnecting() {
|
|
75
|
+
return disconnecting;
|
|
76
|
+
},
|
|
77
|
+
async connect() {
|
|
78
|
+
connecting = true;
|
|
79
|
+
manuallyDisconnected = false;
|
|
80
|
+
options.onChange?.();
|
|
81
|
+
try {
|
|
82
|
+
const feature = wallet.features[features.StandardConnect];
|
|
83
|
+
const result = await feature.connect();
|
|
84
|
+
accounts = result.accounts;
|
|
85
|
+
allowAccountUpdates = true;
|
|
86
|
+
account = getSolanaAccount(accounts, options.chain);
|
|
87
|
+
if (!account) {
|
|
88
|
+
throw new Error("Solana wallet did not authorize a Solana account");
|
|
89
|
+
}
|
|
90
|
+
} finally {
|
|
91
|
+
connecting = false;
|
|
92
|
+
options.onChange?.();
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
async disconnect() {
|
|
96
|
+
const feature = wallet.features[features.StandardDisconnect];
|
|
97
|
+
disconnecting = true;
|
|
98
|
+
manuallyDisconnected = true;
|
|
99
|
+
allowAccountUpdates = false;
|
|
100
|
+
account = void 0;
|
|
101
|
+
options.onChange?.();
|
|
102
|
+
try {
|
|
103
|
+
await feature.disconnect();
|
|
104
|
+
accounts = [];
|
|
105
|
+
account = void 0;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
manuallyDisconnected = false;
|
|
108
|
+
allowAccountUpdates = true;
|
|
109
|
+
account = getSolanaAccount(accounts, options.chain);
|
|
110
|
+
throw error;
|
|
111
|
+
} finally {
|
|
112
|
+
disconnecting = false;
|
|
113
|
+
options.onChange?.();
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
signTransaction: hasSignTransaction(wallet) ? async (transaction) => {
|
|
117
|
+
const activeAccount = getActiveAccount(account);
|
|
118
|
+
const [result] = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction({
|
|
119
|
+
account: activeAccount,
|
|
120
|
+
transaction: serializeTransaction(transaction),
|
|
121
|
+
chain: options.chain
|
|
122
|
+
});
|
|
123
|
+
if (!result) {
|
|
124
|
+
throw new Error("Solana wallet did not return a signed transaction");
|
|
125
|
+
}
|
|
126
|
+
return deserializeTransaction(transaction, result.signedTransaction);
|
|
127
|
+
} : void 0,
|
|
128
|
+
signAllTransactions: hasSignTransaction(wallet) ? async (transactions) => {
|
|
129
|
+
const activeAccount = getActiveAccount(account);
|
|
130
|
+
const results = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction(
|
|
131
|
+
...transactions.map((transaction) => ({
|
|
132
|
+
account: activeAccount,
|
|
133
|
+
transaction: serializeTransaction(transaction),
|
|
134
|
+
chain: options.chain
|
|
135
|
+
}))
|
|
136
|
+
);
|
|
137
|
+
return results.map(
|
|
138
|
+
(result, index) => deserializeTransaction(transactions[index], result.signedTransaction)
|
|
139
|
+
);
|
|
140
|
+
} : void 0,
|
|
141
|
+
signAndSendTransaction: hasSignAndSendTransaction(wallet) ? async (transaction, sendOptions) => {
|
|
142
|
+
const activeAccount = getActiveAccount(account);
|
|
143
|
+
const [result] = await wallet.features[walletStandardFeatures.SolanaSignAndSendTransaction].signAndSendTransaction({
|
|
144
|
+
account: activeAccount,
|
|
145
|
+
transaction: serializeTransaction(transaction),
|
|
146
|
+
chain: options.chain ?? getSolanaAccountChain(activeAccount),
|
|
147
|
+
options: sendOptions
|
|
148
|
+
});
|
|
149
|
+
if (!result) {
|
|
150
|
+
throw new Error("Solana wallet did not return a transaction signature");
|
|
151
|
+
}
|
|
152
|
+
return { signature: bs58__default.encode(result.signature) };
|
|
153
|
+
} : void 0
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function createSolanaWalletInfo(wallet) {
|
|
157
|
+
const isMobileWallet = wallet.name === walletStandardMobile.SolanaMobileWalletAdapterWalletName;
|
|
158
|
+
return {
|
|
159
|
+
name: wallet.name,
|
|
160
|
+
icon: wallet.icon,
|
|
161
|
+
chains: wallet.chains,
|
|
162
|
+
platform: isMobileWallet ? "mobile" : "browser",
|
|
163
|
+
source: isMobileWallet ? "mobile-wallet-adapter" : "wallet-standard",
|
|
164
|
+
appUrl: getWalletUrl(wallet),
|
|
165
|
+
accounts: wallet.accounts.map((account) => ({
|
|
166
|
+
address: account.address,
|
|
167
|
+
publicKey: Uint8Array.from(account.publicKey),
|
|
168
|
+
chains: account.chains,
|
|
169
|
+
label: account.label,
|
|
170
|
+
icon: account.icon
|
|
171
|
+
})),
|
|
172
|
+
wallet
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function getWalletUrl(wallet) {
|
|
176
|
+
return "url" in wallet && typeof wallet.url === "string" ? wallet.url : void 0;
|
|
177
|
+
}
|
|
178
|
+
function getSolanaAccount(accounts, chain) {
|
|
179
|
+
return accounts.find((account) => account.chains.some((accountChain) => accountChain === chain)) ?? accounts.find(
|
|
180
|
+
(account) => account.chains.some((accountChain) => SOLANA_CHAINS.includes(accountChain))
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
function getActiveAccount(account) {
|
|
184
|
+
if (!account) {
|
|
185
|
+
throw new Error("Solana wallet is not connected");
|
|
186
|
+
}
|
|
187
|
+
return account;
|
|
188
|
+
}
|
|
189
|
+
function getSolanaAccountChain(account) {
|
|
190
|
+
const chain = account.chains.find(
|
|
191
|
+
(accountChain) => SOLANA_CHAINS.includes(accountChain)
|
|
192
|
+
);
|
|
193
|
+
if (!chain) {
|
|
194
|
+
throw new Error("Solana wallet account does not support a Solana chain");
|
|
195
|
+
}
|
|
196
|
+
return chain;
|
|
197
|
+
}
|
|
198
|
+
function hasSignTransaction(wallet) {
|
|
199
|
+
return walletStandardFeatures.SolanaSignTransaction in wallet.features;
|
|
200
|
+
}
|
|
201
|
+
function hasSignAndSendTransaction(wallet) {
|
|
202
|
+
return walletStandardFeatures.SolanaSignAndSendTransaction in wallet.features;
|
|
203
|
+
}
|
|
204
|
+
function serializeTransaction(transaction) {
|
|
205
|
+
if (transaction instanceof web3Compat.Transaction) {
|
|
206
|
+
return transaction.serialize({ requireAllSignatures: false, verifySignatures: false });
|
|
207
|
+
}
|
|
208
|
+
return transaction.serialize();
|
|
209
|
+
}
|
|
210
|
+
function deserializeTransaction(source, bytes) {
|
|
211
|
+
if (source instanceof web3Compat.Transaction) {
|
|
212
|
+
return web3Compat.Transaction.from(bytes);
|
|
213
|
+
}
|
|
214
|
+
return web3Compat.VersionedTransaction.deserialize(bytes);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
exports.adaptSolanaStandardWallet = adaptSolanaStandardWallet;
|
|
218
|
+
exports.getRegisteredSolanaWallets = getRegisteredSolanaWallets;
|
|
219
|
+
exports.getSolanaChain = getSolanaChain;
|
|
220
|
+
exports.isSolanaStandardWallet = isSolanaStandardWallet;
|
|
221
|
+
exports.subscribeSolanaWallets = subscribeSolanaWallets;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WalletAccount, Wallet } from '@wallet-standard/base';
|
|
2
|
+
import { SolanaChain, SolanaWalletInfo, SolanaWallet, SolanaCluster } from './types.cjs';
|
|
3
|
+
import '@solana/web3-compat';
|
|
4
|
+
|
|
5
|
+
interface AdaptSolanaWalletOptions {
|
|
6
|
+
chain?: SolanaChain;
|
|
7
|
+
account?: WalletAccount;
|
|
8
|
+
onChange?: () => void;
|
|
9
|
+
}
|
|
10
|
+
declare function getSolanaChain(cluster: SolanaCluster): SolanaChain;
|
|
11
|
+
declare function isSolanaStandardWallet(wallet: Wallet): boolean;
|
|
12
|
+
declare function getRegisteredSolanaWallets(): SolanaWalletInfo[];
|
|
13
|
+
declare function subscribeSolanaWallets(listener: () => void): () => void;
|
|
14
|
+
declare function adaptSolanaStandardWallet(walletInfo: SolanaWalletInfo, options?: AdaptSolanaWalletOptions): SolanaWallet;
|
|
15
|
+
|
|
16
|
+
export { adaptSolanaStandardWallet, getRegisteredSolanaWallets, getSolanaChain, isSolanaStandardWallet, subscribeSolanaWallets };
|
|
17
|
+
export type { AdaptSolanaWalletOptions };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WalletAccount, Wallet } from '@wallet-standard/base';
|
|
2
|
+
import { SolanaChain, SolanaWalletInfo, SolanaWallet, SolanaCluster } from './types.mjs';
|
|
3
|
+
import '@solana/web3-compat';
|
|
4
|
+
|
|
5
|
+
interface AdaptSolanaWalletOptions {
|
|
6
|
+
chain?: SolanaChain;
|
|
7
|
+
account?: WalletAccount;
|
|
8
|
+
onChange?: () => void;
|
|
9
|
+
}
|
|
10
|
+
declare function getSolanaChain(cluster: SolanaCluster): SolanaChain;
|
|
11
|
+
declare function isSolanaStandardWallet(wallet: Wallet): boolean;
|
|
12
|
+
declare function getRegisteredSolanaWallets(): SolanaWalletInfo[];
|
|
13
|
+
declare function subscribeSolanaWallets(listener: () => void): () => void;
|
|
14
|
+
declare function adaptSolanaStandardWallet(walletInfo: SolanaWalletInfo, options?: AdaptSolanaWalletOptions): SolanaWallet;
|
|
15
|
+
|
|
16
|
+
export { adaptSolanaStandardWallet, getRegisteredSolanaWallets, getSolanaChain, isSolanaStandardWallet, subscribeSolanaWallets };
|
|
17
|
+
export type { AdaptSolanaWalletOptions };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WalletAccount, Wallet } from '@wallet-standard/base';
|
|
2
|
+
import { SolanaChain, SolanaWalletInfo, SolanaWallet, SolanaCluster } from './types.js';
|
|
3
|
+
import '@solana/web3-compat';
|
|
4
|
+
|
|
5
|
+
interface AdaptSolanaWalletOptions {
|
|
6
|
+
chain?: SolanaChain;
|
|
7
|
+
account?: WalletAccount;
|
|
8
|
+
onChange?: () => void;
|
|
9
|
+
}
|
|
10
|
+
declare function getSolanaChain(cluster: SolanaCluster): SolanaChain;
|
|
11
|
+
declare function isSolanaStandardWallet(wallet: Wallet): boolean;
|
|
12
|
+
declare function getRegisteredSolanaWallets(): SolanaWalletInfo[];
|
|
13
|
+
declare function subscribeSolanaWallets(listener: () => void): () => void;
|
|
14
|
+
declare function adaptSolanaStandardWallet(walletInfo: SolanaWalletInfo, options?: AdaptSolanaWalletOptions): SolanaWallet;
|
|
15
|
+
|
|
16
|
+
export { adaptSolanaStandardWallet, getRegisteredSolanaWallets, getSolanaChain, isSolanaStandardWallet, subscribeSolanaWallets };
|
|
17
|
+
export type { AdaptSolanaWalletOptions };
|