@tuwaio/orbit-core 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 +101 -0
- package/dist/index.d.mts +198 -0
- package/dist/index.d.ts +198 -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 +50 -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,101 @@
|
|
|
1
|
+
# Orbit Core
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@tuwaio/orbit-core)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](https://github.com/TuwaIO/orbit-core/actions)
|
|
6
|
+
|
|
7
|
+
A powerful, framework-agnostic library for seamless multi-chain blockchain interactions, providing a unified interface for EVM, Solana, and Starknet operations.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 🏛️ What is `@tuwaio/orbit-core`?
|
|
12
|
+
|
|
13
|
+
`@tuwaio/orbit-core` is the foundation of the TUWA ecosystem. It's designed as a **headless** and **framework-agnostic** library that provides essential infrastructure for multi-chain blockchain interactions. The library doesn't include UI components or framework-specific code, making it versatile for any JavaScript or TypeScript application.
|
|
14
|
+
|
|
15
|
+
Its primary purpose is to provide a unified interface for interacting with different blockchain architectures through a flexible adapter system. Built with TypeScript for type safety and maintainability, it serves as the backbone for blockchain applications requiring multi-chain support.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## ✨ Key Features
|
|
20
|
+
|
|
21
|
+
- **Multi-Chain Architecture:** Native support for EVM, Solana, and Starknet through a unified adapter interface
|
|
22
|
+
- **Framework Independence:** Compatible with any JavaScript framework or vanilla JS
|
|
23
|
+
- **Type-Safe Development:** Full TypeScript support with comprehensive type definitions
|
|
24
|
+
- **Flexible Adapter System:** Easily extensible for new blockchain architectures
|
|
25
|
+
- **Optimized Performance:** Minimal overhead for blockchain operations
|
|
26
|
+
- **Robust Error Handling:** Comprehensive error management across different chains
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 💾 Installation
|
|
31
|
+
```bash
|
|
32
|
+
# Using pnpm
|
|
33
|
+
pnpm add @tuwaio/orbit-core zustand
|
|
34
|
+
# Using npm
|
|
35
|
+
npm install @tuwaio/orbit-core zustand
|
|
36
|
+
# Using yarn
|
|
37
|
+
yarn add @tuwaio/orbit-core zustand
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 🚀 Quick Start
|
|
43
|
+
|
|
44
|
+
### Basic Usage
|
|
45
|
+
```typescript
|
|
46
|
+
import { OrbitAdapter, selectAdapterByKey } from '@tuwaio/orbit-core';
|
|
47
|
+
// Configure your adapter
|
|
48
|
+
const adapter = { key: OrbitAdapter.EVM }; // adapter implementation
|
|
49
|
+
// Select adapter for specific chain
|
|
50
|
+
const evmAdapter = selectAdapterByKey({ adapterKey: OrbitAdapter.EVM, adapter, });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Supported Chain Types
|
|
54
|
+
```typescript
|
|
55
|
+
// Available blockchain adapters
|
|
56
|
+
import { OrbitAdapter } from '@tuwaio/orbit-core';
|
|
57
|
+
const chains = { evm: OrbitAdapter.EVM }; // Ethereum, Polygon, BSC, etc. solana: OrbitAdapter.SOLANA, // Solana blockchain starknet: OrbitAdapter.Starknet // Starknet L2
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 🔧 Architecture
|
|
63
|
+
|
|
64
|
+
Orbit Core is built on these main concepts:
|
|
65
|
+
|
|
66
|
+
1. **Adapters:** Chain-specific implementations that handle blockchain interactions
|
|
67
|
+
2. **Type System:** Comprehensive TypeScript definitions for type-safe development
|
|
68
|
+
3. **Utilities:** Helper functions for common blockchain operations
|
|
69
|
+
|
|
70
|
+
### Core Components
|
|
71
|
+
|
|
72
|
+
- `OrbitAdapter`: Enum defining supported blockchain types
|
|
73
|
+
- `selectAdapterByKey`: Utility for runtime adapter selection
|
|
74
|
+
- `createBoundedUseStore`: Store creation helper for state management
|
|
75
|
+
- Chain-specific helpers and utilities
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## ✨ How It Connects to the Ecosystem
|
|
80
|
+
|
|
81
|
+
The Orbit ecosystem consists of several packages:
|
|
82
|
+
|
|
83
|
+
- **`@tuwaio/orbit-core`:** The foundation providing core functionality
|
|
84
|
+
- **`@tuwaio/orbit-evm`:** EVM-specific helpers implementation
|
|
85
|
+
- **`@tuwaio/orbit-solana`:** Solana blockchain helpers
|
|
86
|
+
|
|
87
|
+
Each package serves a specific purpose while maintaining modularity and flexibility.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 🤝 Contributing & Support
|
|
92
|
+
|
|
93
|
+
Contributions are welcome! Please read our main **[Contribution Guidelines](https://github.com/TuwaIO/workflows/blob/main/CONTRIBUTING.md)**.
|
|
94
|
+
|
|
95
|
+
If you find this library useful, please consider supporting its development. Every contribution helps!
|
|
96
|
+
|
|
97
|
+
[**➡️ View Support Options**](https://github.com/TuwaIO/workflows/blob/main/Donation.md)
|
|
98
|
+
|
|
99
|
+
## 📄 License
|
|
100
|
+
|
|
101
|
+
This project is licensed under the **Apache-2.0 License** - see the [LICENSE](./LICENSE) file for details.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { StoreApi } from 'zustand';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file
|
|
5
|
+
* Core type definitions for the Orbit blockchain adapter system.
|
|
6
|
+
* This file contains fundamental enums and types that define the supported blockchain architectures
|
|
7
|
+
* and their adapter interfaces.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Defines the supported blockchain adapters in the Orbit system.
|
|
11
|
+
* Each adapter corresponds to a specific blockchain architecture and implements
|
|
12
|
+
* the necessary interfaces for that chain's functionality.
|
|
13
|
+
*
|
|
14
|
+
* @enum {string}
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Using adapter types in configuration
|
|
19
|
+
* const config = {
|
|
20
|
+
* chainType: OrbitAdapter.EVM,
|
|
21
|
+
* // other configuration...
|
|
22
|
+
* };
|
|
23
|
+
*
|
|
24
|
+
* // Checking adapter compatibility
|
|
25
|
+
* if (chainType === OrbitAdapter.SOLANA) {
|
|
26
|
+
* // Solana-specific logic
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare enum OrbitAdapter {
|
|
31
|
+
/**
|
|
32
|
+
* For Ethereum Virtual Machine (EVM) compatible chains.
|
|
33
|
+
* Supports networks like:
|
|
34
|
+
* - Ethereum Mainnet
|
|
35
|
+
* - Polygon
|
|
36
|
+
* - Binance Smart Chain
|
|
37
|
+
* - Avalanche
|
|
38
|
+
* - Other EVM-compatible L1/L2 chains
|
|
39
|
+
*/
|
|
40
|
+
EVM = "evm",
|
|
41
|
+
/**
|
|
42
|
+
* For the Solana blockchain.
|
|
43
|
+
* Supports:
|
|
44
|
+
* - Solana Mainnet
|
|
45
|
+
* - Devnet
|
|
46
|
+
* - Testnet
|
|
47
|
+
*/
|
|
48
|
+
SOLANA = "solana",
|
|
49
|
+
/**
|
|
50
|
+
* For the Starknet L2 network.
|
|
51
|
+
* Supports:
|
|
52
|
+
* - Starknet Mainnet
|
|
53
|
+
* - Testnet (Goerli)
|
|
54
|
+
* - Other Starknet deployments
|
|
55
|
+
*/
|
|
56
|
+
Starknet = "starknet"
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Generic type for creating blockchain adapters with type safety.
|
|
60
|
+
* This type ensures that all adapters implement the required interface
|
|
61
|
+
* and are properly keyed by their blockchain type.
|
|
62
|
+
*
|
|
63
|
+
* @typeParam A - Type that extends the base adapter interface with a key property
|
|
64
|
+
*
|
|
65
|
+
* @property {A | A[]} adapter - Single adapter instance or array of adapters
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* // Single adapter implementation
|
|
70
|
+
* interface EVMAdapter extends BaseAdapter {
|
|
71
|
+
* key: OrbitAdapter.EVM;
|
|
72
|
+
* // EVM-specific methods...
|
|
73
|
+
* }
|
|
74
|
+
* const evmConfig: OrbitGenericAdapter<EVMAdapter> = {
|
|
75
|
+
* adapter: {
|
|
76
|
+
* key: OrbitAdapter.EVM,
|
|
77
|
+
* // implementation...
|
|
78
|
+
* }
|
|
79
|
+
* };
|
|
80
|
+
*
|
|
81
|
+
* // Multiple adapters
|
|
82
|
+
* const multiChainConfig: OrbitGenericAdapter<BaseAdapter> = {
|
|
83
|
+
* adapter: [
|
|
84
|
+
* { key: OrbitAdapter.EVM, ... },
|
|
85
|
+
* { key: OrbitAdapter.SOLANA, ... }
|
|
86
|
+
* ]
|
|
87
|
+
* };
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
type OrbitGenericAdapter<A extends {
|
|
91
|
+
key: OrbitAdapter;
|
|
92
|
+
}> = {
|
|
93
|
+
adapter: A | A[];
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.
|
|
98
|
+
* This pattern is recommended by the official Zustand documentation to ensure full type
|
|
99
|
+
* safety when integrating vanilla stores with React.
|
|
100
|
+
*
|
|
101
|
+
* @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A utility type that infers the state shape from a Zustand `StoreApi`.
|
|
106
|
+
* It extracts the return type of the `getState` method.
|
|
107
|
+
* @template S - The type of the Zustand store (`StoreApi`).
|
|
108
|
+
*/
|
|
109
|
+
type ExtractState<S> = S extends {
|
|
110
|
+
getState: () => infer T;
|
|
111
|
+
} ? T : never;
|
|
112
|
+
/**
|
|
113
|
+
* Creates a bounded `useStore` hook from a vanilla Zustand store.
|
|
114
|
+
*
|
|
115
|
+
* This function takes a vanilla Zustand store instance and returns a React hook
|
|
116
|
+
* that is pre-bound to that store. This approach provides a cleaner API and
|
|
117
|
+
* enhances type inference, eliminating the need to pass the store instance
|
|
118
|
+
* on every use.
|
|
119
|
+
*
|
|
120
|
+
* The returned hook supports two signatures:
|
|
121
|
+
* 1. `useBoundedStore()`: Selects the entire state.
|
|
122
|
+
* 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.
|
|
123
|
+
*
|
|
124
|
+
* @template S - The type of the Zustand store (`StoreApi`).
|
|
125
|
+
* @param {S} store - The vanilla Zustand store instance to bind the hook to.
|
|
126
|
+
* @returns {function} A fully typed React hook for accessing the store's state.
|
|
127
|
+
*/
|
|
128
|
+
declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) => {
|
|
129
|
+
(): ExtractState<S>;
|
|
130
|
+
<T>(selector: (state: ExtractState<S>) => T): T;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @file
|
|
135
|
+
* This module provides adapter selection functionality for the Orbit system.
|
|
136
|
+
* Part of the core infrastructure for managing blockchain adapters.
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Selects an appropriate adapter based on the provided key from either a single adapter
|
|
141
|
+
* or an array of adapters.
|
|
142
|
+
*
|
|
143
|
+
* @typeParam A - Type extending basic adapter interface with a key property
|
|
144
|
+
*
|
|
145
|
+
* @param options - Selection configuration object
|
|
146
|
+
* @param options.adapterKey - Target adapter key to search for
|
|
147
|
+
* @param options.adapter - Single adapter or array of adapters to search within
|
|
148
|
+
*
|
|
149
|
+
* @returns Selected adapter or undefined if no suitable adapter found
|
|
150
|
+
*
|
|
151
|
+
* @remarks
|
|
152
|
+
* If an array is provided but no matching adapter is found, falls back to the first adapter
|
|
153
|
+
* in the array with a warning message.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* // Single adapter usage
|
|
158
|
+
* const singleResult = selectAdapterByKey({
|
|
159
|
+
* adapterKey: OrbitAdapter.SOLANA,
|
|
160
|
+
* adapter: { key: OrbitAdapter.SOLANA, connect: async () => {...} }
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* // Multiple adapters usage
|
|
164
|
+
* const multiResult = selectAdapterByKey({
|
|
165
|
+
* adapterKey: OrbitAdapter.EVM,
|
|
166
|
+
* adapter: [
|
|
167
|
+
* { key: OrbitAdapter.SOLANA, connect: async () => {...} },
|
|
168
|
+
* { key: OrbitAdapter.EVM, connect: async () => {...} }
|
|
169
|
+
* ]
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @throws {Error} Logs error if adapter array is empty
|
|
174
|
+
* @throws {Warning} Logs warning if requested adapter key not found in array
|
|
175
|
+
*/
|
|
176
|
+
declare const selectAdapterByKey: <A extends {
|
|
177
|
+
key: OrbitAdapter;
|
|
178
|
+
}>({ adapterKey, adapter, }: {
|
|
179
|
+
adapterKey: OrbitAdapter;
|
|
180
|
+
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Checks whether the given chain ID belongs to a Solana network.
|
|
184
|
+
* Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.
|
|
185
|
+
*
|
|
186
|
+
* @param {number | string} chainId - The chain ID or chain name.
|
|
187
|
+
* @returns {boolean} - True if the chain ID corresponds to a Solana network, false otherwise.
|
|
188
|
+
*/
|
|
189
|
+
declare function isSolanaChain(chainId: number | string): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Sets the chain ID to a Solana-specific format if the chain is a Solana network.
|
|
192
|
+
*
|
|
193
|
+
* @param {number | string} chainId - The original chain ID or name.
|
|
194
|
+
* @returns {string | number} - The formatted chain ID prefixed with 'solana:' if Solana, otherwise the original.
|
|
195
|
+
*/
|
|
196
|
+
declare function setChainId(chainId: number | string): string | number;
|
|
197
|
+
|
|
198
|
+
export { OrbitAdapter, type OrbitGenericAdapter, createBoundedUseStore, isSolanaChain, selectAdapterByKey, setChainId };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { StoreApi } from 'zustand';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file
|
|
5
|
+
* Core type definitions for the Orbit blockchain adapter system.
|
|
6
|
+
* This file contains fundamental enums and types that define the supported blockchain architectures
|
|
7
|
+
* and their adapter interfaces.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Defines the supported blockchain adapters in the Orbit system.
|
|
11
|
+
* Each adapter corresponds to a specific blockchain architecture and implements
|
|
12
|
+
* the necessary interfaces for that chain's functionality.
|
|
13
|
+
*
|
|
14
|
+
* @enum {string}
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Using adapter types in configuration
|
|
19
|
+
* const config = {
|
|
20
|
+
* chainType: OrbitAdapter.EVM,
|
|
21
|
+
* // other configuration...
|
|
22
|
+
* };
|
|
23
|
+
*
|
|
24
|
+
* // Checking adapter compatibility
|
|
25
|
+
* if (chainType === OrbitAdapter.SOLANA) {
|
|
26
|
+
* // Solana-specific logic
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare enum OrbitAdapter {
|
|
31
|
+
/**
|
|
32
|
+
* For Ethereum Virtual Machine (EVM) compatible chains.
|
|
33
|
+
* Supports networks like:
|
|
34
|
+
* - Ethereum Mainnet
|
|
35
|
+
* - Polygon
|
|
36
|
+
* - Binance Smart Chain
|
|
37
|
+
* - Avalanche
|
|
38
|
+
* - Other EVM-compatible L1/L2 chains
|
|
39
|
+
*/
|
|
40
|
+
EVM = "evm",
|
|
41
|
+
/**
|
|
42
|
+
* For the Solana blockchain.
|
|
43
|
+
* Supports:
|
|
44
|
+
* - Solana Mainnet
|
|
45
|
+
* - Devnet
|
|
46
|
+
* - Testnet
|
|
47
|
+
*/
|
|
48
|
+
SOLANA = "solana",
|
|
49
|
+
/**
|
|
50
|
+
* For the Starknet L2 network.
|
|
51
|
+
* Supports:
|
|
52
|
+
* - Starknet Mainnet
|
|
53
|
+
* - Testnet (Goerli)
|
|
54
|
+
* - Other Starknet deployments
|
|
55
|
+
*/
|
|
56
|
+
Starknet = "starknet"
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Generic type for creating blockchain adapters with type safety.
|
|
60
|
+
* This type ensures that all adapters implement the required interface
|
|
61
|
+
* and are properly keyed by their blockchain type.
|
|
62
|
+
*
|
|
63
|
+
* @typeParam A - Type that extends the base adapter interface with a key property
|
|
64
|
+
*
|
|
65
|
+
* @property {A | A[]} adapter - Single adapter instance or array of adapters
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* // Single adapter implementation
|
|
70
|
+
* interface EVMAdapter extends BaseAdapter {
|
|
71
|
+
* key: OrbitAdapter.EVM;
|
|
72
|
+
* // EVM-specific methods...
|
|
73
|
+
* }
|
|
74
|
+
* const evmConfig: OrbitGenericAdapter<EVMAdapter> = {
|
|
75
|
+
* adapter: {
|
|
76
|
+
* key: OrbitAdapter.EVM,
|
|
77
|
+
* // implementation...
|
|
78
|
+
* }
|
|
79
|
+
* };
|
|
80
|
+
*
|
|
81
|
+
* // Multiple adapters
|
|
82
|
+
* const multiChainConfig: OrbitGenericAdapter<BaseAdapter> = {
|
|
83
|
+
* adapter: [
|
|
84
|
+
* { key: OrbitAdapter.EVM, ... },
|
|
85
|
+
* { key: OrbitAdapter.SOLANA, ... }
|
|
86
|
+
* ]
|
|
87
|
+
* };
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
type OrbitGenericAdapter<A extends {
|
|
91
|
+
key: OrbitAdapter;
|
|
92
|
+
}> = {
|
|
93
|
+
adapter: A | A[];
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.
|
|
98
|
+
* This pattern is recommended by the official Zustand documentation to ensure full type
|
|
99
|
+
* safety when integrating vanilla stores with React.
|
|
100
|
+
*
|
|
101
|
+
* @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A utility type that infers the state shape from a Zustand `StoreApi`.
|
|
106
|
+
* It extracts the return type of the `getState` method.
|
|
107
|
+
* @template S - The type of the Zustand store (`StoreApi`).
|
|
108
|
+
*/
|
|
109
|
+
type ExtractState<S> = S extends {
|
|
110
|
+
getState: () => infer T;
|
|
111
|
+
} ? T : never;
|
|
112
|
+
/**
|
|
113
|
+
* Creates a bounded `useStore` hook from a vanilla Zustand store.
|
|
114
|
+
*
|
|
115
|
+
* This function takes a vanilla Zustand store instance and returns a React hook
|
|
116
|
+
* that is pre-bound to that store. This approach provides a cleaner API and
|
|
117
|
+
* enhances type inference, eliminating the need to pass the store instance
|
|
118
|
+
* on every use.
|
|
119
|
+
*
|
|
120
|
+
* The returned hook supports two signatures:
|
|
121
|
+
* 1. `useBoundedStore()`: Selects the entire state.
|
|
122
|
+
* 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.
|
|
123
|
+
*
|
|
124
|
+
* @template S - The type of the Zustand store (`StoreApi`).
|
|
125
|
+
* @param {S} store - The vanilla Zustand store instance to bind the hook to.
|
|
126
|
+
* @returns {function} A fully typed React hook for accessing the store's state.
|
|
127
|
+
*/
|
|
128
|
+
declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) => {
|
|
129
|
+
(): ExtractState<S>;
|
|
130
|
+
<T>(selector: (state: ExtractState<S>) => T): T;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @file
|
|
135
|
+
* This module provides adapter selection functionality for the Orbit system.
|
|
136
|
+
* Part of the core infrastructure for managing blockchain adapters.
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Selects an appropriate adapter based on the provided key from either a single adapter
|
|
141
|
+
* or an array of adapters.
|
|
142
|
+
*
|
|
143
|
+
* @typeParam A - Type extending basic adapter interface with a key property
|
|
144
|
+
*
|
|
145
|
+
* @param options - Selection configuration object
|
|
146
|
+
* @param options.adapterKey - Target adapter key to search for
|
|
147
|
+
* @param options.adapter - Single adapter or array of adapters to search within
|
|
148
|
+
*
|
|
149
|
+
* @returns Selected adapter or undefined if no suitable adapter found
|
|
150
|
+
*
|
|
151
|
+
* @remarks
|
|
152
|
+
* If an array is provided but no matching adapter is found, falls back to the first adapter
|
|
153
|
+
* in the array with a warning message.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* // Single adapter usage
|
|
158
|
+
* const singleResult = selectAdapterByKey({
|
|
159
|
+
* adapterKey: OrbitAdapter.SOLANA,
|
|
160
|
+
* adapter: { key: OrbitAdapter.SOLANA, connect: async () => {...} }
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* // Multiple adapters usage
|
|
164
|
+
* const multiResult = selectAdapterByKey({
|
|
165
|
+
* adapterKey: OrbitAdapter.EVM,
|
|
166
|
+
* adapter: [
|
|
167
|
+
* { key: OrbitAdapter.SOLANA, connect: async () => {...} },
|
|
168
|
+
* { key: OrbitAdapter.EVM, connect: async () => {...} }
|
|
169
|
+
* ]
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @throws {Error} Logs error if adapter array is empty
|
|
174
|
+
* @throws {Warning} Logs warning if requested adapter key not found in array
|
|
175
|
+
*/
|
|
176
|
+
declare const selectAdapterByKey: <A extends {
|
|
177
|
+
key: OrbitAdapter;
|
|
178
|
+
}>({ adapterKey, adapter, }: {
|
|
179
|
+
adapterKey: OrbitAdapter;
|
|
180
|
+
} & OrbitGenericAdapter<A>) => A | undefined;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Checks whether the given chain ID belongs to a Solana network.
|
|
184
|
+
* Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.
|
|
185
|
+
*
|
|
186
|
+
* @param {number | string} chainId - The chain ID or chain name.
|
|
187
|
+
* @returns {boolean} - True if the chain ID corresponds to a Solana network, false otherwise.
|
|
188
|
+
*/
|
|
189
|
+
declare function isSolanaChain(chainId: number | string): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Sets the chain ID to a Solana-specific format if the chain is a Solana network.
|
|
192
|
+
*
|
|
193
|
+
* @param {number | string} chainId - The original chain ID or name.
|
|
194
|
+
* @returns {string | number} - The formatted chain ID prefixed with 'solana:' if Solana, otherwise the original.
|
|
195
|
+
*/
|
|
196
|
+
declare function setChainId(chainId: number | string): string | number;
|
|
197
|
+
|
|
198
|
+
export { OrbitAdapter, type OrbitGenericAdapter, createBoundedUseStore, isSolanaChain, selectAdapterByKey, setChainId };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var zustand=require('zustand');var o=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(o||{});var d=(e=>t=>zustand.useStore(e,t));var l=({adapterKey:e,adapter:t})=>{if(Array.isArray(t)){if(t.length===0){console.error("Adapter selection failed: The provided adapters array is empty.");return}let n=t.find(r=>r.key===e);return n||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${t[0].key}".`),t[0])}return t};function i(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function x(e){return i(e)?`solana:${e}`:e}exports.OrbitAdapter=o;exports.createBoundedUseStore=d;exports.isSolanaChain=i;exports.selectAdapterByKey=l;exports.setChainId=x;//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/utils/createBoundedUseStore.ts","../src/utils/selectAdapterByKey.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","createBoundedUseStore","store","selector","useStore","selectAdapterByKey","adapterKey","adapter","foundAdapter","a","isSolanaChain","chainId","setChainId"],"mappings":"4CAgCO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,CAAAA,CAAA,GAAA,CAAM,KAAA,CASNA,CAAAA,CAAA,OAAS,QAAA,CASTA,CAAAA,CAAA,QAAA,CAAW,UAAA,CA5BDA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA,ECCL,IAAMC,CAAAA,EAA0BC,CAAAA,EAAWC,GAAaC,gBAAAA,CAASF,CAAAA,CAAOC,CAAQ,CAAA,ECYhF,IAAME,CAAAA,CAAqB,CAAkC,CAClE,UAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAA4E,CAC1E,GAAI,KAAA,CAAM,OAAA,CAAQA,CAAO,CAAA,CAAG,CAC1B,GAAIA,CAAAA,CAAQ,MAAA,GAAW,CAAA,CAAG,CACxB,OAAA,CAAQ,KAAA,CAAM,iEAAiE,CAAA,CAC/E,MACF,CAEA,IAAMC,CAAAA,CAAeD,CAAAA,CAAQ,IAAA,CAAME,GAAMA,CAAAA,CAAE,GAAA,GAAQH,CAAU,CAAA,CAE7D,OAAIE,CAAAA,GAGF,QAAQ,IAAA,CACN,CAAA,2BAAA,EAA8BF,CAAU,CAAA,iDAAA,EAAoDC,CAAAA,CAAQ,CAAC,EAAE,GAAG,CAAA,EAAA,CAC5G,CAAA,CACOA,CAAAA,CAAQ,CAAC,CAAA,CAEpB,CACA,OAAOA,CACT,EC5DO,SAASG,CAAAA,CAAcC,CAAAA,CAAmC,CAC/D,OAAI,OAAOA,CAAAA,EAAY,QAAA,CACd,CAAC,QAAA,CAAU,UAAW,cAAA,CAAgB,SAAS,CAAA,CAAE,QAAA,CAASA,CAAO,CAAA,CAEnE,KACT,CAQO,SAASC,CAAAA,CAAWD,CAAAA,CAA2C,CACpE,OAAID,CAAAA,CAAcC,CAAO,CAAA,CAChB,CAAA,OAAA,EAAUA,CAAO,CAAA,CAAA,CAEjBA,CAEX","file":"index.js","sourcesContent":["/**\n * @file\n * Core type definitions for the Orbit blockchain adapter system.\n * This file contains fundamental enums and types that define the supported blockchain architectures\n * and their adapter interfaces.\n */\n\n// =================================================================================================\n// 1. ENUMS AND CORE TRANSACTION TYPES\n// =================================================================================================\n\n/**\n * Defines the supported blockchain adapters in the Orbit system.\n * Each adapter corresponds to a specific blockchain architecture and implements\n * the necessary interfaces for that chain's functionality.\n *\n * @enum {string}\n *\n * @example\n * ```typescript\n * // Using adapter types in configuration\n * const config = {\n * chainType: OrbitAdapter.EVM,\n * // other configuration...\n * };\n *\n * // Checking adapter compatibility\n * if (chainType === OrbitAdapter.SOLANA) {\n * // Solana-specific logic\n * }\n * ```\n */\nexport enum OrbitAdapter {\n /**\n * For Ethereum Virtual Machine (EVM) compatible chains.\n * Supports networks like:\n * - Ethereum Mainnet\n * - Polygon\n * - Binance Smart Chain\n * - Avalanche\n * - Other EVM-compatible L1/L2 chains\n */\n EVM = 'evm',\n\n /**\n * For the Solana blockchain.\n * Supports:\n * - Solana Mainnet\n * - Devnet\n * - Testnet\n */\n SOLANA = 'solana',\n\n /**\n * For the Starknet L2 network.\n * Supports:\n * - Starknet Mainnet\n * - Testnet (Goerli)\n * - Other Starknet deployments\n */\n Starknet = 'starknet',\n}\n\n/**\n * Generic type for creating blockchain adapters with type safety.\n * This type ensures that all adapters implement the required interface\n * and are properly keyed by their blockchain type.\n *\n * @typeParam A - Type that extends the base adapter interface with a key property\n *\n * @property {A | A[]} adapter - Single adapter instance or array of adapters\n *\n * @example\n * ```typescript\n * // Single adapter implementation\n * interface EVMAdapter extends BaseAdapter {\n * key: OrbitAdapter.EVM;\n * // EVM-specific methods...\n * }\n * const evmConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: {\n * key: OrbitAdapter.EVM,\n * // implementation...\n * }\n * };\n *\n * // Multiple adapters\n * const multiChainConfig: OrbitGenericAdapter<BaseAdapter> = {\n * adapter: [\n * { key: OrbitAdapter.EVM, ... },\n * { key: OrbitAdapter.SOLANA, ... }\n * ]\n * };\n * ```\n */\nexport type OrbitGenericAdapter<A extends { key: OrbitAdapter }> = {\n adapter: A | A[];\n};\n","/**\n * @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.\n * This pattern is recommended by the official Zustand documentation to ensure full type\n * safety when integrating vanilla stores with React.\n *\n * @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n */\n\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * A utility type that infers the state shape from a Zustand `StoreApi`.\n * It extracts the return type of the `getState` method.\n * @template S - The type of the Zustand store (`StoreApi`).\n */\ntype ExtractState<S> = S extends { getState: () => infer T } ? T : never;\n\n/**\n * Creates a bounded `useStore` hook from a vanilla Zustand store.\n *\n * This function takes a vanilla Zustand store instance and returns a React hook\n * that is pre-bound to that store. This approach provides a cleaner API and\n * enhances type inference, eliminating the need to pass the store instance\n * on every use.\n *\n * The returned hook supports two signatures:\n * 1. `useBoundedStore()`: Selects the entire state.\n * 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.\n *\n * @template S - The type of the Zustand store (`StoreApi`).\n * @param {S} store - The vanilla Zustand store instance to bind the hook to.\n * @returns {function} A fully typed React hook for accessing the store's state.\n */\nexport const createBoundedUseStore = ((store) => (selector) => useStore(store, selector)) as <\n S extends StoreApi<unknown>,\n>(\n store: S,\n) => {\n // This implementation uses a Immediately Invoked Function Expression (IIFE)\n // trick combined with casting to achieve the desired overloaded function signature in a concise way.\n (): ExtractState<S>;\n <T>(selector: (state: ExtractState<S>) => T): T;\n};\n","/**\n * @file\n * This module provides adapter selection functionality for the Orbit system.\n * Part of the core infrastructure for managing blockchain adapters.\n */\n\nimport { OrbitAdapter, OrbitGenericAdapter } from '../types';\n\n/**\n * Selects an appropriate adapter based on the provided key from either a single adapter\n * or an array of adapters.\n *\n * @typeParam A - Type extending basic adapter interface with a key property\n *\n * @param options - Selection configuration object\n * @param options.adapterKey - Target adapter key to search for\n * @param options.adapter - Single adapter or array of adapters to search within\n *\n * @returns Selected adapter or undefined if no suitable adapter found\n *\n * @remarks\n * If an array is provided but no matching adapter is found, falls back to the first adapter\n * in the array with a warning message.\n *\n * @example\n * ```typescript\n * // Single adapter usage\n * const singleResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.SOLANA,\n * adapter: { key: OrbitAdapter.SOLANA, connect: async () => {...} }\n * });\n *\n * // Multiple adapters usage\n * const multiResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.EVM,\n * adapter: [\n * { key: OrbitAdapter.SOLANA, connect: async () => {...} },\n * { key: OrbitAdapter.EVM, connect: async () => {...} }\n * ]\n * });\n * ```\n *\n * @throws {Error} Logs error if adapter array is empty\n * @throws {Warning} Logs warning if requested adapter key not found in array\n */\nexport const selectAdapterByKey = <A extends { key: OrbitAdapter }>({\n adapterKey,\n adapter,\n}: { adapterKey: OrbitAdapter } & OrbitGenericAdapter<A>): A | undefined => {\n if (Array.isArray(adapter)) {\n if (adapter.length === 0) {\n console.error('Adapter selection failed: The provided adapters array is empty.');\n return undefined;\n }\n\n const foundAdapter = adapter.find((a) => a.key === adapterKey);\n\n if (foundAdapter) {\n return foundAdapter;\n } else {\n console.warn(\n `No adapter found for key: \"${adapterKey}\". Falling back to the first available adapter: \"${adapter[0].key}\".`,\n );\n return adapter[0];\n }\n }\n return adapter;\n};\n","/**\n * Checks whether the given chain ID belongs to a Solana network.\n * Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.\n *\n * @param {number | string} chainId - The chain ID or chain name.\n * @returns {boolean} - True if the chain ID corresponds to a Solana network, false otherwise.\n */\nexport function isSolanaChain(chainId: number | string): boolean {\n if (typeof chainId === 'string') {\n return ['devnet', 'testnet', 'mainnet-beta', 'mainnet'].includes(chainId);\n }\n return false;\n}\n\n/**\n * Sets the chain ID to a Solana-specific format if the chain is a Solana network.\n *\n * @param {number | string} chainId - The original chain ID or name.\n * @returns {string | number} - The formatted chain ID prefixed with 'solana:' if Solana, otherwise the original.\n */\nexport function setChainId(chainId: number | string): string | number {\n if (isSolanaChain(chainId)) {\n return `solana:${chainId}`;\n } else {\n return chainId;\n }\n}\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {useStore}from'zustand';var o=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(o||{});var d=(e=>t=>useStore(e,t));var l=({adapterKey:e,adapter:t})=>{if(Array.isArray(t)){if(t.length===0){console.error("Adapter selection failed: The provided adapters array is empty.");return}let n=t.find(r=>r.key===e);return n||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${t[0].key}".`),t[0])}return t};function i(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function x(e){return i(e)?`solana:${e}`:e}export{o as OrbitAdapter,d as createBoundedUseStore,i as isSolanaChain,l as selectAdapterByKey,x as setChainId};//# sourceMappingURL=index.mjs.map
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/utils/createBoundedUseStore.ts","../src/utils/selectAdapterByKey.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","createBoundedUseStore","store","selector","useStore","selectAdapterByKey","adapterKey","adapter","foundAdapter","a","isSolanaChain","chainId","setChainId"],"mappings":"+BAgCO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,CAAAA,CAAA,GAAA,CAAM,KAAA,CASNA,CAAAA,CAAA,OAAS,QAAA,CASTA,CAAAA,CAAA,QAAA,CAAW,UAAA,CA5BDA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA,ECCL,IAAMC,CAAAA,EAA0BC,CAAAA,EAAWC,GAAaC,QAAAA,CAASF,CAAAA,CAAOC,CAAQ,CAAA,ECYhF,IAAME,CAAAA,CAAqB,CAAkC,CAClE,UAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAA4E,CAC1E,GAAI,KAAA,CAAM,OAAA,CAAQA,CAAO,CAAA,CAAG,CAC1B,GAAIA,CAAAA,CAAQ,MAAA,GAAW,CAAA,CAAG,CACxB,OAAA,CAAQ,KAAA,CAAM,iEAAiE,CAAA,CAC/E,MACF,CAEA,IAAMC,CAAAA,CAAeD,CAAAA,CAAQ,IAAA,CAAME,GAAMA,CAAAA,CAAE,GAAA,GAAQH,CAAU,CAAA,CAE7D,OAAIE,CAAAA,GAGF,QAAQ,IAAA,CACN,CAAA,2BAAA,EAA8BF,CAAU,CAAA,iDAAA,EAAoDC,CAAAA,CAAQ,CAAC,EAAE,GAAG,CAAA,EAAA,CAC5G,CAAA,CACOA,CAAAA,CAAQ,CAAC,CAAA,CAEpB,CACA,OAAOA,CACT,EC5DO,SAASG,CAAAA,CAAcC,CAAAA,CAAmC,CAC/D,OAAI,OAAOA,CAAAA,EAAY,QAAA,CACd,CAAC,QAAA,CAAU,UAAW,cAAA,CAAgB,SAAS,CAAA,CAAE,QAAA,CAASA,CAAO,CAAA,CAEnE,KACT,CAQO,SAASC,CAAAA,CAAWD,CAAAA,CAA2C,CACpE,OAAID,CAAAA,CAAcC,CAAO,CAAA,CAChB,CAAA,OAAA,EAAUA,CAAO,CAAA,CAAA,CAEjBA,CAEX","file":"index.mjs","sourcesContent":["/**\n * @file\n * Core type definitions for the Orbit blockchain adapter system.\n * This file contains fundamental enums and types that define the supported blockchain architectures\n * and their adapter interfaces.\n */\n\n// =================================================================================================\n// 1. ENUMS AND CORE TRANSACTION TYPES\n// =================================================================================================\n\n/**\n * Defines the supported blockchain adapters in the Orbit system.\n * Each adapter corresponds to a specific blockchain architecture and implements\n * the necessary interfaces for that chain's functionality.\n *\n * @enum {string}\n *\n * @example\n * ```typescript\n * // Using adapter types in configuration\n * const config = {\n * chainType: OrbitAdapter.EVM,\n * // other configuration...\n * };\n *\n * // Checking adapter compatibility\n * if (chainType === OrbitAdapter.SOLANA) {\n * // Solana-specific logic\n * }\n * ```\n */\nexport enum OrbitAdapter {\n /**\n * For Ethereum Virtual Machine (EVM) compatible chains.\n * Supports networks like:\n * - Ethereum Mainnet\n * - Polygon\n * - Binance Smart Chain\n * - Avalanche\n * - Other EVM-compatible L1/L2 chains\n */\n EVM = 'evm',\n\n /**\n * For the Solana blockchain.\n * Supports:\n * - Solana Mainnet\n * - Devnet\n * - Testnet\n */\n SOLANA = 'solana',\n\n /**\n * For the Starknet L2 network.\n * Supports:\n * - Starknet Mainnet\n * - Testnet (Goerli)\n * - Other Starknet deployments\n */\n Starknet = 'starknet',\n}\n\n/**\n * Generic type for creating blockchain adapters with type safety.\n * This type ensures that all adapters implement the required interface\n * and are properly keyed by their blockchain type.\n *\n * @typeParam A - Type that extends the base adapter interface with a key property\n *\n * @property {A | A[]} adapter - Single adapter instance or array of adapters\n *\n * @example\n * ```typescript\n * // Single adapter implementation\n * interface EVMAdapter extends BaseAdapter {\n * key: OrbitAdapter.EVM;\n * // EVM-specific methods...\n * }\n * const evmConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: {\n * key: OrbitAdapter.EVM,\n * // implementation...\n * }\n * };\n *\n * // Multiple adapters\n * const multiChainConfig: OrbitGenericAdapter<BaseAdapter> = {\n * adapter: [\n * { key: OrbitAdapter.EVM, ... },\n * { key: OrbitAdapter.SOLANA, ... }\n * ]\n * };\n * ```\n */\nexport type OrbitGenericAdapter<A extends { key: OrbitAdapter }> = {\n adapter: A | A[];\n};\n","/**\n * @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.\n * This pattern is recommended by the official Zustand documentation to ensure full type\n * safety when integrating vanilla stores with React.\n *\n * @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n */\n\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * A utility type that infers the state shape from a Zustand `StoreApi`.\n * It extracts the return type of the `getState` method.\n * @template S - The type of the Zustand store (`StoreApi`).\n */\ntype ExtractState<S> = S extends { getState: () => infer T } ? T : never;\n\n/**\n * Creates a bounded `useStore` hook from a vanilla Zustand store.\n *\n * This function takes a vanilla Zustand store instance and returns a React hook\n * that is pre-bound to that store. This approach provides a cleaner API and\n * enhances type inference, eliminating the need to pass the store instance\n * on every use.\n *\n * The returned hook supports two signatures:\n * 1. `useBoundedStore()`: Selects the entire state.\n * 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.\n *\n * @template S - The type of the Zustand store (`StoreApi`).\n * @param {S} store - The vanilla Zustand store instance to bind the hook to.\n * @returns {function} A fully typed React hook for accessing the store's state.\n */\nexport const createBoundedUseStore = ((store) => (selector) => useStore(store, selector)) as <\n S extends StoreApi<unknown>,\n>(\n store: S,\n) => {\n // This implementation uses a Immediately Invoked Function Expression (IIFE)\n // trick combined with casting to achieve the desired overloaded function signature in a concise way.\n (): ExtractState<S>;\n <T>(selector: (state: ExtractState<S>) => T): T;\n};\n","/**\n * @file\n * This module provides adapter selection functionality for the Orbit system.\n * Part of the core infrastructure for managing blockchain adapters.\n */\n\nimport { OrbitAdapter, OrbitGenericAdapter } from '../types';\n\n/**\n * Selects an appropriate adapter based on the provided key from either a single adapter\n * or an array of adapters.\n *\n * @typeParam A - Type extending basic adapter interface with a key property\n *\n * @param options - Selection configuration object\n * @param options.adapterKey - Target adapter key to search for\n * @param options.adapter - Single adapter or array of adapters to search within\n *\n * @returns Selected adapter or undefined if no suitable adapter found\n *\n * @remarks\n * If an array is provided but no matching adapter is found, falls back to the first adapter\n * in the array with a warning message.\n *\n * @example\n * ```typescript\n * // Single adapter usage\n * const singleResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.SOLANA,\n * adapter: { key: OrbitAdapter.SOLANA, connect: async () => {...} }\n * });\n *\n * // Multiple adapters usage\n * const multiResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.EVM,\n * adapter: [\n * { key: OrbitAdapter.SOLANA, connect: async () => {...} },\n * { key: OrbitAdapter.EVM, connect: async () => {...} }\n * ]\n * });\n * ```\n *\n * @throws {Error} Logs error if adapter array is empty\n * @throws {Warning} Logs warning if requested adapter key not found in array\n */\nexport const selectAdapterByKey = <A extends { key: OrbitAdapter }>({\n adapterKey,\n adapter,\n}: { adapterKey: OrbitAdapter } & OrbitGenericAdapter<A>): A | undefined => {\n if (Array.isArray(adapter)) {\n if (adapter.length === 0) {\n console.error('Adapter selection failed: The provided adapters array is empty.');\n return undefined;\n }\n\n const foundAdapter = adapter.find((a) => a.key === adapterKey);\n\n if (foundAdapter) {\n return foundAdapter;\n } else {\n console.warn(\n `No adapter found for key: \"${adapterKey}\". Falling back to the first available adapter: \"${adapter[0].key}\".`,\n );\n return adapter[0];\n }\n }\n return adapter;\n};\n","/**\n * Checks whether the given chain ID belongs to a Solana network.\n * Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.\n *\n * @param {number | string} chainId - The chain ID or chain name.\n * @returns {boolean} - True if the chain ID corresponds to a Solana network, false otherwise.\n */\nexport function isSolanaChain(chainId: number | string): boolean {\n if (typeof chainId === 'string') {\n return ['devnet', 'testnet', 'mainnet-beta', 'mainnet'].includes(chainId);\n }\n return false;\n}\n\n/**\n * Sets the chain ID to a Solana-specific format if the chain is a Solana network.\n *\n * @param {number | string} chainId - The original chain ID or name.\n * @returns {string | number} - The formatted chain ID prefixed with 'solana:' if Solana, otherwise the original.\n */\nexport function setChainId(chainId: number | string): string | number {\n if (isSolanaChain(chainId)) {\n return `solana:${chainId}`;\n } else {\n return chainId;\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tuwaio/orbit-core",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"private": false,
|
|
5
|
+
"author": "Oleksandr Tkach",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"description": "The core, with web3 utilities and helpers for TUWA projects.",
|
|
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
|
+
"typescript",
|
|
20
|
+
"core",
|
|
21
|
+
"headless"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/TuwaIO/satellite-connect.git",
|
|
26
|
+
"directory": "packages/orbit-core"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/TuwaIO/satellite-connect",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/TuwaIO/satellite-connect/issues"
|
|
31
|
+
},
|
|
32
|
+
"contributors": [
|
|
33
|
+
{
|
|
34
|
+
"name": "Oleksandr Tkach",
|
|
35
|
+
"url": "https://github.com/Argeare5"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"zustand": "^5.0.8"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"tsup": "^8.5.0",
|
|
43
|
+
"typescript": "^5.9.2",
|
|
44
|
+
"zustand": "^5.0.8"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"start": "tsup src/index.ts --watch",
|
|
48
|
+
"build": "tsup"
|
|
49
|
+
}
|
|
50
|
+
}
|