Coder Social home page Coder Social logo

thehobbit85 / bip38 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bitcoinjs/bip38

0.0 2.0 0.0 158 KB

BIP38 is a standard process to encrypt Bitcoin and crypto currency private keys that is less susceptible to brute force attacks thus protecting the user.

Home Page: http://cryptocoinjs.com/modules/currency/bip38/

License: MIT License

JavaScript 100.00%

bip38's Introduction

bip38

build status Coverage Status Version

js-standard-style

A JavaScript component that adheres to the BIP38 standard to secure your crypto currency private keys. Fully compliant with Node.js and the browser (via Browserify).

Why?

BIP38 is a standard process to encrypt Bitcoin and crypto currency private keys that is imprevious to brute force attacks thus protecting the user.

Package Info

Usage

Installation

npm install --save bip38

API

Bip38([versions])

Constructor that creates a new Bip38 instance.

  • versions: optional parameter to set the versions. Defaults to Bitcoin.

versions

A field that accepts an object for the address version. This easily allows you to support altcoins. Defaults to Bitcoin values.

example:

var Bip38 = require('bip38')

var privateKeyWif = '5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR'

var bip38 = new Bip38()

// not necessary, as Bitcoin is supported by default
bip38.versions = {
	private: 0x80, 
  public: 0x0
}
bip38.encrypt(privateKeyWif, "super-secret", "1Jq6MksXQVWzrznvZzxkV6oY57oWXD9TXB"})

scryptParams

A field that accepts an object with the follow properties: N, r, and p to control the scrypt. The BIP38 standard suggests N = 16384, r = 8, and p = 8. However, this may yield unacceptable performance on a mobile phone. If you alter these parameters, it wouldn't be wise to suggest to your users that your import/export encrypted keys are BIP38 compatible. If you do, you may want to alert them of your parameter changes.

example:

bip38.scryptParams = {
  N: 8192, 
  r: 8, 
  p: 8
}

encrypt(wif, passphrase, address, progressCallback)

A method that encrypts the private key. wif is the string value of the wallet import format key. passphrase the passphrase to encrypt the key with. address is the public address. progressCallback is a function that receives an object in the form of: {current: 1000, total: 262144, percent: 0.3814697265625}

Returns the encrypted string.

example:

var Bip38 = require('bip38')

var privateKeyWif = '5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR'

var bip38 = new Bip38()
var encrypted = bip38.encrypt(privateKeyWif, 'TestingOneTwoThree', "1Jq6MksXQVWzrznvZzxkV6oY57oWXD9TXB", function (status) {
    console.log(status.percent) // Will print the precent every time current increases by 1000
})
console.log(encrypted) 
// => 6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg

decrypt(encryptedKey, passhprase, progressCallback)

A method that decrypts the encrypted string. encryptedKey is the string value of the encrypted key. passphrase is the passphrase to decrypt the key with. progressCallback is a function that receives an object in the form of: {current: 1000, total: 262144, percent: 0.3814697265625}

var Bip38 = require('bip38')

var encryptedKey = '6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg'

var bip38 = new Bip38()
var privateKeyWif = bip38.decrypt(encryptedKey, 'TestingOneTwoThree', function (status) {
    console.log(status.percent) // Will print the precent every time current increases by 1000
})
console.log(privateKeyWif) 
// =>  '5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR'

note: To check for an invalid password, you'll want to generate the public address from the output of the decrypt() function. If it doesn't equal the expected address or the address checksum, then chances are, it's an invalid password. The reason that this logic was not included is because it would have required a lot of dependencies: ECKey and Address. Currently, ECKey is pretty heavy on dependencies.

References

bip38's People

Contributors

dcousens avatar jprichardson avatar midnightlightning avatar thehobbit85 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.