@meshsdk/react 1.9.0-beta.98 → 2.0.0-beta.2

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 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 [yyyy] [name of copyright owner]
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 CHANGED
@@ -1,5 +1,330 @@
1
- # mesh-react
1
+ # @meshsdk/react
2
2
 
3
- React component library - [meshjs.dev/react](https://meshjs.dev/react)
3
+ React component library for Cardano blockchain wallet integration. Provides wallet connection UI components, React hooks for wallet state management, and context providers for the [MeshSDK](https://meshjs.dev/) ecosystem.
4
4
 
5
- [meshjs.dev](https://meshjs.dev/)
5
+ **Docs:** [meshjs.dev/react](https://meshjs.dev/react) | **Formats:** ESM + CJS + TypeScript declarations
6
+
7
+ ## Quick Start
8
+
9
+ ```bash
10
+ npm install @meshsdk/react @meshsdk/wallet @meshsdk/common
11
+ ```
12
+
13
+ ```tsx
14
+ import { MeshProvider, CardanoWallet } from "@meshsdk/react";
15
+ import "@meshsdk/react/styles.css";
16
+
17
+ function App() {
18
+ return (
19
+ <MeshProvider>
20
+ <CardanoWallet />
21
+ </MeshProvider>
22
+ );
23
+ }
24
+ ```
25
+
26
+ > All hooks and wallet components **must** be rendered inside a `<MeshProvider>`.
27
+ > The CSS import (`styles.css`) is required for component styling.
28
+
29
+ ## Wallet API (v2 — Breaking Changes)
30
+
31
+ The wallet instance exposed via `useWallet().wallet` is typed as `MeshCardanoBrowserWallet`, which provides **two sets of methods**:
32
+
33
+ ### Base methods (breaking — raw CIP-30 passthrough)
34
+
35
+ These return the raw data from the browser wallet's CIP-30 API. **This is a breaking change** from v1 where these methods returned human-friendly formats.
36
+
37
+ | Method | Returns | v1 behavior (old) | v2 behavior (new) |
38
+ |--------|---------|--------------------|--------------------|
39
+ | `wallet.getChangeAddress()` | `Promise<string>` | bech32 address | **hex address** |
40
+ | `wallet.getUsedAddresses()` | `Promise<string[]>` | bech32 addresses | **hex addresses** |
41
+ | `wallet.getUnusedAddresses()` | `Promise<string[]>` | bech32 addresses | **hex addresses** |
42
+ | `wallet.getRewardAddresses()` | `Promise<string[]>` | bech32 addresses | **hex addresses** |
43
+ | `wallet.signTx(tx, partialSign)` | `Promise<string>` | full signed transaction | **witness set CBOR only** |
44
+ | `wallet.getBalance()` | `Promise<string>` | `Asset[]` | **CBOR hex string** |
45
+ | `wallet.getUtxos()` | `Promise<string[]>` | `UTxO[]` | **CBOR hex strings** |
46
+ | `wallet.getCollateral()` | `Promise<string[]>` | `UTxO[]` | **CBOR hex strings** |
47
+ | `wallet.signData(addressHex, data)` | `Promise<DataSignature>` | `(payload, address?)` | **address first, required; params swapped** |
48
+ | `wallet.getNetworkId()` | `Promise<number>` | unchanged | unchanged |
49
+ | `wallet.submitTx(tx)` | `Promise<string>` | unchanged | unchanged |
50
+
51
+ ### Convenience methods (new — human-friendly formats)
52
+
53
+ These restore the v1 behavior under new explicit method names:
54
+
55
+ | Method | Returns | Description |
56
+ |--------|---------|-------------|
57
+ | `wallet.getChangeAddressBech32()` | `Promise<string>` | Change address in bech32 format |
58
+ | `wallet.getUsedAddressesBech32()` | `Promise<string[]>` | Used addresses in bech32 format |
59
+ | `wallet.getUnusedAddressesBech32()` | `Promise<string[]>` | Unused addresses in bech32 format |
60
+ | `wallet.getRewardAddressesBech32()` | `Promise<string[]>` | Reward addresses in bech32 format |
61
+ | `wallet.signTxReturnFullTx(tx, partialSign?)` | `Promise<string>` | Sign and return full signed transaction |
62
+ | `wallet.getBalanceMesh()` | `Promise<Asset[]>` | Balance as Mesh `Asset[]` objects |
63
+ | `wallet.getUtxosMesh()` | `Promise<UTxO[]>` | UTxOs as Mesh `UTxO[]` objects |
64
+ | `wallet.getCollateralMesh()` | `Promise<UTxO[]>` | Collateral as Mesh `UTxO[]` objects |
65
+
66
+ ### Migration from v1
67
+
68
+ | v1 call | v2 equivalent |
69
+ |---------|---------------|
70
+ | `wallet.getChangeAddress()` (expected bech32) | `wallet.getChangeAddressBech32()` |
71
+ | `wallet.getUsedAddresses()` (expected bech32) | `wallet.getUsedAddressesBech32()` |
72
+ | `wallet.signTx(tx)` (expected full signed tx) | `wallet.signTxReturnFullTx(tx)` |
73
+ | `wallet.signTx(tx, partial, false)` (witness set) | `wallet.signTx(tx, partial)` |
74
+ | `wallet.getBalance()` (expected Asset[]) | `wallet.getBalanceMesh()` |
75
+ | `wallet.getUtxos()` (expected UTxO[]) | `wallet.getUtxosMesh()` |
76
+ | `wallet.getCollateral()` (expected UTxO[]) | `wallet.getCollateralMesh()` |
77
+ | `wallet.getLovelace()` | `(await wallet.getBalanceMesh()).find(v => v.unit === "lovelace")?.quantity` |
78
+ | `wallet.getAssets()` | Derive from `wallet.getBalanceMesh()` — filter non-lovelace assets |
79
+ | `wallet.signData(payload, address?)` | `wallet.signData(address, hexPayload)` — params swapped, address required |
80
+ | `BrowserWallet.enable(name)` | `MeshCardanoBrowserWallet.enable(name)` |
81
+ | `BrowserWallet.getInstalledWallets()` | `MeshCardanoBrowserWallet.getInstalledWallets()` |
82
+ | `new MeshWallet({...key})` | `await MeshCardanoHeadlessWallet.fromMnemonic({...})` or `.fromBip32Root({...})` |
83
+
84
+ ### Removed methods (no v2 equivalent)
85
+
86
+ These methods were removed from `@meshsdk/wallet` v2 and have no direct replacement:
87
+
88
+ - `wallet.getDRep()` / `wallet.getPubDRepKey()` — Use raw CIP-95 API
89
+ - `wallet.getRegisteredPubStakeKeys()` / `wallet.getUnregisteredPubStakeKeys()` — Use raw CIP-95 API
90
+ - `wallet.getExtensions()` — Check raw wallet instance
91
+ - `wallet.signTxs(txs, partial)` — Loop with `signTxReturnFullTx()` individually
92
+ - `BrowserWallet.getAvailableWallets()` — Use `MeshCardanoBrowserWallet.getInstalledWallets()` (synchronous)
93
+ - `BrowserWallet.getSupportedExtensions(name)` — Use `globalThis?.cardano?.[name]?.supportedExtensions`
94
+ - `MeshWallet.brew()` — Use `generateMnemonic()` from `@meshsdk/common`
95
+
96
+ ### Internal usage
97
+
98
+ All hooks and context code in this package use the **convenience methods** internally. The base (breaking) methods are only exposed for consumers who need raw CIP-30 data.
99
+
100
+ ## Class Hierarchy
101
+
102
+ ```
103
+ CardanoBrowserWallet (implements ICardanoWallet)
104
+ └── MeshCardanoBrowserWallet (adds Bech32/Mesh/FullTx convenience methods)
105
+
106
+ CardanoHeadlessWallet (implements ICardanoWallet)
107
+ └── MeshCardanoHeadlessWallet (adds Bech32/Mesh/FullTx convenience methods)
108
+ ```
109
+
110
+ - **`CardanoBrowserWallet`** — Thin CIP-30 passthrough for browser extension wallets
111
+ - **`MeshCardanoBrowserWallet`** — Adds `*Bech32()`, `*Mesh()`, `signTxReturnFullTx()` methods
112
+ - **`CardanoHeadlessWallet`** — Server-side/headless wallet (mnemonic, keys)
113
+ - **`MeshCardanoHeadlessWallet`** — Adds convenience methods to headless wallet
114
+ - **`ICardanoWallet`** — Base interface all wallets implement (CIP-30 shape)
115
+
116
+ The `useWallet().wallet` is always `MeshCardanoBrowserWallet`. When non-browser wallets (headless, Web3) are passed via `setWallet()`, they are automatically wrapped in `MeshCardanoBrowserWallet` to ensure the convenience methods are available.
117
+
118
+ ## Architecture
119
+
120
+ ### State Management
121
+
122
+ Wallet state flows through React Context with a three-state machine:
123
+
124
+ ```
125
+ NOT_CONNECTED ──connectWallet()──> CONNECTING ──success──> CONNECTED
126
+ |
127
+ error──> NOT_CONNECTED
128
+ ```
129
+
130
+ - **`WalletContext.ts`** defines the store via `useWalletStore()` hook (internal)
131
+ - **`MeshProvider`** wraps children with `WalletContext.Provider`
132
+ - The `connectedWalletInstance` is typed as `MeshCardanoBrowserWallet`
133
+ - Sessions persist to `localStorage` under key `"mesh-wallet-persist"`
134
+ - On mount, persisted sessions auto-reconnect (except `utxos` web3 wallets which require re-auth)
135
+
136
+ ### Wallet Connection Flow
137
+
138
+ 1. **Browser wallet:** `MeshCardanoBrowserWallet.enable(walletName, extensions)` returns a `MeshCardanoBrowserWallet` directly
139
+ 2. **Headless wallet (burner):** `MeshCardanoHeadlessWallet.fromMnemonic({...})` creates wallet, passed to `setWallet()` which wraps it in `MeshCardanoBrowserWallet`
140
+ 3. **Web3 wallet (social login):** `Web3Wallet.enable(options)` returns a wallet, its `.cardano` property is wrapped in `MeshCardanoBrowserWallet` via `setWallet()`
141
+
142
+ All paths result in `connectedWalletInstance` being a `MeshCardanoBrowserWallet` with both base and convenience methods available.
143
+
144
+ ### Address Resolution (after connection)
145
+
146
+ ```typescript
147
+ // WalletContext.ts — runs after wallet connects
148
+ let address = (await connectedWalletInstance.getUnusedAddressesBech32())[0];
149
+ if (!address) address = await connectedWalletInstance.getChangeAddressBech32();
150
+ ```
151
+
152
+ ### Component Hierarchy
153
+
154
+ ```
155
+ <MeshProvider> # contexts/index.tsx — required wrapper
156
+ <CardanoWallet /> # cardano-wallet/index.tsx — dialog variant
157
+ +-- <ConnectedButton /> # Shows wallet info when connected
158
+ +-- <Dialog> # Radix dialog with screen navigation
159
+ +-- <ScreenMain /> # Lists installed wallets
160
+ +-- <ScreenBurner /> # In-browser burner wallet
161
+ +-- <ScreenWebauthn /> # Passkey-derived wallet
162
+ ```
163
+
164
+ ### Styling Conventions
165
+
166
+ - **Tailwind CSS** with `mesh-` prefix on all utility classes (avoids conflicts with consumer apps)
167
+ - **Dark mode** via `class` strategy — toggle with `isDark` prop or `mesh-dark` class
168
+ - **`cn()` utility** (`src/common/cn.ts`) merges classes using `clsx` + `tailwind-merge`
169
+ - Source styles: `src/styles.css` -> compiled to `dist/index.css`
170
+ - Consumer import: `import "@meshsdk/react/styles.css"`
171
+
172
+ ### Build Pipeline
173
+
174
+ - **TSUP** bundles `src/index.ts` -> `dist/index.js` (ESM) + `dist/index.cjs` (CJS) + `dist/index.d.ts` (types)
175
+ - **Tailwind** compiles `src/styles.css` -> `dist/index.css`
176
+ - Both run concurrently in dev mode
177
+
178
+ ## Exported API
179
+
180
+ ### Components
181
+
182
+ #### `CardanoWallet` (from `cardano-wallet/`)
183
+
184
+ Dialog-based wallet connection component. Shows a "Connect Wallet" button that opens a modal listing available browser wallets, with optional burner wallet and WebAuthn/passkey screens.
185
+
186
+ ```tsx
187
+ <CardanoWallet
188
+ label="Connect Wallet" // Button text (default: "Connect Wallet")
189
+ onConnected={() => {}} // Callback after successful connection
190
+ isDark={false} // Dark mode toggle
191
+ persist={false} // Persist session to localStorage
192
+ injectFn={async () => {}} // Custom wallet injection function
193
+ burnerWallet={{ // Enable burner wallet screen
194
+ networkId: 0, // 0 = testnet, 1 = mainnet
195
+ provider: fetcher, // IFetcher & ISubmitter instance
196
+ }}
197
+ webauthn={{ // Enable WebAuthn/passkey screen
198
+ networkId: 0,
199
+ provider: fetcher,
200
+ url: "https://...",
201
+ }}
202
+ showDownload={true} // Show wallet download links
203
+ web3Services={options} // EnableWeb3WalletOptions for social login
204
+ />
205
+ ```
206
+
207
+ #### `CardanoWallet` (from `cardano-wallet-dropdown/`)
208
+
209
+ Dropdown (hover-based) variant. Simpler API, no dialog — shows wallet list in a dropdown menu.
210
+
211
+ ```tsx
212
+ import { CardanoWallet } from "@meshsdk/react"; // Both export as CardanoWallet
213
+ // The dialog variant from cardano-wallet/ is the one exported from the barrel
214
+
215
+ <CardanoWallet
216
+ label="Connect Wallet"
217
+ onConnected={() => {}}
218
+ isDark={false}
219
+ persist={false}
220
+ />
221
+ ```
222
+
223
+ > **Note:** Only the **dialog variant** (`cardano-wallet/`) is exported from the package barrel (`src/index.ts`). The dropdown variant exists in the source but is not currently re-exported.
224
+
225
+ #### `MeshProvider`
226
+
227
+ Required context wrapper. Must be an ancestor of any component or hook from this library.
228
+
229
+ ```tsx
230
+ <MeshProvider>
231
+ {children}
232
+ </MeshProvider>
233
+ ```
234
+
235
+ #### `MeshBadge`
236
+
237
+ Branding badge linking to meshjs.dev.
238
+
239
+ ```tsx
240
+ <MeshBadge isDark={false} />
241
+ ```
242
+
243
+ ### Hooks
244
+
245
+ All hooks must be called within a `<MeshProvider>`. They read from `WalletContext`.
246
+
247
+ | Hook | Returns | Description |
248
+ |------|---------|-------------|
249
+ | `useWallet()` | `{ name, connecting, connected, wallet, connect, disconnect, setWallet, setPersist, setWeb3Services, web3UserData, setWeb3UserData, error, address, state }` | Primary hook. `wallet` is typed as `MeshCardanoBrowserWallet`. |
250
+ | `useAddress(accountId?)` | `string \| undefined` | Bech32 used address. Internally calls `getUsedAddressesBech32()`. `accountId` defaults to `0`. |
251
+ | `useAssets()` | `AssetExtended[] \| undefined` | All non-lovelace assets with policyId, assetName, fingerprint. Derived from `getBalanceMesh()`. |
252
+ | `useLovelace()` | `string \| undefined` | ADA balance in lovelace. Derived from `getBalanceMesh()`. Fetches once per connection. |
253
+ | `useNetwork()` | `number \| undefined` | Network ID (`0` = testnet, `1` = mainnet). Calls `getNetworkId()`. |
254
+ | `useRewardAddress(accountId?)` | `string \| undefined` | Bech32 staking/reward address. Internally calls `getRewardAddressesBech32()`. `accountId` defaults to `0`. |
255
+ | `useWalletList({ injectFn? })` | `Wallet[]` | Browser-installed Cardano wallets. Calls `MeshCardanoBrowserWallet.getInstalledWallets()`. |
256
+ | `useWalletSubmit()` | `{ submitTx, submitting, result, error }` | Submit a signed transaction. Calls `wallet.submitTx()`. Returns tx hash on success. |
257
+
258
+ ### Context & Types
259
+
260
+ | Export | From | Description |
261
+ |--------|------|-------------|
262
+ | `WalletContext` | `contexts/WalletContext.ts` | The React Context object (for advanced use with `useContext`) |
263
+ | `WalletState` | `contexts/WalletContext.ts` | Enum: `NOT_CONNECTED`, `CONNECTING`, `CONNECTED` |
264
+ | `MeshProvider` | `contexts/index.tsx` | Context provider component |
265
+ | `MeshCardanoBrowserWallet` | re-exported from `@meshsdk/wallet` | Browser wallet with convenience methods |
266
+ | `MeshCardanoHeadlessWallet` | re-exported from `@meshsdk/wallet` | Headless wallet with convenience methods |
267
+ | `CardanoBrowserWallet` | re-exported from `@meshsdk/wallet` | Base browser wallet (CIP-30 passthrough) |
268
+ | `CardanoHeadlessWallet` | re-exported from `@meshsdk/wallet` | Base headless wallet |
269
+ | `ICardanoWallet` | re-exported from `@meshsdk/wallet` | Base interface for all wallet types |
270
+
271
+ ## Build & Development
272
+
273
+ ```bash
274
+ # Build (bundles JS + compiles Tailwind CSS)
275
+ pnpm run build
276
+
277
+ # Dev mode (watch mode for both tsup and tailwind, concurrent)
278
+ pnpm run dev
279
+
280
+ # Type checking only
281
+ pnpm run type-check
282
+
283
+ # Lint (ESLint)
284
+ pnpm run lint
285
+
286
+ # Format check (Prettier)
287
+ pnpm run format
288
+
289
+ # Create npm tarball in dist/
290
+ pnpm run pack
291
+
292
+ # Clean all build artifacts (dist/, node_modules/, .turbo/)
293
+ pnpm run clean
294
+ ```
295
+
296
+ **Output files after build:**
297
+ - `dist/index.js` — ESM bundle
298
+ - `dist/index.cjs` — CJS bundle
299
+ - `dist/index.d.ts` — TypeScript declarations
300
+ - `dist/index.css` — Compiled Tailwind styles
301
+
302
+ ## Dependencies
303
+
304
+ ### Runtime
305
+ | Package | Purpose |
306
+ |---------|---------|
307
+ | `@meshsdk/common` | Shared types (`Asset`, `AssetExtended`, `UTxO`, `Wallet`, `DataSignature`), utilities (`POLICY_ID_LENGTH`, `resolveFingerprint`, `generateMnemonic`) |
308
+ | `@meshsdk/wallet` | `MeshCardanoBrowserWallet`, `MeshCardanoHeadlessWallet`, `CardanoBrowserWallet`, `CardanoHeadlessWallet`, `ICardanoWallet` — wallet adapters for browser and headless wallets |
309
+ | `@utxos/sdk` | Web3 wallet services (`Web3Wallet` for social login via Google/Discord/Twitter) |
310
+ | `@radix-ui/react-dialog` | Accessible dialog/modal primitive |
311
+ | `@radix-ui/react-dropdown-menu` | Accessible dropdown menu primitive |
312
+ | `@radix-ui/react-icons` | Icon set |
313
+ | `@radix-ui/react-label` | Accessible label primitive |
314
+ | `@radix-ui/react-tooltip` | Accessible tooltip primitive |
315
+ | `class-variance-authority` | Type-safe CSS variant management for Button |
316
+ | `tailwind-merge` | Intelligent Tailwind class merging |
317
+ | `tailwindcss-animate` | Animation utilities for Tailwind |
318
+
319
+ ### Peer Dependencies
320
+ - `react` >= 16 < 20
321
+ - `react-dom` >= 16 < 20
322
+
323
+ ## Known Gaps
324
+
325
+ - **WebAuthn `connect` function** was removed from `@meshsdk/wallet` v2. The `screen-webauthn.tsx` has a runtime fallback that will log an error if the function is unavailable. Needs re-implementation via WebAuthn API or a compatible package.
326
+ - **`@utxos/sdk` type mismatch**: `Web3Wallet.cardano` returns a `MeshWallet` (old type from bundled dependency). It is cast as `any` and wrapped in `MeshCardanoBrowserWallet`. This will resolve when `@utxos/sdk` updates to `@meshsdk/wallet` v2.
327
+
328
+ ## License
329
+
330
+ Apache-2.0
package/dist/index.cjs CHANGED
@@ -30,8 +30,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ CardanoBrowserWallet: () => import_wallet6.CardanoBrowserWallet,
34
+ CardanoHeadlessWallet: () => import_wallet6.CardanoHeadlessWallet,
33
35
  CardanoWallet: () => CardanoWallet,
34
36
  MeshBadge: () => MeshBadge,
37
+ MeshCardanoBrowserWallet: () => import_wallet6.MeshCardanoBrowserWallet,
38
+ MeshCardanoHeadlessWallet: () => import_wallet6.MeshCardanoHeadlessWallet,
35
39
  MeshProvider: () => MeshProvider,
36
40
  WalletContext: () => WalletContext,
37
41
  useAddress: () => useAddress,
@@ -249,8 +253,8 @@ var useWalletStore = () => {
249
253
  setConnectingWallet(true);
250
254
  setState("CONNECTING" /* CONNECTING */);
251
255
  try {
252
- const extensions = import_wallet.BrowserWallet.getSupportedExtensions(walletName);
253
- const walletInstance = await import_wallet.BrowserWallet.enable(
256
+ const extensions = globalThis?.cardano?.[walletName]?.supportedExtensions ?? [];
257
+ const walletInstance = await import_wallet.MeshCardanoBrowserWallet.enable(
254
258
  walletName,
255
259
  extensions
256
260
  );
@@ -282,7 +286,8 @@ var useWalletStore = () => {
282
286
  }, []);
283
287
  const setWallet = (0, import_react.useCallback)(
284
288
  async (walletInstance, walletName, persist) => {
285
- setConnectedWalletInstance(walletInstance);
289
+ const wrapped = walletInstance instanceof import_wallet.MeshCardanoBrowserWallet ? walletInstance : new import_wallet.MeshCardanoBrowserWallet(walletInstance);
290
+ setConnectedWalletInstance(wrapped);
286
291
  setConnectedWalletName(walletName);
287
292
  setState("CONNECTED" /* CONNECTED */);
288
293
  if (persist) {
@@ -300,9 +305,9 @@ var useWalletStore = () => {
300
305
  (0, import_react.useEffect)(() => {
301
306
  async function load() {
302
307
  if (Object.keys(connectedWalletInstance).length > 0 && address.length === 0) {
303
- let address2 = (await connectedWalletInstance.getUnusedAddresses())[0];
308
+ let address2 = (await connectedWalletInstance.getUnusedAddressesBech32())[0];
304
309
  if (!address2)
305
- address2 = await connectedWalletInstance.getChangeAddress();
310
+ address2 = await connectedWalletInstance.getChangeAddressBech32();
306
311
  setAddress(address2);
307
312
  }
308
313
  }
@@ -379,7 +384,7 @@ var useAddress = (accountId = 0) => {
379
384
  const { hasConnectedWallet, connectedWalletInstance } = (0, import_react2.useContext)(WalletContext);
380
385
  (0, import_react2.useEffect)(() => {
381
386
  if (hasConnectedWallet) {
382
- connectedWalletInstance.getUsedAddresses().then((addresses) => {
387
+ connectedWalletInstance.getUsedAddressesBech32().then((addresses) => {
383
388
  if (addresses[accountId]) {
384
389
  setAddress(addresses[accountId]);
385
390
  }
@@ -391,12 +396,21 @@ var useAddress = (accountId = 0) => {
391
396
 
392
397
  // src/hooks/useAssets.ts
393
398
  var import_react3 = require("react");
399
+ var import_common = require("@meshsdk/common");
394
400
  var useAssets = () => {
395
401
  const [assets, setAssets] = (0, import_react3.useState)();
396
402
  const { hasConnectedWallet, connectedWalletInstance } = (0, import_react3.useContext)(WalletContext);
397
403
  (0, import_react3.useEffect)(() => {
398
404
  if (hasConnectedWallet) {
399
- connectedWalletInstance.getAssets().then(setAssets);
405
+ connectedWalletInstance.getBalanceMesh().then((balance) => {
406
+ const derived = balance.filter((v) => v.unit !== "lovelace").map((v) => {
407
+ const policyId = v.unit.slice(0, import_common.POLICY_ID_LENGTH);
408
+ const assetName = v.unit.slice(import_common.POLICY_ID_LENGTH);
409
+ const fingerprint = (0, import_common.resolveFingerprint)(policyId, assetName);
410
+ return { unit: v.unit, policyId, assetName, fingerprint, quantity: v.quantity };
411
+ });
412
+ setAssets(derived);
413
+ });
400
414
  }
401
415
  }, [hasConnectedWallet, connectedWalletInstance]);
402
416
  return assets;
@@ -411,7 +425,10 @@ var useWalletList = ({
411
425
  const [wallets, setWallets] = (0, import_react4.useState)([]);
412
426
  (0, import_react4.useEffect)(() => {
413
427
  async function get() {
414
- setWallets(await import_wallet2.BrowserWallet.getAvailableWallets({ injectFn }));
428
+ if (injectFn) {
429
+ await injectFn();
430
+ }
431
+ setWallets(import_wallet2.MeshCardanoBrowserWallet.getInstalledWallets());
415
432
  }
416
433
  get();
417
434
  }, []);
@@ -427,7 +444,9 @@ var useLovelace = () => {
427
444
  (0, import_react5.useEffect)(() => {
428
445
  async function getLovelace() {
429
446
  if (hasConnectedWallet && !hasFetchedLovelace.current) {
430
- setLovelace(await connectedWalletInstance.getLovelace());
447
+ const balance = await connectedWalletInstance.getBalanceMesh();
448
+ const lovelaceAmount = balance.find((v) => v.unit === "lovelace")?.quantity ?? "0";
449
+ setLovelace(lovelaceAmount);
431
450
  hasFetchedLovelace.current = true;
432
451
  }
433
452
  }
@@ -461,7 +480,7 @@ var useRewardAddress = (accountId = 0) => {
461
480
  const { hasConnectedWallet, connectedWalletInstance } = (0, import_react7.useContext)(WalletContext);
462
481
  (0, import_react7.useEffect)(() => {
463
482
  if (hasConnectedWallet) {
464
- connectedWalletInstance.getRewardAddresses().then((addresses) => {
483
+ connectedWalletInstance.getRewardAddressesBech32().then((addresses) => {
465
484
  if (addresses[accountId]) {
466
485
  setRewardAddress(addresses[accountId]);
467
486
  }
@@ -746,6 +765,7 @@ var screens = {
746
765
 
747
766
  // src/cardano-wallet/screen-burner.tsx
748
767
  var import_react10 = require("react");
768
+ var import_common2 = require("@meshsdk/common");
749
769
  var import_wallet3 = require("@meshsdk/wallet");
750
770
  var import_jsx_runtime7 = require("react/jsx-runtime");
751
771
  var localstoragekey = "mesh-burnerwallet";
@@ -766,34 +786,45 @@ function ScreenBurner({
766
786
  setHasKeyInStorage(true);
767
787
  }
768
788
  }, []);
769
- function createWallet(key) {
770
- setTimeout(() => {
771
- const wallet = new import_wallet3.MeshWallet({
772
- networkId,
773
- fetcher: provider,
774
- submitter: provider,
775
- key: {
776
- type: "root",
777
- bech32: key
778
- }
779
- });
780
- if (!hasKeyInStorage) {
781
- localStorage.setItem(localstoragekey, key);
782
- }
783
- setWallet(wallet, screens.burner.title);
784
- setLoading(false);
785
- setOpen(false);
786
- }, 500);
789
+ async function createWalletFromMnemonic(mnemonic) {
790
+ const wallet = await import_wallet3.MeshCardanoHeadlessWallet.fromMnemonic({
791
+ mnemonic,
792
+ networkId,
793
+ walletAddressType: import_wallet3.AddressType.Base,
794
+ fetcher: provider,
795
+ submitter: provider
796
+ });
797
+ if (!hasKeyInStorage) {
798
+ localStorage.setItem(localstoragekey, mnemonic.join(" "));
799
+ }
800
+ setWallet(wallet, screens.burner.title);
801
+ setLoading(false);
802
+ setOpen(false);
787
803
  }
788
- function handleRestoreWallet() {
804
+ async function handleRestoreWallet() {
789
805
  setLoading(true);
790
- const key = getKeyFromStorage();
791
- createWallet(key);
806
+ const stored = getKeyFromStorage();
807
+ if (stored) {
808
+ if (stored.includes(" ")) {
809
+ await createWalletFromMnemonic(stored.split(" "));
810
+ } else {
811
+ const wallet = await import_wallet3.MeshCardanoHeadlessWallet.fromBip32Root({
812
+ bech32: stored,
813
+ networkId,
814
+ walletAddressType: import_wallet3.AddressType.Base,
815
+ fetcher: provider,
816
+ submitter: provider
817
+ });
818
+ setWallet(wallet, screens.burner.title);
819
+ setLoading(false);
820
+ setOpen(false);
821
+ }
822
+ }
792
823
  }
793
- function handleCreateWallet() {
824
+ async function handleCreateWallet() {
794
825
  setLoading(true);
795
- const key = import_wallet3.MeshWallet.brew(true);
796
- createWallet(key);
826
+ const mnemonic = (0, import_common2.generateMnemonic)(256).split(" ");
827
+ await createWalletFromMnemonic(mnemonic);
797
828
  }
798
829
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "mesh-flex mesh-flex-row mesh-flex-gap-4 mesh-items-center mesh-justify-center", children: loading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: "Setting up wallet..." }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
799
830
  hasKeyInStorage && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
@@ -977,6 +1008,7 @@ function WalletIcon({
977
1008
 
978
1009
  // src/cardano-wallet/web3-services.tsx
979
1010
  var import_react11 = require("react");
1011
+ var import_wallet4 = require("@meshsdk/wallet");
980
1012
  var import_sdk = require("@utxos/sdk");
981
1013
 
982
1014
  // src/common/icons/icon-discord.tsx
@@ -1089,11 +1121,13 @@ function Web3Services({
1089
1121
  const wallet = await import_sdk.Web3Wallet.enable(_options);
1090
1122
  const user = wallet.getUser();
1091
1123
  setWeb3UserData(user);
1124
+ const wrapped = new import_wallet4.MeshCardanoBrowserWallet(wallet.cardano);
1125
+ const walletAddress = await wrapped.getChangeAddressBech32();
1092
1126
  setWallet(
1093
- wallet.cardano,
1127
+ wrapped,
1094
1128
  "utxos",
1095
1129
  persist ? {
1096
- walletAddress: await wallet.cardano.getChangeAddress(),
1130
+ walletAddress,
1097
1131
  user
1098
1132
  } : void 0
1099
1133
  );
@@ -1144,7 +1178,7 @@ function ScreenMain({
1144
1178
  web3Services
1145
1179
  }) {
1146
1180
  const wallets = useWalletList({ injectFn });
1147
- const { connect: connect2 } = useWallet();
1181
+ const { connect } = useWallet();
1148
1182
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(TooltipProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "mesh-grid mesh-gap-4 mesh-py-4 mesh-grid-cols-5 mesh-place-items-center mesh-gap-y-8", children: [
1149
1183
  wallets.map((wallet, index) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1150
1184
  WalletIcon,
@@ -1152,7 +1186,7 @@ function ScreenMain({
1152
1186
  icon: wallet.icon,
1153
1187
  name: wallet.name,
1154
1188
  action: () => {
1155
- connect2(wallet.id, persist);
1189
+ connect(wallet.id, persist);
1156
1190
  setOpen(false);
1157
1191
  }
1158
1192
  },
@@ -1204,7 +1238,7 @@ function ScreenMain({
1204
1238
 
1205
1239
  // src/cardano-wallet/screen-webauthn.tsx
1206
1240
  var import_react12 = require("react");
1207
- var import_wallet4 = require("@meshsdk/wallet");
1241
+ var import_wallet5 = require("@meshsdk/wallet");
1208
1242
 
1209
1243
  // src/common/input.tsx
1210
1244
  var React5 = __toESM(require("react"), 1);
@@ -1257,27 +1291,29 @@ function ScreenWebauthn({
1257
1291
  const [userName, setUserName] = (0, import_react12.useState)("");
1258
1292
  const [password, setPassword] = (0, import_react12.useState)("");
1259
1293
  const { setWallet } = useWallet();
1260
- function createWallet(root) {
1261
- setTimeout(() => {
1262
- const wallet = new import_wallet4.MeshWallet({
1263
- networkId,
1264
- fetcher: provider,
1265
- submitter: provider,
1266
- key: {
1267
- type: "root",
1268
- bech32: root
1269
- }
1270
- });
1271
- setWallet(wallet, screens.webauthn.title);
1272
- setLoading(false);
1273
- setOpen(false);
1274
- }, 500);
1294
+ async function createWallet(root) {
1295
+ const wallet = await import_wallet5.MeshCardanoHeadlessWallet.fromBip32Root({
1296
+ bech32: root,
1297
+ networkId,
1298
+ walletAddressType: import_wallet5.AddressType.Base,
1299
+ fetcher: provider,
1300
+ submitter: provider
1301
+ });
1302
+ setWallet(wallet, screens.webauthn.title);
1303
+ setLoading(false);
1304
+ setOpen(false);
1275
1305
  }
1276
1306
  async function handleConnect() {
1277
1307
  setLoading(true);
1278
- const res = await (0, import_wallet4.connect)({ username: userName, password, serverUrl: url });
1279
- if (res.success && res.wallet) {
1280
- createWallet(res.wallet.bech32PrivateKey);
1308
+ const connectModule = await import("@meshsdk/wallet");
1309
+ if (typeof connectModule.connect === "function") {
1310
+ const res = await connectModule.connect({ username: userName, password, serverUrl: url });
1311
+ if (res.success && res.wallet) {
1312
+ await createWallet(res.wallet.bech32PrivateKey);
1313
+ }
1314
+ } else {
1315
+ console.error("WebAuthn connect is not available in this version of @meshsdk/wallet");
1316
+ setLoading(false);
1281
1317
  }
1282
1318
  }
1283
1319
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "mesh-flex mesh-flex-row mesh-flex-gap-4 mesh-items-center mesh-justify-center", children: loading ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_jsx_runtime20.Fragment, { children: "Connecting wallet..." }) : /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_jsx_runtime20.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "mesh-flex mesh-flex-col mesh-gap-6 mesh-w-full mesh-mx-8", children: [
@@ -1470,10 +1506,17 @@ var MeshBadge = ({ isDark = false }) => /* @__PURE__ */ (0, import_jsx_runtime23
1470
1506
  ]
1471
1507
  }
1472
1508
  );
1509
+
1510
+ // src/index.ts
1511
+ var import_wallet6 = require("@meshsdk/wallet");
1473
1512
  // Annotate the CommonJS export names for ESM import in node:
1474
1513
  0 && (module.exports = {
1514
+ CardanoBrowserWallet,
1515
+ CardanoHeadlessWallet,
1475
1516
  CardanoWallet,
1476
1517
  MeshBadge,
1518
+ MeshCardanoBrowserWallet,
1519
+ MeshCardanoHeadlessWallet,
1477
1520
  MeshProvider,
1478
1521
  WalletContext,
1479
1522
  useAddress,
package/dist/index.d.cts CHANGED
@@ -1,9 +1,11 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as _meshsdk_common from '@meshsdk/common';
3
- import { IFetcher, ISubmitter, IWallet, Asset, Wallet } from '@meshsdk/common';
2
+ import { IFetcher, ISubmitter, AssetExtended, Wallet } from '@meshsdk/common';
4
3
  import * as _utxos_sdk from '@utxos/sdk';
5
4
  import { EnableWeb3WalletOptions, UserSocialData } from '@utxos/sdk';
6
5
  import * as react from 'react';
6
+ import * as _meshsdk_wallet from '@meshsdk/wallet';
7
+ import { MeshCardanoBrowserWallet, ICardanoWallet } from '@meshsdk/wallet';
8
+ export { CardanoBrowserWallet, CardanoHeadlessWallet, ICardanoWallet, MeshCardanoBrowserWallet, MeshCardanoHeadlessWallet } from '@meshsdk/wallet';
7
9
 
8
10
  interface ButtonProps {
9
11
  label?: string;
@@ -32,12 +34,12 @@ declare enum WalletState {
32
34
  }
33
35
  interface WalletContext {
34
36
  hasConnectedWallet: boolean;
35
- connectedWalletInstance: IWallet;
37
+ connectedWalletInstance: MeshCardanoBrowserWallet;
36
38
  connectedWalletName: string | undefined;
37
39
  connectingWallet: boolean;
38
40
  connectWallet: (walletName: string, persist?: boolean) => Promise<void>;
39
41
  disconnect: () => void;
40
- setWallet: (walletInstance: IWallet, walletName: string, persist?: {
42
+ setWallet: (walletInstance: ICardanoWallet, walletName: string, persist?: {
41
43
  [key: string]: any;
42
44
  }) => void;
43
45
  setPersist: (persist: boolean) => void;
@@ -57,7 +59,7 @@ declare const MeshProvider: React.FC<Props>;
57
59
 
58
60
  declare const useAddress: (accountId?: number) => string | undefined;
59
61
 
60
- declare const useAssets: () => Asset[] | undefined;
62
+ declare const useAssets: () => AssetExtended[] | undefined;
61
63
 
62
64
  declare const useWalletList: ({ injectFn, }?: {
63
65
  injectFn?: () => Promise<void>;
@@ -73,10 +75,10 @@ declare const useWallet: () => {
73
75
  name: string | undefined;
74
76
  connecting: boolean;
75
77
  connected: boolean;
76
- wallet: _meshsdk_common.IWallet;
78
+ wallet: _meshsdk_wallet.MeshCardanoBrowserWallet;
77
79
  connect: (walletName: string, persist?: boolean) => Promise<void>;
78
80
  disconnect: () => void;
79
- setWallet: (walletInstance: _meshsdk_common.IWallet, walletName: string, persist?: {
81
+ setWallet: (walletInstance: _meshsdk_wallet.ICardanoWallet, walletName: string, persist?: {
80
82
  [key: string]: any;
81
83
  }) => void;
82
84
  setPersist: (persist: boolean) => void;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as _meshsdk_common from '@meshsdk/common';
3
- import { IFetcher, ISubmitter, IWallet, Asset, Wallet } from '@meshsdk/common';
2
+ import { IFetcher, ISubmitter, AssetExtended, Wallet } from '@meshsdk/common';
4
3
  import * as _utxos_sdk from '@utxos/sdk';
5
4
  import { EnableWeb3WalletOptions, UserSocialData } from '@utxos/sdk';
6
5
  import * as react from 'react';
6
+ import * as _meshsdk_wallet from '@meshsdk/wallet';
7
+ import { MeshCardanoBrowserWallet, ICardanoWallet } from '@meshsdk/wallet';
8
+ export { CardanoBrowserWallet, CardanoHeadlessWallet, ICardanoWallet, MeshCardanoBrowserWallet, MeshCardanoHeadlessWallet } from '@meshsdk/wallet';
7
9
 
8
10
  interface ButtonProps {
9
11
  label?: string;
@@ -32,12 +34,12 @@ declare enum WalletState {
32
34
  }
33
35
  interface WalletContext {
34
36
  hasConnectedWallet: boolean;
35
- connectedWalletInstance: IWallet;
37
+ connectedWalletInstance: MeshCardanoBrowserWallet;
36
38
  connectedWalletName: string | undefined;
37
39
  connectingWallet: boolean;
38
40
  connectWallet: (walletName: string, persist?: boolean) => Promise<void>;
39
41
  disconnect: () => void;
40
- setWallet: (walletInstance: IWallet, walletName: string, persist?: {
42
+ setWallet: (walletInstance: ICardanoWallet, walletName: string, persist?: {
41
43
  [key: string]: any;
42
44
  }) => void;
43
45
  setPersist: (persist: boolean) => void;
@@ -57,7 +59,7 @@ declare const MeshProvider: React.FC<Props>;
57
59
 
58
60
  declare const useAddress: (accountId?: number) => string | undefined;
59
61
 
60
- declare const useAssets: () => Asset[] | undefined;
62
+ declare const useAssets: () => AssetExtended[] | undefined;
61
63
 
62
64
  declare const useWalletList: ({ injectFn, }?: {
63
65
  injectFn?: () => Promise<void>;
@@ -73,10 +75,10 @@ declare const useWallet: () => {
73
75
  name: string | undefined;
74
76
  connecting: boolean;
75
77
  connected: boolean;
76
- wallet: _meshsdk_common.IWallet;
78
+ wallet: _meshsdk_wallet.MeshCardanoBrowserWallet;
77
79
  connect: (walletName: string, persist?: boolean) => Promise<void>;
78
80
  disconnect: () => void;
79
- setWallet: (walletInstance: _meshsdk_common.IWallet, walletName: string, persist?: {
81
+ setWallet: (walletInstance: _meshsdk_wallet.ICardanoWallet, walletName: string, persist?: {
80
82
  [key: string]: any;
81
83
  }) => void;
82
84
  setPersist: (persist: boolean) => void;
package/dist/index.js CHANGED
@@ -179,7 +179,7 @@ import { useContext, useEffect as useEffect2, useState as useState2 } from "reac
179
179
 
180
180
  // src/contexts/WalletContext.ts
181
181
  import { createContext, useCallback, useEffect, useState } from "react";
182
- import { BrowserWallet } from "@meshsdk/wallet";
182
+ import { MeshCardanoBrowserWallet } from "@meshsdk/wallet";
183
183
  var INITIAL_STATE = {
184
184
  walletName: void 0,
185
185
  walletInstance: {}
@@ -202,8 +202,8 @@ var useWalletStore = () => {
202
202
  setConnectingWallet(true);
203
203
  setState("CONNECTING" /* CONNECTING */);
204
204
  try {
205
- const extensions = BrowserWallet.getSupportedExtensions(walletName);
206
- const walletInstance = await BrowserWallet.enable(
205
+ const extensions = globalThis?.cardano?.[walletName]?.supportedExtensions ?? [];
206
+ const walletInstance = await MeshCardanoBrowserWallet.enable(
207
207
  walletName,
208
208
  extensions
209
209
  );
@@ -235,7 +235,8 @@ var useWalletStore = () => {
235
235
  }, []);
236
236
  const setWallet = useCallback(
237
237
  async (walletInstance, walletName, persist) => {
238
- setConnectedWalletInstance(walletInstance);
238
+ const wrapped = walletInstance instanceof MeshCardanoBrowserWallet ? walletInstance : new MeshCardanoBrowserWallet(walletInstance);
239
+ setConnectedWalletInstance(wrapped);
239
240
  setConnectedWalletName(walletName);
240
241
  setState("CONNECTED" /* CONNECTED */);
241
242
  if (persist) {
@@ -253,9 +254,9 @@ var useWalletStore = () => {
253
254
  useEffect(() => {
254
255
  async function load() {
255
256
  if (Object.keys(connectedWalletInstance).length > 0 && address.length === 0) {
256
- let address2 = (await connectedWalletInstance.getUnusedAddresses())[0];
257
+ let address2 = (await connectedWalletInstance.getUnusedAddressesBech32())[0];
257
258
  if (!address2)
258
- address2 = await connectedWalletInstance.getChangeAddress();
259
+ address2 = await connectedWalletInstance.getChangeAddressBech32();
259
260
  setAddress(address2);
260
261
  }
261
262
  }
@@ -332,7 +333,7 @@ var useAddress = (accountId = 0) => {
332
333
  const { hasConnectedWallet, connectedWalletInstance } = useContext(WalletContext);
333
334
  useEffect2(() => {
334
335
  if (hasConnectedWallet) {
335
- connectedWalletInstance.getUsedAddresses().then((addresses) => {
336
+ connectedWalletInstance.getUsedAddressesBech32().then((addresses) => {
336
337
  if (addresses[accountId]) {
337
338
  setAddress(addresses[accountId]);
338
339
  }
@@ -344,12 +345,21 @@ var useAddress = (accountId = 0) => {
344
345
 
345
346
  // src/hooks/useAssets.ts
346
347
  import { useContext as useContext2, useEffect as useEffect3, useState as useState3 } from "react";
348
+ import { POLICY_ID_LENGTH, resolveFingerprint } from "@meshsdk/common";
347
349
  var useAssets = () => {
348
350
  const [assets, setAssets] = useState3();
349
351
  const { hasConnectedWallet, connectedWalletInstance } = useContext2(WalletContext);
350
352
  useEffect3(() => {
351
353
  if (hasConnectedWallet) {
352
- connectedWalletInstance.getAssets().then(setAssets);
354
+ connectedWalletInstance.getBalanceMesh().then((balance) => {
355
+ const derived = balance.filter((v) => v.unit !== "lovelace").map((v) => {
356
+ const policyId = v.unit.slice(0, POLICY_ID_LENGTH);
357
+ const assetName = v.unit.slice(POLICY_ID_LENGTH);
358
+ const fingerprint = resolveFingerprint(policyId, assetName);
359
+ return { unit: v.unit, policyId, assetName, fingerprint, quantity: v.quantity };
360
+ });
361
+ setAssets(derived);
362
+ });
353
363
  }
354
364
  }, [hasConnectedWallet, connectedWalletInstance]);
355
365
  return assets;
@@ -357,14 +367,17 @@ var useAssets = () => {
357
367
 
358
368
  // src/hooks/useWalletList.ts
359
369
  import { useEffect as useEffect4, useState as useState4 } from "react";
360
- import { BrowserWallet as BrowserWallet2 } from "@meshsdk/wallet";
370
+ import { MeshCardanoBrowserWallet as MeshCardanoBrowserWallet2 } from "@meshsdk/wallet";
361
371
  var useWalletList = ({
362
372
  injectFn = void 0
363
373
  } = {}) => {
364
374
  const [wallets, setWallets] = useState4([]);
365
375
  useEffect4(() => {
366
376
  async function get() {
367
- setWallets(await BrowserWallet2.getAvailableWallets({ injectFn }));
377
+ if (injectFn) {
378
+ await injectFn();
379
+ }
380
+ setWallets(MeshCardanoBrowserWallet2.getInstalledWallets());
368
381
  }
369
382
  get();
370
383
  }, []);
@@ -380,7 +393,9 @@ var useLovelace = () => {
380
393
  useEffect5(() => {
381
394
  async function getLovelace() {
382
395
  if (hasConnectedWallet && !hasFetchedLovelace.current) {
383
- setLovelace(await connectedWalletInstance.getLovelace());
396
+ const balance = await connectedWalletInstance.getBalanceMesh();
397
+ const lovelaceAmount = balance.find((v) => v.unit === "lovelace")?.quantity ?? "0";
398
+ setLovelace(lovelaceAmount);
384
399
  hasFetchedLovelace.current = true;
385
400
  }
386
401
  }
@@ -414,7 +429,7 @@ var useRewardAddress = (accountId = 0) => {
414
429
  const { hasConnectedWallet, connectedWalletInstance } = useContext5(WalletContext);
415
430
  useEffect7(() => {
416
431
  if (hasConnectedWallet) {
417
- connectedWalletInstance.getRewardAddresses().then((addresses) => {
432
+ connectedWalletInstance.getRewardAddressesBech32().then((addresses) => {
418
433
  if (addresses[accountId]) {
419
434
  setRewardAddress(addresses[accountId]);
420
435
  }
@@ -703,7 +718,8 @@ var screens = {
703
718
 
704
719
  // src/cardano-wallet/screen-burner.tsx
705
720
  import { useEffect as useEffect8, useState as useState9 } from "react";
706
- import { MeshWallet } from "@meshsdk/wallet";
721
+ import { generateMnemonic } from "@meshsdk/common";
722
+ import { MeshCardanoHeadlessWallet, AddressType } from "@meshsdk/wallet";
707
723
  import { Fragment as Fragment2, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
708
724
  var localstoragekey = "mesh-burnerwallet";
709
725
  function ScreenBurner({
@@ -723,34 +739,45 @@ function ScreenBurner({
723
739
  setHasKeyInStorage(true);
724
740
  }
725
741
  }, []);
726
- function createWallet(key) {
727
- setTimeout(() => {
728
- const wallet = new MeshWallet({
729
- networkId,
730
- fetcher: provider,
731
- submitter: provider,
732
- key: {
733
- type: "root",
734
- bech32: key
735
- }
736
- });
737
- if (!hasKeyInStorage) {
738
- localStorage.setItem(localstoragekey, key);
739
- }
740
- setWallet(wallet, screens.burner.title);
741
- setLoading(false);
742
- setOpen(false);
743
- }, 500);
742
+ async function createWalletFromMnemonic(mnemonic) {
743
+ const wallet = await MeshCardanoHeadlessWallet.fromMnemonic({
744
+ mnemonic,
745
+ networkId,
746
+ walletAddressType: AddressType.Base,
747
+ fetcher: provider,
748
+ submitter: provider
749
+ });
750
+ if (!hasKeyInStorage) {
751
+ localStorage.setItem(localstoragekey, mnemonic.join(" "));
752
+ }
753
+ setWallet(wallet, screens.burner.title);
754
+ setLoading(false);
755
+ setOpen(false);
744
756
  }
745
- function handleRestoreWallet() {
757
+ async function handleRestoreWallet() {
746
758
  setLoading(true);
747
- const key = getKeyFromStorage();
748
- createWallet(key);
759
+ const stored = getKeyFromStorage();
760
+ if (stored) {
761
+ if (stored.includes(" ")) {
762
+ await createWalletFromMnemonic(stored.split(" "));
763
+ } else {
764
+ const wallet = await MeshCardanoHeadlessWallet.fromBip32Root({
765
+ bech32: stored,
766
+ networkId,
767
+ walletAddressType: AddressType.Base,
768
+ fetcher: provider,
769
+ submitter: provider
770
+ });
771
+ setWallet(wallet, screens.burner.title);
772
+ setLoading(false);
773
+ setOpen(false);
774
+ }
775
+ }
749
776
  }
750
- function handleCreateWallet() {
777
+ async function handleCreateWallet() {
751
778
  setLoading(true);
752
- const key = MeshWallet.brew(true);
753
- createWallet(key);
779
+ const mnemonic = generateMnemonic(256).split(" ");
780
+ await createWalletFromMnemonic(mnemonic);
754
781
  }
755
782
  return /* @__PURE__ */ jsx7("div", { className: "mesh-flex mesh-flex-row mesh-flex-gap-4 mesh-items-center mesh-justify-center", children: loading ? /* @__PURE__ */ jsx7(Fragment2, { children: "Setting up wallet..." }) : /* @__PURE__ */ jsxs4(Fragment2, { children: [
756
783
  hasKeyInStorage && /* @__PURE__ */ jsx7(
@@ -934,6 +961,7 @@ function WalletIcon({
934
961
 
935
962
  // src/cardano-wallet/web3-services.tsx
936
963
  import { useState as useState10 } from "react";
964
+ import { MeshCardanoBrowserWallet as MeshCardanoBrowserWallet3 } from "@meshsdk/wallet";
937
965
  import {
938
966
  Web3Wallet
939
967
  } from "@utxos/sdk";
@@ -1048,11 +1076,13 @@ function Web3Services({
1048
1076
  const wallet = await Web3Wallet.enable(_options);
1049
1077
  const user = wallet.getUser();
1050
1078
  setWeb3UserData(user);
1079
+ const wrapped = new MeshCardanoBrowserWallet3(wallet.cardano);
1080
+ const walletAddress = await wrapped.getChangeAddressBech32();
1051
1081
  setWallet(
1052
- wallet.cardano,
1082
+ wrapped,
1053
1083
  "utxos",
1054
1084
  persist ? {
1055
- walletAddress: await wallet.cardano.getChangeAddress(),
1085
+ walletAddress,
1056
1086
  user
1057
1087
  } : void 0
1058
1088
  );
@@ -1103,7 +1133,7 @@ function ScreenMain({
1103
1133
  web3Services
1104
1134
  }) {
1105
1135
  const wallets = useWalletList({ injectFn });
1106
- const { connect: connect2 } = useWallet();
1136
+ const { connect } = useWallet();
1107
1137
  return /* @__PURE__ */ jsx17(TooltipProvider, { children: /* @__PURE__ */ jsxs11("div", { className: "mesh-grid mesh-gap-4 mesh-py-4 mesh-grid-cols-5 mesh-place-items-center mesh-gap-y-8", children: [
1108
1138
  wallets.map((wallet, index) => /* @__PURE__ */ jsx17(
1109
1139
  WalletIcon,
@@ -1111,7 +1141,7 @@ function ScreenMain({
1111
1141
  icon: wallet.icon,
1112
1142
  name: wallet.name,
1113
1143
  action: () => {
1114
- connect2(wallet.id, persist);
1144
+ connect(wallet.id, persist);
1115
1145
  setOpen(false);
1116
1146
  }
1117
1147
  },
@@ -1163,7 +1193,7 @@ function ScreenMain({
1163
1193
 
1164
1194
  // src/cardano-wallet/screen-webauthn.tsx
1165
1195
  import { useState as useState11 } from "react";
1166
- import { connect, MeshWallet as MeshWallet2 } from "@meshsdk/wallet";
1196
+ import { MeshCardanoHeadlessWallet as MeshCardanoHeadlessWallet2, AddressType as AddressType2 } from "@meshsdk/wallet";
1167
1197
 
1168
1198
  // src/common/input.tsx
1169
1199
  import * as React5 from "react";
@@ -1216,27 +1246,29 @@ function ScreenWebauthn({
1216
1246
  const [userName, setUserName] = useState11("");
1217
1247
  const [password, setPassword] = useState11("");
1218
1248
  const { setWallet } = useWallet();
1219
- function createWallet(root) {
1220
- setTimeout(() => {
1221
- const wallet = new MeshWallet2({
1222
- networkId,
1223
- fetcher: provider,
1224
- submitter: provider,
1225
- key: {
1226
- type: "root",
1227
- bech32: root
1228
- }
1229
- });
1230
- setWallet(wallet, screens.webauthn.title);
1231
- setLoading(false);
1232
- setOpen(false);
1233
- }, 500);
1249
+ async function createWallet(root) {
1250
+ const wallet = await MeshCardanoHeadlessWallet2.fromBip32Root({
1251
+ bech32: root,
1252
+ networkId,
1253
+ walletAddressType: AddressType2.Base,
1254
+ fetcher: provider,
1255
+ submitter: provider
1256
+ });
1257
+ setWallet(wallet, screens.webauthn.title);
1258
+ setLoading(false);
1259
+ setOpen(false);
1234
1260
  }
1235
1261
  async function handleConnect() {
1236
1262
  setLoading(true);
1237
- const res = await connect({ username: userName, password, serverUrl: url });
1238
- if (res.success && res.wallet) {
1239
- createWallet(res.wallet.bech32PrivateKey);
1263
+ const connectModule = await import("@meshsdk/wallet");
1264
+ if (typeof connectModule.connect === "function") {
1265
+ const res = await connectModule.connect({ username: userName, password, serverUrl: url });
1266
+ if (res.success && res.wallet) {
1267
+ await createWallet(res.wallet.bech32PrivateKey);
1268
+ }
1269
+ } else {
1270
+ console.error("WebAuthn connect is not available in this version of @meshsdk/wallet");
1271
+ setLoading(false);
1240
1272
  }
1241
1273
  }
1242
1274
  return /* @__PURE__ */ jsx20("div", { className: "mesh-flex mesh-flex-row mesh-flex-gap-4 mesh-items-center mesh-justify-center", children: loading ? /* @__PURE__ */ jsx20(Fragment4, { children: "Connecting wallet..." }) : /* @__PURE__ */ jsx20(Fragment4, { children: /* @__PURE__ */ jsxs12("div", { className: "mesh-flex mesh-flex-col mesh-gap-6 mesh-w-full mesh-mx-8", children: [
@@ -1429,9 +1461,21 @@ var MeshBadge = ({ isDark = false }) => /* @__PURE__ */ jsxs14(
1429
1461
  ]
1430
1462
  }
1431
1463
  );
1464
+
1465
+ // src/index.ts
1466
+ import {
1467
+ MeshCardanoBrowserWallet as MeshCardanoBrowserWallet4,
1468
+ MeshCardanoHeadlessWallet as MeshCardanoHeadlessWallet3,
1469
+ CardanoBrowserWallet,
1470
+ CardanoHeadlessWallet
1471
+ } from "@meshsdk/wallet";
1432
1472
  export {
1473
+ CardanoBrowserWallet,
1474
+ CardanoHeadlessWallet,
1433
1475
  CardanoWallet,
1434
1476
  MeshBadge,
1477
+ MeshCardanoBrowserWallet4 as MeshCardanoBrowserWallet,
1478
+ MeshCardanoHeadlessWallet3 as MeshCardanoHeadlessWallet,
1435
1479
  MeshProvider,
1436
1480
  WalletContext,
1437
1481
  useAddress,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshsdk/react",
3
- "version": "1.9.0-beta.98",
3
+ "version": "2.0.0-beta.2",
4
4
  "description": "React component library - https://meshjs.dev/react",
5
5
  "main": "./dist/index.cjs",
6
6
  "browser": "./dist/index.js",
@@ -19,8 +19,7 @@
19
19
  "dist/**"
20
20
  ],
21
21
  "scripts": {
22
- "build:mesh_old": "tsup src/index.ts --format esm,cjs --cjsInterop --dts && tailwindcss -i ./src/styles.css -o ./dist/index.css",
23
- "build:mesh": "tsup && tailwindcss -i ./src/styles.css -o ./dist/index.css",
22
+ "build": "tsup && tailwindcss -i ./src/styles.css -o ./dist/index.css",
24
23
  "dev": "concurrently \"tsup src/index.ts --format esm,cjs --watch --dts\" \"tailwindcss -i ./src/styles.css -o ./dist/index.css --watch\"",
25
24
  "clean": "rm -rf .turbo && rm -rf dist && rm -rf node_modules",
26
25
  "format": "prettier --check . --ignore-path ../../.gitignore",
@@ -30,9 +29,8 @@
30
29
  },
31
30
  "dependencies": {
32
31
  "@meshsdk/common": "1.9.0-beta.98",
33
- "@meshsdk/transaction": "1.9.0-beta.98",
34
- "@meshsdk/wallet": "1.9.0-beta.98",
35
- "@utxos/sdk": "0.1.0",
32
+ "@meshsdk/wallet": "2.0.0-beta.5",
33
+ "@utxos/sdk": "0.1.5",
36
34
  "@radix-ui/react-dialog": "^1.1.2",
37
35
  "@radix-ui/react-dropdown-menu": "^2.1.2",
38
36
  "@radix-ui/react-icons": "^1.3.2",
@@ -43,7 +41,6 @@
43
41
  "tailwindcss-animate": "^1.0.7"
44
42
  },
45
43
  "devDependencies": {
46
- "@meshsdk/configs": "*",
47
44
  "@types/react": "^18.2.61",
48
45
  "autoprefixer": "^10.4.18",
49
46
  "concurrently": "^8.0.1",
@@ -60,7 +57,6 @@
60
57
  "overrides": {
61
58
  "ip": "npm:@webpod/ip@latest"
62
59
  },
63
- "prettier": "@meshsdk/configs/prettier",
64
60
  "publishConfig": {
65
61
  "access": "public"
66
62
  },