Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!_secret)
throw new Error(`Withdrawal is automatic. For manual withdrawal, provide a secret`)
if (!usdtScriptValues)
throw new Error(`Cannot withdraw without script values`)
if (secret && secret != _secret)
console.warn(`Secret already known and is different. Are you sure?`)
if (isBtcWithdrawn)
console.warn(`Looks like money were already withdrawn, are you sure?`)
debug('swap.core:flow')(`WITHDRAW using secret = ${_secret}`)
const _secretHash = crypto.ripemd160(Buffer.from(_secret, 'hex')).toString('hex')
if (secretHash != _secretHash)
console.warn(`Hash does not match!`)
const { scriptAddress } = this.usdtSwap.createScript(usdtScriptValues)
const balance = await this.usdtSwap.getBalance(scriptAddress)
debug('swap.core:flow')(`address=${scriptAddress}, balance=${balance}`)
if (balance === 0) {
flow.finishStep({
isBtcWithdrawn: true,
}, { step: 'withdraw-usdt' })
throw new Error(`Already withdrawn: address=${scriptAddress},balance=${balance}`)
if (!_secret)
throw new Error(`Withdrawal is automatic. For manual withdrawal, provide a secret`)
if (!bchScriptValues)
throw new Error(`Cannot withdraw without script values`)
if (secret && secret != _secret)
console.warn(`Secret already known and is different. Are you sure?`)
if (isBchWithdrawn)
console.warn(`Looks like money were already withdrawn, are you sure?`)
debug('swap.core:flow')(`WITHDRAW using secret = ${_secret}`)
const _secretHash = crypto.ripemd160(Buffer.from(_secret, 'hex')).toString('hex')
if (secretHash != _secretHash)
console.warn(`Hash does not match! state: ${secretHash}, given: ${_secretHash}`)
const { scriptAddress } = this.bchSwap.createScript(bchScriptValues)
const balance = await this.bchSwap.getBalance(scriptAddress)
debug('swap.core:flow')(`address=${scriptAddress}, balance=${balance}`)
if (balance === 0) {
this.finishStep({
isBchWithdrawn: true,
}, { step: 'withdraw-bch' })
throw new Error(`Already withdrawn: address=${scriptAddress},balance=${balance}`)
}
await this.bchSwap.withdraw({
const { secret, secretHash, isLtcWithdrawn, isBtcWithdrawn, btcScriptValues } = this.state
if (!_secret)
throw new Error(`Withdrawal is automatic. For manual withdrawal, provide a secret`)
if (!btcScriptValues)
throw new Error(`Cannot withdraw without script values`)
if (secret && secret != _secret)
console.warn(`Secret already known and is different. Are you sure?`)
if (isBtcWithdrawn)
console.warn(`Looks like money were already withdrawn, are you sure?`)
debug('swap.core:flow')(`WITHDRAW using secret = ${_secret}`)
const _secretHash = crypto.ripemd160(Buffer.from(_secret, 'hex')).toString('hex')
if (secretHash != _secretHash)
console.warn(`Hash does not match!`)
const { scriptAddress } = this.btcSwap.createScript(btcScriptValues)
const balance = await this.btcSwap.getBalance(scriptAddress)
debug('swap.core:flow')(`address=${scriptAddress}, balance=${balance}`)
if (balance === 0) {
this.finishStep({
isBtcWithdrawn: true,
}, { step: 'withdraw-btc' })
throw new Error(`Already withdrawn: address=${scriptAddress},balance=${balance}`)
}
await this.btcSwap.withdraw({
async tryWithdraw(_secret) {
const { secret, secretHash, isEthWithdrawn, isBchWithdrawn } = this.state
if (!_secret)
throw new Error(`Withdrawal is automatic. For manual withdrawal, provide a secret`)
if (secret && secret != _secret)
console.warn(`Secret already known and is different. Are you sure?`)
if (isEthWithdrawn)
console.warn(`Looks like money were already withdrawn, are you sure?`)
debug('swap.core:flow')(`WITHDRAW using secret = ${_secret}`)
const _secretHash = crypto.ripemd160(Buffer.from(_secret, 'hex')).toString('hex')
if (secretHash != _secretHash)
console.warn(`Hash does not match! state: ${secretHash}, given: ${_secretHash}`)
const { participant } = this.swap
const data = {
ownerAddress: participant.eth.address,
secret: _secret,
}
await this.ethSwap.withdraw(data, (hash) => {
debug('swap.core:flow')(`TX hash=${hash}`)
this.setState({
ethSwapWithdrawTransactionHash: hash,
canCreateEthTransaction: true,
submitSecret(secret) {
if (this.state.secretHash) return true
if (!this.state.isParticipantSigned)
throw new Error(`Cannot proceed: participant not signed. step=${this.state.step}`)
const secretHash = crypto.ripemd160(Buffer.from(secret, 'hex')).toString('hex')
this.finishStep({
secret,
secretHash,
}, { step: 'submit-secret' })
return true
}
return btchip.getWalletPublicKey_async(previousPath).then(function(res) {
var compressedKey = btchip.compressPublicKey(res['publicKey']);
fingerprint = new ByteString(Crypto.ripemd160(Crypto.sha256(compressedKey.toBuffer()))).bytes(0, 4);
return fingerprint;
});
}
submitSecret(secret) {
if (this.state.secret) { return }
if (!this.state.isParticipantSigned) {
throw new Error(`Cannot proceed: participant not signed. step=${this.state.step}`)
}
const secretHash = crypto.ripemd160(Buffer.from(secret, 'hex')).toString('hex')
this.finishStep({
secret,
secretHash,
}, { step: 'submit-secret' })
}
submitSecret(secret) {
const secretHash = crypto.ripemd160(Buffer.from(secret, 'hex')).toString('hex')
this.finishStep({
secret,
secretHash,
})
}
submitSecret(secret) {
const secretHash = crypto.ripemd160(Buffer.from(secret, 'hex')).toString('hex')
this.finishStep({
secret,
secretHash,
})
}
submitSecret(secret) {
if (this.state.secret) { return }
if (!this.state.isParticipantSigned) {
throw new Error(`Cannot proceed: participant not signed. step=${this.state.step}`)
}
const secretHash = crypto.ripemd160(Buffer.from(secret, 'hex')).toString('hex')
this.finishStep({
secret,
secretHash,
}, { step: 'submit-secret' })
}