UNPKG

eip-712

Version:

Tiny library with utility functions that can help with signing and verifying EIP-712 based messages

21 lines (18 loc) 565 B
import { keccak_256 } from '@noble/hashes/sha3'; import { hexToBytes, utf8ToBytes } from '@noble/hashes/utils'; export const keccak256 = (data, encoding) => { if (typeof data === 'string' && encoding === 'utf8') { return keccak_256(toBuffer(data, encoding)); } return keccak_256(data); }; export const toBuffer = (data, encoding = 'hex') => { if (encoding === 'hex') { if (data.startsWith('0x')) { return hexToBytes(data.substring(2)); } return hexToBytes(data); } return utf8ToBytes(data); }; //# sourceMappingURL=buffer.js.map