1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const crypto_1 = require("crypto");
|
4 | const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
5 | function getEntropy(numberOfBytes) {
|
6 | if (!numberOfBytes) {
|
7 | numberOfBytes = 32;
|
8 | }
|
9 | return crypto_1.randomBytes(numberOfBytes);
|
10 | }
|
11 | exports.getEntropy = getEntropy;
|
12 | function makeECPrivateKey() {
|
13 | const keyPair = bitcoinjs_lib_1.ECPair.makeRandom({ rng: getEntropy });
|
14 | return keyPair.privateKey.toString('hex');
|
15 | }
|
16 | exports.makeECPrivateKey = makeECPrivateKey;
|
17 | function 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 | }
|
23 | exports.publicKeyToAddress = publicKeyToAddress;
|
24 | function getPublicKeyFromPrivate(privateKey) {
|
25 | const keyPair = bitcoinjs_lib_1.ECPair.fromPrivateKey(Buffer.from(privateKey, 'hex'));
|
26 | return keyPair.publicKey.toString('hex');
|
27 | }
|
28 | exports.getPublicKeyFromPrivate = getPublicKeyFromPrivate;
|
29 |
|
\ | No newline at end of file |