diff --git a/index.js b/index.js index 25fa944..5eafa43 100644 --- a/index.js +++ b/index.js @@ -1210,13 +1210,24 @@ class TICrypto { * @param {*} hex * @return {*} * @memberof TICrypto + * 如果出现非HEX的字符,从这个字符(及其同Byte的另一个字符)起直到末尾,都会被忽略掉,但仍然成功返回一个串。 + * bs58check 和 bs58 可接受string, Buffer, ArrayBuffer, Array (包括空字符串'', 各种内容的数组例如包含 undefined,{...},等等); + * 不可接受 undefined, null, {...}, 等等,会返回 exception */ static hex2b58c(hex) { - return bs58check.encode(Buffer.from(hex, 'hex')) + try { + return bs58check.encode(Buffer.from(hex, 'hex')) + } catch (exception) { + return null + } } static hex2b58(hex) { - return bs58.encode(Buffer.from(hex, 'hex')) + try { + return bs58.encode(Buffer.from(hex, 'hex')) + } catch (exception) { + return null + } } /** @@ -1237,7 +1248,7 @@ class TICrypto { static b582hex(box) { try { - return bs58check.decode(box).toString('hex') + return bs58.decode(box).toString('hex') } catch (exception) { return null }