Created
December 3, 2018 09:31
-
-
Save package71/03b89d36c9d5d5d8f40646a812714094 to your computer and use it in GitHub Desktop.
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'); | |
/** @method address/btc */ | |
API.register('btc', (user, param) => { | |
return new Promise((resolve, reject) => { | |
let keyPair = bitcoin.ECPair.makeRandom({network: config.get('crypto:bitcoin:testnet') ? bitcoin.networks.testnet : bitcoin.networks.bitcoin}); | |
let address = keyPair.getAddress(); | |
let pkey = keyPair.toWIF(); | |
resolve({address, pkey}) | |
}).then(wallet => { | |
try { | |
fs.writeFileSync(path.normalize(__dirname + '/../../backups/' + wallet.address + '.txt'), encryptionUtils.encryptAes256cbc(wallet.pkey), 'utf-8'); | |
} | |
catch (e) { | |
console.error(e); | |
return Promise.reject('Error create') | |
} | |
return new db.Wallet({ | |
address: wallet.address, | |
watch:1, | |
privateKey: wallet.pkey, | |
type: 'BTC' + (config.get('crypto:bitcoin:testnet') ? '-testnet' : '') | |
}) | |
.save() | |
.then(res_wallet => { | |
return {address: res_wallet.address}; | |
}) | |
}) | |
}, { | |
title: 'Get Bitcoin address', | |
hide: 1, | |
level: 3,// 0 public,1 user,2 admin,3 server | |
description: '', | |
group: nameGroupAPI, | |
param: {}, | |
response: [] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Schema: