@meshsdk/wallet 2.0.0-beta.1 → 2.0.0-beta.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/README.md CHANGED
@@ -15,7 +15,7 @@ It is possible that when querying balance for example, the same mnemonic will pr
15
15
  #### Deriving from mnemonic
16
16
 
17
17
  ```typescript
18
- const wallet = await MeshWallet.fromMnemonic({
18
+ const wallet = await MeshCardanoHeadlessWallet.fromMnemonic({
19
19
  mnemonic:
20
20
  "globe cupboard camera aim congress cradle decorate enter fringe dove margin witness police coral junk genius harbor fire evolve climb rather broccoli post snack".split(
21
21
  " "
@@ -28,11 +28,11 @@ const wallet = await MeshWallet.fromMnemonic({
28
28
  wallet.signTx(txHex);
29
29
  ```
30
30
 
31
- The `BaseCardanoWallet` mostly needs a fetcher to function properly, because when signing a txCborHex, the wallet searches through the transaction to identify which part of the wallet needs to sign the transaction. Without a fetcher, input information cannot be obtained, and signing functionality doesn't work.
31
+ The `CardanoHeadlessWallet` mostly needs a fetcher to function properly, because when signing a txCborHex, the wallet searches through the transaction to identify which part of the wallet needs to sign the transaction. Without a fetcher, input information cannot be obtained, and signing functionality doesn't work.
32
32
 
33
33
  #### Blind signing
34
34
 
35
- If you wanted to blindly sign a transaction (without first attempting to identify IF the wallet needs to sign). Then it is possible by using the more primitive classes that `BaseCardanoWallet` or `MeshWallet` was built upon.
35
+ If you wanted to blindly sign a transaction (without first attempting to identify IF the wallet needs to sign). Then it is possible by using the more primitive classes that `CardanoHeadlessWallet` or `MeshCardanoHeadlessWallet` was built upon.
36
36
 
37
37
  #### In Memory BIP32
38
38
 
@@ -74,9 +74,9 @@ const signedTx = CardanoSigner.signTx(txHex, [paymentSigner], true);
74
74
 
75
75
  #### Other derivation paths
76
76
 
77
- The `MeshWallet` class is quite good out of the box as a single address wallet, but if you wanted to use other derivation paths, it is possible, but will be slightly more cumbersome.
77
+ The `MeshCardanoHeadlessWallet` class is quite good out of the box as a single address wallet, but if you wanted to use other derivation paths, it is possible, but will be slightly more cumbersome.
78
78
 
79
- `MeshWallet` has a constructor that allows custom `payment`, `staking` and `drep` credential sources. Note that these constructors do accept `scriptHash` or `ISigner` except for `payment` key.
79
+ `MeshCardanoHeadlessWallet` has a constructor that allows custom `payment`, `staking` and `drep` credential sources. Note that these constructors do accept `scriptHash` or `ISigner` except for `payment` key.
80
80
 
81
81
  `payment` key has to be able to be used for signing, but it is fully possible to use `scriptHash` for the staking and/or drep part. The wallet will not attempt to sign with any `scriptHash` keys, but will use them to derive the `BaseAddress` and `DrepIds`.
82
82
 
@@ -89,7 +89,7 @@ const paymentSigner = await bip32.getSigner([
89
89
  5,
90
90
  ]);
91
91
 
