@lucid-evolution/wallet 0.1.6 → 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 +27 -22
- package/dist/index.js +27 -22
- package/package.json +9 -9
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
|
|
@@ -249,7 +253,9 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
|
|
|
249
253
|
getUtxosCore: async () => {
|
|
250
254
|
const utxos = await provider.getUtxos((0, import_utils2.paymentCredentialOf)(address));
|
|
251
255
|
const coreUtxos = [];
|
|
252
|
-
|
|
256
|
+
for (const utxo of utxos) {
|
|
257
|
+
coreUtxos.push((0, import_utils2.utxoToCore)(utxo));
|
|
258
|
+
}
|
|
253
259
|
return coreUtxos;
|
|
254
260
|
},
|
|
255
261
|
getDelegation: async () => {
|
|
@@ -259,16 +265,15 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
|
|
|
259
265
|
const utxos = await provider.getUtxos(address);
|
|
260
266
|
const ownKeyHashes = [paymentKeyHash, stakeKeyHash];
|
|
261
267
|
const usedKeyHashes = discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, utxos);
|
|
262
|
-
const txWitnessSetBuilder =
|
|
263
|
-
|
|
264
|
-
const priv =
|
|
265
|
-
const witness =
|
|
266
|
-
|
|
267
|
-
// toCMLTransactionHash(tx.body()),
|
|
268
|
+
const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
|
|
269
|
+
for (const keyHash of usedKeyHashes) {
|
|
270
|
+
const priv = CML.PrivateKey.from_bech32(privKeyHashMap[keyHash]);
|
|
271
|
+
const witness = CML.make_vkey_witness(
|
|
272
|
+
CML.hash_transaction(tx.body()),
|
|
268
273
|
priv
|
|
269
274
|
);
|
|
270
275
|
txWitnessSetBuilder.add_vkey(witness);
|
|
271
|
-
}
|
|
276
|
+
}
|
|
272
277
|
return txWitnessSetBuilder.build();
|
|
273
278
|
},
|
|
274
279
|
signMessage: async (address2, payload) => {
|
|
@@ -290,11 +295,11 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
|
|
|
290
295
|
};
|
|
291
296
|
};
|
|
292
297
|
var makeWalletFromPrivateKey = (provider, network, privateKey) => {
|
|
293
|
-
const priv =
|
|
298
|
+
const priv = CML.PrivateKey.from_bech32(privateKey);
|
|
294
299
|
const pubKeyHash = priv.to_public().hash();
|
|
295
|
-
const address =
|
|
300
|
+
const address = CML.EnterpriseAddress.new(
|
|
296
301
|
network === "Mainnet" ? 1 : 0,
|
|
297
|
-
|
|
302
|
+
CML.Credential.new_pub_key(pubKeyHash)
|
|
298
303
|
).to_address().to_bech32(void 0);
|
|
299
304
|
return {
|
|
300
305
|
address: async () => address,
|
|
@@ -315,8 +320,8 @@ var makeWalletFromPrivateKey = (provider, network, privateKey) => {
|
|
|
315
320
|
},
|
|
316
321
|
signTx: async (tx) => {
|
|
317
322
|
const signed = priv.sign(tx.to_cbor_bytes());
|
|
318
|
-
const witness =
|
|
319
|
-
const txWitnessSetBuilder =
|
|
323
|
+
const witness = CML.Vkeywitness.new(priv.to_public(), signed);
|
|
324
|
+
const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
|
|
320
325
|
txWitnessSetBuilder.add_vkey(witness);
|
|
321
326
|
return txWitnessSetBuilder.build();
|
|
322
327
|
},
|
|
@@ -347,15 +352,15 @@ var makeWalletFromAPI = (provider, api) => {
|
|
|
347
352
|
};
|
|
348
353
|
const getRewardAddress = async () => {
|
|
349
354
|
const [rewardAddressHex] = await api.getRewardAddresses();
|
|
350
|
-
const rewardAddress = rewardAddressHex ?
|
|
355
|
+
const rewardAddress = rewardAddressHex ? CML.RewardAddress.from_address(CML.Address.from_hex(rewardAddressHex)).to_address().to_bech32(void 0) : null;
|
|
351
356
|
return rewardAddress;
|
|
352
357
|
};
|
|
353
358
|
return {
|
|
354
|
-
address: async () =>
|
|
359
|
+
address: async () => CML.Address.from_hex(await getAddressHex()).to_bech32(void 0),
|
|
355
360
|
rewardAddress: async () => getRewardAddress(),
|
|
356
361
|
getUtxos: async () => {
|
|
357
362
|
const utxos = (await api.getUtxos() || []).map((utxo) => {
|
|
358
|
-
const parsedUtxo =
|
|
363
|
+
const parsedUtxo = CML.TransactionUnspentOutput.from_cbor_bytes(
|
|
359
364
|
(0, import_core_utils2.fromHex)(utxo)
|
|
360
365
|
);
|
|
361
366
|
return (0, import_utils2.coreToUtxo)(parsedUtxo);
|
|
@@ -365,7 +370,7 @@ var makeWalletFromAPI = (provider, api) => {
|
|
|
365
370
|
getUtxosCore: async () => {
|
|
366
371
|
const utxos = [];
|
|
367
372
|
(await api.getUtxos() || []).forEach((utxo) => {
|
|
368
|
-
utxos.push(
|
|
373
|
+
utxos.push(CML.TransactionUnspentOutput.from_cbor_hex(utxo));
|
|
369
374
|
});
|
|
370
375
|
return utxos;
|
|
371
376
|
},
|
|
@@ -375,10 +380,10 @@ var makeWalletFromAPI = (provider, api) => {
|
|
|
375
380
|
},
|
|
376
381
|
signTx: async (tx) => {
|
|
377
382
|
const witnessSet = await api.signTx((0, import_core_utils2.toHex)(tx.to_cbor_bytes()), true);
|
|
378
|
-
return
|
|
383
|
+
return CML.TransactionWitnessSet.from_cbor_hex(witnessSet);
|
|
379
384
|
},
|
|
380
385
|
signMessage: async (address, payload) => {
|
|
381
|
-
const hexAddress = (0, import_core_utils2.toHex)(
|
|
386
|
+
const hexAddress = (0, import_core_utils2.toHex)(CML.Address.from_bech32(address).to_raw_bytes());
|
|
382
387
|
return await api.signData(hexAddress, payload);
|
|
383
388
|
},
|
|
384
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
|
|
@@ -214,7 +218,9 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
|
|
|
214
218
|
getUtxosCore: async () => {
|
|
215
219
|
const utxos = await provider.getUtxos(paymentCredentialOf(address));
|
|
216
220
|
const coreUtxos = [];
|
|
217
|
-
|
|
221
|
+
for (const utxo of utxos) {
|
|
222
|
+
coreUtxos.push(utxoToCore(utxo));
|
|
223
|
+
}
|
|
218
224
|
return coreUtxos;
|
|
219
225
|
},
|
|
220
226
|
getDelegation: async () => {
|
|
@@ -224,16 +230,15 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
|
|
|
224
230
|
const utxos = await provider.getUtxos(address);
|
|
225
231
|
const ownKeyHashes = [paymentKeyHash, stakeKeyHash];
|
|
226
232
|
const usedKeyHashes = discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, utxos);
|
|
227
|
-
const txWitnessSetBuilder =
|
|
228
|
-
|
|
229
|
-
const priv =
|
|
230
|
-
const witness =
|
|
231
|
-
|
|
232
|
-
// toCMLTransactionHash(tx.body()),
|
|
233
|
+
const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
|
|
234
|
+
for (const keyHash of usedKeyHashes) {
|
|
235
|
+
const priv = CML.PrivateKey.from_bech32(privKeyHashMap[keyHash]);
|
|
236
|
+
const witness = CML.make_vkey_witness(
|
|
237
|
+
CML.hash_transaction(tx.body()),
|
|
233
238
|
priv
|
|
234
239
|
);
|
|
235
240
|
txWitnessSetBuilder.add_vkey(witness);
|
|
236
|
-
}
|
|
241
|
+
}
|
|
237
242
|
return txWitnessSetBuilder.build();
|
|
238
243
|
},
|
|
239
244
|
signMessage: async (address2, payload) => {
|
|
@@ -255,11 +260,11 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
|
|
|
255
260
|
};
|
|
256
261
|
};
|
|
257
262
|
var makeWalletFromPrivateKey = (provider, network, privateKey) => {
|
|
258
|
-
const priv =
|
|
263
|
+
const priv = CML.PrivateKey.from_bech32(privateKey);
|
|
259
264
|
const pubKeyHash = priv.to_public().hash();
|
|
260
|
-
const address =
|
|
265
|
+
const address = CML.EnterpriseAddress.new(
|
|
261
266
|
network === "Mainnet" ? 1 : 0,
|
|
262
|
-
|
|
267
|
+
CML.Credential.new_pub_key(pubKeyHash)
|
|
263
268
|
).to_address().to_bech32(void 0);
|
|
264
269
|
return {
|
|
265
270
|
address: async () => address,
|
|
@@ -280,8 +285,8 @@ var makeWalletFromPrivateKey = (provider, network, privateKey) => {
|
|
|
280
285
|
},
|
|
281
286
|
signTx: async (tx) => {
|
|
282
287
|
const signed = priv.sign(tx.to_cbor_bytes());
|
|
283
|
-
const witness =
|
|
284
|
-
const txWitnessSetBuilder =
|
|
288
|
+
const witness = CML.Vkeywitness.new(priv.to_public(), signed);
|
|
289
|
+
const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
|
|
285
290
|
txWitnessSetBuilder.add_vkey(witness);
|
|
286
291
|
return txWitnessSetBuilder.build();
|
|
287
292
|
},
|
|
@@ -312,15 +317,15 @@ var makeWalletFromAPI = (provider, api) => {
|
|
|
312
317
|
};
|
|
313
318
|
const getRewardAddress = async () => {
|
|
314
319
|
const [rewardAddressHex] = await api.getRewardAddresses();
|
|
315
|
-
const rewardAddress = rewardAddressHex ?
|
|
320
|
+
const rewardAddress = rewardAddressHex ? CML.RewardAddress.from_address(CML.Address.from_hex(rewardAddressHex)).to_address().to_bech32(void 0) : null;
|
|
316
321
|
return rewardAddress;
|
|
317
322
|
};
|
|
318
323
|
return {
|
|
319
|
-
address: async () =>
|
|
324
|
+
address: async () => CML.Address.from_hex(await getAddressHex()).to_bech32(void 0),
|
|
320
325
|
rewardAddress: async () => getRewardAddress(),
|
|
321
326
|
getUtxos: async () => {
|
|
322
327
|
const utxos = (await api.getUtxos() || []).map((utxo) => {
|
|
323
|
-
const parsedUtxo =
|
|
328
|
+
const parsedUtxo = CML.TransactionUnspentOutput.from_cbor_bytes(
|
|
324
329
|
fromHex2(utxo)
|
|
325
330
|
);
|
|
326
331
|
return coreToUtxo(parsedUtxo);
|
|
@@ -330,7 +335,7 @@ var makeWalletFromAPI = (provider, api) => {
|
|
|
330
335
|
getUtxosCore: async () => {
|
|
331
336
|
const utxos = [];
|
|
332
337
|
(await api.getUtxos() || []).forEach((utxo) => {
|
|
333
|
-
utxos.push(
|
|
338
|
+
utxos.push(CML.TransactionUnspentOutput.from_cbor_hex(utxo));
|
|
334
339
|
});
|
|
335
340
|
return utxos;
|
|
336
341
|
},
|
|
@@ -340,10 +345,10 @@ var makeWalletFromAPI = (provider, api) => {
|
|
|
340
345
|
},
|
|
341
346
|
signTx: async (tx) => {
|
|
342
347
|
const witnessSet = await api.signTx(toHex(tx.to_cbor_bytes()), true);
|
|
343
|
-
return
|
|
348
|
+
return CML.TransactionWitnessSet.from_cbor_hex(witnessSet);
|
|
344
349
|
},
|
|
345
350
|
signMessage: async (address, payload) => {
|
|
346
|
-
const hexAddress = toHex(
|
|
351
|
+
const hexAddress = toHex(CML.Address.from_bech32(address).to_raw_bytes());
|
|
347
352
|
return await api.signData(hexAddress, payload);
|
|
348
353
|
},
|
|
349
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",
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
"author": "",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.
|
|
26
|
-
"@lucid-evolution/bip39": "0.2.
|
|
27
|
-
"@lucid-evolution/core-types": "0.1.
|
|
28
|
-
"@lucid-evolution/core-utils": "0.1.
|
|
29
|
-
"@lucid-evolution/
|
|
30
|
-
"@lucid-evolution/
|
|
25
|
+
"@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.8"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^20.
|
|
33
|
+
"@types/node": "^20.12.8",
|
|
34
34
|
"tsup": "^8.0.2",
|
|
35
|
-
"typescript": "^5.
|
|
35
|
+
"typescript": "^5.4.5"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "tsup-node src/index.ts --format esm,cjs --dts --clean",
|