@voidaisdk/bridge-sdk 0.0.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.
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ /**
3
+ * Bittensor Wallet Connection
4
+ * Handles connection to Bittensor-compatible wallets (Talisman, Subwallet, Polkadot.js)
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.BittensorWallet = void 0;
8
+ class BittensorWallet {
9
+ constructor() {
10
+ this.extension = null;
11
+ this.account = null;
12
+ this.extensionName = null;
13
+ }
14
+ /**
15
+ * Connect to a Bittensor-compatible wallet
16
+ * @param extensionName - Optional: specific extension name ('talisman', 'subwallet-js', 'polkadot-js')
17
+ * @returns Connected account information
18
+ */
19
+ async connect(extensionName) {
20
+ // Check if running in browser environment
21
+ if (typeof window === 'undefined') {
22
+ throw new Error('BittensorWallet: Browser environment required for wallet connection');
23
+ }
24
+ // Check if any compatible extension is available
25
+ if (typeof window.injectedWeb3 === 'undefined') {
26
+ throw new Error('No compatible wallet extension found. Please install Talisman, Subwallet, or Polkadot.js extension.');
27
+ }
28
+ const injectedWeb3 = window.injectedWeb3;
29
+ const supportedExtensions = ['talisman', 'subwallet-js', 'polkadot-js'];
30
+ let targetExtension = null;
31
+ let selectedExtensionName = '';
32
+ // If specific extension requested, use it
33
+ if (extensionName && injectedWeb3[extensionName]) {
34
+ targetExtension = injectedWeb3[extensionName];
35
+ selectedExtensionName = extensionName;
36
+ }
37
+ else {
38
+ // Find the first available supported extension
39
+ for (const name of supportedExtensions) {
40
+ if (injectedWeb3[name]) {
41
+ targetExtension = injectedWeb3[name];
42
+ selectedExtensionName = name;
43
+ break;
44
+ }
45
+ }
46
+ // Fallback: try to pick the first one available
47
+ if (!targetExtension) {
48
+ const available = Object.keys(injectedWeb3);
49
+ if (available.length > 0) {
50
+ selectedExtensionName = available[0];
51
+ targetExtension = injectedWeb3[selectedExtensionName];
52
+ }
53
+ else {
54
+ throw new Error('No compatible wallet extension found.');
55
+ }
56
+ }
57
+ }
58
+ // Request access to extension - this will trigger a popup for account authorization
59
+ let extension;
60
+ try {
61
+ extension = await targetExtension.enable('VoidAI Bridge SDK');
62
+ }
63
+ catch (error) {
64
+ // Handle case where user rejects authorization or no accounts are authorized
65
+ if (error.message && error.message.includes('authorised')) {
66
+ throw new Error('No accounts are authorized. Please authorize accounts in your wallet extension and try again.');
67
+ }
68
+ throw new Error(`Failed to enable wallet extension: ${error.message || error}`);
69
+ }
70
+ if (!extension) {
71
+ throw new Error('Failed to enable wallet extension. Please try again.');
72
+ }
73
+ // Get all authorized accounts
74
+ let allAccounts;
75
+ try {
76
+ allAccounts = await extension.accounts.get();
77
+ }
78
+ catch (error) {
79
+ throw new Error(`Failed to get accounts: ${error.message || error}`);
80
+ }
81
+ if (allAccounts.length === 0) {
82
+ throw new Error('No accounts found. Please authorize at least one account in your wallet extension and try again.');
83
+ }
84
+ // Store extension and use first account
85
+ this.extension = extension;
86
+ const account = allAccounts[0];
87
+ this.account = account;
88
+ this.extensionName = selectedExtensionName;
89
+ return account;
90
+ }
91
+ /**
92
+ * Get currently connected account
93
+ */
94
+ getAccount() {
95
+ return this.account;
96
+ }
97
+ /**
98
+ * Get extension name
99
+ */
100
+ getExtensionName() {
101
+ return this.extensionName;
102
+ }
103
+ /**
104
+ * Check if wallet is connected
105
+ */
106
+ isConnected() {
107
+ return this.account !== null && this.extension !== null;
108
+ }
109
+ /**
110
+ * Disconnect wallet
111
+ * Note: This only disconnects from the SDK. To fully disconnect from the extension,
112
+ * users need to disconnect accounts in their wallet extension settings.
113
+ */
114
+ disconnect() {
115
+ this.extension = null;
116
+ this.account = null;
117
+ this.extensionName = null;
118
+ }
119
+ /**
120
+ * Check if wallet extension is available
121
+ */
122
+ static isExtensionAvailable(extensionName) {
123
+ if (typeof window === 'undefined') {
124
+ return false;
125
+ }
126
+ const injectedWeb3 = window.injectedWeb3;
127
+ if (!injectedWeb3) {
128
+ return false;
129
+ }
130
+ if (extensionName) {
131
+ return !!injectedWeb3[extensionName];
132
+ }
133
+ const supportedExtensions = ['talisman', 'subwallet-js', 'polkadot-js'];
134
+ return supportedExtensions.some(name => !!injectedWeb3[name]) || Object.keys(injectedWeb3).length > 0;
135
+ }
136
+ /**
137
+ * Get the wallet extension instance (for advanced usage)
138
+ */
139
+ getExtension() {
140
+ return this.extension;
141
+ }
142
+ }
143
+ exports.BittensorWallet = BittensorWallet;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Ethereum Wallet Connection (MetaMask)
3
+ */
4
+ export interface EthereumAccount {
5
+ address: string;
6
+ chainId?: string;
7
+ }
8
+ export declare class EthereumWallet {
9
+ private account;
10
+ private chainId;
11
+ /**
12
+ * Check if MetaMask is installed
13
+ */
14
+ static isMetaMaskInstalled(): boolean;
15
+ /**
16
+ * Connect to MetaMask wallet
17
+ * @returns Connected account information
18
+ */
19
+ connect(): Promise<EthereumAccount>;
20
+ /**
21
+ * Get currently connected account
22
+ */
23
+ getAccount(): EthereumAccount | null;
24
+ /**
25
+ * Get current chain ID
26
+ */
27
+ getChainId(): string | null;
28
+ /**
29
+ * Check if wallet is connected
30
+ */
31
+ isConnected(): boolean;
32
+ /**
33
+ * Disconnect wallet
34
+ */
35
+ disconnect(): void;
36
+ /**
37
+ * Get the ethereum provider (for advanced usage)
38
+ */
39
+ getProvider(): any;
40
+ private handleAccountsChanged;
41
+ private handleChainChanged;
42
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ /**
3
+ * Ethereum Wallet Connection (MetaMask)
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EthereumWallet = void 0;
7
+ class EthereumWallet {
8
+ constructor() {
9
+ this.account = null;
10
+ this.chainId = null;
11
+ }
12
+ /**
13
+ * Check if MetaMask is installed
14
+ */
15
+ static isMetaMaskInstalled() {
16
+ if (typeof window === 'undefined') {
17
+ return false;
18
+ }
19
+ return typeof window.ethereum !== 'undefined' && window.ethereum.isMetaMask;
20
+ }
21
+ /**
22
+ * Connect to MetaMask wallet
23
+ * @returns Connected account information
24
+ */
25
+ async connect() {
26
+ if (typeof window === 'undefined') {
27
+ throw new Error('EthereumWallet: Browser environment required');
28
+ }
29
+ if (!EthereumWallet.isMetaMaskInstalled()) {
30
+ throw new Error('MetaMask is not installed. Please install MetaMask extension from https://metamask.io/');
31
+ }
32
+ const ethereum = window.ethereum;
33
+ try {
34
+ // Request account access - this will trigger MetaMask popup
35
+ const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
36
+ if (!accounts || accounts.length === 0) {
37
+ throw new Error('No accounts found. Please unlock MetaMask and try again.');
38
+ }
39
+ // Get chain ID
40
+ const chainId = await ethereum.request({ method: 'eth_chainId' });
41
+ this.account = {
42
+ address: accounts[0],
43
+ chainId: chainId
44
+ };
45
+ this.chainId = chainId;
46
+ // Listen for account changes
47
+ ethereum.on('accountsChanged', this.handleAccountsChanged.bind(this));
48
+ ethereum.on('chainChanged', this.handleChainChanged.bind(this));
49
+ return this.account;
50
+ }
51
+ catch (error) {
52
+ if (error.code === 4001) {
53
+ throw new Error('User rejected the connection request');
54
+ }
55
+ throw new Error(`Failed to connect to MetaMask: ${error.message || error}`);
56
+ }
57
+ }
58
+ /**
59
+ * Get currently connected account
60
+ */
61
+ getAccount() {
62
+ return this.account;
63
+ }
64
+ /**
65
+ * Get current chain ID
66
+ */
67
+ getChainId() {
68
+ return this.chainId;
69
+ }
70
+ /**
71
+ * Check if wallet is connected
72
+ */
73
+ isConnected() {
74
+ return this.account !== null;
75
+ }
76
+ /**
77
+ * Disconnect wallet
78
+ */
79
+ disconnect() {
80
+ this.account = null;
81
+ this.chainId = null;
82
+ }
83
+ /**
84
+ * Get the ethereum provider (for advanced usage)
85
+ */
86
+ getProvider() {
87
+ if (typeof window === 'undefined') {
88
+ return null;
89
+ }
90
+ return window.ethereum;
91
+ }
92
+ handleAccountsChanged(accounts) {
93
+ if (accounts.length === 0) {
94
+ this.disconnect();
95
+ }
96
+ else if (this.account && accounts[0] !== this.account.address) {
97
+ this.account.address = accounts[0];
98
+ }
99
+ }
100
+ handleChainChanged(chainId) {
101
+ this.chainId = chainId;
102
+ if (this.account) {
103
+ this.account.chainId = chainId;
104
+ }
105
+ }
106
+ }
107
+ exports.EthereumWallet = EthereumWallet;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Solana Wallet Connection (Phantom)
3
+ */
4
+ export interface SolanaAccount {
5
+ address: string;
6
+ publicKey: string;
7
+ }
8
+ export declare class SolanaWallet {
9
+ private account;
10
+ /**
11
+ * Check if Phantom is installed
12
+ */
13
+ static isPhantomInstalled(): boolean;
14
+ /**
15
+ * Connect to Phantom wallet
16
+ * @returns Connected account information
17
+ */
18
+ connect(): Promise<SolanaAccount>;
19
+ /**
20
+ * Get currently connected account
21
+ */
22
+ getAccount(): SolanaAccount | null;
23
+ /**
24
+ * Check if wallet is connected
25
+ */
26
+ isConnected(): boolean;
27
+ /**
28
+ * Disconnect wallet
29
+ */
30
+ disconnect(): void;
31
+ /**
32
+ * Get the Solana provider (for advanced usage)
33
+ */
34
+ getProvider(): any;
35
+ private handleDisconnect;
36
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ /**
3
+ * Solana Wallet Connection (Phantom)
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SolanaWallet = void 0;
7
+ class SolanaWallet {
8
+ constructor() {
9
+ this.account = null;
10
+ }
11
+ /**
12
+ * Check if Phantom is installed
13
+ */
14
+ static isPhantomInstalled() {
15
+ if (typeof window === 'undefined') {
16
+ return false;
17
+ }
18
+ return typeof window.solana !== 'undefined' && window.solana.isPhantom;
19
+ }
20
+ /**
21
+ * Connect to Phantom wallet
22
+ * @returns Connected account information
23
+ */
24
+ async connect() {
25
+ if (typeof window === 'undefined') {
26
+ throw new Error('SolanaWallet: Browser environment required');
27
+ }
28
+ if (!SolanaWallet.isPhantomInstalled()) {
29
+ throw new Error('Phantom is not installed. Please install Phantom extension from https://phantom.app/');
30
+ }
31
+ const solana = window.solana;
32
+ try {
33
+ // Request connection - this will trigger Phantom popup
34
+ const response = await solana.connect();
35
+ if (!response || !response.publicKey) {
36
+ throw new Error('Failed to connect to Phantom wallet');
37
+ }
38
+ this.account = {
39
+ address: response.publicKey.toString(),
40
+ publicKey: response.publicKey.toString()
41
+ };
42
+ // Listen for disconnect
43
+ solana.on('disconnect', this.handleDisconnect.bind(this));
44
+ return this.account;
45
+ }
46
+ catch (error) {
47
+ if (error.code === 4001) {
48
+ throw new Error('User rejected the connection request');
49
+ }
50
+ throw new Error(`Failed to connect to Phantom: ${error.message || error}`);
51
+ }
52
+ }
53
+ /**
54
+ * Get currently connected account
55
+ */
56
+ getAccount() {
57
+ return this.account;
58
+ }
59
+ /**
60
+ * Check if wallet is connected
61
+ */
62
+ isConnected() {
63
+ return this.account !== null;
64
+ }
65
+ /**
66
+ * Disconnect wallet
67
+ */
68
+ disconnect() {
69
+ if (this.account && typeof window !== 'undefined') {
70
+ const solana = window.solana;
71
+ if (solana && solana.disconnect && typeof solana.disconnect === 'function') {
72
+ try {
73
+ const disconnectResult = solana.disconnect();
74
+ if (disconnectResult && typeof disconnectResult.catch === 'function') {
75
+ disconnectResult.catch(() => {
76
+ // Ignore disconnect errors
77
+ });
78
+ }
79
+ }
80
+ catch (error) {
81
+ // Ignore disconnect errors
82
+ }
83
+ }
84
+ }
85
+ this.account = null;
86
+ }
87
+ /**
88
+ * Get the Solana provider (for advanced usage)
89
+ */
90
+ getProvider() {
91
+ if (typeof window === 'undefined') {
92
+ return null;
93
+ }
94
+ return window.solana;
95
+ }
96
+ handleDisconnect() {
97
+ this.disconnect();
98
+ }
99
+ }
100
+ exports.SolanaWallet = SolanaWallet;