@lucid-evolution/wallet 0.1.7 → 0.1.8
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 +22 -18
- package/dist/index.js +22 -18
- package/package.json +2 -2
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 =
|
|
240
|
-
const stakeKeyHash = stakeKey ?
|
|
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 =
|
|
268
|
+
const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
|
|
265
269
|
for (const keyHash of usedKeyHashes) {
|
|
266
|
-
const priv =
|
|
267
|
-
const witness =
|
|
268
|
-
|
|
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 =
|
|
298
|
+
const priv = CML.PrivateKey.from_bech32(privateKey);
|
|
295
299
|
const pubKeyHash = priv.to_public().hash();
|
|
296
|
-
const address =
|
|
300
|
+
const address = CML.EnterpriseAddress.new(
|
|
297
301
|
network === "Mainnet" ? 1 : 0,
|
|
298
|
-
|
|
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 =
|
|
320
|
-
const txWitnessSetBuilder =
|
|
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 ?
|
|
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 () =>
|
|
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 =
|
|
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(
|
|
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
|
|
383
|
+
return CML.TransactionWitnessSet.from_cbor_hex(witnessSet);
|
|
380
384
|
},
|
|
381
385
|
signMessage: async (address, payload) => {
|
|
382
|
-
const hexAddress = (0, import_core_utils2.toHex)(
|
|
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 =
|
|
205
|
-
const stakeKeyHash = stakeKey ?
|
|
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 =
|
|
233
|
+
const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
|
|
230
234
|
for (const keyHash of usedKeyHashes) {
|
|
231
|
-
const priv =
|
|
232
|
-
const witness =
|
|
233
|
-
|
|
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 =
|
|
263
|
+
const priv = CML.PrivateKey.from_bech32(privateKey);
|
|
260
264
|
const pubKeyHash = priv.to_public().hash();
|
|
261
|
-
const address =
|
|
265
|
+
const address = CML.EnterpriseAddress.new(
|
|
262
266
|
network === "Mainnet" ? 1 : 0,
|
|
263
|
-
|
|
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 =
|
|
285
|
-
const txWitnessSetBuilder =
|
|
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 ?
|
|
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 () =>
|
|
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 =
|
|
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(
|
|
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
|
|
348
|
+
return CML.TransactionWitnessSet.from_cbor_hex(witnessSet);
|
|
345
349
|
},
|
|
346
350
|
signMessage: async (address, payload) => {
|
|
347
|
-
const hexAddress = toHex(
|
|
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.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@lucid-evolution/core-types": "0.1.5",
|
|
28
28
|
"@lucid-evolution/core-utils": "0.1.5",
|
|
29
29
|
"@lucid-evolution/sign_data": "0.1.5",
|
|
30
|
-
"@lucid-evolution/utils": "0.1.
|
|
30
|
+
"@lucid-evolution/utils": "0.1.8"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^20.12.8",
|