Skip to content

Instantly share code, notes, and snippets.

@BluSyn
Last active April 30, 2017 06:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BluSyn/6854460ec2fea0be33b1 to your computer and use it in GitHub Desktop.
Save BluSyn/6854460ec2fea0be33b1 to your computer and use it in GitHub Desktop.
/**
* FOR COPAY WALLET
* Converts multisig xpubs into addresses
*
* Dependencies:
* npm install bitcore
*
* NOTE: You can retrieve xpubs from copay using JSON backup
* Decrypt json backup using sjcl @ https://github.com/bitwiseshiftleft/sjcl
*/
var bitcore = require('bitcore');
// For 2-of-3 multisig, you need all 3 xpubs
var pubkeys = [
// List xpubs for all singers here
];
// Number of signers required
var signers = 1;
var keys = [];
for (var x in pubkeys) {
var parent = new bitcore.HDPublicKey(pubkeys[x]);
// WTF COPAY? Why use 2147483647?
// Spent hours trying to figure this out
// Finally discovered the solution in bitcore-wallet-serivce : lib/model/addressmanager.js
// Stored as SHARED_INDEX = 0x80000000 - 1
// Again... WTF. BIP45 says to use m/<cosigner>/0/0,
// so this should be m/0/0/0 and m/1/0/0 for the first 2 addresses
var key = parent.derive('m/2147483647/0/0').publicKey;
keys.push(key);
}
var address = new bitcore.Address(keys, signers, 'livenet');
// Verify first address to confirm proper derivation
console.log('First Address: ', address.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment