Created
November 10, 2016 13:46
-
-
Save you21979/3578908054b0a017871671eeec43d36a to your computer and use it in GitHub Desktop.
coinomiウォレット救済ツール
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
const bitcoin = require("bitcoinjs-lib") | |
const bip39 = require('bip39') | |
const bip32utils = require('bip32-utils') | |
const insight = require('insight-cli').RestClient | |
const bip44_account = (m, BIP44) => m.deriveHardened(BIP44.PURPOSE).deriveHardened(BIP44.COINTYPE).deriveHardened(BIP44.ACCOUNT) | |
const mnemonic = "" | |
const seed = bip39.mnemonicToSeed(mnemonic, "") | |
const m = bitcoin.HDNode.fromSeedBuffer(seed, bitcoin.networks["testnet"]) | |
const BIP44_TESTNET = { | |
PURPOSE : 44, | |
COINTYPE : 1, | |
ACCOUNT : 0, | |
} | |
const i = bip44_account(m, BIP44_TESTNET) | |
const external = i.derive(0) | |
const internal = i.derive(1) | |
const account = new bip32utils.Account([ | |
new bip32utils.Chain(external.neutered()), | |
new bip32utils.Chain(internal.neutered()) | |
]) | |
for(let i=0;i<30;i++)account.nextChainAddress(0) | |
for(let i=0;i<30;i++)account.nextChainAddress(1) | |
var tbl = account.toJSON() | |
const be = new insight("https://test-insight.bitpay.com/api"); | |
const out = "bitcoinaddres"; | |
const fee = 10000; | |
const getHDWalletUTXO = (be, map, i) => be.utxo(Object.keys(map)).then(txs => txs.map(tx => ({ | |
idx : map[tx.address], | |
node : i.derive(map[tx.address]), | |
address : tx.address, | |
satoshis : tx.satoshis, | |
txid : tx.txid, | |
vout : tx.vout, | |
}))) | |
const createTX = (be, out, map, chain) => | |
getHDWalletUTXO(be, map, chain).then(utxos => { | |
let tx = new bitcoin.TransactionBuilder(bitcoin.networks["testnet"]) | |
let amount = 0; | |
utxos.forEach((utxo, idx) => { | |
tx.addInput(utxo.txid, utxo.vout) | |
amount += utxo.satoshis; | |
}) | |
tx.addOutput(out, amount - fee) | |
utxos.forEach((utxo, idx) => { | |
tx.sign(idx, utxo.node.keyPair) | |
}) | |
return tx.build().toHex() | |
}) | |
createTX(be, out, tbl[0].map, external).then(txex => { | |
return createTX(be, out, tbl[1].map, internal).then(txin => { | |
console.log(txex, txin) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
テストネットのHDウォレット壊れたので作った