UNPKG

1.32 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const crypto_1 = require("crypto");
4const bitcoinjs_lib_1 = require("bitcoinjs-lib");
5/**
6 *
7 * @param numberOfBytes
8 *
9 * @ignore
10 */
11function getEntropy(arg) {
12 if (!arg) {
13 arg = 32;
14 }
15 if (typeof arg === 'number') {
16 return crypto_1.randomBytes(arg);
17 }
18 else {
19 return crypto_1.randomFillSync(arg);
20 }
21}
22exports.getEntropy = getEntropy;
23/**
24* @ignore
25*/
26function makeECPrivateKey() {
27 const keyPair = bitcoinjs_lib_1.ECPair.makeRandom({ rng: getEntropy });
28 return keyPair.privateKey.toString('hex');
29}
30exports.makeECPrivateKey = makeECPrivateKey;
31/**
32* @ignore
33*/
34function publicKeyToAddress(publicKey) {
35 const publicKeyBuffer = Buffer.from(publicKey, 'hex');
36 const publicKeyHash160 = bitcoinjs_lib_1.crypto.hash160(publicKeyBuffer);
37 const address = bitcoinjs_lib_1.address.toBase58Check(publicKeyHash160, 0x00);
38 return address;
39}
40exports.publicKeyToAddress = publicKeyToAddress;
41/**
42* @ignore
43*/
44function getPublicKeyFromPrivate(privateKey) {
45 const keyPair = bitcoinjs_lib_1.ECPair.fromPrivateKey(Buffer.from(privateKey, 'hex'));
46 return keyPair.publicKey.toString('hex');
47}
48exports.getPublicKeyFromPrivate = getPublicKeyFromPrivate;
49//# sourceMappingURL=keys.js.map
\No newline at end of file