How to use the crypto-browserify.randomBytes function in crypto-browserify

To help you get started, we’ve selected a few crypto-browserify 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 AltCoinExchange / altcoin-atomic-trading-platform / ethatomicswap / dist / common.js View on Github external
this.GenerateSecret = function () {

        var RIPEMD160 = require('ripemd160');
        var crypto = require('crypto-browserify');

        var secretBuffer = crypto.randomBytes(32);
        var secret = secretBuffer.toString('hex');
        var hashedSecret = new RIPEMD160().update(secretBuffer).digest('hex');

        console.log("\nSecret:\t\t\t", secret);
        console.log("\Hashed Secret:\t\t", hashedSecret, "\n");

        return { "secret": secret, "hashedSecret": hashedSecret };
    };
github AraiEzzra / DDKCORE / core / service / transaction.ts View on Github external
if (errors.length) {
            return new ResponseEntity({ errors });
        }

        const service: ITransactionService = getTransactionServiceByType(data.type);
        service.create(data);

        const trs = new Transaction({
            senderPublicKey: data.senderPublicKey,
            senderAddress: data.senderAddress,
            recipientAddress: data.recipientAddress,
            type: data.type,
            amount: data.amount,
            fee: service.calculateFee(data, sender),
            salt: cryptoBrowserify.randomBytes(SALT_LENGTH).toString('hex'),
        });

        trs.signature = this.sign(keyPair, trs);
        trs.id = this.getId(trs);

        return new ResponseEntity({ data: trs });
    }
