Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Electrum #10

Open
nikolai-b opened this issue May 28, 2018 · 7 comments
Open

Remove Electrum #10

nikolai-b opened this issue May 28, 2018 · 7 comments
Labels
for later This is not a priority yet

Comments

@nikolai-b
Copy link
Member

Electrum doesn't really do wallet creation and their RPC changes between versions.

Plan:

  1. Use something like https://github.com/you21979/node-multisig-wallet/blob/master/lib/wallet.js#L11 to generate the muti sig wallet
  2. Something like
    https://github.com/pocesar/node-stratum/blob/master/README.md to connect to the bitcoin network.
@nikolai-b nikolai-b added the for later This is not a priority yet label May 28, 2018
@ameba23
Copy link
Member

ameba23 commented May 28, 2018

@nikolai-b
Copy link
Member Author

@ameba23 as you've thought about this more than I have do you mind adding where you think we will need that as it'd be great to flesh this issue out as it's a big one. The more small steps the easier it will be to pick up later.

@ameba23
Copy link
Member

ameba23 commented May 28, 2018

bip32 is the deterministic wallet-from-a-seed thing that pretty much all modern bitcoin wallets use. there used to be 'loose keys' wallets which required backing up constantly to prevent loosing money in case of broken computer.

So we need bip32 utils for generating addresses deterministically from a seed. Theres already a function in our src/bitcoin-utils.js that turns a mnemonic seed into a master public key:

function bip32xpub() {
 // var mnemonic = bip39.generateMnemonic()
  var mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost'
  var seed = bip39.mnemonicToSeed(mnemonic)
  var node = bip32.fromSeed(seed)
  return node.neutered().toBase58()
}

and the next step is to generate addresses. You can see how this is done in this rather cool web demo that dan posted somewhere: http://bip32.org/ its open source and uses bitcoinjs-lib. also see some other interesting stuff from ian coleman: https://iancoleman.io/bip39/

and i just found a simplified walkthrough of creating transactions with bitcoinjs

@ameba23
Copy link
Member

ameba23 commented Jun 3, 2018

electrum 3.1.4 just been released on github.

this project works with 3.1.3. it seems there are pretty big differences in the json rpc even between minor version updates. so i suggest we stick with 3.1.3 and give an extra 👍 for remove electrum cos we can't keep adapting things but we also cant expect people to install and outdated electrum version.

@ameba23
Copy link
Member

ameba23 commented Jun 18, 2018

bit stuck on this one: (made extra complicated by the fact that btcnodejs's bip39 (mnemonic) functions are not in the node module but are on github... but i found the bitcoinjs ones work much the same)

const btcnodejs = require('btcnodejs');
const bip39 = require('./bip39') // locally cloned off github and dependencies manually installed
const bip39_fromBitcoinJS = require('bip39')

btcnodejs.network.setup('testnet');

// heres a mnemonic generated by electrum.  We can get something similar with: 
// var mnemonic = bip39.generateMnemonic(16)
var mnemonic = [
  'present',
  'wolf', 
  'ring', 
  'camp', 
  'miracle', 
  'matter', 
  'bracket', 
  'genre', 
  'ten', 
  'like', 
  'midnight', 
  'phrase']

// Heres the 'xpub' electrum gives us (it calls testnet ones vpub wheres btcnodejs calls them tpub)
//vpub5URCYqhTWwMGiTZCBPRdB6nVPKngtGrwkxxYd5jeU5yuQWnitmBwshigvdMgtyZtLK5WzaSdgSgziPPdXVzb6YUU4bcxVZGywNwFvasrzre

console.log(mnemonic)

var seed = bip39.generateSeed(mnemonic,"")
console.log('seed: ', seed)

var mstring = mnemonic.join(' ')
var seed_fromBitcoinJS = bip39_fromBitcoinJS.mnemonicToSeed(mstring)
console.log('seed from bitcoinJS: ', seed_fromBitcoinJS)
// it is indeed the same (just formatted as buffer not a string)

var priv = btcnodejs.HDPrivateKey.fromSeed(seed);
console.log('xprv: ', priv._bckey.toString())

// master public key from master private key:
console.log('xpub: ', priv.getPublic()._bckey.toString())

// both the private and public keys differ from the ones electrum gives us for the same seed.
// (when choosing 'segwit' (bech32) address format)
// if i enter the private key electrum gives us, and try to derive the public key using btcnodejs
// i get an error saying something about not valid base58. so it is not making bech32 keys.

// both bitcoinjs and btcnodejs offer functions for encoding and decoding bech32
// but the examples given are at the address level rather than at the key level. hmmm...


// first steps to deriving addresses... 
console.log('derive m', priv.derive("m")._bckey.toString())
console.log("derive m/0'", priv.derive("m/0'")._bckey.toString())

@ameba23
Copy link
Member

ameba23 commented Jun 18, 2018

although theres nothing 'wrong' here i would really like that we follow just the same key and address derivation procedure as electrum, such that exactly the same addresses would be generated for a given mnemonic, meaning one could effectively recover a wallet using either program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for later This is not a priority yet
Projects
None yet
Development

No branches or pull requests

2 participants