@lucid-evolution/wallet 0.1.7 → 0.1.9

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/dist/index.cjs CHANGED
@@ -41,7 +41,11 @@ module.exports = __toCommonJS(src_exports);
41
41
  // src/wallet.ts
42
42
  var import_utils = require("@lucid-evolution/utils");
43
43
  var import_core_utils = require("@lucid-evolution/core-utils");
44
+
45
+ // src/core.ts
44
46
  var CML = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
47
+
48
+ // src/wallet.ts
45
49
  var import_bip39 = require("@lucid-evolution/bip39");
46
50
  function walletFromSeed(seed, options = { addressType: "Base", accountIndex: 0, network: "Mainnet" }) {
47
51
  function harden(num) {
@@ -55,6 +59,7 @@ function walletFromSeed(seed, options = { addressType: "Base", accountIndex: 0,
55
59
  options.password ? new TextEncoder().encode(options.password) : new Uint8Array()
56
60
  );
57
61
  const accountKey = rootKey.derive(harden(1852)).derive(harden(1815)).derive(harden(options.accountIndex));
62
+ rootKey.free();
58
63
  const paymentKey = accountKey.derive(0).derive(0).to_raw_key();
59
64
  const stakeKey = accountKey.derive(2).derive(0).to_raw_key();
60
65
  const paymentKeyHash = paymentKey.to_public().hash();
@@ -224,7 +229,6 @@ function discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, ownUtxos) {
224
229
  // src/wallet_selection.ts
225
230
  var import_core_utils2 = require("@lucid-evolution/core-utils");
226
231
  var import_utils2 = require("@lucid-evolution/utils");
227
- var CML2 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
228
232
  var import_sign_data = require("@lucid-evolution/sign_data");
229
233
  var makeWalletFromSeed = (provider, network, seed, options) => {
230
234
  const { address, rewardAddress, paymentKey, stakeKey } = walletFromSeed(
@@ -236,8 +240,8 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
236
240
  network
237
241
  }
238
242
  );
239
- const paymentKeyHash = CML2.PrivateKey.from_bech32(paymentKey).to_public().hash().to_hex();
240
- const stakeKeyHash = stakeKey ? CML2.PrivateKey.from_bech32(stakeKey).to_public().hash().to_hex() : "";
243
+ const paymentKeyHash = CML.PrivateKey.from_bech32(paymentKey).to_public().hash().to_hex();
244
+ const stakeKeyHash = stakeKey ? CML.PrivateKey.from_bech32(stakeKey).to_public().hash().to_hex() : "";
241
245
  const privKeyHashMap = {
242
246
  [paymentKeyHash]: paymentKey,
243
247
  [stakeKeyHash]: stakeKey
@@ -261,11 +265,11 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
261
265
  const utxos = await provider.getUtxos(address);
262
266
  const ownKeyHashes = [paymentKeyHash, stakeKeyHash];
263
267
  const usedKeyHashes = discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, utxos);
264
- const txWitnessSetBuilder = CML2.TransactionWitnessSetBuilder.new();
268
+ const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
265
269
  for (const keyHash of usedKeyHashes) {
266
- const priv = CML2.PrivateKey.from_bech32(privKeyHashMap[keyHash]);
267
- const witness = CML2.make_vkey_witness(
268
- CML2.hash_transaction(tx.body()),
270
+ const priv = CML.PrivateKey.from_bech32(privKeyHashMap[keyHash]);
271
+ const witness = CML.make_vkey_witness(
272
+ CML.hash_transaction(tx.body()),
269
273
  priv
270
274
  );
271
275
  txWitnessSetBuilder.add_vkey(witness);
@@ -291,11 +295,11 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
291
295
  };
292
296
  };
293
297
  var makeWalletFromPrivateKey = (provider, network, privateKey) => {
294
- const priv = CML2.PrivateKey.from_bech32(privateKey);
298
+ const priv = CML.PrivateKey.from_bech32(privateKey);
295
299
  const pubKeyHash = priv.to_public().hash();
296
- const address = CML2.EnterpriseAddress.new(
300
+ const address = CML.EnterpriseAddress.new(
297
301
  network === "Mainnet" ? 1 : 0,
298
- CML2.Credential.new_pub_key(pubKeyHash)
302
+ CML.Credential.new_pub_key(pubKeyHash)
299
303
  ).to_address().to_bech32(void 0);
300
304
  return {
301
305
  address: async () => address,
@@ -316,8 +320,8 @@ var makeWalletFromPrivateKey = (provider, network, privateKey) => {
316
320
  },
317
321
  signTx: async (tx) => {
318
322
  const signed = priv.sign(tx.to_cbor_bytes());
319
- const witness = CML2.Vkeywitness.new(priv.to_public(), signed);
320
- const txWitnessSetBuilder = CML2.TransactionWitnessSetBuilder.new();
323
+ const witness = CML.Vkeywitness.new(priv.to_public(), signed);
324
+ const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
321
325
  txWitnessSetBuilder.add_vkey(witness);
322
326
  return txWitnessSetBuilder.build();
323
327
  },
@@ -348,15 +352,15 @@ var makeWalletFromAPI = (provider, api) => {
348
352
  };
349
353
  const getRewardAddress = async () => {
350
354
  const [rewardAddressHex] = await api.getRewardAddresses();
351
- const rewardAddress = rewardAddressHex ? CML2.RewardAddress.from_address(CML2.Address.from_hex(rewardAddressHex)).to_address().to_bech32(void 0) : null;
355
+ const rewardAddress = rewardAddressHex ? CML.RewardAddress.from_address(CML.Address.from_hex(rewardAddressHex)).to_address().to_bech32(void 0) : null;
352
356
  return rewardAddress;
353
357
  };
354
358
  return {
355
- address: async () => CML2.Address.from_hex(await getAddressHex()).to_bech32(void 0),
359
+ address: async () => CML.Address.from_hex(await getAddressHex()).to_bech32(void 0),
356
360
  rewardAddress: async () => getRewardAddress(),
357
361
  getUtxos: async () => {
358
362
  const utxos = (await api.getUtxos() || []).map((utxo) => {
359
- const parsedUtxo = CML2.TransactionUnspentOutput.from_cbor_bytes(
363
+ const parsedUtxo = CML.TransactionUnspentOutput.from_cbor_bytes(
360
364
  (0, import_core_utils2.fromHex)(utxo)
361
365
  );
362
366
  return (0, import_utils2.coreToUtxo)(parsedUtxo);
@@ -366,7 +370,7 @@ var makeWalletFromAPI = (provider, api) => {
366
370
  getUtxosCore: async () => {
367
371
  const utxos = [];
368
372
  (await api.getUtxos() || []).forEach((utxo) => {
369
- utxos.push(CML2.TransactionUnspentOutput.from_cbor_hex(utxo));
373
+ utxos.push(CML.TransactionUnspentOutput.from_cbor_hex(utxo));
370
374
  });
371
375
  return utxos;
372
376
  },
@@ -376,10 +380,10 @@ var makeWalletFromAPI = (provider, api) => {
376
380
  },
377
381
  signTx: async (tx) => {
378
382
  const witnessSet = await api.signTx((0, import_core_utils2.toHex)(tx.to_cbor_bytes()), true);
379
- return CML2.TransactionWitnessSet.from_cbor_hex(witnessSet);
383
+ return CML.TransactionWitnessSet.from_cbor_hex(witnessSet);
380
384
  },
381
385
  signMessage: async (address, payload) => {
382
- const hexAddress = (0, import_core_utils2.toHex)(CML2.Address.from_bech32(address).to_raw_bytes());
386
+ const hexAddress = (0, import_core_utils2.toHex)(CML.Address.from_bech32(address).to_raw_bytes());
383
387
  return await api.signData(hexAddress, payload);
384
388
  },
385
389
  submitTx: async (tx) => {
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  // src/wallet.ts
2
2
  import { getAddressDetails } from "@lucid-evolution/utils";
3
3
  import { fromHex } from "@lucid-evolution/core-utils";
4
+
5
+ // src/core.ts
4
6
  import * as CML from "@dcspark/cardano-multiplatform-lib-nodejs";
7
+
8
+ // src/wallet.ts
5
9
  import { mnemonicToEntropy } from "@lucid-evolution/bip39";
6
10
  function walletFromSeed(seed, options = { addressType: "Base", accountIndex: 0, network: "Mainnet" }) {
7
11
  function harden(num) {
@@ -15,6 +19,7 @@ function walletFromSeed(seed, options = { addressType: "Base", accountIndex: 0,
15
19
  options.password ? new TextEncoder().encode(options.password) : new Uint8Array()
16
20
  );
17
21
  const accountKey = rootKey.derive(harden(1852)).derive(harden(1815)).derive(harden(options.accountIndex));
22
+ rootKey.free();
18
23
  const paymentKey = accountKey.derive(0).derive(0).to_raw_key();
19
24
  const stakeKey = accountKey.derive(2).derive(0).to_raw_key();
20
25
  const paymentKeyHash = paymentKey.to_public().hash();
@@ -189,7 +194,6 @@ import {
189
194
  paymentCredentialOf,
190
195
  utxoToCore
191
196
  } from "@lucid-evolution/utils";
192
- import * as CML2 from "@dcspark/cardano-multiplatform-lib-nodejs";
193
197
  import { signData } from "@lucid-evolution/sign_data";
194
198
  var makeWalletFromSeed = (provider, network, seed, options) => {
195
199
  const { address, rewardAddress, paymentKey, stakeKey } = walletFromSeed(
@@ -201,8 +205,8 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
201
205
  network
202
206
  }
203
207
  );
204
- const paymentKeyHash = CML2.PrivateKey.from_bech32(paymentKey).to_public().hash().to_hex();
205
- const stakeKeyHash = stakeKey ? CML2.PrivateKey.from_bech32(stakeKey).to_public().hash().to_hex() : "";
208
+ const paymentKeyHash = CML.PrivateKey.from_bech32(paymentKey).to_public().hash().to_hex();
209
+ const stakeKeyHash = stakeKey ? CML.PrivateKey.from_bech32(stakeKey).to_public().hash().to_hex() : "";
206
210
  const privKeyHashMap = {
207
211
  [paymentKeyHash]: paymentKey,
208
212
  [stakeKeyHash]: stakeKey
@@ -226,11 +230,11 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
226
230
  const utxos = await provider.getUtxos(address);
227
231
  const ownKeyHashes = [paymentKeyHash, stakeKeyHash];
228
232
  const usedKeyHashes = discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, utxos);
229
- const txWitnessSetBuilder = CML2.TransactionWitnessSetBuilder.new();
233
+ const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
230
234
  for (const keyHash of usedKeyHashes) {
231
- const priv = CML2.PrivateKey.from_bech32(privKeyHashMap[keyHash]);
232
- const witness = CML2.make_vkey_witness(
233
- CML2.hash_transaction(tx.body()),
235
+ const priv = CML.PrivateKey.from_bech32(privKeyHashMap[keyHash]);
236
+ const witness = CML.make_vkey_witness(
237
+ CML.hash_transaction(tx.body()),
234
238
  priv
235
239
  );
236
240
  txWitnessSetBuilder.add_vkey(witness);
@@ -256,11 +260,11 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
256
260
  };
257
261
  };
258
262
  var makeWalletFromPrivateKey = (provider, network, privateKey) => {
259
- const priv = CML2.PrivateKey.from_bech32(privateKey);
263
+ const priv = CML.PrivateKey.from_bech32(privateKey);
260
264
  const pubKeyHash = priv.to_public().hash();
261
- const address = CML2.EnterpriseAddress.new(
265
+ const address = CML.EnterpriseAddress.new(
262
266
  network === "Mainnet" ? 1 : 0,
263
- CML2.Credential.new_pub_key(pubKeyHash)
267
+ CML.Credential.new_pub_key(pubKeyHash)
264
268
  ).to_address().to_bech32(void 0);
265
269
  return {
266
270
  address: async () => address,
@@ -281,8 +285,8 @@ var makeWalletFromPrivateKey = (provider, network, privateKey) => {
281
285
  },
282
286
  signTx: async (tx) => {
283
287
  const signed = priv.sign(tx.to_cbor_bytes());
284
- const witness = CML2.Vkeywitness.new(priv.to_public(), signed);
285
- const txWitnessSetBuilder = CML2.TransactionWitnessSetBuilder.new();
288
+ const witness = CML.Vkeywitness.new(priv.to_public(), signed);
289
+ const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
286
290
  txWitnessSetBuilder.add_vkey(witness);
287
291
  return txWitnessSetBuilder.build();
288
292
  },
@@ -313,15 +317,15 @@ var makeWalletFromAPI = (provider, api) => {
313
317
  };
314
318
  const getRewardAddress = async () => {
315
319
  const [rewardAddressHex] = await api.getRewardAddresses();
316
- const rewardAddress = rewardAddressHex ? CML2.RewardAddress.from_address(CML2.Address.from_hex(rewardAddressHex)).to_address().to_bech32(void 0) : null;
320
+ const rewardAddress = rewardAddressHex ? CML.RewardAddress.from_address(CML.Address.from_hex(rewardAddressHex)).to_address().to_bech32(void 0) : null;
317
321
  return rewardAddress;
318
322
  };
319
323
  return {
320
- address: async () => CML2.Address.from_hex(await getAddressHex()).to_bech32(void 0),
324
+ address: async () => CML.Address.from_hex(await getAddressHex()).to_bech32(void 0),
321
325
  rewardAddress: async () => getRewardAddress(),
322
326
  getUtxos: async () => {
323
327
  const utxos = (await api.getUtxos() || []).map((utxo) => {
324
- const parsedUtxo = CML2.TransactionUnspentOutput.from_cbor_bytes(
328
+ const parsedUtxo = CML.TransactionUnspentOutput.from_cbor_bytes(
325
329
  fromHex2(utxo)
326
330
  );
327
331
  return coreToUtxo(parsedUtxo);
@@ -331,7 +335,7 @@ var makeWalletFromAPI = (provider, api) => {
331
335
  getUtxosCore: async () => {
332
336
  const utxos = [];
333
337
  (await api.getUtxos() || []).forEach((utxo) => {
334
- utxos.push(CML2.TransactionUnspentOutput.from_cbor_hex(utxo));
338
+ utxos.push(CML.TransactionUnspentOutput.from_cbor_hex(utxo));
335
339
  });
336
340
  return utxos;
337
341
  },
@@ -341,10 +345,10 @@ var makeWalletFromAPI = (provider, api) => {
341
345
  },
342
346
  signTx: async (tx) => {
343
347
  const witnessSet = await api.signTx(toHex(tx.to_cbor_bytes()), true);
344
- return CML2.TransactionWitnessSet.from_cbor_hex(witnessSet);
348
+ return CML.TransactionWitnessSet.from_cbor_hex(witnessSet);
345
349
  },
346
350
  signMessage: async (address, payload) => {
347
- const hexAddress = toHex(CML2.Address.from_bech32(address).to_raw_bytes());
351
+ const hexAddress = toHex(CML.Address.from_bech32(address).to_raw_bytes());
348
352
  return await api.signData(hexAddress, payload);
349
353
  },
350
354
  submitTx: async (tx) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/wallet",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -21,13 +21,16 @@
21
21
  "keywords": [],
22
22
  "author": "",
23
23
  "license": "MIT",
24
+ "browser": {
25
+ "@dcspark/cardano-multiplatform-lib-nodejs": "@dcspark/cardano-multiplatform-lib-browser"
26
+ },
24
27
  "dependencies": {
25
28
  "@dcspark/cardano-multiplatform-lib-nodejs": "^5.3.0",
26
- "@lucid-evolution/bip39": "0.2.6",
27
- "@lucid-evolution/core-types": "0.1.5",
28
- "@lucid-evolution/core-utils": "0.1.5",
29
- "@lucid-evolution/sign_data": "0.1.5",
30
- "@lucid-evolution/utils": "0.1.7"
29
+ "@lucid-evolution/bip39": "0.2.7",
30
+ "@lucid-evolution/core-types": "0.1.6",
31
+ "@lucid-evolution/core-utils": "0.1.6",
32
+ "@lucid-evolution/sign_data": "0.1.6",
33
+ "@lucid-evolution/utils": "0.1.9"
31
34
  },
32
35
  "devDependencies": {
33
36
  "@types/node": "^20.12.8",
@@ -35,7 +38,7 @@
35
38
  "typescript": "^5.4.5"
36
39
  },
37
40
  "scripts": {
38
- "build": "tsup-node src/index.ts --format esm,cjs --dts --clean",
41
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
39
42
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
40
43
  }
41
44
  }