Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
requiresSecret = true
}
if (period === 'loanPeriod') {
lockTime = 0
} else if (period === 'biddingPeriod') {
lockTime = loanExpiration + 100
} else if (period === 'seizurePeriod') {
lockTime = biddingExpiration + 100
} else {
lockTime = seizureExpiration + 100
}
const lockTimeHex = padHexStart(scriptNumEncode(lockTime).toString('hex'), 8)
const pubKey = (period === 'seizurePeriod' && requiresSecret) ? lenderPubKey : borrowerPubKey
const to = pubKeyToAddress(pubKey, this._network.name, 'pubKeyHash')
const scriptPubKey = padHexStart(script)
const p2shAddress = pubKeyToAddress(scriptPubKey, this._network.name, 'scriptHash')
const sendScript = this.getMethod('createScript')(p2shAddress)
const initiationTxRaw = await this.getMethod('getRawTransactionByHash')(initiationTxHash)
const initiationTx = await this.getMethod('splitTransaction')(initiationTxRaw, true)
const voutIndex = initiationTx.outputs.findIndex((output) => output.script.toString('hex') === sendScript)
const txHashLE = Buffer.from(initiationTxHash, 'hex').reverse().toString('hex') // TX HASH IN LITTLE ENDIAN
const newTxInput = this.generateSigTxInput(txHashLE, voutIndex, script)
const newTx = this.generateRawTx(initiationTx, voutIndex, to, newTxInput, lockTimeHex)
const splitNewTx = await this.getMethod('splitTransaction')(newTx, true)
const outputScriptObj = await this.getMethod('serializeTransactionOutputs')(splitNewTx)
const outputScript = outputScriptObj.toString('hex')
async _multisigSignCollateral (initiationTxHash, script, loanExpiration, to, from) {
const lockTime = loanExpiration + 100
const lockTimeHex = padHexStart(scriptNumEncode(lockTime).toString('hex'), 8)
const scriptPubKey = padHexStart(script)
const p2shAddress = pubKeyToAddress(scriptPubKey, this._network.name, 'scriptHash')
const sendScript = this.getMethod('createScript')(p2shAddress)
const initiationTxRaw = await this.getMethod('getRawTransactionByHash')(initiationTxHash)
const initiationTx = await this.getMethod('splitTransaction')(initiationTxRaw, true)
const voutIndex = initiationTx.outputs.findIndex((output) => output.script.toString('hex') === sendScript)
const txHashLE = Buffer.from(initiationTxHash, 'hex').reverse().toString('hex') // TX HASH IN LITTLE ENDIAN
const newTxInput = this.generateSigTxInput(txHashLE, voutIndex, script)
const newTx = this.generateRawTx(initiationTx, voutIndex, to, newTxInput, lockTimeHex)
const splitNewTx = await this.getMethod('splitTransaction')(newTx, true)
const outputScriptObj = await this.getMethod('serializeTransactionOutputs')(splitNewTx)
const outputScript = outputScriptObj.toString('hex')
const walletAddress = await this.getMethod('getWalletAddress')(from)
const signature = await this.getMethod('signP2SHTransaction')(
if (period === 'loanPeriod') {
lockTime = 0
} else if (period === 'biddingPeriod') {
lockTime = loanExpiration + 100
} else if (period === 'seizurePeriod') {
lockTime = biddingExpiration + 100
} else {
lockTime = seizureExpiration + 100
}
const lockTimeHex = padHexStart(scriptNumEncode(lockTime).toString('hex'), 8)
const pubKey = (period === 'seizurePeriod' && requiresSecret) ? lenderPubKey : borrowerPubKey
const to = pubKeyToAddress(pubKey, this._network.name, 'pubKeyHash')
const scriptPubKey = padHexStart(script)
const p2shAddress = pubKeyToAddress(scriptPubKey, this._network.name, 'scriptHash')
const sendScript = this.getMethod('createScript')(p2shAddress)
const initiationTxRaw = await this.getMethod('getRawTransactionByHash')(initiationTxHash)
const initiationTx = await this.getMethod('splitTransaction')(initiationTxRaw, true)
const voutIndex = initiationTx.outputs.findIndex((output) => output.script.toString('hex') === sendScript)
const txHashLE = Buffer.from(initiationTxHash, 'hex').reverse().toString('hex') // TX HASH IN LITTLE ENDIAN
const newTxInput = this.generateSigTxInput(txHashLE, voutIndex, script)
const newTx = this.generateRawTx(initiationTx, voutIndex, to, newTxInput, lockTimeHex)
const splitNewTx = await this.getMethod('splitTransaction')(newTx, true)
const outputScriptObj = await this.getMethod('serializeTransactionOutputs')(splitNewTx)
const outputScript = outputScriptObj.toString('hex')
const walletAddress = await this.getMethod('getWalletAddress')(to)
const signature = await this.getMethod('signP2SHTransaction')(
async sendTransaction (to, value, data, from, extraOutputs) {
const app = await this.getApp()
if (data) {
const scriptPubKey = padHexStart(data)
to = pubKeyToAddress(scriptPubKey, this._network.name, 'scriptHash')
}
let totalValue = value
if (extraOutputs) {
extraOutputs.forEach((output) => {
totalValue += output.value
})
}
const unusedAddress = await this.getUnusedAddress(true)
const { inputs, change } = await this.getInputsForAmount(totalValue)
const ledgerInputs = await this.getLedgerInputs(inputs)
const paths = inputs.map(utxo => utxo.derivationPath)
async lockCollateral (refundableValue, seizableValue, borrowerPubKey, lenderPubKey, secretHashA1, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration, seizureExpiration) {
const refundableScript = this.createRefundableCollateralScript(borrowerPubKey, lenderPubKey, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration)
const seizableScript = this.createSeizableCollateralScript(borrowerPubKey, lenderPubKey, secretHashA1, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration, seizureExpiration)
const refundableScriptPubKey = padHexStart(refundableScript)
const seizableScriptPubKey = padHexStart(seizableScript)
const refundableP2shAddress = pubKeyToAddress(refundableScriptPubKey, this._network.name, 'scriptHash')
const seizableP2shAddress = pubKeyToAddress(seizableScriptPubKey, this._network.name, 'scriptHash')
const refundableResult = await this.getMethod('sendTransaction')(refundableP2shAddress, refundableValue, refundableScript)
const seizableResult = await this.getMethod('sendTransaction')(seizableP2shAddress, seizableValue, seizableScript)
return { refundableResult, seizableResult }
}
async multisigSignCollateral (refundableTxHash, seizableTxHash, borrowerPubKey, lenderPubKey, secretHashA1, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration, seizureExpiration, isBorrower, to) {
const refundableScript = this.createRefundableCollateralScript(borrowerPubKey, lenderPubKey, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration)
const seizableScript = this.createSeizableCollateralScript(borrowerPubKey, lenderPubKey, secretHashA1, secretHashA2, secretHashB2, secretHashB3, loanExpiration, biddingExpiration, seizureExpiration)
const from = isBorrower ? pubKeyToAddress(borrowerPubKey, this._network.name, 'pubKeyHash') : pubKeyToAddress(lenderPubKey, this._network.name, 'pubKeyHash')
const refundableSignature = await this._multisigSignCollateral(refundableTxHash, refundableScript, loanExpiration, to, from)
const seizableSignature = await this._multisigSignCollateral(seizableTxHash, seizableScript, loanExpiration, to, from)
return { refundableSignature, seizableSignature }
}
const walletPubKey = await this.getWalletPublicKey(this._baseDerivationPath)
const compressedPubKey = compressPubKey(walletPubKey.publicKey)
const node = bip32.fromPublicKey(
Buffer.from(compressedPubKey, 'hex'),
Buffer.from(walletPubKey.chainCode, 'hex'),
this._network
)
const addresses = []
const lastIndex = startingIndex + numAddresses
const changeVal = change ? '1' : '0'
for (let currentIndex = startingIndex; currentIndex < lastIndex; currentIndex++) {
const subPath = changeVal + '/' + currentIndex
const publicKey = node.derivePath(subPath).publicKey
const address = pubKeyToAddress(publicKey, this._network.name, 'pubKeyHash')
const path = this._baseDerivationPath + subPath
addresses.push(new Address({
address,
publicKey: publicKey.toString('hex'),
derivationPath: path,
index: currentIndex
}))
}
return addresses
}