How to use the web3.utils.sha3 function in web3

To help you get started, we’ve selected a few web3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github validitylabs / hopr / old / js / payments / contract.js View on Github external
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)
    }
}
github validitylabs / hopr / old / js / payments / contract.js View on Github external
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
}
github validitylabs / hopr / old / js / payments / contract.js View on Github external
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
}
github validitylabs / hopr / old / js / payments / contract.js View on Github external
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) {
github validitylabs / hopr / old / js / payments / contract.js View on Github external
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
}
github validitylabs / hopr / old / js / payments / contract.js View on Github external
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