forked from vrde/ethnode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto.js
More file actions
27 lines (24 loc) · 688 Bytes
/
Copy pathcrypto.js
File metadata and controls
27 lines (24 loc) · 688 Bytes
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
const fs = require("fs");
const path = require("path");
const ethers = require("ethers");
async function getKeypair(json, password) {
const wallet = await ethers.Wallet.fromEncryptedJson(json, password);
return {
address: wallet.address,
privateKey: wallet.privateKey,
};
}
async function getKeypairs(keysDir, password) {
const result = [];
for (let filename of fs.readdirSync(keysDir)) {
if (filename.startsWith("UTC--")) {
const content = fs.readFileSync(path.join(keysDir, filename), "utf8");
result.push(await getKeypair(content, password));
}
}
return result;
}
module.exports = {
getKeypair: getKeypair,
getKeypairs: getKeypairs,
};