Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ This example should work successfully, it's the same used in the jest test, this
bip38d 6PYWpYms78Q3vJPVHvsHFCF1AKtd1PayV9qSeVGV47FtyXWHRJMreWsXYL .password


### Usage with extra script to derive public address

./get_public_address.py $(node bip38-decrypt.js 6PYWpYms78Q3vJPVHvsHFCF1AKtd1PayV9qSeVGV47FtyXWHRJMreWsXYL .password )


### Test

This will run the jest test
Expand Down
6 changes: 5 additions & 1 deletion bip38-decrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs')
const exists = fs.existsSync
const readFile = fs.readFileSync
const bip38 = require('bip38')
const bip38Decrypt = require('bip38-decrypt')
const wif = require('wif')
const decrypt = bip38.decrypt

Expand All @@ -22,7 +23,10 @@ const emptyPasswordError = new Error("Empty BIP38 password, aborting!")
if (!password || password == "") throw emptyPasswordError
password = password.toString().trim()
if (password == "") throw new emptyPasswordError
if (process.env.NODE_ENV != "test") c.log("decrypting private key...")
/* if (process.env.NODE_ENV != "test") c.log("decrypting private key...")
*/

bip38Decrypt(bip38PrivateKey, password, function(err,decryptedPrivateWif) { console.log(err ? err.msg : decryptedPrivateWif) });

module.exports = {
bip38PrivateKey: bip38PrivateKey,
Expand Down
41 changes: 41 additions & 0 deletions genpaperwallet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3

import binascii
from bip_utils import Bip38PubKeyModes, Bip38Encrypter
from bitcoin import *
from qrcode import *
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw

k = random_key()
priv = binascii.unhexlify(encode_privkey(k, 'hex'))
addr = privtoaddr(priv)
bip = Bip38Encrypter.EncryptNoEc(priv, sys.argv[1], Bip38PubKeyModes.UNCOMPRESSED)

#print("Unencrypted private key: " + encode_privkey(k, 'wif'))
print("BIP38-encrypted private key: " + bip)
print("Address: " + addr)

# QR-code generation based on https://github.com/decentropy/bip38
img = Image.new('RGB', (1000, 500), color = 'white')
img_w, img_h = img.size
qr = QRCode(box_size=8, border=3, error_correction=ERROR_CORRECT_Q)
qr.add_data(addr)
im = qr.make_image()
im_w, im_h = im.size
qr2 = QRCode(box_size=6, border=3, error_correction=ERROR_CORRECT_M)
qr2.add_data(bip)
im2 = qr2.make_image()
im2_w, im2_h = im2.size
offs = round((img_w - im_w - im2_w) / 4)
img.paste(im, (offs,round((img_h-im_h)/2)) )
img.paste(im2, (im_w+(3*offs),round((img_h-im2_h)/2)) )
draw = ImageDraw.Draw(img)
fcolor = (0,0,0)
draw.text((im_w+(3*offs),(img_h-im_h)/2-10), 'BIP38 Key', fcolor)
draw.text((20, 70), 'ADDRESS: ' + addr, fcolor)
draw.text((20, (img_h - 100)), 'BIP38 KEY: ' + bip, fcolor)
img.save(addr+'.jpg', "JPEG")

print("generated image " + addr+'.jpg')
7 changes: 7 additions & 0 deletions get_public_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python3

import sys
from pycoin.symbols.btc import network

k = network.parse.private_key(sys.argv[1])
print(k.address())
Loading