How to use the supercop.js.verify function in supercop

To help you get started, we’ve selected a few supercop 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 nomic-io / js-tendermint / src / verify.js View on Github external
if (precommit == null) continue
    if (!precommit.block_id.hash) continue

    let validator = validatorsByAddress[precommit.validator_address]

    // skip if this validator isn't in the set
    // (we allow precommits from validators not in the set,
    // because we sometimes check the commit against older
    // validator sets)
    if (!validator) continue

    let signature = Buffer.from(precommit.signature, 'base64')
    let signBytes = getVoteSignBytes(header.chain_id, precommit)
    let pubKey = Buffer.from(validator.pub_key.value, 'base64')

    if (!ed25519.verify(signature, signBytes, pubKey)) {
      throw Error('Invalid precommit signature')
    }

    // count this validator's voting power
    committedVotingPower += safeParseInt(validator.voting_power)
  }

  // sum all validators' voting power
  let totalVotingPower = validators.reduce(
    (sum, v) => sum + safeParseInt(v.voting_power), 0)
  // JS numbers have no loss of precision up to 2^53, but we
  // error at over 2^52 since we have to do arithmetic. apps
  // should be able to keep voting power lower than this anyway
  if (totalVotingPower > 2 ** 52) {
    throw Error('Total voting power must be less than 2^52')
  }
github nomic-io / coins / src / ed25519Account.js View on Github external
onSpend ({ pubkey, signature }, { sigHash }) {
    // verify signature
    if (!ed25519.verify(signature, sigHash, pubkey)) {
      throw Error('Invalid signature')
    }
  }
}
github hyperledger / iroha-javascript / src / irohajs.ts View on Github external
export function verify (opt: { publicKey: string, message: string, signature: string }) {
  const valid = supercop.verify(
    new Buffer(opt.signature, "base64"),
    new Buffer(opt.message),
    new Buffer(opt.publicKey, "base64")
  );
  return valid;
}

supercop

cross-compiled javascript implementation of ed25519 based on supercop-ref10

MIT
Latest version published 4 months ago

Package Health Score

59 / 100
Full package analysis