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 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function 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 | }
|
22 | exports.getEntropy = getEntropy;
|
23 |
|
24 |
|
25 |
|
26 | function makeECPrivateKey() {
|
27 | const keyPair = bitcoinjs_lib_1.ECPair.makeRandom({ rng: getEntropy });
|
28 | return keyPair.privateKey.toString('hex');
|
29 | }
|
30 | exports.makeECPrivateKey = makeECPrivateKey;
|
31 |
|
32 |
|
33 |
|
34 | function 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 | }
|
40 | exports.publicKeyToAddress = publicKeyToAddress;
|
41 |
|
42 |
|
43 |
|
44 | function getPublicKeyFromPrivate(privateKey) {
|
45 | const keyPair = bitcoinjs_lib_1.ECPair.fromPrivateKey(Buffer.from(privateKey, 'hex'));
|
46 | return keyPair.publicKey.toString('hex');
|
47 | }
|
48 | exports.getPublicKeyFromPrivate = getPublicKeyFromPrivate;
|
49 |
|
\ | No newline at end of file |