@asoltys/bip38
TypeScript icon, indicating that this package has built-in type declarations

4.0.3 • Public • Published

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 impervious to brute force attacks thus protecting the user.

Package Info

Usage

Installation

npm install --save bip38

Async methods

Async methods are available. Using them will be slower but will free up the event loop. You can set asyncTickInterval in the scryptParams to control the maximum amount of time the function can block.

N is cpu/mem work factor (power of 2 e.g. 2**18) r is block size (8 is common), fine-tunes sequential memory read size and performance p is parallelization factor (1 is common) dkLen is output key length in bytes e.g. 32. asyncTick - (default: 10) max time in ms for which async function can block execution maxmem - (default: 1024 ** 3 + 1024 aka 1GB+1KB). A limit that the app could use for scrypt onProgress - callback function that would be executed for progress report

API

encrypt(buffer, compressed, passphrase[, progressCallback, scryptParams])

import { encrypt } from "bip38"
import wif from "wif"

const myWifString = '5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR'
const decoded = wif.decode(myWifString)

const encryptedKey = encrypt(decoded.privateKey, decoded.compressed, 'TestingOneTwoThree')
console.log(encryptedKey)
// => '6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg'

decrypt(encryptedKey, passphrase[, progressCallback, scryptParams])

import { decrypt } from "bip38"
import wif from "wif"

var encryptedKey = '6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg'
var decryptedKey = decrypt(encryptedKey, 'TestingOneTwoThree', function (percent) {
  console.log(percent) // will print the percent every time current increases by 1000
})

console.log(wif.encode(0x80, decryptedKey.privateKey, decryptedKey.compressed))
// => '5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR'

References

Package Sidebar

Install

npm i @asoltys/bip38

Weekly Downloads

0

Version

4.0.3

License

none

Unpacked Size

35.7 kB

Total Files

9

Last publish

Collaborators

  • asoltys