@yoroi/common
Version:
The Common package of Yoroi SDK
25 lines (24 loc) • 649 B
JavaScript
;
export function hex(value) {
if (!hex.isHexString(value)) {
throw new Error('Invalid hex string');
}
return {
get value() {
return value.toLowerCase();
},
get bytes() {
return new Uint8Array(Buffer.from(value, 'hex'));
},
get utf8() {
return Buffer.from(value, 'hex').toString('utf8');
},
equals(other) {
return this.value === other.value;
}
};
}
hex.isHexString = str => /^[0-9a-fA-F]+$/.test(str);
hex.fromUtf8 = str => hex(Buffer.from(str, 'utf8').toString('hex'));
hex.fromBytes = bytes => hex(Buffer.from(bytes).toString('hex'));
//# sourceMappingURL=hex.js.map