UNPKG

1.15 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const crypto_1 = require("crypto");
4const bitcoinjs_lib_1 = require("bitcoinjs-lib");
5function getEntropy(numberOfBytes) {
6 if (!numberOfBytes) {
7 numberOfBytes = 32;
8 }
9 return crypto_1.randomBytes(numberOfBytes);
10}
11exports.getEntropy = getEntropy;
12function makeECPrivateKey() {
13 const keyPair = bitcoinjs_lib_1.ECPair.makeRandom({ rng: getEntropy });
14 return keyPair.privateKey.toString('hex');
15}
16exports.makeECPrivateKey = makeECPrivateKey;
17function publicKeyToAddress(publicKey) {
18 const publicKeyBuffer = Buffer.from(publicKey, 'hex');
19 const publicKeyHash160 = bitcoinjs_lib_1.crypto.hash160(publicKeyBuffer);
20 const address = bitcoinjs_lib_1.address.toBase58Check(publicKeyHash160, 0x00);
21 return address;
22}
23exports.publicKeyToAddress = publicKeyToAddress;
24function getPublicKeyFromPrivate(privateKey) {
25 const keyPair = bitcoinjs_lib_1.ECPair.fromPrivateKey(Buffer.from(privateKey, 'hex'));
26 return keyPair.publicKey.toString('hex');
27}
28exports.getPublicKeyFromPrivate = getPublicKeyFromPrivate;
29//# sourceMappingURL=keys.js.map
\No newline at end of file