Giter Club home page Giter Club logo

bitcoin-keys's Introduction

Bitcoin::Keys

Generate and manage Bitcoin keys. Using Ruby stlib only.

Installation

Add this line to your Gemfile:

gem 'bitcoin-keys', require: 'bitcoin/keys'

Usage

Generate keys pair

pubkey, privkey = Bitcoin::Keys.generate    # Default to main network

pubkey.to_s     # => '16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM'
privkey.to_s    # => '18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725'

Generate public key from private key

privkey_hex = '18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725'
pubkey, privkey = Bitcoin::Keys.generate_from_private_key(privkey_hex)   # Default to main network

pubkey.address    # => '16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM'
privkey.to_hex    # => '18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725'

Public key

From a non compressed hexadecimal representation

pubkey = Bitcoin::Keys::PublicKey.new(pubkey_hex)

pubkey.to_s                  # => '16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM'
pubkey.address               # => '16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM'
pubkey.compressed_address    # => '1PMycacnJaSqwwJqjawXBErnLsZ7RkXUAs'
pubkey.to_hex                # => '0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD4702...'
pubkey.compressed            # => '0250863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B2352'

Private key

From a hexadecimal representation

privkey = Bitcoin::Keys::PrivateKey.new(privkey_hex)            # => For mainnet

privkey.to_s           # => '1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD'
privkey.to_hex         # => '1E99423A4ED27608A15A2616A2B0E9E52CED330AC530EDCC32C8FFC6A526AEDD'
privkey.wif            # => '5J3mBbAH58CpQ3Y5RNJpUKPE62SQ5tfcvU2JpbnkeyhfsYB1Jcn'
privkey.wif_compressed # => 'KxFC1jmwwCoACiCAWZ3eXa96mBM6tb3TYzGmf6YwgdGWZgawvrtJ'

privkey = Bitcoin::Keys::PrivateKey.new(privkey_hex, :testnet)   # => For testnet
...

bitcoin-keys's People

Contributors

simcap avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.