UNPKG

aladinnetwork-blockstack

Version:

The Aladin Javascript library for authentication, identity, and storage.

49 lines 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const crypto_1 = require("crypto"); const bitcoinjs_lib_1 = require("bitcoinjs-lib"); /** * * @param numberOfBytes * * @ignore */ function getEntropy(arg) { if (!arg) { arg = 32; } if (typeof arg === 'number') { return crypto_1.randomBytes(arg); } else { return crypto_1.randomFillSync(arg); } } exports.getEntropy = getEntropy; /** * @ignore */ function makeECPrivateKey() { const keyPair = bitcoinjs_lib_1.ECPair.makeRandom({ rng: getEntropy }); return keyPair.privateKey.toString('hex'); } exports.makeECPrivateKey = makeECPrivateKey; /** * @ignore */ function publicKeyToAddress(publicKey) { const publicKeyBuffer = Buffer.from(publicKey, 'hex'); const publicKeyHash160 = bitcoinjs_lib_1.crypto.hash160(publicKeyBuffer); const address = bitcoinjs_lib_1.address.toBase58Check(publicKeyHash160, 0x00); return address; } exports.publicKeyToAddress = publicKeyToAddress; /** * @ignore */ function getPublicKeyFromPrivate(privateKey) { const keyPair = bitcoinjs_lib_1.ECPair.fromPrivateKey(Buffer.from(privateKey, 'hex')); return keyPair.publicKey.toString('hex'); } exports.getPublicKeyFromPrivate = getPublicKeyFromPrivate; //# sourceMappingURL=keys.js.map