Created
January 11, 2017 16:43
-
-
Save rjmacarthy/722a78ac73096168afd786a6035fa44d to your computer and use it in GitHub Desktop.
BIP38 Derived Public/Private key Bitcore.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bitcore = require('bitcore'); | |
var assert = require('assert'); | |
var index = 1; | |
// Create a new HD private key. | |
var hdPrivateKey = new bitcore.HDPrivateKey(); //returns xpriv... | |
//Use private key to create drived public key. | |
var hdPublicKey = hdPrivateKey.hdPublicKey; | |
// Derive address from public key | |
var derivedPublic = hdPublicKey.derive(index).publicKey.toAddress(); | |
// Derive address from private key | |
var derivedPrivate = hdPrivateKey.derive(index).privateKey.toAddress(); | |
assert(derivedPublic.toString() === derivedPrivate.toString()); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment