How to use supercop - 10 common examples

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 nomic-io / js-tendermint / test / verify.js View on Github external
let precommits = []
  let time = new Date(header.time).getTime()
  for (let i = 0; i < validators.length; i++) {
    let validator = validators[i]
    let precommit = {
      validator_address: validator.address,
      validator_index: String(i),
      height: header.height,
      round: '0',
      timestamp: new Date(time + Math.random() * 1000).toISOString(),
      type: 2,
      block_id: blockId
    }
    let signBytes = Buffer.from(getVoteSignBytes(header.chain_id, precommit))
    let pub = Buffer.from(validator.pub_key.value, 'base64')
    let signature = ed25519.sign(signBytes, pub, validator.priv_key)
    precommit.signature = {
      type: 'tendermint/SignatureEd25519',
      value: signature.toString('base64')
    }
    precommits.push(precommit)
  }
  return {
    block_id: blockId,
    precommits
  }
}
github hyperledger / iroha-javascript / src / irohajs.ts View on Github external
sign (msg: string): string {
    const message = new Buffer(sha3_256(msg));
    return supercop.sign(message, this.publicKey, this.privateKey).toString("base64");
  }
}
github OwenRay / Remote-MediaServer / backend / modules / sharing / EDHT.js View on Github external
        sign: buf => ed.sign(buf, this.keypair.publicKey, this.keypair.secretKey),
      };
github vacuumlabs / adalite / withNode / utils.js View on Github external
exports.sign = function(message, extendedPrivateKey) {
  const privKey = extendedPrivateKey.getSecretKey() //extendedPrivateKey.substr(0, 128);
  const pubKey = extendedPrivateKey.getPublicKey() //substr(128, 64);

  const messageToSign = new Buffer(message, 'hex')

  return ed25519
    .sign(messageToSign, new Buffer(pubKey, 'hex'), new Buffer(privKey, 'hex'))
    .toString('hex')
}
github hyperledger / iroha-javascript / src / irohajs.ts View on Github external
export function sign (opt: { publicKey: string, privateKey: string, message: string }): string {
  const publicKey = new Buffer(opt.publicKey, "base64");
  const privateKey = new Buffer(opt.privateKey, "base64");
  const sha3Message = new Buffer(sha3_256(opt.message));

  const sig = supercop.sign(
    sha3Message,
    publicKey,
    privateKey
  ).toString("base64");

  return sig;
}
github nomic-io / shea / bin / cmd.js View on Github external
function getSignature(req) {
    return ed
      .sign(
        Buffer.isBuffer(req.body) ? req.body : Buffer.from(stringify(req.body)),
        req.keypair.publicKey,
        req.keypair.secretKey
      )
      .toString('base64')
  }
  expressApp.post('/sign', ensureKey, (req, res) => {
github vacuumlabs / adalite / utils.js View on Github external
exports.sign = function(message, extendedPrivateKey) {
  const privKey = extendedPrivateKey.getSecretKey() //extendedPrivateKey.substr(0, 128);
  const pubKey = extendedPrivateKey.getPublicKey() //substr(128, 64);

  const messageToSign = new Buffer(message, 'hex')

  return ed25519
    .sign(messageToSign, new Buffer(pubKey, 'hex'), new Buffer(privKey, 'hex'))
    .toString('hex')
}
github OwenRay / Remote-MediaServer / backend / modules / sharing / EDHT.js View on Github external
checkForKeys() {
    if (!Settings.getValue('dht25519pub')) {
      const keypair = ed.createKeyPair(ed.createSeed());
      Settings.setValue('dht25519pub', keypair.publicKey.toString('hex'));
      Settings.setValue('dht25519priv', keypair.secretKey.toString('hex'));
      Settings.save();
      this.keypair = keypair;
      return;
    }
    this.keypair = {
      publicKey: Buffer.from(Settings.getValue('dht25519pub'), 'hex'),
      secretKey: Buffer.from(Settings.getValue('dht25519priv'), 'hex'),
    };
  }

supercop

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

MIT
Latest version published 11 months ago

Package Health Score

56 / 100
Full package analysis