Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Buffer.concat(
[key, signatureHop],
HASH_LENGTH + SIGNATURE_LENGTH
)
).slice(2)
if (!secp256k1.verify(Buffer.from(bitStr), signatureNextHop, pubKeyNextHop))
throw Error('Drop transaction')
if (!secp256k1.verify(hashedKey, signatureHop, pubKeyHop))
throw Error('Invalid signature')
if (!Buffer.isBuffer(signature) || signature.length !== SIGNATURE_LENGTH)
throw Error('Invalid input')
if (!utils.sha3(key).slice(2).compare(hashedKey) === 0) {
setTimeout(() => {
punish(pubKeyNextHop, 'hard')
}, TIMEOUT)
} else {
// misuse of calling node
punish(pubKeyHop)
}
}
function InvalidTXContract(keyHalfA, keyHalfB, hashedKey, encryptedSignature, signature, pubKey) {
if (!Buffer.isBuffer(signature) || signature.length !== SIGNATURE_LENGTH)
throw Error('Invalid input')
if (!Buffer.isBuffer(encryptedSignature) || encryptedSignature.length !== SIGNATURE_LENGTH)
throw Error('Invalid input')
if (!Buffer.isBuffer(pubKey) || !secp256k1.publicKeyVerify(pubKey))
throw Error('Invalid input')
if (!Buffer.isBuffer(hashedKey) || hashedKey.length !== HASH_LENGTH)
throw Error('Invalid input')
let _keyHalfA = utils.sha3(keyHalfA)
let _keyHalfB = utils.sha3(keyHalfB)
let key = utils.sha3(bufferXOR_in_place(keyHalfA, keyHalfB))
if (hashedKey.compare(utils.sha3(utils.sha3(key))) === 0)
throw Error('...')
let txSignature = bufferXOR(encryptedSignature, key)
if (!secp256k1.verify(Buffer.from('some tx'), txSignature, pubKey))
throw Error('...')
let bitStr = Buffer.concat([_keyHalfA, _keyHalfB, encryptedSignature, hashedKey], 3 * HASH_LENGTH + SIGNATURE_LENGTH)
if (!secp256k1.verify(bitStr, signature, pubKey))
throw Error('...') //TODO
}
if (!Buffer.isBuffer(encryptedSignature) || encryptedSignature.length !== SIGNATURE_LENGTH)
throw Error('Invalid input')
if (!Buffer.isBuffer(pubKey) || !secp256k1.publicKeyVerify(pubKey))
throw Error('Invalid input')
if (!Buffer.isBuffer(hashedKey) || hashedKey.length !== HASH_LENGTH)
throw Error('Invalid input')
let _keyHalfA = utils.sha3(keyHalfA)
let _keyHalfB = utils.sha3(keyHalfB)
let key = utils.sha3(bufferXOR_in_place(keyHalfA, keyHalfB))
if (hashedKey.compare(utils.sha3(utils.sha3(key))) === 0)
throw Error('...')
let txSignature = bufferXOR(encryptedSignature, key)
if (!secp256k1.verify(Buffer.from('some tx'), txSignature, pubKey))
throw Error('...')
let bitStr = Buffer.concat([_keyHalfA, _keyHalfB, encryptedSignature, hashedKey], 3 * HASH_LENGTH + SIGNATURE_LENGTH)
if (!secp256k1.verify(bitStr, signature, pubKey))
throw Error('...') //TODO
}
function WrongACKContract(signatureNextHop, pubKeyNextHop, key, signatureHop, pubKeyHop, hashedKey) {
let bitStr = utils.sha3(
Buffer.concat(
[key, signatureHop],
HASH_LENGTH + SIGNATURE_LENGTH
)
).slice(2)
if (!secp256k1.verify(Buffer.from(bitStr), signatureNextHop, pubKeyNextHop))
throw Error('Drop transaction')
if (!secp256k1.verify(hashedKey, signatureHop, pubKeyHop))
throw Error('Invalid signature')
if (!Buffer.isBuffer(signature) || signature.length !== SIGNATURE_LENGTH)
throw Error('Invalid input')
if (!utils.sha3(key).slice(2).compare(hashedKey) === 0) {
if (!Buffer.isBuffer(signature) || signature.length !== SIGNATURE_LENGTH)
throw Error('Invalid input')
if (!Buffer.isBuffer(encryptedSignature) || encryptedSignature.length !== SIGNATURE_LENGTH)
throw Error('Invalid input')
if (!Buffer.isBuffer(pubKey) || !secp256k1.publicKeyVerify(pubKey))
throw Error('Invalid input')
if (!Buffer.isBuffer(hashedKey) || hashedKey.length !== HASH_LENGTH)
throw Error('Invalid input')
let _keyHalfA = utils.sha3(keyHalfA)
let _keyHalfB = utils.sha3(keyHalfB)
let key = utils.sha3(bufferXOR_in_place(keyHalfA, keyHalfB))
if (hashedKey.compare(utils.sha3(utils.sha3(key))) === 0)
throw Error('...')
let txSignature = bufferXOR(encryptedSignature, key)
if (!secp256k1.verify(Buffer.from('some tx'), txSignature, pubKey))
throw Error('...')
let bitStr = Buffer.concat([_keyHalfA, _keyHalfB, encryptedSignature, hashedKey], 3 * HASH_LENGTH + SIGNATURE_LENGTH)
if (!secp256k1.verify(bitStr, signature, pubKey))
throw Error('...') //TODO
}
function InvalidTXContract(keyHalfA, keyHalfB, hashedKey, encryptedSignature, signature, pubKey) {
if (!Buffer.isBuffer(signature) || signature.length !== SIGNATURE_LENGTH)
throw Error('Invalid input')
if (!Buffer.isBuffer(encryptedSignature) || encryptedSignature.length !== SIGNATURE_LENGTH)
throw Error('Invalid input')
if (!Buffer.isBuffer(pubKey) || !secp256k1.publicKeyVerify(pubKey))
throw Error('Invalid input')
if (!Buffer.isBuffer(hashedKey) || hashedKey.length !== HASH_LENGTH)
throw Error('Invalid input')
let _keyHalfA = utils.sha3(keyHalfA)
let _keyHalfB = utils.sha3(keyHalfB)
let key = utils.sha3(bufferXOR_in_place(keyHalfA, keyHalfB))
if (hashedKey.compare(utils.sha3(utils.sha3(key))) === 0)
throw Error('...')
let txSignature = bufferXOR(encryptedSignature, key)
if (!secp256k1.verify(Buffer.from('some tx'), txSignature, pubKey))
throw Error('...')
let bitStr = Buffer.concat([_keyHalfA, _keyHalfB, encryptedSignature, hashedKey], 3 * HASH_LENGTH + SIGNATURE_LENGTH)
if (!secp256k1.verify(bitStr, signature, pubKey))
throw Error('...') //TODO