@findeth/abi
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -26,3 +26,3 @@ "use strict"; | ||
const types = contractFunction.inputs.map(parseType).join(','); | ||
return (0, _utils.keccak256)(`${contractFunction.name}(${types})`).slice(0, 8); | ||
return (0, _utils.toHex)((0, _utils.keccak256)((0, _utils.fromUtf8)(`${contractFunction.name}(${types})`))).slice(0, 8); | ||
}; | ||
@@ -29,0 +29,0 @@ |
@@ -15,3 +15,4 @@ "use strict"; | ||
const keccak256 = input => { | ||
return (0, _buffer.toHex)((0, _keccak.default)('keccak256').update(input).digest()); | ||
const buffer = (0, _buffer.toBuffer)(input); | ||
return (0, _buffer.fromHex)((0, _keccak.default)('keccak256').update((0, _buffer.toHex)(buffer), 'hex').digest('hex')); | ||
}; | ||
@@ -18,0 +19,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { keccak256 } from './utils'; | ||
import { fromUtf8, keccak256, toHex } from './utils'; | ||
@@ -16,4 +16,4 @@ const isTuple = input => { | ||
const types = contractFunction.inputs.map(parseType).join(','); | ||
return keccak256(`${contractFunction.name}(${types})`).slice(0, 8); | ||
return toHex(keccak256(fromUtf8(`${contractFunction.name}(${types})`))).slice(0, 8); | ||
}; | ||
//# sourceMappingURL=identifier.js.map |
import createKeccakHash from 'keccak'; | ||
import { toHex } from './buffer'; | ||
import { fromHex, toBuffer, toHex } from './buffer'; | ||
export const keccak256 = input => { | ||
return toHex(createKeccakHash('keccak256').update(input).digest()); | ||
const buffer = toBuffer(input); | ||
return fromHex(createKeccakHash('keccak256').update(toHex(buffer), 'hex').digest('hex')); | ||
}; | ||
//# sourceMappingURL=keccak256.js.map |
{ | ||
"name": "@findeth/abi", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "A tiny Solidity ABI encoder and decoder", | ||
@@ -68,2 +68,3 @@ "author": "Maarten Zuidhoorn <maarten@zuidhoorn.com>", | ||
"@types/jest": "^26.0.15", | ||
"@types/node": "^14.14.22", | ||
"@typescript-eslint/eslint-plugin": "^4.14.0", | ||
@@ -70,0 +71,0 @@ "@typescript-eslint/parser": "^4.14.0", |
import { ContractFunction, ContractInput, ContractInputTuple } from './contract'; | ||
import { keccak256 } from './utils'; | ||
import { fromUtf8, keccak256, toHex } from './utils'; | ||
@@ -31,3 +31,3 @@ const isTuple = (input: ContractInput): input is ContractInputTuple => { | ||
return keccak256(`${contractFunction.name}(${types})`).slice(0, 8); | ||
return toHex(keccak256(fromUtf8(`${contractFunction.name}(${types})`))).slice(0, 8); | ||
}; |
@@ -0,1 +1,2 @@ | ||
import { fromUtf8, toHex } from './buffer'; | ||
import { keccak256 } from './keccak256'; | ||
@@ -5,6 +6,6 @@ | ||
it('returns the keccak256 hash of a string', () => { | ||
expect(keccak256('transfer(address,uint256)')).toBe( | ||
expect(toHex(keccak256(fromUtf8('transfer(address,uint256)')))).toBe( | ||
'a9059cbb2ab09eb219583f4a59a5d0623ade346d962bcd4e46b11da047c9049b' | ||
); | ||
expect(keccak256('approve(address,uint256)')).toBe( | ||
expect(toHex(keccak256(fromUtf8('approve(address,uint256)')))).toBe( | ||
'095ea7b334ae44009aa867bfb386f5c3b4b443ac6f0ee573fa91c4608fbadfba' | ||
@@ -11,0 +12,0 @@ ); |
import createKeccakHash from 'keccak'; | ||
import { toHex } from './buffer'; | ||
import { BinaryLike, fromHex, toBuffer, toHex } from './buffer'; | ||
@@ -10,4 +10,5 @@ /** | ||
*/ | ||
export const keccak256 = (input: string): string => { | ||
return toHex(createKeccakHash('keccak256').update(input).digest()); | ||
export const keccak256 = (input: BinaryLike): Uint8Array => { | ||
const buffer = toBuffer(input); | ||
return fromHex(createKeccakHash('keccak256').update(toHex(buffer), 'hex').digest('hex')); | ||
}; |
@@ -0,1 +1,2 @@ | ||
import { BinaryLike } from './buffer'; | ||
/** | ||
@@ -7,2 +8,2 @@ * Returns the Keccak-256 hash of a string, as a hexadecimal string. | ||
*/ | ||
export declare const keccak256: (input: string) => string; | ||
export declare const keccak256: (input: BinaryLike) => Uint8Array; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172950
2557
29