How to use the sodium-native.crypto_sign_BYTES function in sodium-native

To help you get started, we’ve selected a few sodium-native 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 chm-diederichs / minisign / test / parse-signature.js View on Github external
fs.readFile('./test/fixtures/example.txt.minisig', (err, signature) => {
    t.error(err)
    var sigInfo = minisign.parseSignature(signature)

    t.equal(sigInfo.signature.length, sodium.crypto_sign_BYTES)
    t.deepEqual(sigInfo.signatureAlgorithm, Buffer.from('Ed'))
    t.equal(sigInfo.keyID.byteLength, 8)
    t.equal(sigInfo.globalSignature.length, sodium.crypto_sign_BYTES)
    t.end()
  })
})
github chm-diederichs / minisign / test / parse-signature.js View on Github external
fs.readFile('./test/fixtures/pre-hashed.txt.minisig', (err, signature) => {
    t.error(err)
    var sigInfo = minisign.parseSignature(signature)

    t.equal(sigInfo.signature.length, sodium.crypto_sign_BYTES)
    t.deepEqual(sigInfo.signatureAlgorithm, Buffer.from('ED'))
    t.equal(sigInfo.keyID.byteLength, 8)
    t.equal(sigInfo.globalSignature.length, sodium.crypto_sign_BYTES)
    t.end()
  })
})
github LiskHQ / lisk-sdk / elements / lisk-cryptography / src / nacl / fast.ts View on Github external
export const signDetached: NaclInterface['signDetached'] = (
	messageBytes,
	privateKeyBytes,
) => {
	const signatureBytes = Buffer.alloc(sodium.crypto_sign_BYTES);
	sodium.crypto_sign_detached(signatureBytes, messageBytes, privateKeyBytes);

	return signatureBytes;
};
github AraiEzzra / DDKCORE / shared / util / ed.ts View on Github external
public sign(hash: Buffer, keyPair: IKeyPair): Buffer {
        const sig: Buffer = Buffer.alloc(sodium.crypto_sign_BYTES);
        sodium.crypto_sign_detached(sig, hash, keyPair.privateKey);
        return sig;
    }
github chm-diederichs / minisign / minisignTool.js View on Github external
function signContent (content, comment, SKdetails, trustComment, sigAlgorithm = 'Ed') {
  var contentToSign
  var signatureAlgorithm

  if (sigAlgorithm === 'ED') {
    var hashedContent = Buffer.alloc(sodium.crypto_generichash_BYTES_MAX)
    sodium.crypto_generichash(hashedContent, content)
    contentToSign = hashedContent
    signatureAlgorithm = Buffer.from(sigAlgorithm)
  } else {
    contentToSign = content
    signatureAlgorithm = Buffer.from(SKdetails.signatureAlgorithm)
  }

  var signature = Buffer.alloc(sodium.crypto_sign_BYTES)
  var globalSignature = Buffer.alloc(sodium.crypto_sign_BYTES)

  sodium.crypto_sign_detached(signature, contentToSign, SKdetails.secretKey)

  var signatureInfo = Buffer.concat([signatureAlgorithm, SKdetails.keyID, signature])
  var untrustedComment = ('untrusted comment: ' + comment + '\n')
  var trustedComment = ('trusted comment: ' + trustComment.toString('ascii') + '\n')

  var forGlobalSig = Buffer.concat([signature, Buffer.from(trustComment)])
  sodium.crypto_sign_detached(globalSignature, forGlobalSig, SKdetails.secretKey)

  var minisignStr = (untrustedComment + signatureInfo.toString('base64') + '\n' + trustedComment + globalSignature.toString('base64'))
  return Buffer.from(minisignStr)
}
github chm-diederichs / minisign / minisign.js View on Github external
var contentToSign
  var signatureAlgorithm
  var trustComment

  if (sigAlgorithm.equals(Buffer.from('ED'))) {
    var hashedContent = Buffer.alloc(sodium.crypto_generichash_BYTES_MAX)
    sodium.crypto_generichash(hashedContent, content)
    contentToSign = hashedContent
    signatureAlgorithm = Buffer.from(sigAlgorithm)
  } else {
    assert(sigAlgorithm.equals(Buffer.from('Ed')), 'algorithm not recognised')
    contentToSign = content
    signatureAlgorithm = Buffer.from(SKdetails.signatureAlgorithm)
  }

  var signature = Buffer.alloc(sodium.crypto_sign_BYTES)
  var globalSignature = Buffer.alloc(sodium.crypto_sign_BYTES)

  sodium.sodium_mprotect_readwrite(SKdetails.secretKey)
  sodium.crypto_sign_detached(signature, contentToSign, SKdetails.secretKey)

  var signatureInfo = Buffer.concat([signatureAlgorithm, SKdetails.keyID, signature])
  var untrustedComment = Buffer.from('untrusted comment: ' + comment + '\n')
  var trustedComment = Buffer.from('\ntrusted comment: ' + tComment + '\n')
  var sigInfoBase64 = Buffer.from(signatureInfo.toString('base64'))

  var forGlobalSig = Buffer.concat([signature, Buffer.from(tComment)])
  sodium.crypto_sign_detached(globalSignature, forGlobalSig, SKdetails.secretKey)
  sodium.sodium_memzero(SKdetails.secretKey)
  sodium.sodium_mprotect_noaccess(SKdetails.secretKey)

  var globalSigBase64 = Buffer.from(globalSignature.toString('base64') + '\n')
github RiseVision / rise-node / packages / core-crypto / src / crypto_sodium_native.ts View on Github external
public sign(hash: Buffer, keypair: IKeypair): Buffer {
    const signature = Buffer.alloc(sodium.crypto_sign_BYTES);
    sodium.crypto_sign_detached(signature, hash, keypair.privateKey);
    return signature;
  }
github automerge / hypermerge / src / Crypto.ts View on Github external
export function sign(secretKey: EncodedSecretSigningKey, message: Buffer): EncodedSignature {
  const secretKeyBuffer = decode(secretKey)
  const signatureBuffer = Buffer.alloc(sodium.crypto_sign_BYTES) as sodium.Signature
  sodium.crypto_sign_detached(signatureBuffer, message, secretKeyBuffer)
  return encode(signatureBuffer)
}
github emilbayes / rendezvous-point / index.js View on Github external
sign: function (buf) {
      var sig = Buffer.alloc(sodium.crypto_sign_BYTES)
      sodium.crypto_sign_detached(sig, buf, discoverySk)
      return sig
    }
  }, cb)