-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (42 loc) · 1.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import fs from 'fs';
import { exportWalletSecretDef } from './src/keypass.js';
import pkg from 'cardano-crypto.js';
import readline from 'readline';
const { _seedToKeypairV2 } = pkg;
// Function to prompt the user for input
function promptUser(query) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
return new Promise(resolve => rl.question(query, answer => {
rl.close();
resolve(answer);
}));
}
// Create Cardano key file from mnemonic
async function createCardanoKeyFile(privateKey, password) {
const pkBuf = await _seedToKeypairV2(Buffer.from(privateKey, 'hex'), '');
const res = await exportWalletSecretDef({
rootSecret: pkBuf,
derivationScheme: {
type: 'v2',
ed25519Mode: 2,
keyfileVersion: '2.0.0',
}
}, password, 'Cardano Key File');
console.log(res);
// Save key file
fs.writeFileSync('cardano_key.json', JSON.stringify(res, null, 2));
console.log('Cardano key file created: cardano_key.json');
}
// Main function
(async () => {
try {
const privateKey = await promptUser('Enter your private key: ');
const password = await promptUser('Enter your password: ');
await createCardanoKeyFile(privateKey, password);
} catch (error) {
console.error(error);
}
})();