UNPKG

@hashgraph/sdk

Version:
3 lines (2 loc) 702 B
function t(t){return Buffer.from(t).toString("hex")}function r(t){const r=t.startsWith("0x")?t.substring(2):t;if(r.length%2!=0)throw new Error("Invalid hex string: Must have an even number of characters.");if(/[^0-9a-fA-F]/.test(r))throw new Error("Invalid hex string: Contains non-hexadecimal characters.");const n=new Uint8Array(r.length/2);for(let t=0;t<r.length;t+=2){const e=parseInt(r.substring(t,t+2),16);n[t/2]=e}return Buffer.from(r,"hex")}function n(t){if("string"!=typeof t)return!1;const r=t.startsWith("0x")?t.substring(2):t;if(0===r.length)return!1;if(r.length%2!=0)return!1;return/^[0-9a-fA-F]+$/.test(r)}export{r as decode,t as encode,n as isHexString}; //# sourceMappingURL=hex.js.map