• Stars
    star
    149
  • Rank 248,551 (Top 5 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

secp256k1-node

Node.js binding for an Optimized C library for EC operations on curve secp256k1
JavaScript
341
star
2

base-x

Encode/decode any base
JavaScript
312
star
3

bs58

Base58 encoding/decoding for Bitcoin
JavaScript
212
star
4

hdkey

JavaScript component for Bitcoin hierarchical deterministic keys (BIP32)
JavaScript
201
star
5

cryptocoin

JavaScript library for crypto currencies like Bitcoin and Litecoin.
JavaScript
140
star
6

coininfo

JavaScript component for crypto currency specific information.
JavaScript
116
star
7

keccak

Keccak sponge function family
C
86
star
8

p2p-node

Manage peer-to-peer communications for cryptocurrency implementations
JavaScript
61
star
9

ecurve

JavaScript component for Eliptic Curve Cryptography
JavaScript
58
star
10

awesome-cryptocoinjs

Useful crypto coins JavaScript libraries
58
star
11

bigi

JavaScript Big Integer library based upon Tom Wu's work.
JavaScript
49
star
12

sha256

DEPRECATED - JavaScript component to compute the SHA256 of strings or bytes.
JavaScript
47
star
13

scryptsy

Scrypt KDF is used for BIP38 (encryption of private keys) and proof of work for some crypto currencies.
JavaScript
45
star
14

stealth

Stealth addresses for Bitcoin and other crypto currencies.
JavaScript
42
star
15

ecdsa

DEPRECATED - JavaScript component to Eliptical Curve Cryptography signing and verify.
JavaScript
38
star
16

qr-encode

JavaScript component to encode strings into QR codes.
JavaScript
25
star
17

pbkdf2-sha256

DEPRECATED - Key derivation function primarily used for Scrypt
JavaScript
22
star
18

aes

A JavaScript component for the Advanced Encryption Standard (AES). Important for BIP38
JavaScript
21
star
19

eckey

A JavaScript component for Eliptical curve cryptography for crypto currencies such as Litecoin and Bitcoin
JavaScript
17
star
20

coinstring

DEPRECATED - Create and parse crypto currency addresses and wallet import formats.
JavaScript
16
star
21

scrypt

Scrypt for node and browser
C
14
star
22

binstring

DEPRECATED - Convert binary data to and from various string/integer representations
JavaScript
12
star
23

blake-hash

SHA-3 proposal Blake
C
12
star
24

btc-transaction

Create, parse, serialize Bitcoin transactions.
JavaScript
11
star
25

btc-address

JavaScript component to handle Bitcoin addresses.
JavaScript
10
star
26

crypto-hashing

JavaScript hashing libraries wrapped up into one module. Compatible with Node and the browser.
JavaScript
10
star
27

sha512

DEPRECATED - SHA 512 secure hashing algorithm
JavaScript
9
star
28

cryptocoinjs.com

CryptoCoinJS Docs
HTML
9
star
29

drbg.js

Deterministic Random Bit Generators from NIST SP 800-90A
JavaScript
8
star
30

btc-p2p

Bitcoin peer network manager
JavaScript
8
star
31

btc-blockchain

Bitcoin blockchain management
JavaScript
7
star
32

btc-script

Script support for Bitcoin
JavaScript
7
star
33

eip55

An EIP55 compatible address encoding library
JavaScript
7
star
34

coinmsg

Message signing for Bitcoin and other cryptocurrencies.
JavaScript
7
star
35

btc-scriptinterpreter

JavaScript
6
star
36

crypto-binary

Assemble and disassemble binary messages used in cryptocoin applications
JavaScript
5
star
37

p2p-manager

Manage peer connections to a P2P network
JavaScript
5
star
38

btc-opcode

Opcode support for Bitcoin.
JavaScript
5
star