@meshsdk/wallet 1.9.0 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +226 -3
- package/dist/index.cjs +5631 -1491
- package/dist/index.d.ts +1072 -615
- package/dist/index.js +6441 -1774
- package/package.json +32 -10
- package/dist/index.d.cts +0 -802
package/README.md
CHANGED
|
@@ -1,5 +1,228 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @meshsdk/wallet
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Cardano wallet library for signing transactions, managing keys, and interacting with browser wallets. Provides both headless (server-side / Node.js) and browser wallet support with a CIP-30 compatible interface.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
```bash
|
|
6
|
+
npm install @meshsdk/wallet
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
> **Migrating from v1 (`MeshWallet` or `BrowserWallet`)?** This version has breaking changes. See:
|
|
10
|
+
> - [`mesh-wallet-migration.md`](./mesh-wallet-migration.md) — for `MeshWallet` to `MeshCardanoHeadlessWallet`
|
|
11
|
+
> - [`browser-wallet-migration.md`](./browser-wallet-migration.md) — for `BrowserWallet` to `MeshCardanoBrowserWallet`
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Table of Contents
|
|
16
|
+
|
|
17
|
+
- [Architecture Overview](#architecture-overview)
|
|
18
|
+
- [Exported Classes](#exported-classes)
|
|
19
|
+
- [Headless Wallet (Server-Side)](#headless-wallet-server-side)
|
|
20
|
+
- [Browser Wallet (Client-Side)](#browser-wallet-client-side)
|
|
21
|
+
- [Low-Level Components](#low-level-components)
|
|
22
|
+
- [CIP-30 Compatibility](#cip-30-compatibility)
|
|
23
|
+
- [CardanoHeadlessWallet vs MeshCardanoHeadlessWallet](#cardanoheadlesswallet-vs-meshcardanoheadlesswallet)
|
|
24
|
+
- [Migration from v1](#migration-from-v1)
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Architecture Overview
|
|
29
|
+
|
|
30
|
+
This package uses a two-tier class hierarchy for both headless and browser wallets:
|
|
31
|
+
|
|
32
|
+
- **Base classes** (`CardanoHeadlessWallet`, `CardanoBrowserWallet`) implement the CIP-30 interface strictly — all methods return raw hex/CBOR exactly as CIP-30 specifies.
|
|
33
|
+
- **Mesh classes** (`MeshCardanoHeadlessWallet`, `MeshCardanoBrowserWallet`) extend the base classes with convenience methods (`*Bech32()`, `*Mesh()`, `signTxReturnFullTx()`) that return human-friendly formats.
|
|
34
|
+
|
|
35
|
+
**For most use cases, use the Mesh classes.** The base classes are for advanced users who need raw CIP-30 output.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Exported Classes
|
|
40
|
+
|
|
41
|
+
| Class | Purpose | Use When |
|
|
42
|
+
|-------|---------|----------|
|
|
43
|
+
| `MeshCardanoHeadlessWallet` | Full-featured headless wallet with convenience methods | Server-side signing, backend transaction building, testing |
|
|
44
|
+
| `CardanoHeadlessWallet` | CIP-30 strict headless wallet (raw hex/CBOR returns) | You need raw CIP-30 output without conversion |
|
|
45
|
+
| `MeshCardanoBrowserWallet` | Full-featured browser wallet wrapper with convenience methods | dApp frontend integration with browser wallets (Eternl, Nami, etc.) |
|
|
46
|
+
| `CardanoBrowserWallet` | CIP-30 strict browser wallet wrapper (raw hex/CBOR returns) | You need raw CIP-30 passthrough from browser wallets |
|
|
47
|
+
| `InMemoryBip32` | BIP32 key derivation from mnemonic (keys stored in memory) | Deriving payment/stake/DRep keys from a mnemonic |
|
|
48
|
+
| `BaseSigner` | Ed25519 signer from raw private keys | Signing with raw private keys (normal or extended) |
|
|
49
|
+
| `CardanoAddress` | Cardano address construction and utilities | Building addresses from credentials |
|
|
50
|
+
| `ICardanoWallet` | Interface definition for Cardano wallets | Type-checking and implementing custom wallets |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Headless Wallet (Server-Side)
|
|
55
|
+
|
|
56
|
+
### Create from Mnemonic
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { MeshCardanoHeadlessWallet, AddressType } from "@meshsdk/wallet";
|
|
60
|
+
|
|
61
|
+
const wallet = await MeshCardanoHeadlessWallet.fromMnemonic({
|
|
62
|
+
mnemonic: "globe cupboard camera ...".split(" "),
|
|
63
|
+
networkId: 0,
|
|
64
|
+
walletAddressType: AddressType.Base,
|
|
65
|
+
fetcher: fetcher,
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The `fetcher` is needed for signing transactions — the wallet uses it to look up input information to determine which keys need to sign. Without a fetcher, signing will not work.
|
|
70
|
+
|
|
71
|
+
### Create from Raw Private Key
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { MeshCardanoHeadlessWallet, AddressType, BaseSigner } from "@meshsdk/wallet";
|
|
75
|
+
|
|
76
|
+
const paymentSigner = BaseSigner.fromNormalKeyHex(
|
|
77
|
+
"d4ffb1e83d44b66849b4f16183cbf2ba1358c491cfeb39f0b66b5f811a88f182"
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const wallet = await MeshCardanoHeadlessWallet.fromCredentialSources({
|
|
81
|
+
networkId: 0,
|
|
82
|
+
walletAddressType: AddressType.Enterprise,
|
|
83
|
+
paymentCredentialSource: {
|
|
84
|
+
type: "signer",
|
|
85
|
+
signer: paymentSigner,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Sign a Transaction
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// Returns the full signed transaction (ready to submit)
|
|
94
|
+
const signedTx = await wallet.signTxReturnFullTx(unsignedTxHex);
|
|
95
|
+
|
|
96
|
+
// Returns only the witness set CBOR (for partial signing workflows)
|
|
97
|
+
const witnessSet = await wallet.signTx(unsignedTxHex);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Custom Derivation Paths
|
|
101
|
+
|
|
102
|
+
Use `InMemoryBip32` directly for custom key derivation:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { InMemoryBip32 } from "@meshsdk/wallet";
|
|
106
|
+
|
|
107
|
+
const HARDENED_OFFSET = 0x80000000;
|
|
108
|
+
const bip32 = await InMemoryBip32.fromMnemonic(
|
|
109
|
+
"globe cupboard camera ...".split(" ")
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const paymentSigner = await bip32.getSigner([
|
|
113
|
+
1852 + HARDENED_OFFSET,
|
|
114
|
+
1815 + HARDENED_OFFSET,
|
|
115
|
+
0 + HARDENED_OFFSET,
|
|
116
|
+
0,
|
|
117
|
+
5, // key index 5
|
|
118
|
+
]);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Blind Signing with CardanoSigner
|
|
122
|
+
|
|
123
|
+
For signing without wallet-level input resolution:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { CardanoSigner } from "@meshsdk/wallet";
|
|
127
|
+
|
|
128
|
+
// Returns witness set CBOR
|
|
129
|
+
const txWitnessSet = CardanoSigner.signTx(txHex, [paymentSigner]);
|
|
130
|
+
|
|
131
|
+
// Returns full signed transaction CBOR
|
|
132
|
+
const signedTx = CardanoSigner.signTx(txHex, [paymentSigner], true);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Browser Wallet (Client-Side)
|
|
138
|
+
|
|
139
|
+
### Enable a Browser Wallet
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { MeshCardanoBrowserWallet } from "@meshsdk/wallet";
|
|
143
|
+
|
|
144
|
+
const wallet = await MeshCardanoBrowserWallet.enable("eternl");
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### List Installed Wallets
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
const wallets = MeshCardanoBrowserWallet.getInstalledWallets();
|
|
151
|
+
// Returns: Array<{ id, name, icon, version }>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Common Operations
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
const balance = await wallet.getBalanceMesh(); // Asset[]
|
|
158
|
+
const address = await wallet.getChangeAddressBech32(); // bech32 string
|
|
159
|
+
const utxos = await wallet.getUtxosMesh(); // UTxO[]
|
|
160
|
+
const collateral = await wallet.getCollateralMesh(); // UTxO[]
|
|
161
|
+
const networkId = await wallet.getNetworkId(); // number
|
|
162
|
+
const rewards = await wallet.getRewardAddressesBech32(); // string[]
|
|
163
|
+
|
|
164
|
+
// Sign and get the full transaction back (ready to submit)
|
|
165
|
+
const signedTx = await wallet.signTxReturnFullTx(unsignedTxHex, partialSign);
|
|
166
|
+
|
|
167
|
+
// Sign data
|
|
168
|
+
const signature = await wallet.signData(addressBech32, hexPayload);
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Low-Level Components
|
|
174
|
+
|
|
175
|
+
### InMemoryBip32
|
|
176
|
+
|
|
177
|
+
Derives Ed25519 signing keys from a BIP39 mnemonic. Keys are held in memory. You can implement your own `Bip32` class (e.g., HSM-backed) as long as it satisfies the same interface.
|
|
178
|
+
|
|
179
|
+
### BaseSigner
|
|
180
|
+
|
|
181
|
+
Creates signers from raw Ed25519 private keys:
|
|
182
|
+
|
|
183
|
+
- `BaseSigner.fromNormalKeyHex(hex)` — from a 32-byte normal private key
|
|
184
|
+
- `BaseSigner.fromExtendedKeyHex(hex)` — from a 64-byte extended private key
|
|
185
|
+
|
|
186
|
+
### CardanoSigner
|
|
187
|
+
|
|
188
|
+
Signs Cardano transactions given an array of `ISigner` instances. Can return either a witness set or the full signed transaction.
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## CIP-30 Compatibility
|
|
193
|
+
|
|
194
|
+
Both `MeshCardanoHeadlessWallet` and `MeshCardanoBrowserWallet` provide CIP-30 compatible methods: `getBalance`, `getChangeAddress`, `getNetworkId`, `getCollateral`, `getUtxos`, `getRewardAddresses`, `signTx`, `signData`, `submitTx`.
|
|
195
|
+
|
|
196
|
+
**Important caveat for headless wallets:** The headless wallet simulates CIP-30 using a data provider (e.g., Blockfrost). It does not perform key derivation across multiple indices — it only derives keys at index 0 on all derivation paths (payment, stake, DRep). This means `getBalance` or `getUtxos` may return different results than a real browser wallet using the same mnemonic, since real wallets index multiple key derivations.
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## CardanoHeadlessWallet vs MeshCardanoHeadlessWallet
|
|
201
|
+
|
|
202
|
+
`CardanoHeadlessWallet` adheres strictly to CIP-30 return types — everything comes back as CBOR hex, which requires a serialization library to parse.
|
|
203
|
+
|
|
204
|
+
`MeshCardanoHeadlessWallet` extends it with convenience methods:
|
|
205
|
+
|
|
206
|
+
| Need | Base method (hex/CBOR) | Mesh method (parsed) |
|
|
207
|
+
|------|----------------------|---------------------|
|
|
208
|
+
| Balance | `getBalance()` → CBOR hex | `getBalanceMesh()` → `Asset[]` |
|
|
209
|
+
| Address | `getChangeAddress()` → hex | `getChangeAddressBech32()` → bech32 |
|
|
210
|
+
| UTxOs | `getUtxos()` → CBOR hex[] | `getUtxosMesh()` → `UTxO[]` |
|
|
211
|
+
| Sign tx | `signTx()` → witness set | `signTxReturnFullTx()` → full signed tx |
|
|
212
|
+
|
|
213
|
+
The same pattern applies to `CardanoBrowserWallet` vs `MeshCardanoBrowserWallet`.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Migration from v1
|
|
218
|
+
|
|
219
|
+
This package (`@meshsdk/wallet` v2) has breaking changes from the previous `MeshWallet` and `BrowserWallet` classes.
|
|
220
|
+
|
|
221
|
+
**Do not attempt to upgrade without reading the migration guides.** Key breaking changes include renamed classes, swapped method parameters, changed return types, and removed methods. Many changes compile without errors but fail silently at runtime.
|
|
222
|
+
|
|
223
|
+
| Migrating from | Migrating to | Guide |
|
|
224
|
+
|----------------|-------------|-------|
|
|
225
|
+
| `MeshWallet` (from `@meshsdk/wallet` or `@meshsdk/core`) | `MeshCardanoHeadlessWallet` | [`mesh-wallet-migration.md`](./mesh-wallet-migration.md) |
|
|
226
|
+
| `BrowserWallet` (from `@meshsdk/wallet` or `@meshsdk/core`) | `MeshCardanoBrowserWallet` | [`browser-wallet-migration.md`](./browser-wallet-migration.md) |
|
|
227
|
+
|
|
228
|
+
The migration guides are written for both human developers and LLM agents — they contain deterministic SEARCH/REPLACE patterns that can be applied file-by-file.
|