UNPKG

check-ethereum-scanner

Version:

Safety checks for new Ethereum tokens

22 lines (20 loc) 488 B
'use strict' const { Buffer } = require('buffer') module.exports = function base16 (alphabet) { return { encode (input) { if (typeof input === 'string') { return Buffer.from(input).toString('hex') } return input.toString('hex') }, decode (input) { for (const char of input) { if (alphabet.indexOf(char) < 0) { throw new Error('invalid base16 character') } } return Buffer.from(input, 'hex') } } }