How to use the eth-crypto.hash function in eth-crypto

To help you get started, we’ve selected a few eth-crypto 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 cryptoeconomics-study / code / ch1 / 1.2 / solutions / demo.js View on Github external
const EthCrypto = require('eth-crypto');
const Client = require('./client.js');
const Paypal = require('./paypal.js');

console.log('/////////////////////////////////////');
console.log('// Hashing and Public/Private Keys //');
console.log('/////////////////////////////////////');

// Hashing A Message
console.log("\nLet's hash a message!");
const message = 'Hello World';
console.log('The message is: ', message);
const messageHash = EthCrypto.hash.keccak256(message);
console.log('The hash of that message is: ', messageHash);

// Creating Public/Private Keys
console.log('\nCreating public/private key pairs to sign and verify messages.');

// Init Alice
const alice = new Client();
console.log("Init Alice's Client\n", alice);

// Init Bob
const bob = new Client();
console.log("Init Bob's Client\n", bob);

// Init Carol
const carol = new Client();
console.log("Init Carol's Client\n", carol);
github cryptoeconomics-study / code / ch1 / 1.2 / demo.js View on Github external
const EthCrypto = require('eth-crypto');
const Client = require('./Client.js');
const Paypal = require('./Paypal.js');

console.log('/////////////////////////////////////');
console.log('// Hashing and Public/Private Keys //');
console.log('/////////////////////////////////////');

// Hashing A Message
console.log("\nLet's hash a message!");
const message = 'Hello World';
console.log('The message is: ', message);
const messageHash = EthCrypto.hash.keccak256(message);
console.log('The hash of that message is: ', messageHash);

// Creating Public/Private Keys
console.log('\nCreating public/private key pairs to sign and verify messages.');

// Init Alice
const alice = new Client();
console.log("Init Alice's Client\n", alice);

// Init Bob
const bob = new Client();
console.log("Init Bob's Client\n", bob);

// Init Carol
const carol = new Client();
console.log("Init Carol's Client\n", carol);
github liquality / chainabstractionlayer / packages / ethereum-rpc-wallet-provider / lib / EthereumRPCWalletProvider.js View on Github external
async signMessage (message) {
    const hex = Buffer.from(message).toString('hex')
    const messageHash = EthCrypto.hash.keccak256(message);

    const signature = EthCrypto.sign(
      ensure0x(this.wallet.getPrivateKey().toString('hex')), // private key
      messageHash // hash of message
    );

    return remove0x(signature)
  }
github cryptoeconomics-study / code / ch1 / 1.2 / solution / Client.js View on Github external
toHash(data) {
				// ?! why is this JSON.stringify thing here, but not in 1.1 ???
        const dataStr = JSON.stringify(data)
        return EthCrypto.hash.keccak256(dataStr)
    }
github ShipChain / engine / src / __tests__ / wallets.ts View on Github external
it(`signs messages and recovers keys`, async () => {
        const wallet = await Wallet.generate_entity();

        const message = 'SHIPTest';

        const hash = EthCrypto.hash.keccak256([{value: message, type: 'string'}]);

        expect(hash).toEqual("0x6eba83aa272e398b5cddf2055bb404f84c3fd8e42dd96e80edb204f64bff73ab");

        const signed = wallet.sign_hash(hash);

        expect(Wallet.recover_signer_address(signed, hash)).toEqual(wallet.address);

        expect(Wallet.recover_signer_public_key(signed, hash)).toEqual(wallet.public_key);
    });
};
github cryptoeconomics-study / code / ch3 / nodeAgent.js View on Github external
function getTxHash (tx) {
  return EthCrypto.hash.keccak256(JSON.stringify(tx))
}
github cryptoeconomics-study / code / ch2 / nodeAgent.js View on Github external
function getTxHash(tx) {
  return EthCrypto.hash.keccak256(JSON.stringify(tx));
}
github RequestNetwork / requestNetwork / packages / utils / src / crypto.ts View on Github external
function keccak256Hash(data: string): string {
  return EthCrypto.hash.keccak256(data);
}
github ShipChain / engine / src / utils.ts View on Github external
export function stringHash(value: string, alg?: string) {
    if (!alg) {
        alg = DEFAULT_HASH_ALG;
    }

    switch (alg) {
        case 'sha256':
            const hash = crypto.createHash('sha256');
            hash.update(value);
            return '0x' + hash.digest('hex');

        case 'keccak256':
            return EthCrypto.hash.keccak256([{ value: value, type: 'string' }]);

        default:
            throw new Error(`Invalid hashing algorithm ${alg}`);
    }
}
github cryptoeconomics-study / code / c1_CentralPaymentOperator / paypalWithSigs.js View on Github external
function getTxHash (tx) {
  return EthCrypto.hash.keccak256(JSON.stringify(tx))
}