github irisnet / irisnet-crypto / src / chains / iris / crypto.js View on Github external
exportKeystore(privateKeyHex,password){
        if (Utils.isEmpty(password) || password.length < 8){
            throw new Error("password's length must be greater than 8")
        }
        if (Utils.isEmpty(privateKeyHex)){
            throw new Error("private key must be not empty")
        }
        const salt = Cryp.randomBytes(32);
        const iv = Cryp.randomBytes(16);
        const cipherAlg = Config.iris.keystore.cipherAlg;
        const kdf = Config.iris.keystore.kdf;
        const address = this.import(privateKeyHex).address;

        const kdfparams = {
            dklen: 32,
            salt: salt.toString("hex"),
            c: Config.iris.keystore.c,
            prf: "hmac-sha256"
        };
        const derivedKey = Cryp.pbkdf2Sync(Buffer.from(password), salt, kdfparams.c, kdfparams.dklen, "sha256");
        const cipher = Cryp.createCipheriv(cipherAlg, derivedKey.slice(0, 16), iv);
        if (!cipher) {
            throw new Error("Unsupported cipher")
        }
github AltCoinExchange / altcoin-atomic-trading-platform / legacy / btcatomicswap / src / common / secret-hash.js View on Github external
export const generateSecret = () => {
  const secretBuffer = crypto.randomBytes(32);
  const secret = secretBuffer.toString('hex');
  const secretHash = ripemd160(secretBuffer);

  return {
    secret,
    secretHash,
  };
};
github irisnet / irisnet-crypto / src / chains / iris / crypto.js View on Github external
exportKeystore(privateKeyHex,password){
        if (Utils.isEmpty(password) || password.length < 8){
            throw new Error("password's length must be greater than 8")
        }
        if (Utils.isEmpty(privateKeyHex)){
            throw new Error("private key must be not empty")
        }
        const salt = Cryp.randomBytes(32);
        const iv = Cryp.randomBytes(16);
        const cipherAlg = Config.iris.keystore.cipherAlg;
        const kdf = Config.iris.keystore.kdf;
        const address = this.import(privateKeyHex).address;

        const kdfparams = {
            dklen: 32,
            salt: salt.toString("hex"),
            c: Config.iris.keystore.c,
            prf: "hmac-sha256"
        };
        const derivedKey = Cryp.pbkdf2Sync(Buffer.from(password), salt, kdfparams.c, kdfparams.dklen, "sha256");
        const cipher = Cryp.createCipheriv(cipherAlg, derivedKey.slice(0, 16), iv);
        if (!cipher) {
            throw new Error("Unsupported cipher")
        }
github AltCoinExchange / altcoin-atomic-trading-platform / wallet / src / common / hashing.ts View on Github external
public static generateSecret(algo: AlgoTypes = AlgoTypes.Ripemd160) {

    let algoInstance: IHashAlgo;
    if (algo === AlgoTypes.Ripemd160) {
      algoInstance = new Ripemd160();
    } else if (algo === AlgoTypes.Hash160) {
      algoInstance = new Hash160();
    }

    const secretBuffer = crypto.randomBytes(32);
    const secret = secretBuffer.toString("hex");
    const secretHash = algoInstance.hash(secretBuffer);
    return new SecretResult(secret, secretHash);
  }
}
github AraiEzzra / DDKCORE / src / logic / transaction.js View on Github external
if (!data.keypair) {
        throw 'Invalid keypair';
    }

    let trs = {
        type: data.type,
        amount: 0,
        senderPublicKey: data.sender.publicKey,
        requesterPublicKey: data.requester ? data.requester.publicKey.toString('hex') : null,
        timestamp: slots.getTime(),
        asset: {},
        stakedAmount: 0,
        trsName: 'NA',
        groupBonus: 0,
        salt: cryptoBrowserify.randomBytes(16).toString('hex'),
        reward: data.rewardPercentage || null
    };

    trs = await __private.types[trs.type].create.call(this, data, trs);
    trs.signature = this.sign(data.keypair, trs);

    if (data.sender.secondSignature && data.secondKeypair) {
        trs.signSignature = this.sign(data.secondKeypair, trs);
    }

    trs.id = this.getId(trs);
    trs.fee = __private.types[trs.type].calculateFee.call(this, trs, data.sender) || 0;

    return trs;
};
github irisnet / irisnet-crypto / src / chains / iris / crypto.js View on Github external
};
        const derivedKey = Cryp.pbkdf2Sync(Buffer.from(password), salt, kdfparams.c, kdfparams.dklen, "sha256");
        const cipher = Cryp.createCipheriv(cipherAlg, derivedKey.slice(0, 16), iv);
        if (!cipher) {
            throw new Error("Unsupported cipher")
        }

        const cipherBuffer = Buffer.concat([cipher.update(Buffer.from(privateKeyHex, "hex")), cipher.final()]);
        const bufferValue = Buffer.concat([derivedKey.slice(16, 32), cipherBuffer]);
        let hashCiper = Cryp.createHash("sha256");
        hashCiper.update(bufferValue);
        const mac = hashCiper.digest().toString("hex");
        return {
            version: "1",
            id: UUID.v4({
                random: Cryp.randomBytes(16)
            }),
            address: address,
            crypto: {
                ciphertext: cipherBuffer.toString("hex"),
                cipherparams: {
                    iv: iv.toString("hex")
                },
                cipher: cipherAlg,
                kdf,
                kdfparams: kdfparams,
                mac: mac
            }
        }
    }
    importKeystore(keystore, password){
github AraiEzzra / DDKCORE / backlog / logic / transaction.js View on Github external
if (!data.keypair) {
        throw 'Invalid keypair';
    }

    let trs = {
        type: data.type,
        amount: 0,
        senderPublicKey: data.sender.publicKey,
        requesterPublicKey: data.requester ? data.requester.publicKey.toString('hex') : null,
        timestamp: slots.getTime(),
        asset: {},
        stakedAmount: 0,
        trsName: 'NA',
        groupBonus: 0,
        salt: cryptoBrowserify.randomBytes(16).toString('hex'),
        reward: data.rewardPercentage || null
    };

    trs = await __private.types[trs.type].create.call(self, data, trs);
    trs.signature = self.sign(data.keypair, trs);

    if (data.sender.secondSignature && data.secondKeypair) {
        trs.signSignature = self.sign(data.secondKeypair, trs);
    }

    trs.id = self.getId(trs);
    trs.fee = __private.types[trs.type].calculateFee.call(self, trs, data.sender) || 0;

    return trs;
};
github AltCoinExchange / altcoin-atomic-trading-platform / btcatomicswap / dist / common / secret-hash.js View on Github external
var generateSecret = exports.generateSecret = function generateSecret() {
  var secretBuffer = crypto.randomBytes(32);
  var secret = secretBuffer.toString('hex');
  var secretHash = ripemd160(secretBuffer);

  return {
    secret: secret,
    secretHash: secretHash
  };
};

crypto-browserify

implementation of crypto for the browser

MIT
Latest version published 2 months ago

Package Health Score

81 / 100
Full package analysis

Similar packages