coinkey
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
- github: https://github.com/cryptocoinjs/coinkey
- tests: https://github.com/cryptocoinjs/coinkey/tree/master/test
- issues: https://github.com/cryptocoinjs/coinkey/issues
- license: MIT
- versioning: SemVer
Installation
npm i --save coinkey
Usage
Common Use Cases
Generate a Bunch of Bitcoin Keys/Addresses
var CoinKey = var bitcoinKeys = for var i = 0; i < 10; ++i // bitcoin supported by default bitcoinKeys
Generate a Bunch of Namecoin Keys/Addresses
var CoinKey = // npm install --save coininfovar ci = var namecoins = for var i = 0; i < 10; ++i namecoins
Parse a Wallet Import Key and Determine Crypto Currency
var CoinKey = var ci = var ck = CoinKey console // => c4bbcb1fbec99d65bf59d85c8cb62ee2db963f0fe106f483d9afa73bd4e39a8aconsole // => DGG6AicS4Qg8Y3UFtcuwJqbuRZ3Q7WtYXvconsole // => trueconsole // => true
Change to Testnet Later
var CoinKey = var ci = var ck = '1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd' 'hex'console // => 16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS //change to Testnetckversions = console // => mkzgubTA5Ahi6BPSkE6MN9pEafRutznkMe
API
CoinKey(privateKey, [versions])
Constructor function.
- privateKey: The private key bytes. Must be 32 bytes in length. Should be an
Array
,Uint8Array
, or aBuffer
. - 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 = //npm install --save secure-random@1.xvar secureRandom = var bytes = secureRandomvar key1 = bytesconsole // => 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 = var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd" //Bitcoin WIFvar key = privateKeyHex 'hex'keycompressed = falseconsole // => 5Hx15HFGyep2CfPxsJKe2fXJsCVn5DEiyoeGGF6JZjGbTRnqfiD //Litecoin WIFvar key = privateKeyHex 'hex' private: 0xB0 public: 0x30keycompressed = falseconsole // => 6uFjYQnot5Gtg3HpP87bp4JUpg4FH1gkkV3RyS7LHBbD9Hpt1na
publicKey
Inherited from ECKey. eckey.publicKey
publicAddress
Get the public address.
var CoinKey = var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd" // Bitcoin Addressvar key = privatKeyHex 'hex'console // => 16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS // Litecoin Addressvar key = privateKeyHex 'hex' private: 0xB0 public: 0x30console // => 'LZyGd5dCPVkVUjA5QbpuUfMNgcmNDLjswH'
publicHash
Alias: pubKeyHash
Inherited from ECKey. eckey.publicHash
publicPoint
Inherited from ECKey. eckey.publicPoint
toString()
Returns the string representation.
var CoinKey = var privateKeyHex = "1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fd" //Litecoin Addressvar key = privateKeyHex 'hex' private: 0xB0 public: 0x30console// => T3e2me1BvRs95K7E8eQ8eha9oRPL1g2U6vmjE5px6RjzbUTvKZsf: LZyGd5dCPVkVUjA5QbpuUfMNgcmNDLjswH
Methods
fromWif(wif, [versions])
Class method to create a CoinKey
from a wif.
var ck = CoinKey;console // => trueconsole // => 1184cd2cdd640ca42cfc3a091c51d549b2f016d454b2774019c2b2d2e08529fdconsole // => 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.