本文整理汇总了TypeScript中ethereumjs-util.toBuffer函数的典型用法代码示例。如果您正苦于以下问题:TypeScript toBuffer函数的具体用法?TypeScript toBuffer怎么用?TypeScript toBuffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了toBuffer函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: hash
/**
* Computes a sha3-256 hash of the serialized tx
* @param includeSignature - Whether or not to include the signature
*/
hash(includeSignature: boolean = true): Buffer {
let items
if (includeSignature) {
items = this.raw
} else {
// EIP155 spec:
// If block.number >= 2,675,000 and v = CHAIN_ID * 2 + 35 or v = CHAIN_ID * 2 + 36, then when computing
// the hash of a transaction for purposes of signing or recovering, instead of hashing only the first six
// elements (i.e. nonce, gasprice, startgas, to, value, data), hash nine elements, with v replaced by
// CHAIN_ID, r = 0 and s = 0.
const v = bufferToInt(this.v)
const onEIP155BlockOrLater = this._common.gteHardfork('spuriousDragon')
const vAndChainIdMeetEIP155Conditions =
v === this._chainId * 2 + 35 || v === this._chainId * 2 + 36
const meetsAllEIP155Conditions = vAndChainIdMeetEIP155Conditions && onEIP155BlockOrLater
const unsigned = !this.r.length && !this.s.length
const seeksReplayProtection = this._chainId > 0
if ((unsigned && seeksReplayProtection) || (!unsigned && meetsAllEIP155Conditions)) {
const raw = this.raw.slice()
this.v = toBuffer(this._chainId)
this.r = toBuffer(0)
this.s = toBuffer(0)
items = this.raw
this.raw = raw
} else {
items = this.raw.slice(0, 6)
}
}
// create hash
return rlphash(items)
}
开发者ID:ethereumjs,项目名称:ethereumjs-tx,代码行数:39,代码来源:transaction.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: takeSnapshotAsync
public async takeSnapshotAsync(): Promise<number> {
const method = 'evm_snapshot';
const params: any[] = [];
const payload = this.toPayload(method, params);
const snapshotIdHex = await this.sendAsync(payload);
const snapshotId = ethUtil.bufferToInt(ethUtil.toBuffer(snapshotIdHex));
return snapshotId;
}
开发者ID:linki,项目名称:0x.js,代码行数:8,代码来源:rpc.ts
示例4: function
t.test('should round trip decode a tx', function(st) {
const tx = new Transaction()
tx.value = toBuffer(5000)
const s1 = tx.serialize().toString('hex')
const tx2 = new Transaction(s1)
const s2 = tx2.serialize().toString('hex')
st.equals(s1, s2)
st.end()
})
开发者ID:ethereumjs,项目名称:ethereumjs-tx,代码行数:9,代码来源:api.ts
示例5: function
web3.currentProvider.sendAsync = function(payload, callback) {
let args = [].slice.call(arguments, 0);
if (payload['method'] === 'eth_signTypedData') {
try {
const [ params, account ] = payload['params'];
const pk = accountsKeys.filter((k) => bufferToHex(privateToAddress(k.secretKey)) === account)[0].secretKey;
const sig = signTypedData(toBuffer(pk), { data: params });
return callback(null, { result: sig, error: null });
} catch(err) {
return callback({ result: null, error: err });
}
} else {
return origSendAsync.apply(this, args);
}
}
开发者ID:AlphaX-IBS,项目名称:microraiden,代码行数:15,代码来源:microraiden.ts
示例6: 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
示例7: toBuffer
t.test(testName, st => {
const rawTx = toBuffer(testData.rlp)
let tx
forkNames.forEach(forkName => {
const forkTestData = testData[forkName]
const shouldBeInvalid = Object.keys(forkTestData).length === 0
try {
tx = new Tx(rawTx, {
hardfork: forkNameMap[forkName],
chain: 1,
})
const sender = tx.getSenderAddress().toString('hex')
const hash = tx.hash().toString('hex')
const validationErrors = tx.validate(true)
const transactionIsValid = validationErrors.length === 0
const hashAndSenderAreCorrect =
forkTestData && (sender === forkTestData.sender && hash === forkTestData.hash)
if (shouldBeInvalid) {
st.assert(!transactionIsValid, `Transaction should be invalid on ${forkName}`)
} else {
st.assert(
hashAndSenderAreCorrect && transactionIsValid,
`Transaction should be valid on ${forkName}`,
)
}
} catch (e) {
if (shouldBeInvalid) {
st.assert(shouldBeInvalid, `Transaction should be invalid on ${forkName}`)
} else {
st.fail(`Transaction should be valid on ${forkName}`)
}
}
})
st.end()
})
开发者ID:ethereumjs,项目名称:ethereumjs-tx,代码行数:39,代码来源:transactionRunner.ts
示例8: constructor
constructor(
data: Buffer | PrefixedHexString | BufferLike[] | FakeTxData = {},
opts: TransactionOptions = {},
) {
super(data, opts)
Object.defineProperty(this, 'from', {
enumerable: true,
configurable: true,
get: () => this.getSenderAddress(),
set: val => {
if (val) {
this._from = toBuffer(val)
}
},
})
const txData = data as FakeTxData
if (txData.from) {
this.from = toBuffer(txData.from)
}
}
开发者ID:ethereumjs,项目名称:ethereumjs-tx,代码行数:22,代码来源:fake.ts
示例9: parseSignatureHexAsVRS
import * as ethUtil from 'ethereumjs-util';
import {ECSignature} from '../types';
export const signatureUtils = {
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),
s: ethUtil.bufferToHex(s),
};
return ecSignature;
},
parseSignatureHexAsRSV(signatureHex: string): ECSignature {
const {v, r, s} = ethUtil.fromRpcSig(signatureHex);
const ecSignature: ECSignature = {
v,
r: ethUtil.bufferToHex(r),
s: ethUtil.bufferToHex(s),
};
return ecSignature;
},
};
开发者ID:linki,项目名称:0x.js,代码行数:29,代码来源:signature_utils.ts
示例10: getTopicsForIndexedArgs
const types = _.map(eventAbi.inputs, 'type');
const signature = `${eventAbi.name}(${types.join(',')})`;
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;
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:31,代码来源:filter_utils.ts
示例11: toBuffer
set: val => {
if (val) {
this._from = toBuffer(val)
}
},
开发者ID:ethereumjs,项目名称:ethereumjs-tx,代码行数:5,代码来源:fake.ts
示例12: getAccounts
type Callback = (err: Error | null, result: any) => void;
export const idManagement = {
getAccounts(callback: Callback) {
callback(null, [configs.DISPENSER_ADDRESS]);
},
approveTransaction(txData: object, callback: Callback) {
callback(null, true);
},
signTransaction(txData: object, callback: Callback) {
const tx = new EthereumTx(txData);
const privateKeyBuffer = new Buffer(configs.DISPENSER_PRIVATE_KEY as string, 'hex');
tx.sign(privateKeyBuffer);
const rawTx = `0x${tx.serialize().toString('hex')}`;
callback(null, rawTx);
},
signMessage(message: object, callback: Callback) {
const dataIfExists = _.get(message, 'data');
if (_.isUndefined(dataIfExists)) {
callback(new Error('NO_DATA_TO_SIGN'), null);
}
const privateKeyBuffer = new Buffer(configs.DISPENSER_PRIVATE_KEY as string, 'hex');
const dataBuff = ethUtil.toBuffer(dataIfExists);
const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff);
const sig = ethUtil.ecsign(msgHashBuff, privateKeyBuffer);
const rpcSig = ethUtil.toRpcSig(sig.v, sig.r, sig.s);
callback(null, rpcSig);
},
};
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:29,代码来源:id_management.ts
示例13: 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
示例14: toBuffer
transactions.forEach(function(tx) {
tx.gasLimit = toBuffer(30000)
st.equals(tx.validate(true), '')
})
开发者ID:ethereumjs,项目名称:ethereumjs-tx,代码行数:4,代码来源:api.ts
注:本文中的ethereumjs-util.toBuffer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论