@tuwaio/satellite-solana 0.0.3
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/LICENSE +201 -0
- package/README.md +127 -0
- package/dist/index.d.mts +109 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 FOP Tkach Oleksandr
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Satellite Connect Solana
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@tuwaio/satellite-solana)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](https://github.com/TuwaIO/satellite-solana/actions)
|
|
6
|
+
|
|
7
|
+
Solana-specific implementation for the Satellite Connect ecosystem, providing comprehensive utilities and adapters for interacting with Solana wallets and networks.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 🏛️ What is `@tuwaio/satellite-solana`?
|
|
12
|
+
|
|
13
|
+
`@tuwaio/satellite-solana` is the Solana implementation of the Satellite ecosystem's wallet connection system. It provides specialized adapters and utilities for interacting with Solana-compatible wallets like Phantom, Solflare, and others.
|
|
14
|
+
|
|
15
|
+
Built on top of `@tuwaio/satellite-core` and leveraging `@tuwaio/orbit-solana` for enhanced Solana interactions.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## ✨ Key Features
|
|
20
|
+
|
|
21
|
+
- **Type Safety:** Full TypeScript support with proper type definitions
|
|
22
|
+
- **Mobile Support:** Built-in mobile wallet connection support
|
|
23
|
+
- **Modern Architecture:** Built on Gill for optimal performance
|
|
24
|
+
- **Multi-Network:** Support for mainnet, devnet and testnet
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 💾 Installation
|
|
29
|
+
|
|
30
|
+
### Requirements
|
|
31
|
+
- Node.js 20+
|
|
32
|
+
- TypeScript 5.9+
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Using pnpm (recommended)
|
|
36
|
+
pnpm add @tuwaio/satellite-solana @tuwaio/satellite-core @tuwaio/orbit-core @tuwaio/orbit-solana gill @solana-mobile/wallet-standard-mobile immer zustand wagmi/core @wallet-standard/app @wallet-standard/base @wallet-standard/features @wallet-standard/ui @wallet-standard/ui-registry
|
|
37
|
+
|
|
38
|
+
# Using npm
|
|
39
|
+
npm install @tuwaio/satellite-solana @tuwaio/satellite-core @tuwaio/orbit-core @tuwaio/orbit-solana gill @solana-mobile/wallet-standard-mobile immer zustand wagmi/core @wallet-standard/app @wallet-standard/base @wallet-standard/features @wallet-standard/ui @wallet-standard/ui-registry
|
|
40
|
+
|
|
41
|
+
# Using yarn
|
|
42
|
+
yarn add @tuwaio/satellite-solana @tuwaio/satellite-core @tuwaio/orbit-core @tuwaio/orbit-solana gill @solana-mobile/wallet-standard-mobile immer zustand wagmi/core @wallet-standard/app @wallet-standard/base @wallet-standard/features @wallet-standard/ui @wallet-standard/ui-registry
|
|
43
|
+
```
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 🚀 Quick Start
|
|
47
|
+
|
|
48
|
+
### Basic Setup
|
|
49
|
+
```typescript
|
|
50
|
+
import { satelliteSolanaAdapter } from '@tuwaio/satellite-solana';
|
|
51
|
+
|
|
52
|
+
// Configure RPC endpoints
|
|
53
|
+
const solanaRPCUrls = {
|
|
54
|
+
devnet: 'https://api.devnet.solana.com',
|
|
55
|
+
mainnet: 'https://api.mainnet-beta.solana.com'
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Create Solana adapter
|
|
59
|
+
const adapter = satelliteSolanaAdapter({
|
|
60
|
+
rpcUrls: solanaRPCUrls
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Mobile Support Setup
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { initializeSolanaMobileConnectors } from '@tuwaio/satellite-solana';
|
|
68
|
+
|
|
69
|
+
// Initialize mobile connectors
|
|
70
|
+
initializeSolanaMobileConnectors({
|
|
71
|
+
rpcUrls: solanaRPCUrls,
|
|
72
|
+
appName: 'Your dApp Name'
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
### Core Components
|
|
78
|
+
|
|
79
|
+
1. **Adapters**
|
|
80
|
+
- Wallet-specific implementations
|
|
81
|
+
- Mobile wallet adapters
|
|
82
|
+
|
|
83
|
+
2. **Mobile Support**
|
|
84
|
+
- Mobile wallet detection
|
|
85
|
+
- Mobile-specific connection flows
|
|
86
|
+
- Universal link handlers
|
|
87
|
+
|
|
88
|
+
3. **Utils**
|
|
89
|
+
- Connection utilities
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 🌐 Supported Wallets
|
|
94
|
+
|
|
95
|
+
- Phantom
|
|
96
|
+
- Solflare
|
|
97
|
+
- Backpack
|
|
98
|
+
- Trust Wallet (Solana)
|
|
99
|
+
- Mobile Wallets (via Mobile Wallet Adapter)
|
|
100
|
+
- And other Solana-compatible wallets
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 🔗 Network Support
|
|
105
|
+
|
|
106
|
+
Built-in support for all Solana networks:
|
|
107
|
+
- Mainnet
|
|
108
|
+
- Devnet
|
|
109
|
+
- Testnet
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 🤝 Contributing & Support
|
|
114
|
+
|
|
115
|
+
Contributions are welcome! Please read our main **[Contribution Guidelines](https://github.com/TuwaIO/workflows/blob/main/CONTRIBUTING.md)**.
|
|
116
|
+
|
|
117
|
+
If you find this library useful, please consider supporting its development. Every contribution helps!
|
|
118
|
+
|
|
119
|
+
[**➡️ View Support Options**](https://github.com/TuwaIO/workflows/blob/main/Donation.md)
|
|
120
|
+
|
|
121
|
+
## 📄 License
|
|
122
|
+
|
|
123
|
+
This project is licensed under the **Apache-2.0 License** - see the [LICENSE](./LICENSE) file for details.
|
|
124
|
+
|
|
125
|
+
## 👥 Contributors
|
|
126
|
+
|
|
127
|
+
- **Oleksandr Tkach** - [GitHub](https://github.com/Argeare5)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { SolanaRPCUrls } from '@tuwaio/orbit-solana';
|
|
2
|
+
import { SatelliteAdapter, ConnectorsInitProps } from '@tuwaio/satellite-core';
|
|
3
|
+
import { StandardConnectMethod } from '@wallet-standard/features';
|
|
4
|
+
import { UiWallet, UiWalletAccount } from '@wallet-standard/ui';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Solana blockchain adapter for the Satellite Connect system
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This adapter implements the SatelliteAdapter interface for Solana blockchain,
|
|
11
|
+
* providing wallet connection, network switching, and name resolution capabilities.
|
|
12
|
+
* It uses the Wallet Standard for consistent wallet interactions.
|
|
13
|
+
*
|
|
14
|
+
* @param rpcUrls - Configuration object containing RPC endpoints for different Solana networks
|
|
15
|
+
* @returns SatelliteAdapter implementation for Solana
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const solanaAdapter = satelliteSolanaAdapter({
|
|
20
|
+
* rpcUrls: {
|
|
21
|
+
* mainnet: 'https://api.mainnet-beta.solana.com',
|
|
22
|
+
* devnet: 'https://api.devnet.solana.com',
|
|
23
|
+
* testnet: 'https://api.testnet.solana.com'
|
|
24
|
+
* }
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function satelliteSolanaAdapter({ rpcUrls }: SolanaRPCUrls): SatelliteAdapter;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Combined props for initializing Solana mobile connectors
|
|
32
|
+
*/
|
|
33
|
+
type InitializeSolanaMobileConnectorsProps = ConnectorsInitProps & SolanaRPCUrls;
|
|
34
|
+
/**
|
|
35
|
+
* Initializes Solana Mobile Wallet Adapter (MWA) for mobile wallet connections
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* This function sets up the Solana Mobile Wallet Adapter with appropriate configuration
|
|
39
|
+
* for secure mobile wallet connections. It includes security checks and chain validation.
|
|
40
|
+
* Only works in secure contexts (HTTPS) and requires at least one valid chain configuration.
|
|
41
|
+
*
|
|
42
|
+
* @param props - Combined initialization properties
|
|
43
|
+
* @param props.rpcUrls - RPC endpoints for different Solana networks
|
|
44
|
+
* @param props.appName - Application name to display in wallet
|
|
45
|
+
* @param props.appUrl - Application URL
|
|
46
|
+
* @param props.appLogoUrl - Application logo URL
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* initializeSolanaMobileConnectors({
|
|
51
|
+
* rpcUrls: {
|
|
52
|
+
* mainnet: 'https://api.mainnet-beta.solana.com',
|
|
53
|
+
* devnet: 'https://api.devnet.solana.com'
|
|
54
|
+
* },
|
|
55
|
+
* appName: 'My Solana App',
|
|
56
|
+
* appUrl: 'https://myapp.com',
|
|
57
|
+
* appLogoUrl: 'https://myapp.com/logo.png'
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @throws {Warning} If not in secure context (non-HTTPS)
|
|
62
|
+
* @throws {Warning} If no chains are configured
|
|
63
|
+
*/
|
|
64
|
+
declare function initializeSolanaMobileConnectors({ rpcUrls, ...props }: InitializeSolanaMobileConnectorsProps): void;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Establishes connection with a wallet using Wallet Standard
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* Connects to a wallet that implements the Wallet Standard interface.
|
|
71
|
+
* Uses the StandardConnect feature to establish connection and retrieve accounts.
|
|
72
|
+
* Converts standard wallet accounts to UI wallet accounts.
|
|
73
|
+
*
|
|
74
|
+
* @param uiWallet - Wallet instance implementing the UI Wallet interface
|
|
75
|
+
* @param input - Optional connection parameters (excluding silent flag)
|
|
76
|
+
* @returns Promise resolving to array of connected wallet accounts
|
|
77
|
+
*
|
|
78
|
+
* @throws {Error} If wallet doesn't support StandardConnect feature
|
|
79
|
+
* @throws {Error} If connection attempt fails
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const accounts = await connect(wallet, {
|
|
84
|
+
* // Optional connection parameters
|
|
85
|
+
* });
|
|
86
|
+
* const firstAccount = accounts[0];
|
|
87
|
+
* console.log('Connected account:', firstAccount.address);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare function connect(uiWallet: UiWallet, input?: Omit<NonNullable<Parameters<StandardConnectMethod>[0]>, 'silent'>): Promise<readonly UiWalletAccount[]>;
|
|
91
|
+
/**
|
|
92
|
+
* Disconnects from a connected wallet
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* Safely disconnects from a wallet if it supports the StandardDisconnect feature.
|
|
96
|
+
* If the wallet doesn't support disconnection, the operation is silently ignored.
|
|
97
|
+
*
|
|
98
|
+
* @param uiWallet - Wallet instance implementing the UI Wallet interface
|
|
99
|
+
* @returns Promise that resolves when disconnection is complete
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* await disconnect(wallet);
|
|
104
|
+
* console.log('Wallet disconnected');
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare function disconnect(uiWallet: UiWallet): Promise<void>;
|
|
108
|
+
|
|
109
|
+
export { connect, disconnect, initializeSolanaMobileConnectors, satelliteSolanaAdapter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { SolanaRPCUrls } from '@tuwaio/orbit-solana';
|
|
2
|
+
import { SatelliteAdapter, ConnectorsInitProps } from '@tuwaio/satellite-core';
|
|
3
|
+
import { StandardConnectMethod } from '@wallet-standard/features';
|
|
4
|
+
import { UiWallet, UiWalletAccount } from '@wallet-standard/ui';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Solana blockchain adapter for the Satellite Connect system
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This adapter implements the SatelliteAdapter interface for Solana blockchain,
|
|
11
|
+
* providing wallet connection, network switching, and name resolution capabilities.
|
|
12
|
+
* It uses the Wallet Standard for consistent wallet interactions.
|
|
13
|
+
*
|
|
14
|
+
* @param rpcUrls - Configuration object containing RPC endpoints for different Solana networks
|
|
15
|
+
* @returns SatelliteAdapter implementation for Solana
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const solanaAdapter = satelliteSolanaAdapter({
|
|
20
|
+
* rpcUrls: {
|
|
21
|
+
* mainnet: 'https://api.mainnet-beta.solana.com',
|
|
22
|
+
* devnet: 'https://api.devnet.solana.com',
|
|
23
|
+
* testnet: 'https://api.testnet.solana.com'
|
|
24
|
+
* }
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function satelliteSolanaAdapter({ rpcUrls }: SolanaRPCUrls): SatelliteAdapter;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Combined props for initializing Solana mobile connectors
|
|
32
|
+
*/
|
|
33
|
+
type InitializeSolanaMobileConnectorsProps = ConnectorsInitProps & SolanaRPCUrls;
|
|
34
|
+
/**
|
|
35
|
+
* Initializes Solana Mobile Wallet Adapter (MWA) for mobile wallet connections
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* This function sets up the Solana Mobile Wallet Adapter with appropriate configuration
|
|
39
|
+
* for secure mobile wallet connections. It includes security checks and chain validation.
|
|
40
|
+
* Only works in secure contexts (HTTPS) and requires at least one valid chain configuration.
|
|
41
|
+
*
|
|
42
|
+
* @param props - Combined initialization properties
|
|
43
|
+
* @param props.rpcUrls - RPC endpoints for different Solana networks
|
|
44
|
+
* @param props.appName - Application name to display in wallet
|
|
45
|
+
* @param props.appUrl - Application URL
|
|
46
|
+
* @param props.appLogoUrl - Application logo URL
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* initializeSolanaMobileConnectors({
|
|
51
|
+
* rpcUrls: {
|
|
52
|
+
* mainnet: 'https://api.mainnet-beta.solana.com',
|
|
53
|
+
* devnet: 'https://api.devnet.solana.com'
|
|
54
|
+
* },
|
|
55
|
+
* appName: 'My Solana App',
|
|
56
|
+
* appUrl: 'https://myapp.com',
|
|
57
|
+
* appLogoUrl: 'https://myapp.com/logo.png'
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @throws {Warning} If not in secure context (non-HTTPS)
|
|
62
|
+
* @throws {Warning} If no chains are configured
|
|
63
|
+
*/
|
|
64
|
+
declare function initializeSolanaMobileConnectors({ rpcUrls, ...props }: InitializeSolanaMobileConnectorsProps): void;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Establishes connection with a wallet using Wallet Standard
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* Connects to a wallet that implements the Wallet Standard interface.
|
|
71
|
+
* Uses the StandardConnect feature to establish connection and retrieve accounts.
|
|
72
|
+
* Converts standard wallet accounts to UI wallet accounts.
|
|
73
|
+
*
|
|
74
|
+
* @param uiWallet - Wallet instance implementing the UI Wallet interface
|
|
75
|
+
* @param input - Optional connection parameters (excluding silent flag)
|
|
76
|
+
* @returns Promise resolving to array of connected wallet accounts
|
|
77
|
+
*
|
|
78
|
+
* @throws {Error} If wallet doesn't support StandardConnect feature
|
|
79
|
+
* @throws {Error} If connection attempt fails
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const accounts = await connect(wallet, {
|
|
84
|
+
* // Optional connection parameters
|
|
85
|
+
* });
|
|
86
|
+
* const firstAccount = accounts[0];
|
|
87
|
+
* console.log('Connected account:', firstAccount.address);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare function connect(uiWallet: UiWallet, input?: Omit<NonNullable<Parameters<StandardConnectMethod>[0]>, 'silent'>): Promise<readonly UiWalletAccount[]>;
|
|
91
|
+
/**
|
|
92
|
+
* Disconnects from a connected wallet
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* Safely disconnects from a wallet if it supports the StandardDisconnect feature.
|
|
96
|
+
* If the wallet doesn't support disconnection, the operation is silently ignored.
|
|
97
|
+
*
|
|
98
|
+
* @param uiWallet - Wallet instance implementing the UI Wallet interface
|
|
99
|
+
* @returns Promise that resolves when disconnection is complete
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* await disconnect(wallet);
|
|
104
|
+
* console.log('Wallet disconnected');
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare function disconnect(uiWallet: UiWallet): Promise<void>;
|
|
108
|
+
|
|
109
|
+
export { connect, disconnect, initializeSolanaMobileConnectors, satelliteSolanaAdapter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var orbitCore=require('@tuwaio/orbit-core'),orbitSolana=require('@tuwaio/orbit-solana'),satelliteCore=require('@tuwaio/satellite-core'),app=require('@wallet-standard/app'),uiRegistry=require('@wallet-standard/ui-registry'),features=require('@wallet-standard/features'),ui=require('@wallet-standard/ui'),walletStandardMobile=require('@solana-mobile/wallet-standard-mobile');async function u(r,n){let t=ui.getWalletFeature(r,features.StandardConnect),{accounts:e}=await t.connect(n);return e.map(o=>uiRegistry.getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiRegistry.getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(r),o))}async function p(r){await ui.getWalletFeature(r,features.StandardDisconnect)?.disconnect();}function H({rpcUrls:r}){let n=()=>app.getWallets().get().map(uiRegistry.getOrCreateUiWalletForStandardWallet_DO_NOT_USE_OR_YOU_WILL_BE_FIRED);return {key:orbitCore.OrbitAdapter.SOLANA,async connect({walletType:t,chainId:e,connectors:o}){let c=o.find(a=>satelliteCore.getWalletTypeFromConnectorName(orbitCore.OrbitAdapter.SOLANA,a.name)===t);if(!c)throw new Error("Cannot find connector with this wallet type");try{let a=await u(c),f=n(),i=orbitSolana.getCluster({cluster:e});return {walletType:t,address:a[0].address,chainId:i,rpcURL:orbitSolana.getRpcUrlForCluster({cluster:i,rpcUrls:r}),isConnected:!0,isContractAddress:!1,connectedAccount:a,connectedWallet:f.filter(S=>S.accounts.length>0)[0]}}catch(a){throw new Error(a instanceof Error?a.message:String(a))}},async disconnect(){let e=n().filter(o=>o.accounts.length>0)[0];await p(e);},async getConnectors(){let t=n();return {adapter:orbitCore.OrbitAdapter.SOLANA,connectors:t}},async checkAndSwitchNetwork(t,e,o){if(e!==t&&o){let c=orbitSolana.getCluster({cluster:t});o({chainId:c,rpcURL:orbitSolana.getRpcUrlForCluster({cluster:c,rpcUrls:r})});}},getExplorerUrl(t,e){let o=orbitSolana.getCluster({cluster:e})??"mainnet";return orbitSolana.getSolanaExplorerLink(t,o)},async getName(t){return n().filter(c=>c.accounts.some(a=>a.address.toLowerCase()===t.toLowerCase()))[0]?.accounts[0]?.label??t},async getAvatar(t){return n().filter(c=>c.accounts.some(a=>a.label?.toLowerCase()===t.toLowerCase()))[0]?.accounts[0]?.icon??t}}}function $({rpcUrls:r,...n}){if(typeof window>"u")return;if(!window.isSecureContext){console.warn("Solana Mobile Connectors not loaded: https connection required");return}let t=Object.keys(r).map(e=>`solana:${e}`);if(t.length===0){console.warn("Solana Mobile Connectors not loaded: no chains provided");return}walletStandardMobile.registerMwa({appIdentity:{uri:n?.appUrl,icon:n?.appLogoUrl,name:n?.appName},authorizationCache:walletStandardMobile.createDefaultAuthorizationCache(),chains:t,chainSelector:walletStandardMobile.createDefaultChainSelector(),onWalletNotFound:walletStandardMobile.createDefaultWalletNotFoundHandler()});}exports.connect=u;exports.disconnect=p;exports.initializeSolanaMobileConnectors=$;exports.satelliteSolanaAdapter=H;//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/connectionUtils.ts","../src/adapters/solanaAdapter.ts","../src/connectors/initializeSolanaMobileConnectors.ts"],"names":["connect","uiWallet","input","connectFeature","getWalletFeature","StandardConnect","accounts","account","getOrCreateUiWalletAccountForStandardWalletAccount","getWalletForHandle","disconnect","StandardDisconnect","satelliteSolanaAdapter","rpcUrls","getAvailableWallets","getWallets","getOrCreateUiWalletForStandardWallet","OrbitAdapter","walletType","chainId","connectors","connector","getWalletTypeFromConnectorName","connectedAccount","wallets","cluster","getCluster","getRpcUrlForCluster","wallet","e","connectedWallet","currentChainId","updateActiveWallet","url","getSolanaExplorerLink","address","name","initializeSolanaMobileConnectors","props","chains","key","registerMwa","createDefaultAuthorizationCache","createDefaultChainSelector","createDefaultWalletNotFoundHandler"],"mappings":"kYAoCA,eAAsBA,EACpBC,CAAAA,CACAC,CAAAA,CACqC,CAErC,IAAMC,CAAAA,CAAiBC,mBAAAA,CAAiBH,EAAUI,wBAAe,CAAA,CAG3D,CAAE,QAAA,CAAAC,CAAS,CAAA,CAAI,MAAMH,CAAAA,CAAe,OAAA,CAAQD,CAAK,CAAA,CAGvD,OAAOI,CAAAA,CAAS,IAAKC,CAAA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AAA,EACpB,CAAC,EACH","file":"index.js","sourcesContent":["import type {\n StandardConnectFeature,\n StandardConnectMethod,\n StandardDisconnectFeature,\n} from '@wallet-standard/features';\nimport { StandardConnect, StandardDisconnect } from '@wallet-standard/features';\nimport { getWalletFeature, type UiWallet, type UiWalletAccount } from '@wallet-standard/ui';\nimport {\n getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as getOrCreateUiWalletAccountForStandardWalletAccount,\n getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as getWalletForHandle,\n} from '@wallet-standard/ui-registry';\n\n/**\n * Establishes connection with a wallet using Wallet Standard\n *\n * @remarks\n * Connects to a wallet that implements the Wallet Standard interface.\n * Uses the StandardConnect feature to establish connection and retrieve accounts.\n * Converts standard wallet accounts to UI wallet accounts.\n *\n * @param uiWallet - Wallet instance implementing the UI Wallet interface\n * @param input - Optional connection parameters (excluding silent flag)\n * @returns Promise resolving to array of connected wallet accounts\n *\n * @throws {Error} If wallet doesn't support StandardConnect feature\n * @throws {Error} If connection attempt fails\n *\n * @example\n * ```typescript\n * const accounts = await connect(wallet, {\n * // Optional connection parameters\n * });\n * const firstAccount = accounts[0];\n * console.log('Connected account:', firstAccount.address);\n * ```\n */\nexport async function connect(\n uiWallet: UiWallet,\n input?: Omit<NonNullable<Parameters<StandardConnectMethod>[0]>, 'silent'>,\n): Promise<readonly UiWalletAccount[]> {\n // Get the connect feature from the wallet\n const connectFeature = getWalletFeature(uiWallet, StandardConnect) as StandardConnectFeature[typeof StandardConnect];\n\n // Initiate connection and get accounts\n const { accounts } = await connectFeature.connect(input);\n\n // Convert accounts to UI wallet accounts\n return accounts.map((account) =>\n getOrCreateUiWalletAccountForStandardWalletAccount(getWalletForHandle(uiWallet), account),\n );\n}\n\n/**\n * Disconnects from a connected wallet\n *\n * @remarks\n * Safely disconnects from a wallet if it supports the StandardDisconnect feature.\n * If the wallet doesn't support disconnection, the operation is silently ignored.\n *\n * @param uiWallet - Wallet instance implementing the UI Wallet interface\n * @returns Promise that resolves when disconnection is complete\n *\n * @example\n * ```typescript\n * await disconnect(wallet);\n * console.log('Wallet disconnected');\n * ```\n */\nexport async function disconnect(uiWallet: UiWallet): Promise<void> {\n // Get the disconnect feature if available\n const disconnectFeature = getWalletFeature(uiWallet, StandardDisconnect) as\n | StandardDisconnectFeature[typeof StandardDisconnect]\n | undefined;\n\n // Attempt disconnection if feature is supported\n await disconnectFeature?.disconnect();\n}\n","import { OrbitAdapter } from '@tuwaio/orbit-core';\nimport { getCluster, getRpcUrlForCluster, getSolanaExplorerLink, SolanaRPCUrls } from '@tuwaio/orbit-solana';\nimport { ConnectorSolana, getWalletTypeFromConnectorName, SatelliteAdapter } from '@tuwaio/satellite-core';\nimport { getWallets } from '@wallet-standard/app';\nimport { UiWallet } from '@wallet-standard/ui';\nimport { getOrCreateUiWalletForStandardWallet_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as getOrCreateUiWalletForStandardWallet } from '@wallet-standard/ui-registry';\nimport { SolanaClusterMoniker } from 'gill';\n\nimport { connect, disconnect } from '../utils/connectionUtils';\n\n/**\n * Creates a Solana blockchain adapter for the Satellite Connect system\n *\n * @remarks\n * This adapter implements the SatelliteAdapter interface for Solana blockchain,\n * providing wallet connection, network switching, and name resolution capabilities.\n * It uses the Wallet Standard for consistent wallet interactions.\n *\n * @param rpcUrls - Configuration object containing RPC endpoints for different Solana networks\n * @returns SatelliteAdapter implementation for Solana\n *\n * @example\n * ```typescript\n * const solanaAdapter = satelliteSolanaAdapter({\n * rpcUrls: {\n * mainnet: 'https://api.mainnet-beta.solana.com',\n * devnet: 'https://api.devnet.solana.com',\n * testnet: 'https://api.testnet.solana.com'\n * }\n * });\n * ```\n */\nexport function satelliteSolanaAdapter({ rpcUrls }: SolanaRPCUrls): SatelliteAdapter {\n /**\n * Helper to get all available wallets\n */\n const getAvailableWallets = () => getWallets().get().map(getOrCreateUiWalletForStandardWallet);\n\n return {\n key: OrbitAdapter.SOLANA,\n\n async connect({ walletType, chainId, connectors }) {\n const connector = connectors.find(\n (connector) => getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, connector.name) === walletType,\n );\n if (!connector) throw new Error('Cannot find connector with this wallet type');\n\n try {\n const connectedAccount = await connect(connector as UiWallet);\n const wallets = getAvailableWallets();\n const cluster = getCluster({ cluster: chainId as string });\n\n return {\n walletType,\n address: connectedAccount[0].address,\n chainId: cluster,\n rpcURL: getRpcUrlForCluster({\n cluster: cluster as SolanaClusterMoniker,\n rpcUrls,\n }),\n isConnected: true,\n isContractAddress: false,\n connectedAccount,\n connectedWallet: wallets.filter((wallet) => wallet.accounts.length > 0)[0],\n };\n } catch (e) {\n throw new Error(e instanceof Error ? e.message : String(e));\n }\n },\n\n async disconnect() {\n const wallets = getAvailableWallets();\n const connectedWallet = wallets.filter((wallet) => wallet.accounts.length > 0)[0];\n await disconnect(connectedWallet);\n },\n\n async getConnectors() {\n const connectors = getAvailableWallets();\n return {\n adapter: OrbitAdapter.SOLANA,\n connectors: connectors as ConnectorSolana[],\n };\n },\n\n async checkAndSwitchNetwork(chainId, currentChainId, updateActiveWallet) {\n if (currentChainId !== chainId && updateActiveWallet) {\n const cluster = getCluster({ cluster: chainId as string });\n updateActiveWallet({\n chainId: cluster,\n rpcURL: getRpcUrlForCluster({\n cluster: cluster as SolanaClusterMoniker,\n rpcUrls,\n }),\n });\n }\n },\n\n getExplorerUrl(url, chainId) {\n const cluster = getCluster({ cluster: chainId as string }) ?? 'mainnet';\n return getSolanaExplorerLink(url, cluster as SolanaClusterMoniker);\n },\n\n async getName(address) {\n const wallets = getAvailableWallets();\n const connectedWallet = wallets.filter((wallet) =>\n wallet.accounts.some((account) => account.address.toLowerCase() === address.toLowerCase()),\n )[0];\n return connectedWallet?.accounts[0]?.label ?? address;\n },\n\n async getAvatar(name) {\n const wallets = getAvailableWallets();\n const connectedWallet = wallets.filter((wallet) =>\n wallet.accounts.some((account) => account.label?.toLowerCase() === name.toLowerCase()),\n )[0];\n return connectedWallet?.accounts[0]?.icon ?? name;\n },\n };\n}\n","import {\n createDefaultAuthorizationCache,\n createDefaultChainSelector,\n createDefaultWalletNotFoundHandler,\n registerMwa,\n} from '@solana-mobile/wallet-standard-mobile';\nimport { SolanaRPCUrls } from '@tuwaio/orbit-solana';\nimport { ConnectorsInitProps } from '@tuwaio/satellite-core';\n\n/**\n * Combined props for initializing Solana mobile connectors\n */\ntype InitializeSolanaMobileConnectorsProps = ConnectorsInitProps & SolanaRPCUrls;\n\n/**\n * Initializes Solana Mobile Wallet Adapter (MWA) for mobile wallet connections\n *\n * @remarks\n * This function sets up the Solana Mobile Wallet Adapter with appropriate configuration\n * for secure mobile wallet connections. It includes security checks and chain validation.\n * Only works in secure contexts (HTTPS) and requires at least one valid chain configuration.\n *\n * @param props - Combined initialization properties\n * @param props.rpcUrls - RPC endpoints for different Solana networks\n * @param props.appName - Application name to display in wallet\n * @param props.appUrl - Application URL\n * @param props.appLogoUrl - Application logo URL\n *\n * @example\n * ```typescript\n * initializeSolanaMobileConnectors({\n * rpcUrls: {\n * mainnet: 'https://api.mainnet-beta.solana.com',\n * devnet: 'https://api.devnet.solana.com'\n * },\n * appName: 'My Solana App',\n * appUrl: 'https://myapp.com',\n * appLogoUrl: 'https://myapp.com/logo.png'\n * });\n * ```\n *\n * @throws {Warning} If not in secure context (non-HTTPS)\n * @throws {Warning} If no chains are configured\n */\nexport function initializeSolanaMobileConnectors({ rpcUrls, ...props }: InitializeSolanaMobileConnectorsProps): void {\n // Only run in browser environment\n if (typeof window === 'undefined') {\n return;\n }\n // Ensure secure context (HTTPS)\n if (!window.isSecureContext) {\n console.warn('Solana Mobile Connectors not loaded: https connection required');\n return;\n }\n\n // Generate chain identifiers\n const chains = Object.keys(rpcUrls).map((key) => `solana:${key}` as `solana:${string}`);\n\n // Validate chain configuration\n if (chains.length === 0) {\n console.warn('Solana Mobile Connectors not loaded: no chains provided');\n return;\n }\n\n // Register Mobile Wallet Adapter\n registerMwa({\n appIdentity: {\n uri: props?.appUrl,\n icon: props?.appLogoUrl,\n name: props?.appName,\n },\n authorizationCache: createDefaultAuthorizationCache(),\n chains,\n chainSelector: createDefaultChainSelector(),\n onWalletNotFound: createDefaultWalletNotFoundHandler(),\n });\n}\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {OrbitAdapter}from'@tuwaio/orbit-core';import {getCluster,getSolanaExplorerLink,getRpcUrlForCluster}from'@tuwaio/orbit-solana';import {getWalletTypeFromConnectorName}from'@tuwaio/satellite-core';import {getWallets}from'@wallet-standard/app';import {getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,getOrCreateUiWalletForStandardWallet_DO_NOT_USE_OR_YOU_WILL_BE_FIRED}from'@wallet-standard/ui-registry';import {StandardConnect,StandardDisconnect}from'@wallet-standard/features';import {getWalletFeature}from'@wallet-standard/ui';import {registerMwa,createDefaultWalletNotFoundHandler,createDefaultChainSelector,createDefaultAuthorizationCache}from'@solana-mobile/wallet-standard-mobile';async function u(r,n){let t=getWalletFeature(r,StandardConnect),{accounts:e}=await t.connect(n);return e.map(o=>getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(r),o))}async function p(r){await getWalletFeature(r,StandardDisconnect)?.disconnect();}function H({rpcUrls:r}){let n=()=>getWallets().get().map(getOrCreateUiWalletForStandardWallet_DO_NOT_USE_OR_YOU_WILL_BE_FIRED);return {key:OrbitAdapter.SOLANA,async connect({walletType:t,chainId:e,connectors:o}){let c=o.find(a=>getWalletTypeFromConnectorName(OrbitAdapter.SOLANA,a.name)===t);if(!c)throw new Error("Cannot find connector with this wallet type");try{let a=await u(c),f=n(),i=getCluster({cluster:e});return {walletType:t,address:a[0].address,chainId:i,rpcURL:getRpcUrlForCluster({cluster:i,rpcUrls:r}),isConnected:!0,isContractAddress:!1,connectedAccount:a,connectedWallet:f.filter(S=>S.accounts.length>0)[0]}}catch(a){throw new Error(a instanceof Error?a.message:String(a))}},async disconnect(){let e=n().filter(o=>o.accounts.length>0)[0];await p(e);},async getConnectors(){let t=n();return {adapter:OrbitAdapter.SOLANA,connectors:t}},async checkAndSwitchNetwork(t,e,o){if(e!==t&&o){let c=getCluster({cluster:t});o({chainId:c,rpcURL:getRpcUrlForCluster({cluster:c,rpcUrls:r})});}},getExplorerUrl(t,e){let o=getCluster({cluster:e})??"mainnet";return getSolanaExplorerLink(t,o)},async getName(t){return n().filter(c=>c.accounts.some(a=>a.address.toLowerCase()===t.toLowerCase()))[0]?.accounts[0]?.label??t},async getAvatar(t){return n().filter(c=>c.accounts.some(a=>a.label?.toLowerCase()===t.toLowerCase()))[0]?.accounts[0]?.icon??t}}}function $({rpcUrls:r,...n}){if(typeof window>"u")return;if(!window.isSecureContext){console.warn("Solana Mobile Connectors not loaded: https connection required");return}let t=Object.keys(r).map(e=>`solana:${e}`);if(t.length===0){console.warn("Solana Mobile Connectors not loaded: no chains provided");return}registerMwa({appIdentity:{uri:n?.appUrl,icon:n?.appLogoUrl,name:n?.appName},authorizationCache:createDefaultAuthorizationCache(),chains:t,chainSelector:createDefaultChainSelector(),onWalletNotFound:createDefaultWalletNotFoundHandler()});}export{u as connect,p as disconnect,$ as initializeSolanaMobileConnectors,H as satelliteSolanaAdapter};//# sourceMappingURL=index.mjs.map
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/connectionUtils.ts","../src/adapters/solanaAdapter.ts","../src/connectors/initializeSolanaMobileConnectors.ts"],"names":["connect","uiWallet","input","connectFeature","getWalletFeature","StandardConnect","accounts","account","getOrCreateUiWalletAccountForStandardWalletAccount","getWalletForHandle","disconnect","StandardDisconnect","satelliteSolanaAdapter","rpcUrls","getAvailableWallets","getWallets","getOrCreateUiWalletForStandardWallet","OrbitAdapter","walletType","chainId","connectors","connector","getWalletTypeFromConnectorName","connectedAccount","wallets","cluster","getCluster","getRpcUrlForCluster","wallet","e","connectedWallet","currentChainId","updateActiveWallet","url","getSolanaExplorerLink","address","name","initializeSolanaMobileConnectors","props","chains","key","registerMwa","createDefaultAuthorizationCache","createDefaultChainSelector","createDefaultWalletNotFoundHandler"],"mappings":"0wBAoCA,eAAsBA,EACpBC,CAAAA,CACAC,CAAAA,CACqC,CAErC,IAAMC,CAAAA,CAAiBC,gBAAAA,CAAiBH,EAAUI,eAAe,CAAA,CAG3D,CAAE,QAAA,CAAAC,CAAS,CAAA,CAAI,MAAMH,CAAAA,CAAe,OAAA,CAAQD,CAAK,CAAA,CAGvD,OAAOI,CAAAA,CAAS,IAAKC,CAAAA,EACnBC,kFAAAA,CAAmDC,kDAAAA,CAAmBR,CAAQ,CAAA,CAAGM,CAAO,CAC1F,CACF,CAkBA,eAAsBG,CAAAA,CAAWT,CAAAA,CAAmC,CAOlE,MAL0BG,gBAAAA,CAAiBH,CAAAA,CAAUU,kBAAkB,CAAA,EAK9C,UAAA,GAC3B,CC5CO,SAASC,CAAAA,CAAuB,CAAE,OAAA,CAAAC,CAAQ,CAAA,CAAoC,CAInF,IAAMC,CAAAA,CAAsB,IAAMC,UAAAA,EAAW,CAAE,GAAA,GAAM,GAAA,CAAIC,oEAAoC,CAAA,CAE7F,OAAO,CACL,GAAA,CAAKC,aAAa,MAAA,CAElB,MAAM,OAAA,CAAQ,CAAE,UAAA,CAAAC,CAAAA,CAAY,QAAAC,CAAAA,CAAS,UAAA,CAAAC,CAAW,CAAA,CAAG,CACjD,IAAMC,EAAYD,CAAAA,CAAW,IAAA,CAC1BC,CAAAA,EAAcC,8BAAAA,CAA+BL,YAAAA,CAAa,MAAA,CAAQI,EAAU,IAAI,CAAA,GAAMH,CACzF,CAAA,CACA,GAAI,CAACG,EAAW,MAAM,IAAI,KAAA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gEAAgE,CAAA,CAC7E,MACF,CAGA,IAAMC,EAAS,MAAA,CAAO,IAAA,CAAK1B,CAAO,CAAA,CAAE,GAAA,CAAK2B,CAAAA,EAAQ,UAAUA,CAAG,CAAA,CAAwB,CAAA,CAGtF,GAAID,CAAAA,CAAO,MAAA,GAAW,EAAG,CACvB,OAAA,CAAQ,IAAA,CAAK,yDAAyD,CAAA,CACtE,MACF,CAGAE,WAAAA,CAAY,CACV,WAAA,CAAa,CACX,GAAA,CAAKH,CAAAA,EAAO,OACZ,IAAA,CAAMA,CAAAA,EAAO,UAAA,CACb,IAAA,CAAMA,CAAAA,EAAO,OACf,EACA,kBAAA,CAAoBI,+BAAAA,EAAgC,CACpD,MAAA,CAAAH,CAAAA,CACA,aAAA,CAAeI,0BAAAA,EAA2B,CAC1C,gBAAA,CAAkBC,kCAAAA,EACpB,CAAC,EACH","file":"index.mjs","sourcesContent":["import type {\n StandardConnectFeature,\n StandardConnectMethod,\n StandardDisconnectFeature,\n} from '@wallet-standard/features';\nimport { StandardConnect, StandardDisconnect } from '@wallet-standard/features';\nimport { getWalletFeature, type UiWallet, type UiWalletAccount } from '@wallet-standard/ui';\nimport {\n getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as getOrCreateUiWalletAccountForStandardWalletAccount,\n getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as getWalletForHandle,\n} from '@wallet-standard/ui-registry';\n\n/**\n * Establishes connection with a wallet using Wallet Standard\n *\n * @remarks\n * Connects to a wallet that implements the Wallet Standard interface.\n * Uses the StandardConnect feature to establish connection and retrieve accounts.\n * Converts standard wallet accounts to UI wallet accounts.\n *\n * @param uiWallet - Wallet instance implementing the UI Wallet interface\n * @param input - Optional connection parameters (excluding silent flag)\n * @returns Promise resolving to array of connected wallet accounts\n *\n * @throws {Error} If wallet doesn't support StandardConnect feature\n * @throws {Error} If connection attempt fails\n *\n * @example\n * ```typescript\n * const accounts = await connect(wallet, {\n * // Optional connection parameters\n * });\n * const firstAccount = accounts[0];\n * console.log('Connected account:', firstAccount.address);\n * ```\n */\nexport async function connect(\n uiWallet: UiWallet,\n input?: Omit<NonNullable<Parameters<StandardConnectMethod>[0]>, 'silent'>,\n): Promise<readonly UiWalletAccount[]> {\n // Get the connect feature from the wallet\n const connectFeature = getWalletFeature(uiWallet, StandardConnect) as StandardConnectFeature[typeof StandardConnect];\n\n // Initiate connection and get accounts\n const { accounts } = await connectFeature.connect(input);\n\n // Convert accounts to UI wallet accounts\n return accounts.map((account) =>\n getOrCreateUiWalletAccountForStandardWalletAccount(getWalletForHandle(uiWallet), account),\n );\n}\n\n/**\n * Disconnects from a connected wallet\n *\n * @remarks\n * Safely disconnects from a wallet if it supports the StandardDisconnect feature.\n * If the wallet doesn't support disconnection, the operation is silently ignored.\n *\n * @param uiWallet - Wallet instance implementing the UI Wallet interface\n * @returns Promise that resolves when disconnection is complete\n *\n * @example\n * ```typescript\n * await disconnect(wallet);\n * console.log('Wallet disconnected');\n * ```\n */\nexport async function disconnect(uiWallet: UiWallet): Promise<void> {\n // Get the disconnect feature if available\n const disconnectFeature = getWalletFeature(uiWallet, StandardDisconnect) as\n | StandardDisconnectFeature[typeof StandardDisconnect]\n | undefined;\n\n // Attempt disconnection if feature is supported\n await disconnectFeature?.disconnect();\n}\n","import { OrbitAdapter } from '@tuwaio/orbit-core';\nimport { getCluster, getRpcUrlForCluster, getSolanaExplorerLink, SolanaRPCUrls } from '@tuwaio/orbit-solana';\nimport { ConnectorSolana, getWalletTypeFromConnectorName, SatelliteAdapter } from '@tuwaio/satellite-core';\nimport { getWallets } from '@wallet-standard/app';\nimport { UiWallet } from '@wallet-standard/ui';\nimport { getOrCreateUiWalletForStandardWallet_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as getOrCreateUiWalletForStandardWallet } from '@wallet-standard/ui-registry';\nimport { SolanaClusterMoniker } from 'gill';\n\nimport { connect, disconnect } from '../utils/connectionUtils';\n\n/**\n * Creates a Solana blockchain adapter for the Satellite Connect system\n *\n * @remarks\n * This adapter implements the SatelliteAdapter interface for Solana blockchain,\n * providing wallet connection, network switching, and name resolution capabilities.\n * It uses the Wallet Standard for consistent wallet interactions.\n *\n * @param rpcUrls - Configuration object containing RPC endpoints for different Solana networks\n * @returns SatelliteAdapter implementation for Solana\n *\n * @example\n * ```typescript\n * const solanaAdapter = satelliteSolanaAdapter({\n * rpcUrls: {\n * mainnet: 'https://api.mainnet-beta.solana.com',\n * devnet: 'https://api.devnet.solana.com',\n * testnet: 'https://api.testnet.solana.com'\n * }\n * });\n * ```\n */\nexport function satelliteSolanaAdapter({ rpcUrls }: SolanaRPCUrls): SatelliteAdapter {\n /**\n * Helper to get all available wallets\n */\n const getAvailableWallets = () => getWallets().get().map(getOrCreateUiWalletForStandardWallet);\n\n return {\n key: OrbitAdapter.SOLANA,\n\n async connect({ walletType, chainId, connectors }) {\n const connector = connectors.find(\n (connector) => getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, connector.name) === walletType,\n );\n if (!connector) throw new Error('Cannot find connector with this wallet type');\n\n try {\n const connectedAccount = await connect(connector as UiWallet);\n const wallets = getAvailableWallets();\n const cluster = getCluster({ cluster: chainId as string });\n\n return {\n walletType,\n address: connectedAccount[0].address,\n chainId: cluster,\n rpcURL: getRpcUrlForCluster({\n cluster: cluster as SolanaClusterMoniker,\n rpcUrls,\n }),\n isConnected: true,\n isContractAddress: false,\n connectedAccount,\n connectedWallet: wallets.filter((wallet) => wallet.accounts.length > 0)[0],\n };\n } catch (e) {\n throw new Error(e instanceof Error ? e.message : String(e));\n }\n },\n\n async disconnect() {\n const wallets = getAvailableWallets();\n const connectedWallet = wallets.filter((wallet) => wallet.accounts.length > 0)[0];\n await disconnect(connectedWallet);\n },\n\n async getConnectors() {\n const connectors = getAvailableWallets();\n return {\n adapter: OrbitAdapter.SOLANA,\n connectors: connectors as ConnectorSolana[],\n };\n },\n\n async checkAndSwitchNetwork(chainId, currentChainId, updateActiveWallet) {\n if (currentChainId !== chainId && updateActiveWallet) {\n const cluster = getCluster({ cluster: chainId as string });\n updateActiveWallet({\n chainId: cluster,\n rpcURL: getRpcUrlForCluster({\n cluster: cluster as SolanaClusterMoniker,\n rpcUrls,\n }),\n });\n }\n },\n\n getExplorerUrl(url, chainId) {\n const cluster = getCluster({ cluster: chainId as string }) ?? 'mainnet';\n return getSolanaExplorerLink(url, cluster as SolanaClusterMoniker);\n },\n\n async getName(address) {\n const wallets = getAvailableWallets();\n const connectedWallet = wallets.filter((wallet) =>\n wallet.accounts.some((account) => account.address.toLowerCase() === address.toLowerCase()),\n )[0];\n return connectedWallet?.accounts[0]?.label ?? address;\n },\n\n async getAvatar(name) {\n const wallets = getAvailableWallets();\n const connectedWallet = wallets.filter((wallet) =>\n wallet.accounts.some((account) => account.label?.toLowerCase() === name.toLowerCase()),\n )[0];\n return connectedWallet?.accounts[0]?.icon ?? name;\n },\n };\n}\n","import {\n createDefaultAuthorizationCache,\n createDefaultChainSelector,\n createDefaultWalletNotFoundHandler,\n registerMwa,\n} from '@solana-mobile/wallet-standard-mobile';\nimport { SolanaRPCUrls } from '@tuwaio/orbit-solana';\nimport { ConnectorsInitProps } from '@tuwaio/satellite-core';\n\n/**\n * Combined props for initializing Solana mobile connectors\n */\ntype InitializeSolanaMobileConnectorsProps = ConnectorsInitProps & SolanaRPCUrls;\n\n/**\n * Initializes Solana Mobile Wallet Adapter (MWA) for mobile wallet connections\n *\n * @remarks\n * This function sets up the Solana Mobile Wallet Adapter with appropriate configuration\n * for secure mobile wallet connections. It includes security checks and chain validation.\n * Only works in secure contexts (HTTPS) and requires at least one valid chain configuration.\n *\n * @param props - Combined initialization properties\n * @param props.rpcUrls - RPC endpoints for different Solana networks\n * @param props.appName - Application name to display in wallet\n * @param props.appUrl - Application URL\n * @param props.appLogoUrl - Application logo URL\n *\n * @example\n * ```typescript\n * initializeSolanaMobileConnectors({\n * rpcUrls: {\n * mainnet: 'https://api.mainnet-beta.solana.com',\n * devnet: 'https://api.devnet.solana.com'\n * },\n * appName: 'My Solana App',\n * appUrl: 'https://myapp.com',\n * appLogoUrl: 'https://myapp.com/logo.png'\n * });\n * ```\n *\n * @throws {Warning} If not in secure context (non-HTTPS)\n * @throws {Warning} If no chains are configured\n */\nexport function initializeSolanaMobileConnectors({ rpcUrls, ...props }: InitializeSolanaMobileConnectorsProps): void {\n // Only run in browser environment\n if (typeof window === 'undefined') {\n return;\n }\n // Ensure secure context (HTTPS)\n if (!window.isSecureContext) {\n console.warn('Solana Mobile Connectors not loaded: https connection required');\n return;\n }\n\n // Generate chain identifiers\n const chains = Object.keys(rpcUrls).map((key) => `solana:${key}` as `solana:${string}`);\n\n // Validate chain configuration\n if (chains.length === 0) {\n console.warn('Solana Mobile Connectors not loaded: no chains provided');\n return;\n }\n\n // Register Mobile Wallet Adapter\n registerMwa({\n appIdentity: {\n uri: props?.appUrl,\n icon: props?.appLogoUrl,\n name: props?.appName,\n },\n authorizationCache: createDefaultAuthorizationCache(),\n chains,\n chainSelector: createDefaultChainSelector(),\n onWalletNotFound: createDefaultWalletNotFoundHandler(),\n });\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tuwaio/satellite-solana",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"private": false,
|
|
5
|
+
"author": "Oleksandr Tkach",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"description": "An adapter for the Satellite Connect that adds support for connect Web3 Wallet on the Solana blockchain.",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"web3",
|
|
19
|
+
"solana",
|
|
20
|
+
"wallet",
|
|
21
|
+
"connect",
|
|
22
|
+
"gill",
|
|
23
|
+
"zustand"
|
|
24
|
+
],
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/TuwaIO/satellite-connect.git",
|
|
28
|
+
"directory": "packages/satellite-solana"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/TuwaIO/satellite-connect",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/TuwaIO/satellite-connect/issues"
|
|
33
|
+
},
|
|
34
|
+
"contributors": [
|
|
35
|
+
{
|
|
36
|
+
"name": "Oleksandr Tkach",
|
|
37
|
+
"url": "https://github.com/Argeare5"
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@tuwaio/orbit-core": ">=0",
|
|
42
|
+
"@tuwaio/orbit-solana": ">=0",
|
|
43
|
+
"@tuwaio/satellite-core": ">=0",
|
|
44
|
+
"@solana-mobile/wallet-standard-mobile": ">=0.4",
|
|
45
|
+
"gill": ">=0.11",
|
|
46
|
+
"immer": ">=10",
|
|
47
|
+
"zustand": ">=5",
|
|
48
|
+
"@wagmi/core": ">=2.2",
|
|
49
|
+
"@wallet-standard/app": ">=1.1",
|
|
50
|
+
"@wallet-standard/base": ">=1.1",
|
|
51
|
+
"@wallet-standard/features": ">=1.1",
|
|
52
|
+
"@wallet-standard/ui": ">=1",
|
|
53
|
+
"@wallet-standard/ui-registry": ">=1"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@solana-mobile/wallet-standard-mobile": "^0.4.1",
|
|
57
|
+
"@wallet-standard/app": "^1.1.0",
|
|
58
|
+
"@wallet-standard/base": "^1.1.0",
|
|
59
|
+
"@wallet-standard/features": "^1.1.0",
|
|
60
|
+
"@wallet-standard/ui": "^1.0.1",
|
|
61
|
+
"@wallet-standard/ui-registry": "^1.0.1",
|
|
62
|
+
"gill": "^0.11.0",
|
|
63
|
+
"immer": "^10.1.3",
|
|
64
|
+
"jsdom": "^26.1.0",
|
|
65
|
+
"tsup": "^8.5.0",
|
|
66
|
+
"typescript": "^5.9.2",
|
|
67
|
+
"vitest": "^3.2.4",
|
|
68
|
+
"zustand": "^5.0.8",
|
|
69
|
+
"@tuwaio/orbit-core": "^0.0.3",
|
|
70
|
+
"@tuwaio/orbit-solana": "^0.0.3",
|
|
71
|
+
"@tuwaio/satellite-core": "^0.0.3"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"start": "tsup src/index.ts --watch",
|
|
75
|
+
"build": "tsup",
|
|
76
|
+
"test": "vitest"
|
|
77
|
+
}
|
|
78
|
+
}
|