ethereumjs-util#setLengthLeft TypeScript Examples
The following examples show how to use
ethereumjs-util#setLengthLeft.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: util.ts From remix-project with MIT License | 7 votes |
/**
* sha3 the given @arg value (left pad to 32 bytes)
*
* @param {String} value - value to sha3
* @return {Object} - return sha3ied value
*/
// eslint-disable-next-line camelcase
export function sha3_256 (value) {
value = toBuffer(addHexPrefix(value))
const retInBuffer: Buffer = keccak(setLengthLeft(value, 32))
return bufferToHex(retInBuffer)
}
Example #2
Source File: Mapping.ts From remix-project with MIT License | 6 votes |
function getMappingLocation (key, position) {
// mapping storage location decribed at http://solidity.readthedocs.io/en/develop/miscellaneous.html#layout-of-state-variables-in-storage
// > the value corresponding to a mapping key k is located at keccak256(k . p) where . is concatenation.
// key should be a hex string, and position an int
const mappingK = toBuffer(addHexPrefix(key))
let mappingP = toBuffer(addHexPrefix(position))
mappingP = setLengthLeft(mappingP, 32)
const mappingKeyBuf = concatTypedArrays(mappingK, mappingP)
const mappingStorageLocation: Buffer = keccak(mappingKeyBuf)
const mappingStorageLocationinBn: BN = new BN(mappingStorageLocation, 16)
return mappingStorageLocationinBn
}
Example #3
Source File: fix-signature.ts From ethereum-sdk with MIT License | 5 votes |
function toRpcSig(v: number, r: Buffer, s: Buffer) {
return bufferToHex(Buffer.concat([setLengthLeft(r, 32), setLengthLeft(s, 32), toBuffer(v)]))
}
Example #4
Source File: is-signer.test.ts From ethereum-sdk with MIT License | 5 votes |
function toRpcSig(v: number, r: Buffer, s: Buffer) {
return bufferToHex(Buffer.concat([setLengthLeft(r, 32), setLengthLeft(s, 32), toBuffer(v)]))
}