How to use sodium-javascript - 10 common examples

To help you get started, we’ve selected a few sodium-javascript 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 AraiEzzra / DDKCORE / backlog / logic / transaction.js View on Github external
Transaction.prototype.verifyBytes = (bytes, publicKey, signature) => {
    const hash = crypto.createHash('sha256').update(bytes).digest();
    const signatureBuffer = Buffer.from(signature, 'hex');
    const publicKeyBuffer = Buffer.from(publicKey, 'hex');
    return sodium.crypto_sign_verify_detached(signatureBuffer, hash, publicKeyBuffer);
};
github AraiEzzra / DDKCORE / core / service / block.ts View on Github external
private verifySignature(block: Block, result: IVerifyResult): IVerifyResult {
        let valid: boolean = false;
        const hash = crypto.createHash('sha256').update(this.getBytes(block)).digest();
        const blockSignatureBuffer = Buffer.from(block.signature, 'hex');
        const generatorPublicKeyBuffer = Buffer.from(block.generatorPublicKey, 'hex');

        try {
            valid = sodium.crypto_sign_verify_detached(blockSignatureBuffer, hash, generatorPublicKeyBuffer);
        } catch (e) {
            if (config.constants.VERIFY_BLOCK_SIGNATURE) {
                result.errors.push(e.toString());
            } else {
                logger.error(e.toString());
            }
        }

        if (!valid) {
            if (config.constants.VERIFY_BLOCK_SIGNATURE) {
                result.errors.push('Failed to verify block signature');
            } else {
                logger.error(`Failed to verify block signature`);
            }
        }
        return result;
github AraiEzzra / DDKCORE / src / logic / transaction.js View on Github external
Transaction.prototype.verifyBytes = function (bytes, publicKey, signature) {
    const hash = crypto.createHash('sha256').update(bytes).digest();
    const signatureBuffer = Buffer.from(signature, 'hex');
    const publicKeyBuffer = Buffer.from(publicKey, 'hex');
    return sodium.crypto_sign_verify_detached(signatureBuffer, hash, publicKeyBuffer);
};
github AraiEzzra / DDKCORE / backlog / logic / block.js View on Github external
Block.prototype.verifySignature = function (block) {
    const hash = crypto.createHash('sha256').update(this.getBytes(block)).digest();
    const blockSignatureBuffer = Buffer.from(block.blockSignature, 'hex');
    const generatorPublicKeyBuffer = Buffer.from(block.generatorPublicKey, 'hex');
    return sodium.crypto_sign_verify_detached(blockSignatureBuffer, hash, generatorPublicKeyBuffer);
};
github AraiEzzra / DDKCORE / backlog / helpers / ed.js View on Github external
ed.verify = function (hash, signatureBuffer, publicKeyBuffer) {
    return sodium.crypto_sign_verify_detached(signatureBuffer, hash, publicKeyBuffer);
};
github AraiEzzra / DDKCORE / backlog / logic / transaction.js View on Github external
Transaction.prototype.sign = (keyPair, trs) => {
    const sig = Buffer.alloc(sodium.crypto_sign_BYTES);

    sodium.crypto_sign_detached(sig, self.getHash(trs), keyPair.privateKey);
    return sig.toString('hex');
};
github AraiEzzra / DDKCORE / backlog / helpers / ed.js View on Github external
ed.sign = function (hash, keyPair) {
    const sig = Buffer.alloc(sodium.crypto_sign_BYTES);
    sodium.crypto_sign_detached(sig, hash, keyPair.privateKey);
    return sig;
};
github AraiEzzra / DDKCORE / core / service / block.ts View on Github external
private sign(block, keyPair): Response {
        const blockHash = this.getHash(block);
        if (!blockHash.success) {
            return new Response({ errors: [...blockHash.errors, 'sign'] });
        }

        const sig = Buffer.alloc(sodium.crypto_sign_BYTES);
        sodium.crypto_sign_detached(sig, blockHash.data, keyPair.privateKey);
        return new Response({ data: sig.toString('hex') });
    }
github AraiEzzra / DDKCORE / src / logic / transaction.js View on Github external
Transaction.prototype.sign = function (keyPair, trs) {
    const sig = Buffer.alloc(sodium.crypto_sign_BYTES);

    sodium.crypto_sign_detached(sig, this.getHash(trs), keyPair.privateKey);
    return sig.toString('hex');
};
github AraiEzzra / DDKCORE / backlog / logic / block.js View on Github external
Block.prototype.sign = function (block, keyPair) {
    const blockHash = this.getHash(block);
    const sig = Buffer.alloc(sodium.crypto_sign_BYTES);

    sodium.crypto_sign_detached(sig, blockHash, keyPair.privateKey);
    return sig.toString('hex');
};

sodium-javascript

WIP - a pure javascript version of sodium-native

MIT
Latest version published 3 years ago

Package Health Score

54 / 100
Full package analysis

Similar packages