ethereum-encryption
Version:
Use this to encrypt, decrypt, sign and verify data with an ethereum public- or privateKey
27 lines (24 loc) • 701 B
JavaScript
/**
* make sure that the given obj is a buffer
* @param {string|Buffer} bufferOrString
* @return {Buffer}
*/
export function ensureBuffer(bufferOrString) {
//make sure its a buffer
if (typeof bufferOrString === 'string')
return new Buffer(bufferOrString, 'hex');
else
return bufferOrString;
};
/**
* Prepair Ethereum address for either raw transactions or browser storage.
*/
export function formatAddress(addr) {
const format = 'hex';
/* if (addr.substr(0, 2) == '0x' && format == 'raw') {
addr = addr.substr(2);
}*/
if (addr.substr(0, 2) !== '0x' && format === 'hex')
addr = '0x' + addr;
return addr;
};