npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coinkey

v3.0.0

Published

JavaScript component for private keys, public keys, and addresess for crypto currencies such as Bitcoin, Litecoin, and Dogecoin

Downloads

66,772

Readme

coinkey

Version build status Coverage Status

JavaScript component for private keys, public keys, and addresses for crypto currencies such as Bitcoin, Litecoin, and Dogecoin. Works in both Node.js and the browser.

Package Info

Installation

npm i --save coinkey

Usage

Common Use Cases

Generate a Bunch of Bitcoin Keys/Addresses

var CoinKey = require('coinkey')

var bitcoinKeys = []
for (var i = 0; i < 10; ++i) {
  // bitcoin supported by default
  bitcoinKeys.push(CoinKey.createRandom())
}

Generate a Bunch of Namecoin Keys/Addresses

var CoinKey = require('coinkey')
// npm install --save coininfo
var ci = require('coininfo')

var namecoins = []
for (var i = 0; i < 10; ++i) {
  namecoins.push(CoinKey.createRandom(ci('NMC')))
}

Parse a Wallet Import Key and Determine Crypto Currency

var CoinKey = require('coinkey')
var ci = require('coininfo')

var ck = CoinKey.fromWif('QVD3x1RPiWPvyxbTsfxVwaYLyeBZrQvjhZ2aZJUsbuRgsEAGpNQ2')

console.log(ck.privateKey.toString('hex')) // => c4bbcb1fbec99d65bf59d85c8cb62ee2db963f0fe106f483d9afa73bd4e39a8a
console.log(ck.publicAddress) // => DGG6AicS4Qg8Y3UFtcuwJqbuRZ3Q7WtYXv
console.log(ck.compressed) // => true
console.log(ck.versions.public === ci('DOGE').versions.public) // => true

Change to Testnet Later

var CoinKey = require('coinkey')
var ci = require('coininfo')

var ck = new CoinKey(new Buffer('1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd', 'hex'))
console.log(ck.publicAddress) // => 16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS

//change to Testnet
ck.versions = ci('BTC-TEST')

console.log(ck.publicAddress) // => mkzgubTA5Ahi6BPSkE6MN9pEafRutznkMe

API

CoinKey(privateKey, [versions])

Constructor function.

  • privateKey: The private key bytes. Must be 32 bytes in length. Should be an Array, Uint8Array, or a Buffer.
  • versions: An object that specifies the public and private key versions for addresses and wifs. Defaults to Bitcoin mainnet.

Keys are default set to compressed is true.

var CoinKey = require('coinkey')
//npm install --save [email protected]
var secureRandom = require('secure-random')

var bytes = secureRandom.randomBuffer(32)
var key1 = new CoinKey(bytes)
console.log(key1.compressed) // => true

Properties

compressed

Inherited from ECKey. eckey.compressed

privateKey

Inherited from ECKey. eckey.privateKey

privateExportKey

Inherited from ECKey. eckey.privateExportKey

privateWif

Get the private WIF (Wallet Import Format).

var CoinKey = require('coinkey')

var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd"

//Bitcoin WIF
var key = new CoinKey(new Buffer(privateKeyHex, 'hex'))
key.compressed = false
console.log(key.privateWif) // => 5Hx15HFGyep2CfPxsJKe2fXJsCVn5DEiyoeGGF6JZjGbTRnqfiD

//Litecoin WIF
var key = new CoinKey(new Buffer(privateKeyHex, 'hex'), {private: 0xB0, public: 0x30})
key.compressed = false
console.log(key.privateWif) // => 6uFjYQnot5Gtg3HpP87bp4JUpg4FH1gkkV3RyS7LHBbD9Hpt1na

publicKey

Inherited from ECKey. eckey.publicKey

publicAddress

Get the public address.

var CoinKey = require('coinkey')

var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd"

// Bitcoin Address
var key = new CoinKey(new Buffer(privatKeyHex, 'hex'))
console.log(key.publicAddress) // => 16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS

// Litecoin Address
var key = new CoinKey(new Buffer(privateKeyHex, 'hex'), {private: 0xB0, public: 0x30})
console.log(key.publicAddress) // => 'LZyGd5dCPVkVUjA5QbpuUfMNgcmNDLjswH'

publicHash

Alias: pubKeyHash

Inherited from ECKey. eckey.publicHash

publicPoint

Inherited from ECKey. eckey.publicPoint

toString()

Returns the string representation.

var CoinKey = require('coinkey')

var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd"

//Litecoin Address
var key = new CoinKey(new Buffer(privateKeyHex, 'hex'), {private: 0xB0, public: 0x30})
console.log(key.toString())
// => T3e2me1BvRs95K7E8eQ8eha9oRPL1g2U6vmjE5px6RjzbUTvKZsf: LZyGd5dCPVkVUjA5QbpuUfMNgcmNDLjswH

Methods

fromWif(wif, [versions])

Class method to create a CoinKey from a wif.

var ck = CoinKey.fromWif('KwomKti1X3tYJUUMb1TGSM2mrZk1wb1aHisUNHCQXTZq5auC2qc3');
console.log(ck.compressed) // => true
console.log(ck.privateKey.toString('hex')) // => 1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd
console.log(ck.publicAddress) // => 1FkKMsKNJqWSDvTvETqcCeHcUQQ64kSC6s

Browser Support

Clone the repo:

git clone https://github.com/cryptocoinjs/coinkey

Install Browserify

npm install -g browserify

Nav to repo:

cd coinkey

Install dependencies:

npm install

Run browserify:

browserify --standalone coinkey lib/coinkey.js > lib/coinkey.bundle.js

You can now drop coinkey.bundle.js in a <script> tag.

Hack on CoinKey

js-standard-style