@lucid-evolution/wallet 0.1.64 → 0.1.66
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 +12 -7
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -7
- package/package.json +6 -4
package/dist/index.cjs
CHANGED
|
@@ -48,7 +48,12 @@ var CML = __toESM(require("@anastasia-labs/cardano-multiplatform-lib-nodejs"), 1
|
|
|
48
48
|
|
|
49
49
|
// src/wallet.ts
|
|
50
50
|
var import_bip39 = require("bip39");
|
|
51
|
-
function walletFromSeed(seed, options = {
|
|
51
|
+
function walletFromSeed(seed, options = {}) {
|
|
52
|
+
const {
|
|
53
|
+
addressType = "Base",
|
|
54
|
+
accountIndex = 0,
|
|
55
|
+
network = "Mainnet"
|
|
56
|
+
} = options;
|
|
52
57
|
function harden(num) {
|
|
53
58
|
if (typeof num !== "number") throw new Error("Type number required here!");
|
|
54
59
|
return 2147483648 + num;
|
|
@@ -56,16 +61,16 @@ function walletFromSeed(seed, options = { addressType: "Base", accountIndex: 0,
|
|
|
56
61
|
const entropy = (0, import_bip39.mnemonicToEntropy)(seed);
|
|
57
62
|
const rootKey = CML.Bip32PrivateKey.from_bip39_entropy(
|
|
58
63
|
(0, import_core_utils.fromHex)(entropy),
|
|
59
|
-
options
|
|
64
|
+
options?.password ? new TextEncoder().encode(options.password) : new Uint8Array()
|
|
60
65
|
);
|
|
61
|
-
const accountKey = rootKey.derive(harden(1852)).derive(harden(1815)).derive(harden(
|
|
66
|
+
const accountKey = rootKey.derive(harden(1852)).derive(harden(1815)).derive(harden(accountIndex));
|
|
62
67
|
rootKey.free();
|
|
63
68
|
const paymentKey = accountKey.derive(0).derive(0).to_raw_key();
|
|
64
69
|
const stakeKey = accountKey.derive(2).derive(0).to_raw_key();
|
|
65
70
|
const paymentKeyHash = paymentKey.to_public().hash();
|
|
66
71
|
const stakeKeyHash = stakeKey.to_public().hash();
|
|
67
|
-
const networkId =
|
|
68
|
-
const address =
|
|
72
|
+
const networkId = network === "Mainnet" ? 1 : 0;
|
|
73
|
+
const address = addressType === "Base" ? CML.BaseAddress.new(
|
|
69
74
|
networkId,
|
|
70
75
|
CML.Credential.new_pub_key(paymentKeyHash),
|
|
71
76
|
CML.Credential.new_pub_key(stakeKeyHash)
|
|
@@ -73,7 +78,7 @@ function walletFromSeed(seed, options = { addressType: "Base", accountIndex: 0,
|
|
|
73
78
|
networkId,
|
|
74
79
|
CML.Credential.new_pub_key(paymentKeyHash)
|
|
75
80
|
).to_address().to_bech32(void 0);
|
|
76
|
-
const rewardAddress =
|
|
81
|
+
const rewardAddress = addressType === "Base" ? CML.RewardAddress.new(
|
|
77
82
|
networkId,
|
|
78
83
|
CML.Credential.new_pub_key(stakeKeyHash)
|
|
79
84
|
).to_address().to_bech32(void 0) : null;
|
|
@@ -81,7 +86,7 @@ function walletFromSeed(seed, options = { addressType: "Base", accountIndex: 0,
|
|
|
81
86
|
address,
|
|
82
87
|
rewardAddress,
|
|
83
88
|
paymentKey: paymentKey.to_bech32(),
|
|
84
|
-
stakeKey:
|
|
89
|
+
stakeKey: addressType === "Base" ? stakeKey.to_bech32() : null
|
|
85
90
|
};
|
|
86
91
|
}
|
|
87
92
|
function discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, ownUtxos) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Address, RewardAddress, PrivateKey, Network, KeyHash, UTxO, Provider, Wallet, WalletApi } from '@lucid-evolution/core-types';
|
|
2
2
|
import * as CML from '@anastasia-labs/cardano-multiplatform-lib-nodejs';
|
|
3
3
|
|
|
4
4
|
type FromSeed = {
|
|
@@ -28,4 +28,4 @@ declare const makeWalletFromPrivateKey: (provider: Provider, network: Network, p
|
|
|
28
28
|
declare const makeWalletFromAPI: (provider: Provider, api: WalletApi) => Wallet;
|
|
29
29
|
declare const makeWalletFromAddress: (provider: Provider, network: Network, address: string, utxos: UTxO[]) => Wallet;
|
|
30
30
|
|
|
31
|
-
export { discoverOwnUsedTxKeyHashes, makeWalletFromAPI, makeWalletFromAddress, makeWalletFromPrivateKey, makeWalletFromSeed, walletFromSeed };
|
|
31
|
+
export { type FromSeed, discoverOwnUsedTxKeyHashes, makeWalletFromAPI, makeWalletFromAddress, makeWalletFromPrivateKey, makeWalletFromSeed, walletFromSeed };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Address, RewardAddress, PrivateKey, Network, KeyHash, UTxO, Provider, Wallet, WalletApi } from '@lucid-evolution/core-types';
|
|
2
2
|
import * as CML from '@anastasia-labs/cardano-multiplatform-lib-nodejs';
|
|
3
3
|
|
|
4
4
|
type FromSeed = {
|
|
@@ -28,4 +28,4 @@ declare const makeWalletFromPrivateKey: (provider: Provider, network: Network, p
|
|
|
28
28
|
declare const makeWalletFromAPI: (provider: Provider, api: WalletApi) => Wallet;
|
|
29
29
|
declare const makeWalletFromAddress: (provider: Provider, network: Network, address: string, utxos: UTxO[]) => Wallet;
|
|
30
30
|
|
|
31
|
-
export { discoverOwnUsedTxKeyHashes, makeWalletFromAPI, makeWalletFromAddress, makeWalletFromPrivateKey, makeWalletFromSeed, walletFromSeed };
|
|
31
|
+
export { type FromSeed, discoverOwnUsedTxKeyHashes, makeWalletFromAPI, makeWalletFromAddress, makeWalletFromPrivateKey, makeWalletFromSeed, walletFromSeed };
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,12 @@ import * as CML from "@anastasia-labs/cardano-multiplatform-lib-nodejs";
|
|
|
7
7
|
|
|
8
8
|
// src/wallet.ts
|
|
9
9
|
import { mnemonicToEntropy } from "bip39";
|
|
10
|
-
function walletFromSeed(seed, options = {
|
|
10
|
+
function walletFromSeed(seed, options = {}) {
|
|
11
|
+
const {
|
|
12
|
+
addressType = "Base",
|
|
13
|
+
accountIndex = 0,
|
|
14
|
+
network = "Mainnet"
|
|
15
|
+
} = options;
|
|
11
16
|
function harden(num) {
|
|
12
17
|
if (typeof num !== "number") throw new Error("Type number required here!");
|
|
13
18
|
return 2147483648 + num;
|
|
@@ -15,16 +20,16 @@ function walletFromSeed(seed, options = { addressType: "Base", accountIndex: 0,
|
|
|
15
20
|
const entropy = mnemonicToEntropy(seed);
|
|
16
21
|
const rootKey = CML.Bip32PrivateKey.from_bip39_entropy(
|
|
17
22
|
fromHex(entropy),
|
|
18
|
-
options
|
|
23
|
+
options?.password ? new TextEncoder().encode(options.password) : new Uint8Array()
|
|
19
24
|
);
|
|
20
|
-
const accountKey = rootKey.derive(harden(1852)).derive(harden(1815)).derive(harden(
|
|
25
|
+
const accountKey = rootKey.derive(harden(1852)).derive(harden(1815)).derive(harden(accountIndex));
|
|
21
26
|
rootKey.free();
|
|
22
27
|
const paymentKey = accountKey.derive(0).derive(0).to_raw_key();
|
|
23
28
|
const stakeKey = accountKey.derive(2).derive(0).to_raw_key();
|
|
24
29
|
const paymentKeyHash = paymentKey.to_public().hash();
|
|
25
30
|
const stakeKeyHash = stakeKey.to_public().hash();
|
|
26
|
-
const networkId =
|
|
27
|
-
const address =
|
|
31
|
+
const networkId = network === "Mainnet" ? 1 : 0;
|
|
32
|
+
const address = addressType === "Base" ? CML.BaseAddress.new(
|
|
28
33
|
networkId,
|
|
29
34
|
CML.Credential.new_pub_key(paymentKeyHash),
|
|
30
35
|
CML.Credential.new_pub_key(stakeKeyHash)
|
|
@@ -32,7 +37,7 @@ function walletFromSeed(seed, options = { addressType: "Base", accountIndex: 0,
|
|
|
32
37
|
networkId,
|
|
33
38
|
CML.Credential.new_pub_key(paymentKeyHash)
|
|
34
39
|
).to_address().to_bech32(void 0);
|
|
35
|
-
const rewardAddress =
|
|
40
|
+
const rewardAddress = addressType === "Base" ? CML.RewardAddress.new(
|
|
36
41
|
networkId,
|
|
37
42
|
CML.Credential.new_pub_key(stakeKeyHash)
|
|
38
43
|
).to_address().to_bech32(void 0) : null;
|
|
@@ -40,7 +45,7 @@ function walletFromSeed(seed, options = { addressType: "Base", accountIndex: 0,
|
|
|
40
45
|
address,
|
|
41
46
|
rewardAddress,
|
|
42
47
|
paymentKey: paymentKey.to_bech32(),
|
|
43
|
-
stakeKey:
|
|
48
|
+
stakeKey: addressType === "Base" ? stakeKey.to_bech32() : null
|
|
44
49
|
};
|
|
45
50
|
}
|
|
46
51
|
function discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, ownUtxos) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/wallet",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.66",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -31,16 +31,18 @@
|
|
|
31
31
|
"@lucid-evolution/core-types": "0.1.21",
|
|
32
32
|
"@lucid-evolution/core-utils": "0.1.16",
|
|
33
33
|
"@lucid-evolution/sign_data": "0.1.24",
|
|
34
|
-
"@lucid-evolution/utils": "0.1.
|
|
34
|
+
"@lucid-evolution/utils": "0.1.60"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^20.12.8",
|
|
38
38
|
"tsup": "^8.0.2",
|
|
39
|
-
"typescript": "^5.4.5"
|
|
39
|
+
"typescript": "^5.4.5",
|
|
40
|
+
"vitest": "^2.1.8"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
43
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
43
44
|
"lint": "tsc --noEmit",
|
|
44
|
-
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
45
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
46
|
+
"test": "vitest run"
|
|
45
47
|
}
|
|
46
48
|
}
|