92
- const wallet = await MeshWallet.fromCredentialSources({
92
+ const wallet = await MeshCardanoHeadlessWallet.fromCredentialSources({
93
93
  networkId: 0,
94
94
  walletAddressType: AddressType.Enterprise,
95
95
  paymentCredentialSource: {
@@ -108,7 +108,7 @@ const paymentSigner = BaseSigner.fromNormalKeyHex(
108
108
  "d4ffb1e83d44b66849b4f16183cbf2ba1358c491cfeb39f0b66b5f811a88f182"
109
109
  );
110
110
 
111
- const wallet = await MeshWallet.fromCredentialSources({
111
+ const wallet = await MeshCardanoHeadlessWallet.fromCredentialSources({
112
112
  networkId: 0,
113
113
  walletAddressType: AddressType.Enterprise,
114
114
  paymentCredentialSource: {
@@ -118,12 +118,82 @@ const wallet = await MeshWallet.fromCredentialSources({
118
118
  });
119
119
  ```
120
120
 
121
- ## BaseCardanoWallet vs MeshWallet
121
+ ## CardanoHeadlessWallet vs MeshCardanoHeadlessWallet
122
122
 
123
- The `BaseCardanoWallet` class acts as the underlying CIP-30 compatible wallet implementation. It attempts to adhere to the available APIs and return types defined in CIP-30.
123
+ The `CardanoHeadlessWallet` class acts as the underlying CIP-30 compatible wallet implementation. It attempts to adhere to the available APIs and return types defined in CIP-30.
124
124
 
125
125
  However, due to our experiences with Cardano development, the return types defined in CIP-30 are all in a very inconvenient format. Everything is returned in CBOR hex format, which is not very useful in its raw format, and generally has to be parsed using a serialization library to obtain it in a more readily consumable format.
126
126
 
127
- `MeshWallet` is an attempt to extend the `BaseCardanoWallet` in such a way that there are extra endpoints that do this parsing of the CBOR hex returns in a more readibly consumable way.
127
+ `MeshCardanoHeadlessWallet` is an attempt to extend the `CardanoHeadlessWallet` in such a way that there are extra endpoints that do this parsing of the CBOR hex returns in a more readibly consumable way.
128
128
 
129
129
  Probably the most relevant of these APIs would be the difference between `signTx` and `signTxReturnFullTx`. As the name of the API suggests, `signTxReturnFullTx` returns the transaction in FULL, with the extra vkey witnesses placed into the witness set. While `signTx` returns the signatures serialized in a transaction witness set, which requires extra manipulation using a serialization library to place the signatures in the transaction's witness set before it can be submitted.
130
+
131
+ ## CIP-30
132
+
133
+ Once a MeshCardanoHeadlessWallet is set up, it is possible to use it as an instance of a CIP-30 wallet.
134
+
135
+ ```typescript
136
+ const meshCardanoHeadlessWallet = await MeshCardanoHeadlessWallet.fromMnemonic({
137
+ networkId: 0,
138
+ walletAddressType: AddressType.Base,
139
+ mnemonic: mnemonic,
140
+ fetcher: fetcher,
141
+ });
142
+
143
+ const meshCardanoHeadlessWalletBalance = await meshCardanoHeadlessWallet.getBalance();
144
+ const meshCardanoHeadlessWalletChangeAddress = await meshCardanoHeadlessWallet.getChangeAddress();
145
+ const meshCardanoHeadlessWalletNetworkId = await meshCardanoHeadlessWallet.getNetworkId();
146
+ const meshCardanoHeadlessWalletCollateral = await meshCardanoHeadlessWallet.getCollateral();
147
+ const meshCardanoHeadlessWalletUtxos = await meshCardanoHeadlessWallet.getUtxos();
148
+ const meshCardanoHeadlessWalletRewardAddresses = await meshCardanoHeadlessWallet.getRewardAddresses();
149
+
150
+ const meshCardanoHeadlessWalletsignedData = await meshCardanoHeadlessWallet.signData(
151
+ meshCardanoHeadlessWalletChangeAddress,
152
+ "abc"
153
+ );
154
+ const signature = await meshCardanoHeadlessWallet.signTx(transactionHex, true);
155
+ ```
156
+
157
+ ## Browser Wallet
158
+
159
+ `mesh-wallet` provides a class that helps with setting up Cardano Browser wallets.
160
+
161
+ Once enabled, the wallet object can be used the same way as a MeshCardanoHeadlessWallet.
162
+
163
+ ```typescript
164
+ const browserWallet = await CardanoBrowserWallet.enable("eternl");
165
+
166
+ const browserBalance = await browserWallet.getBalance();
167
+ const browserChangeAddress = await browserWallet.getChangeAddress();
168
+ const browserCollateral = await browserWallet.getCollateral();
169
+ const browserUtxos = await browserWallet.getUtxos();
170
+ const browserNetworkId = await browserWallet.getNetworkId();
171
+ const browserRewardAddresses = await browserWallet.getRewardAddresses();
172
+
173
+ const browserSignedData = await browserWallet.signData(
174
+ meshCardanoHeadlessWalletChangeAddress,
175
+ "abc"
176
+ );
177
+ const signature = await browserWallet.signTx(transactionHex, true);
178
+ ```
179
+
180
+ ## Mesh Browser Wallet
181
+
182
+ `mesh-wallet` also provides a wrapper class around `CardanoBrowserWallet` called `MeshCardanoBrowserWallet` that implements all the convenient return types that might be easier to consume immediately.
183
+
184
+ ```typescript
185
+ const meshCardanoBrowserWallet = await MeshCardanoBrowserWallet.enable("eternl");
186
+
187
+ const browserBalance = await meshCardanoBrowserWallet.getBalanceMesh();
188
+ const browserChangeAddress = await meshCardanoBrowserWallet.getChangeAddressBech32();
189
+ const browserCollateral = await meshCardanoBrowserWallet.getCollateralMesh();
190
+ const browserUtxos = await meshCardanoBrowserWallet.getUtxosMesh();
191
+ const browserNetworkId = await meshCardanoBrowserWallet.getNetworkId();
192
+ const browserRewardAddresses =
193
+ await meshCardanoBrowserWallet.getRewardAddressesBech32();
194
+
195
+ const signedTx = await meshCardanoBrowserWallet.signTxReturnFullTx(
196
+ transactionHex,
197
+ true
198
+ );
199
+ ```