Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const login = (_privateKey, app) => {
SwapApp.required(app)
const storageKey = `${app.network}:qtum:privateKey`
const privateKey = _privateKey || app.env.storage.getItem(storageKey)
let account
const network = app.isMainNet()
? networks.mainnet
: networks.testnet
// TODO check format private key
if (privateKey) {
account = network.fromWIF(privateKey)
} else {
const mnemonic = generateMnemonic()
account = network.fromMnemonic(mnemonic)
app.env.storage.setItem(storageKey, account.toWIF())
console.log('account', account.address)
}
return account
}
import { networks, generateMnemonic } from 'qtumjs-wallet'
const network = process.env.MAINNET ? networks.mainnet : networks.testnet
let wallet
const _getData = () => {
const publicAddress = wallet.address
const privateKey = wallet.toWIF()
return {
privateKey,
address: publicAddress,
}
}
const createWallet = () => {
const mnemonic = generateMnemonic()
const password = 'superstrong'
this.methods = this.abi.reduce((acc, params) => {
const { name, type } = params
if (type === 'function') {
return {
...acc,
[name]: params,
}
}
return acc
})
const network = this.app.isMainNet()
? networks.mainnet
: networks.testnet
const privateKey = this.app.env.storage.storage.getItem(`${this.app.network}:qtum:privateKey`)
this.wallet = network.fromWIF(privateKey)
}