UNPKG

1.6 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const bcrypto_1 = require("bcrypto");
7const wif_1 = __importDefault(require("wif"));
8const crypto_1 = require("../crypto");
9const errors_1 = require("../errors");
10const managers_1 = require("../managers");
11class Keys {
12 static fromPassphrase(passphrase, compressed = true) {
13 return Keys.fromPrivateKey(crypto_1.HashAlgorithms.sha256(Buffer.from(passphrase, "utf8")), compressed);
14 }
15 static fromPrivateKey(privateKey, compressed = true) {
16 privateKey = privateKey instanceof Buffer ? privateKey : Buffer.from(privateKey, "hex");
17 return {
18 publicKey: bcrypto_1.secp256k1.publicKeyCreate(privateKey, compressed).toString("hex"),
19 privateKey: privateKey.toString("hex"),
20 compressed,
21 };
22 }
23 static fromWIF(wifKey, network) {
24 if (!network) {
25 network = managers_1.configManager.get("network");
26 }
27 const { version, compressed, privateKey } = wif_1.default.decode(wifKey, network.wif);
28 if (version !== network.wif) {
29 throw new errors_1.NetworkVersionError(network.wif, version);
30 }
31 return {
32 publicKey: bcrypto_1.secp256k1.publicKeyCreate(privateKey, compressed).toString("hex"),
33 privateKey: privateKey.toString("hex"),
34 compressed,
35 };
36 }
37}
38exports.Keys = Keys;
39//# sourceMappingURL=keys.js.map
\No newline at end of file