How to use the sodium-native.crypto_sign_detached 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 holochain / n3h / lib / mosodium / sign.js View on Github external
secretKey.readable(_secretKey => {
    sodium.crypto_sign_detached(out, message, _secretKey)
  })
github chm-diederichs / minisign / minisignTool.js View on Github external
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 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 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 chm-diederichs / minisign / minisignTool.js View on Github external
} 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 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 chm-diederichs / minisign / minisign.js View on Github external
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')

  var outputBuf = Buffer.concat([untrustedComment, sigInfoBase64, trustedComment, globalSigBase64])

  return {
github LiskHQ / lisk-sdk / framework / src / modules / chain / helpers / ed.js View on Github external
ed.sign = function(hash, privateKey) {
	if (!(hash instanceof Buffer)) {
		throw new Error('argument message must be a buffer');
	}
	const signature = Buffer.alloc(sodium.crypto_sign_BYTES);
	sodium.crypto_sign_detached(signature, hash, privateKey);

	return signature;
};
github mafintosh / sodium-signatures / sodium.js View on Github external
exports.sign = function (message, secretKey) {
  var signature = new Buffer(sodium.crypto_sign_BYTES)
  sodium.crypto_sign_detached(signature, message, secretKey)
  return signature
}