UNPKG

@ledgerhq/coin-stacks

Version:
17 lines 944 B
// NOTE: inlined now, this shared utils code will be moved to coin-framework in a future PR const validHexRegExp = new RegExp(/^(0x)?[a-fA-F0-9]+$/); const validBase64RegExp = new RegExp(/^(?:[A-Za-z\d+/]{4})*(?:[A-Za-z\d+/]{3}=|[A-Za-z\d+/]{2}==)?$/); export const isValidHex = (msg) => validHexRegExp.test(msg) && msg.length % 2 === 0; export const isValidBase64 = (msg) => validBase64RegExp.test(msg); export const isNoErrorReturnCode = (code) => code === 0x9000; export const getPath = (path) => (path && path.substr(0, 2) !== "m/" ? `m/${path}` : path); export const throwIfError = (r) => { if (!isNoErrorReturnCode(r.returnCode)) throw new Error(`${r.returnCode} - ${r.errorMessage}`); }; export const getBufferFromString = (message) => isValidHex(message) ? Buffer.from(message, "hex") : isValidBase64(message) ? Buffer.from(message, "base64") : Buffer.from(message); //# sourceMappingURL=utils.js.map