@lucid-evolution/wallet 0.0.1
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 +204 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +166 -0
- package/package.json +31 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
discoverOwnUsedTxKeyHashes: () => discoverOwnUsedTxKeyHashes,
|
|
34
|
+
walletFromSeed: () => walletFromSeed
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
|
|
38
|
+
// src/wallet.ts
|
|
39
|
+
var import_utils = require("@lucid-evolution/utils");
|
|
40
|
+
var import_core_utils = require("@lucid-evolution/core-utils");
|
|
41
|
+
var CML = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
42
|
+
var import_bip39 = require("@lucid-evolution/bip39");
|
|
43
|
+
function walletFromSeed(seed, options = { addressType: "Base", accountIndex: 0, network: "Mainnet" }) {
|
|
44
|
+
function harden(num) {
|
|
45
|
+
if (typeof num !== "number")
|
|
46
|
+
throw new Error("Type number required here!");
|
|
47
|
+
return 2147483648 + num;
|
|
48
|
+
}
|
|
49
|
+
const entropy = (0, import_bip39.mnemonicToEntropy)(seed);
|
|
50
|
+
const rootKey = CML.Bip32PrivateKey.from_bip39_entropy(
|
|
51
|
+
(0, import_core_utils.fromHex)(entropy),
|
|
52
|
+
options.password ? new TextEncoder().encode(options.password) : new Uint8Array()
|
|
53
|
+
);
|
|
54
|
+
const accountKey = rootKey.derive(harden(1852)).derive(harden(1815)).derive(harden(options.accountIndex));
|
|
55
|
+
const paymentKey = accountKey.derive(0).derive(0).to_raw_key();
|
|
56
|
+
const stakeKey = accountKey.derive(2).derive(0).to_raw_key();
|
|
57
|
+
const paymentKeyHash = paymentKey.to_public().hash();
|
|
58
|
+
const stakeKeyHash = stakeKey.to_public().hash();
|
|
59
|
+
const networkId = options.network === "Mainnet" ? 1 : 0;
|
|
60
|
+
const address = options.addressType === "Base" ? CML.BaseAddress.new(
|
|
61
|
+
networkId,
|
|
62
|
+
CML.Credential.new_pub_key(paymentKeyHash),
|
|
63
|
+
CML.Credential.new_pub_key(stakeKeyHash)
|
|
64
|
+
).to_address().to_bech32(void 0) : CML.EnterpriseAddress.new(
|
|
65
|
+
networkId,
|
|
66
|
+
CML.Credential.new_pub_key(paymentKeyHash)
|
|
67
|
+
).to_address().to_bech32(void 0);
|
|
68
|
+
const rewardAddress = options.addressType === "Base" ? CML.RewardAddress.new(
|
|
69
|
+
networkId,
|
|
70
|
+
CML.Credential.new_pub_key(stakeKeyHash)
|
|
71
|
+
).to_address().to_bech32(void 0) : null;
|
|
72
|
+
return {
|
|
73
|
+
address,
|
|
74
|
+
rewardAddress,
|
|
75
|
+
paymentKey: paymentKey.to_bech32(),
|
|
76
|
+
stakeKey: options.addressType === "Base" ? stakeKey.to_bech32() : null
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, ownUtxos) {
|
|
80
|
+
const usedKeyHashes = [];
|
|
81
|
+
const inputs = tx.body().inputs();
|
|
82
|
+
for (let i = 0; i < inputs.len(); i++) {
|
|
83
|
+
const input = inputs.get(i);
|
|
84
|
+
const txHash = input.transaction_id().to_hex();
|
|
85
|
+
const outputIndex = Number(input.index());
|
|
86
|
+
const utxo = ownUtxos.find(
|
|
87
|
+
(utxo2) => utxo2.txHash === txHash && utxo2.outputIndex === outputIndex
|
|
88
|
+
);
|
|
89
|
+
if (utxo) {
|
|
90
|
+
const { paymentCredential } = (0, import_utils.getAddressDetails)(utxo.address);
|
|
91
|
+
usedKeyHashes.push(paymentCredential?.hash);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const txBody = tx.body();
|
|
95
|
+
function keyHashFromCert(txBody2) {
|
|
96
|
+
const certs = txBody2.certs();
|
|
97
|
+
if (!certs)
|
|
98
|
+
return;
|
|
99
|
+
for (let i = 0; i < certs.len(); i++) {
|
|
100
|
+
const cert = certs.get(i);
|
|
101
|
+
if (cert.kind() === 0) {
|
|
102
|
+
const credential = cert.as_stake_registration()?.stake_credential();
|
|
103
|
+
if (credential?.kind() === 0) {
|
|
104
|
+
}
|
|
105
|
+
} else if (cert.kind() === 1) {
|
|
106
|
+
const credential = cert.as_stake_deregistration()?.stake_credential();
|
|
107
|
+
if (credential?.kind() === 0) {
|
|
108
|
+
const keyHash = credential.to_cbor_hex();
|
|
109
|
+
usedKeyHashes.push(keyHash);
|
|
110
|
+
}
|
|
111
|
+
} else if (cert.kind() === 2) {
|
|
112
|
+
const credential = cert.as_stake_delegation()?.stake_credential();
|
|
113
|
+
if (credential?.kind() === 0) {
|
|
114
|
+
const keyHash = credential.to_cbor_hex();
|
|
115
|
+
usedKeyHashes.push(keyHash);
|
|
116
|
+
}
|
|
117
|
+
} else if (cert.kind() === 3) {
|
|
118
|
+
const poolParams = cert.as_pool_registration()?.pool_params();
|
|
119
|
+
const owners = poolParams?.pool_owners();
|
|
120
|
+
if (!owners)
|
|
121
|
+
break;
|
|
122
|
+
for (let i2 = 0; i2 < owners.len(); i2++) {
|
|
123
|
+
const keyHash = owners.get(i2).to_hex();
|
|
124
|
+
usedKeyHashes.push(keyHash);
|
|
125
|
+
}
|
|
126
|
+
const operator = poolParams.operator().to_hex();
|
|
127
|
+
usedKeyHashes.push(operator);
|
|
128
|
+
} else if (cert.kind() === 4) {
|
|
129
|
+
const operator = cert.as_pool_retirement()?.pool().to_hex();
|
|
130
|
+
usedKeyHashes.push(operator);
|
|
131
|
+
} else if (cert.kind() === 6) {
|
|
132
|
+
const credential = cert.as_unreg_cert()?.stake_credential();
|
|
133
|
+
if (credential) {
|
|
134
|
+
usedKeyHashes.push(credential.to_cbor_hex());
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (txBody.certs())
|
|
140
|
+
keyHashFromCert(txBody);
|
|
141
|
+
const withdrawals = txBody.withdrawals();
|
|
142
|
+
function keyHashFromWithdrawal(withdrawals2) {
|
|
143
|
+
const rewardAddresses = withdrawals2.keys();
|
|
144
|
+
for (let i = 0; i < rewardAddresses.len(); i++) {
|
|
145
|
+
const credential = rewardAddresses.get(i).payment();
|
|
146
|
+
if (credential.kind() === 0) {
|
|
147
|
+
usedKeyHashes.push(credential.to_cbor_hex());
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (withdrawals)
|
|
152
|
+
keyHashFromWithdrawal(withdrawals);
|
|
153
|
+
const scripts = tx.witness_set().native_scripts();
|
|
154
|
+
function keyHashFromScript(scripts2) {
|
|
155
|
+
for (let i = 0; i < scripts2.len(); i++) {
|
|
156
|
+
const script = scripts2.get(i);
|
|
157
|
+
if (script.kind() === 0) {
|
|
158
|
+
const keyHash = script.as_script_pubkey()?.ed25519_key_hash().to_hex();
|
|
159
|
+
usedKeyHashes.push(keyHash);
|
|
160
|
+
}
|
|
161
|
+
if (script.kind() === 1) {
|
|
162
|
+
keyHashFromScript(script.as_script_all().native_scripts());
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (script.kind() === 2) {
|
|
166
|
+
keyHashFromScript(script.as_script_any().native_scripts());
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (script.kind() === 3) {
|
|
170
|
+
keyHashFromScript(script.as_script_n_of_k().native_scripts());
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (scripts)
|
|
176
|
+
keyHashFromScript(scripts);
|
|
177
|
+
const requiredSigners = txBody.required_signers();
|
|
178
|
+
if (requiredSigners) {
|
|
179
|
+
for (let i = 0; i < requiredSigners.len(); i++) {
|
|
180
|
+
usedKeyHashes.push(requiredSigners.get(i).to_hex());
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const collateral = txBody.collateral_inputs();
|
|
184
|
+
if (collateral) {
|
|
185
|
+
for (let i = 0; i < collateral.len(); i++) {
|
|
186
|
+
const input = collateral.get(i);
|
|
187
|
+
const txHash = input.transaction_id().to_hex();
|
|
188
|
+
const outputIndex = Number(input.index());
|
|
189
|
+
const utxo = ownUtxos.find(
|
|
190
|
+
(utxo2) => utxo2.txHash === txHash && utxo2.outputIndex === outputIndex
|
|
191
|
+
);
|
|
192
|
+
if (utxo) {
|
|
193
|
+
const { paymentCredential } = (0, import_utils.getAddressDetails)(utxo.address);
|
|
194
|
+
usedKeyHashes.push(paymentCredential?.hash);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return usedKeyHashes.filter((k) => ownKeyHashes.includes(k));
|
|
199
|
+
}
|
|
200
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
201
|
+
0 && (module.exports = {
|
|
202
|
+
discoverOwnUsedTxKeyHashes,
|
|
203
|
+
walletFromSeed
|
|
204
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Network, KeyHash, UTxO, Address, RewardAddress, PrivateKey } from '@lucid-evolution/core-types';
|
|
2
|
+
import * as CML from '@dcspark/cardano-multiplatform-lib-nodejs';
|
|
3
|
+
|
|
4
|
+
type FromSeed = {
|
|
5
|
+
address: Address;
|
|
6
|
+
rewardAddress: RewardAddress | null;
|
|
7
|
+
paymentKey: PrivateKey;
|
|
8
|
+
stakeKey: PrivateKey | null;
|
|
9
|
+
};
|
|
10
|
+
declare function walletFromSeed(seed: string, options?: {
|
|
11
|
+
password?: string;
|
|
12
|
+
addressType?: "Base" | "Enterprise";
|
|
13
|
+
accountIndex?: number;
|
|
14
|
+
network?: Network;
|
|
15
|
+
}): FromSeed;
|
|
16
|
+
declare function discoverOwnUsedTxKeyHashes(tx: CML.Transaction, ownKeyHashes: Array<KeyHash>, ownUtxos: Array<UTxO>): Array<KeyHash>;
|
|
17
|
+
|
|
18
|
+
export { discoverOwnUsedTxKeyHashes, walletFromSeed };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Network, KeyHash, UTxO, Address, RewardAddress, PrivateKey } from '@lucid-evolution/core-types';
|
|
2
|
+
import * as CML from '@dcspark/cardano-multiplatform-lib-nodejs';
|
|
3
|
+
|
|
4
|
+
type FromSeed = {
|
|
5
|
+
address: Address;
|
|
6
|
+
rewardAddress: RewardAddress | null;
|
|
7
|
+
paymentKey: PrivateKey;
|
|
8
|
+
stakeKey: PrivateKey | null;
|
|
9
|
+
};
|
|
10
|
+
declare function walletFromSeed(seed: string, options?: {
|
|
11
|
+
password?: string;
|
|
12
|
+
addressType?: "Base" | "Enterprise";
|
|
13
|
+
accountIndex?: number;
|
|
14
|
+
network?: Network;
|
|
15
|
+
}): FromSeed;
|
|
16
|
+
declare function discoverOwnUsedTxKeyHashes(tx: CML.Transaction, ownKeyHashes: Array<KeyHash>, ownUtxos: Array<UTxO>): Array<KeyHash>;
|
|
17
|
+
|
|
18
|
+
export { discoverOwnUsedTxKeyHashes, walletFromSeed };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// src/wallet.ts
|
|
2
|
+
import { getAddressDetails } from "@lucid-evolution/utils";
|
|
3
|
+
import { fromHex } from "@lucid-evolution/core-utils";
|
|
4
|
+
import * as CML from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
5
|
+
import { mnemonicToEntropy } from "@lucid-evolution/bip39";
|
|
6
|
+
function walletFromSeed(seed, options = { addressType: "Base", accountIndex: 0, network: "Mainnet" }) {
|
|
7
|
+
function harden(num) {
|
|
8
|
+
if (typeof num !== "number")
|
|
9
|
+
throw new Error("Type number required here!");
|
|
10
|
+
return 2147483648 + num;
|
|
11
|
+
}
|
|
12
|
+
const entropy = mnemonicToEntropy(seed);
|
|
13
|
+
const rootKey = CML.Bip32PrivateKey.from_bip39_entropy(
|
|
14
|
+
fromHex(entropy),
|
|
15
|
+
options.password ? new TextEncoder().encode(options.password) : new Uint8Array()
|
|
16
|
+
);
|
|
17
|
+
const accountKey = rootKey.derive(harden(1852)).derive(harden(1815)).derive(harden(options.accountIndex));
|
|
18
|
+
const paymentKey = accountKey.derive(0).derive(0).to_raw_key();
|
|
19
|
+
const stakeKey = accountKey.derive(2).derive(0).to_raw_key();
|
|
20
|
+
const paymentKeyHash = paymentKey.to_public().hash();
|
|
21
|
+
const stakeKeyHash = stakeKey.to_public().hash();
|
|
22
|
+
const networkId = options.network === "Mainnet" ? 1 : 0;
|
|
23
|
+
const address = options.addressType === "Base" ? CML.BaseAddress.new(
|
|
24
|
+
networkId,
|
|
25
|
+
CML.Credential.new_pub_key(paymentKeyHash),
|
|
26
|
+
CML.Credential.new_pub_key(stakeKeyHash)
|
|
27
|
+
).to_address().to_bech32(void 0) : CML.EnterpriseAddress.new(
|
|
28
|
+
networkId,
|
|
29
|
+
CML.Credential.new_pub_key(paymentKeyHash)
|
|
30
|
+
).to_address().to_bech32(void 0);
|
|
31
|
+
const rewardAddress = options.addressType === "Base" ? CML.RewardAddress.new(
|
|
32
|
+
networkId,
|
|
33
|
+
CML.Credential.new_pub_key(stakeKeyHash)
|
|
34
|
+
).to_address().to_bech32(void 0) : null;
|
|
35
|
+
return {
|
|
36
|
+
address,
|
|
37
|
+
rewardAddress,
|
|
38
|
+
paymentKey: paymentKey.to_bech32(),
|
|
39
|
+
stakeKey: options.addressType === "Base" ? stakeKey.to_bech32() : null
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, ownUtxos) {
|
|
43
|
+
const usedKeyHashes = [];
|
|
44
|
+
const inputs = tx.body().inputs();
|
|
45
|
+
for (let i = 0; i < inputs.len(); i++) {
|
|
46
|
+
const input = inputs.get(i);
|
|
47
|
+
const txHash = input.transaction_id().to_hex();
|
|
48
|
+
const outputIndex = Number(input.index());
|
|
49
|
+
const utxo = ownUtxos.find(
|
|
50
|
+
(utxo2) => utxo2.txHash === txHash && utxo2.outputIndex === outputIndex
|
|
51
|
+
);
|
|
52
|
+
if (utxo) {
|
|
53
|
+
const { paymentCredential } = getAddressDetails(utxo.address);
|
|
54
|
+
usedKeyHashes.push(paymentCredential?.hash);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const txBody = tx.body();
|
|
58
|
+
function keyHashFromCert(txBody2) {
|
|
59
|
+
const certs = txBody2.certs();
|
|
60
|
+
if (!certs)
|
|
61
|
+
return;
|
|
62
|
+
for (let i = 0; i < certs.len(); i++) {
|
|
63
|
+
const cert = certs.get(i);
|
|
64
|
+
if (cert.kind() === 0) {
|
|
65
|
+
const credential = cert.as_stake_registration()?.stake_credential();
|
|
66
|
+
if (credential?.kind() === 0) {
|
|
67
|
+
}
|
|
68
|
+
} else if (cert.kind() === 1) {
|
|
69
|
+
const credential = cert.as_stake_deregistration()?.stake_credential();
|
|
70
|
+
if (credential?.kind() === 0) {
|
|
71
|
+
const keyHash = credential.to_cbor_hex();
|
|
72
|
+
usedKeyHashes.push(keyHash);
|
|
73
|
+
}
|
|
74
|
+
} else if (cert.kind() === 2) {
|
|
75
|
+
const credential = cert.as_stake_delegation()?.stake_credential();
|
|
76
|
+
if (credential?.kind() === 0) {
|
|
77
|
+
const keyHash = credential.to_cbor_hex();
|
|
78
|
+
usedKeyHashes.push(keyHash);
|
|
79
|
+
}
|
|
80
|
+
} else if (cert.kind() === 3) {
|
|
81
|
+
const poolParams = cert.as_pool_registration()?.pool_params();
|
|
82
|
+
const owners = poolParams?.pool_owners();
|
|
83
|
+
if (!owners)
|
|
84
|
+
break;
|
|
85
|
+
for (let i2 = 0; i2 < owners.len(); i2++) {
|
|
86
|
+
const keyHash = owners.get(i2).to_hex();
|
|
87
|
+
usedKeyHashes.push(keyHash);
|
|
88
|
+
}
|
|
89
|
+
const operator = poolParams.operator().to_hex();
|
|
90
|
+
usedKeyHashes.push(operator);
|
|
91
|
+
} else if (cert.kind() === 4) {
|
|
92
|
+
const operator = cert.as_pool_retirement()?.pool().to_hex();
|
|
93
|
+
usedKeyHashes.push(operator);
|
|
94
|
+
} else if (cert.kind() === 6) {
|
|
95
|
+
const credential = cert.as_unreg_cert()?.stake_credential();
|
|
96
|
+
if (credential) {
|
|
97
|
+
usedKeyHashes.push(credential.to_cbor_hex());
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (txBody.certs())
|
|
103
|
+
keyHashFromCert(txBody);
|
|
104
|
+
const withdrawals = txBody.withdrawals();
|
|
105
|
+
function keyHashFromWithdrawal(withdrawals2) {
|
|
106
|
+
const rewardAddresses = withdrawals2.keys();
|
|
107
|
+
for (let i = 0; i < rewardAddresses.len(); i++) {
|
|
108
|
+
const credential = rewardAddresses.get(i).payment();
|
|
109
|
+
if (credential.kind() === 0) {
|
|
110
|
+
usedKeyHashes.push(credential.to_cbor_hex());
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (withdrawals)
|
|
115
|
+
keyHashFromWithdrawal(withdrawals);
|
|
116
|
+
const scripts = tx.witness_set().native_scripts();
|
|
117
|
+
function keyHashFromScript(scripts2) {
|
|
118
|
+
for (let i = 0; i < scripts2.len(); i++) {
|
|
119
|
+
const script = scripts2.get(i);
|
|
120
|
+
if (script.kind() === 0) {
|
|
121
|
+
const keyHash = script.as_script_pubkey()?.ed25519_key_hash().to_hex();
|
|
122
|
+
usedKeyHashes.push(keyHash);
|
|
123
|
+
}
|
|
124
|
+
if (script.kind() === 1) {
|
|
125
|
+
keyHashFromScript(script.as_script_all().native_scripts());
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (script.kind() === 2) {
|
|
129
|
+
keyHashFromScript(script.as_script_any().native_scripts());
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (script.kind() === 3) {
|
|
133
|
+
keyHashFromScript(script.as_script_n_of_k().native_scripts());
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (scripts)
|
|
139
|
+
keyHashFromScript(scripts);
|
|
140
|
+
const requiredSigners = txBody.required_signers();
|
|
141
|
+
if (requiredSigners) {
|
|
142
|
+
for (let i = 0; i < requiredSigners.len(); i++) {
|
|
143
|
+
usedKeyHashes.push(requiredSigners.get(i).to_hex());
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const collateral = txBody.collateral_inputs();
|
|
147
|
+
if (collateral) {
|
|
148
|
+
for (let i = 0; i < collateral.len(); i++) {
|
|
149
|
+
const input = collateral.get(i);
|
|
150
|
+
const txHash = input.transaction_id().to_hex();
|
|
151
|
+
const outputIndex = Number(input.index());
|
|
152
|
+
const utxo = ownUtxos.find(
|
|
153
|
+
(utxo2) => utxo2.txHash === txHash && utxo2.outputIndex === outputIndex
|
|
154
|
+
);
|
|
155
|
+
if (utxo) {
|
|
156
|
+
const { paymentCredential } = getAddressDetails(utxo.address);
|
|
157
|
+
usedKeyHashes.push(paymentCredential?.hash);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return usedKeyHashes.filter((k) => ownKeyHashes.includes(k));
|
|
162
|
+
}
|
|
163
|
+
export {
|
|
164
|
+
discoverOwnUsedTxKeyHashes,
|
|
165
|
+
walletFromSeed
|
|
166
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lucid-evolution/wallet",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.1.0",
|
|
19
|
+
"@types/node": "^20.11.24",
|
|
20
|
+
"tsup": "^8.0.2",
|
|
21
|
+
"typescript": "^5.3.3",
|
|
22
|
+
"@lucid-evolution/core-types": "0.0.1",
|
|
23
|
+
"@lucid-evolution/core-utils": "0.0.1",
|
|
24
|
+
"@lucid-evolution/utils": "0.0.1",
|
|
25
|
+
"@lucid-evolution/bip39": "0.0.1"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup-node src/index.ts --format esm,cjs --dts --clean",
|
|
29
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
30
|
+
}
|
|
31
|
+
}
|