1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const bcrypto_1 = require("bcrypto");
|
7 | const wif_1 = __importDefault(require("wif"));
|
8 | const crypto_1 = require("../crypto");
|
9 | const errors_1 = require("../errors");
|
10 | const managers_1 = require("../managers");
|
11 | class 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 | }
|
38 | exports.Keys = Keys;
|
39 |
|
\ | No newline at end of file |