How to use the web3-utils.hexToBytes function in web3-utils

To help you get started, we’ve selected a few web3-utils 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 fairDataSociety / fds.js / lib / FDS-SwarmFeeds.js View on Github external
let topicBytes;
        let userBytes;
        let protocolVersion = 0;

        let topicLength = 32;
        let userLength = 20;
        let timeLength = 7;
        let levelLength = 1;
        let headerLength = 8;

        let updateMinLength = topicLength + userLength + timeLength + levelLength + headerLength;

        protocolVersion = metaResponse.protocolVersion;

        try {
            topicBytes = hexToBytes(metaResponse.feed.topic);
        } catch (err) {
            return undefined;
        }

        try {
            userBytes = hexToBytes(metaResponse.feed.user);
        } catch (err) {
            return undefined;
        }

        const buf = new ArrayBuffer(updateMinLength + dataBytes.length);
        const view = new DataView(buf);
        let cursor = 0;

        view.setUint8(cursor, protocolVersion); // first byte is protocol version.
        cursor += headerLength; // leave the next 7 bytes (padding) set to zero
github ninabreznik / voting-ethereum-contract / node_modules / web3-eth-accounts / src / index.js View on Github external
Accounts.prototype.hashMessage = function hashMessage(data) {
    var message = utils.isHexStrict(data) ? utils.hexToBytes(data) : data;
    var messageBuffer = Buffer.from(message);
    var preamble = "\x19Ethereum Signed Message:\n" + message.length;
    var preambleBuffer = Buffer.from(preamble);
    var ethMessage = Buffer.concat([preambleBuffer, messageBuffer]);
    return Hash.keccak256s(ethMessage);
};
github vechain / thorify / src / extend / accounts.ts View on Github external
web3.eth.accounts.hashMessage = function hashMessage(data: string | Buffer) {
        const message = web3Utils.isHexStrict(data) ? web3Utils.hexToBytes(data) : data
        const messageBuffer = Buffer.from(message)
        const prefix = '\u0019VeChain Signed Message:\n' + message.length.toString()
        const prefixBuffer = Buffer.from(prefix)
        const prefixedMessage = Buffer.concat([prefixBuffer, messageBuffer])

        return utils.toPrefixedHex(cry.blake2b256(prefixedMessage).toString('hex'))
    }
github fairDataSociety / fds.js / lib / FDS-SwarmFeeds.js View on Github external
sendRequest(url, requestType, responseType, data = false, pinHeader = false) {
        Trace.time('sendRequest//SwarmFeeds');
        if(data){
            data = Buffer.from(hexToBytes(data));
        }

        let headers = {
            'Accept': 'application/octet-stream',
        }

        if(pinHeader){
            headers['x-swarm-pin'] = true;
        }

        return request({
            responseType: responseType, 
            url: `${this.swarmNode}${url}`, 
            method: requestType,
            headers: headers,
            data: data,
github JoinColony / colonyJS / packages / colony-js-contract-client / src / classes / MultisigOperation.js View on Github external
get _signedMessageDigest() {
    return hexToBytes(
      soliditySha3('\x19Ethereum Signed Message:\n32', this._messageHash),
    );
  }
github citahub / cita-sdk-js / packages / cita-signer / src / index.ts View on Github external
export const hex2bytes = (num: string) => {
  num = num.replace(/^0x/, '')
  num = num.length % 2 ? '0x0' + num : '0x' + num
  return utils.hexToBytes(num)
}
export const bytes2hex = (bytes: Uint8Array) => {
github fairDataSociety / fds.js / lib / FDS-SwarmFeeds.js View on Github external
dataToBuffer(data) {
        return Buffer.from(data, "hex");
        const dataBytes = hexToBytes(data);
        var buf = new ArrayBuffer(dataBytes.length);
        var dataView = new DataView(buf);
        for (var i = 0; i < dataBytes.length; i++) {
            dataView.setUint8(i, dataBytes[i]);
        }
        return buf;
    }
github fairDataSociety / fds.js / lib / FDS-SwarmFeeds.js View on Github external
signData(data, privateKey) {
        const sigObj = secp256k1.sign(Buffer.from(hexToBytes(data)), Buffer.from(hexToBytes(privateKey)));
        return `0x${sigObj.signature.toString('hex')}0${sigObj.recovery.toString()}`;
    }