How to use the tweetnacl.sign function in tweetnacl

To help you get started, we’ve selected a few tweetnacl 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 BrightID / BrightID / webrtc-app / src / actions / exchange.js View on Github external
// obtain local public / secret keys
  // message (publicKey1 + publicKey2 + timestamp) signed by the private key of the user represented by publicKey1
  let msg;
  if (user === 'userA') {
    msg = strToUint8Array(
      publicKey.toString() + publicKey2.toString() + timestamp,
    );
  } else if (user === 'userB') {
    msg = strToUint8Array(
      publicKey2.toString() + publicKey.toString() + timestamp,
    );
  }

  const msgStr = Buffer.from(msg).toString();

  const signedMsg = nacl.sign(msg, secretKey);

  dispatch(
    setPairingMessage({
      msg,
      msgStr,
      signedMsg,
    }),
  );

  // // testing signed message
  // const genKeys = nacl.sign.keyPair();
  // // console.warn(publicKey.toString());
  // console.log(Buffer.from(message).toString());
  // const sig1 = nacl.sign.detached(message, secretKey);
  // const sig2 = nacl.sign.detached(message, genKeys.secretKey);
  // // console.log(publicKey instanceof Uint8Array);
github brave / sync / lib / crypto.js View on Github external
module.exports.sign = function (message/* : Uint8Array */,
  secretKey/* : Uint8Array */) {
  return nacl.sign(message, secretKey)
}
github carlos8f / salty / lib / wallet.js View on Github external
sign: function (signBuf, detach) {
      if (detach) {
        //console.log('signed', crypto.createHash('sha1').update(signBuf).digest('hex'))
        var sig = Buffer.from(nacl.sign.detached(a(signBuf), a(this.signSk)))
        //console.log('sig', crypto.createHash('sha1').update(sig).digest('hex'))
        return sig
      }
      return Buffer(nacl.sign(a(signBuf), a(this.signSk)))
    },
    regen: function () {
github dfinity-side-projects / js-bls-lib / benchmark / benchmark.js View on Github external
const v = bls.verify(sig, pub, msg)

  let end = new Date()
  let time = end.getTime() - start.getTime()
  console.log('finished in', time, 'ms')
  console.log(v)

  bls.free(sec)
  bls.free(sig)
  bls.free(pub)

  const keyPair = nacl.sign.keyPair()

  start = new Date()
  const signedMsg = nacl.sign(msg, keyPair.secretKey)
  const rmsg = nacl.sign.open(signedMsg, keyPair.publicKey)

  end = new Date()
  time = end.getTime() - start.getTime()
  console.log('finished in', time, 'ms')
  console.log(Buffer.from(rmsg).toString())
})
github bogbook / bog / bog.js View on Github external
var message = { 
    author: keys.publicKey 
  }
  
  var feed = await localforage.getItem(keys.publicKey)

  if (feed) {
    var firstMsg = await open(feed[0])
    post.seq = ++firstMsg.seq
  } else {
    post.seq = 1
  }

  message.key = '%' + nacl.util.encodeBase64(nacl.hash(nacl.util.decodeUTF8(JSON.stringify(post)))),
  message.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(post)), nacl.util.decodeBase64(keys.privateKey)))

  var openedMsg = await open(message)

  if (!preview) {
    console.log('ADDING TO LOG AND FEED')
    localforage.getItem('log').then(log => {
      if (log) {
        log.unshift(openedMsg)
        localforage.setItem('log', log)
      } else {
        var newlog = [openedMsg]
        localforage.setItem('log', newlog)
      }
    })

    var subs = [keys.publicKey]
github loomnetwork / loom-js / src / crypto-utils.ts View on Github external
export function sign(msg: Uint8Array, privateKey: Uint8Array): Uint8Array {
  const sigMsg = nacl.sign(msg, privateKey)
  return sigMsg.slice(0, SIGNATURE_LENGTH)
}
github wallix / datapeps-sdk-js / src / CryptoFuncs.js View on Github external
EncryptSES.prototype.encrypt = function (publicKey, message) {
        var nonce = nacl.randomBytes(nacl.box.nonceLength);
        var msgSign = nacl.sign(message, this.signSecretKey);
        var cipher = nacl.box(msgSign, nonce, publicKey, this.boxSecretKey);
        return { nonce: nonce, message: nacl.sign(cipher, this.signSecretKey) };
    };
    return EncryptSES;
github jeffallen6767 / chain / src / utils.js View on Github external
getSignedMessage = function(obj, keyBuffer) {
      return Buffer.from(nacl.sign(
        objToUint8Array(obj), 
        keyBuffer
      )).toString('hex');
    },
    getMessageSignature = function(obj, keyBuffer) {
github wallix / datapeps-sdk-js / src / CryptoFuncs.ts View on Github external
encrypt(
    publicKey: Uint8Array,
    message: Uint8Array
  ): { message: Uint8Array; nonce: Uint8Array } {
    let nonce = nacl.randomBytes(nacl.box.nonceLength);
    let msgSign = nacl.sign(message, this.signSecretKey);
    let cipher = nacl.box(msgSign, nonce, publicKey, this.boxSecretKey);
    return { nonce, message: nacl.sign(cipher, this.signSecretKey) };
  }
}
github loomnetwork / loom-js / signature.js View on Github external
export function sign(msg, privKey) {
    const sigMsg = nacl.sign(msg, privKey);
    const sig = sigMsg.slice(0, signatureLength);
    return new SignatureEd25519(sig);
}