How to use the sodium-native.crypto_sign_verify_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 chm-diederichs / minisign / test / sign-content.js View on Github external
fs.readFile('./test/fixtures/minisign.pub', (err, PK) => {
        t.error(err)
        var PKinfo = minisign.parsePubKey(PK)
        t.ok(minisign.verifySignature(parsedOutput1, contentToSign, PKinfo))
        t.ok(sodium.crypto_sign_verify_detached(parsedOutput2.signature, contentToSign, PKinfo.publicKey))
        t.ok(minisign.verifySignature(parsedOutput2, contentToSign, PKinfo))
        t.end()
      })
    })
github chm-diederichs / minisign / minisignTool.js View on Github external
if (signature.signatureAlgorithm.toString() === 'ED') {
    var hashedContent = Buffer.alloc(sodium.crypto_generichash_BYTES_MAX)
    sodium.crypto_generichash(hashedContent, originalContent)
    contentSigned = hashedContent
  } else {
    contentSigned = originalContent
  }

  if (!(signature.keyID.equals(publicKeyInfo.keyID))) {
    return ("error: keyID's do not match")
  } else {
    if (!(sodium.crypto_sign_verify_detached(signature.signature, contentSigned, publicKeyInfo.publicKey))) {
      return ('error: signature verification failed')
    } else {
      var forGlobalSig = Buffer.concat([signature.signature, Buffer.from(signature.trustedComment)])
      if (!(sodium.crypto_sign_verify_detached(signature.globalSignature, forGlobalSig, publicKeyInfo.publicKey))) {
        return ('error: trusted comment cannot be verified')
      }
    }
  }
  return ('signature and comment successfully verified')
}
github chm-diederichs / minisign / minisignTool.js View on Github external
function verifySignature (signedContent, originalContent, publicKeyInfo) {
  var contentSigned
  var signature = parseSignature(signedContent)
  if (signature.signatureAlgorithm.toString() === 'ED') {
    var hashedContent = Buffer.alloc(sodium.crypto_generichash_BYTES_MAX)
    sodium.crypto_generichash(hashedContent, originalContent)
    contentSigned = hashedContent
  } else {
    contentSigned = originalContent
  }

  if (!(signature.keyID.equals(publicKeyInfo.keyID))) {
    return ("error: keyID's do not match")
  } else {
    if (!(sodium.crypto_sign_verify_detached(signature.signature, contentSigned, publicKeyInfo.publicKey))) {
      return ('error: signature verification failed')
    } else {
      var forGlobalSig = Buffer.concat([signature.signature, Buffer.from(signature.trustedComment)])
      if (!(sodium.crypto_sign_verify_detached(signature.globalSignature, forGlobalSig, publicKeyInfo.publicKey))) {
        return ('error: trusted comment cannot be verified')
      }
    }
  }
  return ('signature and comment successfully verified')
}
github automerge / hypermerge / src / Crypto.ts View on Github external
export function verify(
  publicKey: EncodedPublicSigningKey,
  message: Buffer,
  signature: EncodedSignature
): boolean {
  const publicKeyBuffer = decode(publicKey)
  const signatureBuffer = decode(signature)
  return sodium.crypto_sign_verify_detached(signatureBuffer, message, publicKeyBuffer)
}
github chm-diederichs / minisign / minisign.js View on Github external
if (signature.signatureAlgorithm.equals(Buffer.from('ED'))) {
    var hashedContent = Buffer.alloc(sodium.crypto_generichash_BYTES_MAX)
    sodium.crypto_generichash(hashedContent, originalContent)
    contentSigned = hashedContent
  } else {
    contentSigned = originalContent
  }

  if (!(signature.keyID.equals(publicKeyInfo.keyID))) {
    throw new Error("keyID's do not match")
  } else {
    if (!(sodium.crypto_sign_verify_detached(signature.signature, contentSigned, publicKeyInfo.publicKey))) {
      throw new Error('signature verification failed')
    } else {
      var forGlobalSig = Buffer.concat([signature.signature, Buffer.from(signature.trustedComment)])
      if (!(sodium.crypto_sign_verify_detached(signature.globalSignature, forGlobalSig, publicKeyInfo.publicKey))) {
        throw new Error('trusted comment cannot be verified')
      }
    }
  }
  return true
}
github holochain / n3h / lib / mosodium / sign.js View on Github external
exports.verify = function signVerify (signature, message, publicKey) {
  if (!(signature instanceof Buffer)) {
    throw new Error('signature must be a Buffer')
  }
  if (!(message instanceof Buffer)) {
    throw new Error('message must be a Buffer')
  }
  if (!(publicKey instanceof Buffer)) {
    throw new Error('publicKey must be a Buffer')
  }

  return sodium.crypto_sign_verify_detached(signature, message, publicKey)
}
github chm-diederichs / minisign / minisign.js View on Github external
function verifySignature (signature, originalContent, publicKeyInfo) {
  var contentSigned
  if (signature.signatureAlgorithm.equals(Buffer.from('ED'))) {
    var hashedContent = Buffer.alloc(sodium.crypto_generichash_BYTES_MAX)
    sodium.crypto_generichash(hashedContent, originalContent)
    contentSigned = hashedContent
  } else {
    contentSigned = originalContent
  }

  if (!(signature.keyID.equals(publicKeyInfo.keyID))) {
    throw new Error("keyID's do not match")
  } else {
    if (!(sodium.crypto_sign_verify_detached(signature.signature, contentSigned, publicKeyInfo.publicKey))) {
      throw new Error('signature verification failed')
    } else {
      var forGlobalSig = Buffer.concat([signature.signature, Buffer.from(signature.trustedComment)])
      if (!(sodium.crypto_sign_verify_detached(signature.globalSignature, forGlobalSig, publicKeyInfo.publicKey))) {
        throw new Error('trusted comment cannot be verified')
      }
    }
  }
  return true
}
github mafintosh / sodium-signatures / sodium.js View on Github external
exports.verify = function (message, signature, publicKey) {
  return sodium.crypto_sign_verify_detached(signature, message, publicKey)
}
github LiskHQ / lisk-sdk / elements / lisk-cryptography / src / nacl / fast.ts View on Github external
export const verifyDetached: NaclInterface['verifyDetached'] = (
	messageBytes,
	signatureBytes,
	publicKeyBytes,
) =>
	sodium.crypto_sign_verify_detached(
		signatureBytes,
		messageBytes,
		publicKeyBytes,
	);