當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ethereumjs-util.bufferToHex函數代碼示例

本文整理匯總了TypeScript中ethereumjs-util.bufferToHex函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript bufferToHex函數的具體用法?TypeScript bufferToHex怎麽用?TypeScript bufferToHex使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了bufferToHex函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

 t.test('should not produce hash collsions for different senders', function(st) {
   st.plan(1)
   const txDataModFrom = Object.assign({}, txData, {
     from: '0x2222222222222222222222222222222222222222',
   })
   const tx = new FakeTransaction(txData)
   const txModFrom = new FakeTransaction(txDataModFrom)
   const hash = bufferToHex(tx.hash())
   const hashModFrom = bufferToHex(txModFrom.hash())
   st.notEqual(
     hash,
     hashModFrom,
     'FakeTransactions with different `from` addresses but otherwise identical data should have different hashes',
   )
 })
開發者ID:ethereumjs,項目名稱:ethereumjs-tx,代碼行數:15,代碼來源:fake.ts

示例2: it

 it('signs a personal message', async () => {
     const data = ethUtils.bufferToHex(ethUtils.toBuffer('hello world'));
     const ecSignatureHex = await ledgerSubprovider.signPersonalMessageAsync(data);
     expect(ecSignatureHex).to.be.equal(
         '0xa6cc284bff14b42bdf5e9286730c152be91719d478605ec46b3bebcd0ae491480652a1a7b742ceb0213d1e744316e285f41f878d8af0b8e632cbca4c279132d001',
     );
 });
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:7,代碼來源:ledger_subprovider_test.ts

示例3: reportCallbackErrors

 (async () => {
     const messageHex = ethUtils.bufferToHex(ethUtils.toBuffer('hello world'));
     const accounts = await ledgerSubprovider.getAccountsAsync();
     const signer = accounts[0];
     const payload = {
         jsonrpc: '2.0',
         method: 'personal_sign',
         params: [messageHex, signer],
         id: 1,
     };
     const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
         expect(err).to.be.a('null');
         expect(response.result.length).to.be.equal(132);
         expect(response.result.substr(0, 2)).to.be.equal('0x');
         done();
     });
     ledgerProvider.sendAsync(payload, callback);
 })().catch(done);
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:18,代碼來源:ledger_subprovider_test.ts

示例4: BigNumber

                value: utils.bigNumberToBN(order.takerTokenAmount),
                type: SolidityTypes.Uint256,
            },
            {
                value: utils.bigNumberToBN(order.makerFee),
                type: SolidityTypes.Uint256,
            },
            {
                value: utils.bigNumberToBN(order.takerFee),
                type: SolidityTypes.Uint256,
            },
            {
                value: utils.bigNumberToBN(order.expirationUnixTimestampSec),
                type: SolidityTypes.Uint256,
            },
            { value: utils.bigNumberToBN(order.salt), type: SolidityTypes.Uint256 },
        ];
        const types = _.map(orderParts, o => o.type);
        const values = _.map(orderParts, o => o.value);
        const hashBuff = ethABI.soliditySHA3(types, values);
        const hashHex = ethUtil.bufferToHex(hashBuff);
        return hashHex;
    },
    getCurrentUnixTimestampSec(): BigNumber {
        return new BigNumber(Date.now() / 1000).round();
    },
    getCurrentUnixTimestampMs(): BigNumber {
        return new BigNumber(Date.now());
    },
};
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:30,代碼來源:utils.ts

示例5: bufferToHex

 const pk = accountsKeys.filter((k) => bufferToHex(privateToAddress(k.secretKey)) === account)[0].secretKey;
開發者ID:AlphaX-IBS,項目名稱:microraiden,代碼行數:1,代碼來源:microraiden.ts

示例6: isValidSignature

import { ECSignature } from '@0xproject/types';
import * as ethUtil from 'ethereumjs-util';

export const signatureUtils = {
    isValidSignature(data: string, signature: ECSignature, signerAddress: string): boolean {
        const dataBuff = ethUtil.toBuffer(data);
        const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff);
        try {
            const pubKey = ethUtil.ecrecover(
                msgHashBuff,
                signature.v,
                ethUtil.toBuffer(signature.r),
                ethUtil.toBuffer(signature.s),
            );
            const retrievedAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey));
            return retrievedAddress === signerAddress;
        } catch (err) {
            return false;
        }
    },
    parseSignatureHexAsVRS(signatureHex: string): ECSignature {
        const signatureBuffer = ethUtil.toBuffer(signatureHex);
        let v = signatureBuffer[0];
        if (v < 27) {
            v += 27;
        }
        const r = signatureBuffer.slice(1, 33);
        const s = signatureBuffer.slice(33, 65);
        const ecSignature: ECSignature = {
            v,
            r: ethUtil.bufferToHex(r),
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:31,代碼來源:signature_utils.ts

示例7: getTopicsForIndexedArgs

     return signature;
 },
 getTopicsForIndexedArgs(abi: EventAbi, indexFilterValues: IndexedFilterValues): Array<string | null> {
     const topics: Array<string | null> = [];
     for (const eventInput of abi.inputs) {
         if (!eventInput.indexed) {
             continue;
         }
         if (_.isUndefined(indexFilterValues[eventInput.name])) {
             // Null is a wildcard topic in a JSON-RPC call
             topics.push(null);
         } else {
             const value = indexFilterValues[eventInput.name] as string;
             const buffer = ethUtil.toBuffer(value);
             const paddedBuffer = ethUtil.setLengthLeft(buffer, TOPIC_LENGTH);
             const topic = ethUtil.bufferToHex(paddedBuffer);
             topics.push(topic);
         }
     }
     return topics;
 },
 matchesFilter(log: LogEntry, filter: FilterObject): boolean {
     if (!_.isUndefined(filter.address) && log.address !== filter.address) {
         return false;
     }
     if (!_.isUndefined(filter.topics)) {
         return filterUtils.matchesTopics(log.topics, filter.topics);
     }
     return true;
 },
 matchesTopics(logTopics: string[], filterTopics: Array<string[] | string | null>): boolean {
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:31,代碼來源:filter_utils.ts


注:本文中的ethereumjs-util.bufferToHex函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。