From 50a88a7efdf321005061aae74f3bbcfa565ea598 Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Mon, 15 Nov 2021 23:20:50 +0800 Subject: [PATCH] add hex2b58 and b582hex --- README.horizontal.drawio | 38 +++++++++++++++++++------------------- README.vertical.drawio | 4 ++-- index.js | 13 +++++++++++++ 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/README.horizontal.drawio b/README.horizontal.drawio index 2058c00..2a9055b 100644 --- a/README.horizontal.drawio +++ b/README.horizontal.drawio @@ -1,6 +1,6 @@ - + @@ -55,10 +55,10 @@ - + - + @@ -103,13 +103,13 @@ - + - + @@ -121,13 +121,13 @@ - + - + @@ -147,7 +147,7 @@ - + @@ -156,7 +156,7 @@ - + @@ -166,7 +166,7 @@ - + @@ -174,7 +174,7 @@ - + @@ -201,31 +201,31 @@ - + - + - + - - + + - + - + - + diff --git a/README.vertical.drawio b/README.vertical.drawio index 5ac7a69..94a727c 100644 --- a/README.vertical.drawio +++ b/README.vertical.drawio @@ -106,7 +106,7 @@ - + @@ -128,7 +128,7 @@ - + diff --git a/index.js b/index.js index 73e3bc8..25fa944 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ const BigInt = require('big-integer') // 处理整数 https://github.com/peterol const crypto = require('crypto') const nacl = require('tweetnacl') const bs58check = require('bs58check') +const bs58 = require('bs58') // bs58check depends on bs58 const uuid = require('uuid') const keccak = require('keccak') const eccrypto = require('eccrypto-js') // 用于加解密。eccrypto 在 windows 上和 openssl 的版本兼容性有点麻烦,所以换用 eccrypto-js @@ -1214,6 +1215,10 @@ class TICrypto { return bs58check.encode(Buffer.from(hex, 'hex')) } + static hex2b58(hex) { + return bs58.encode(Buffer.from(hex, 'hex')) + } + /** * b58c 转十六进制 * @@ -1230,6 +1235,14 @@ class TICrypto { } } + static b582hex(box) { + try { + return bs58check.decode(box).toString('hex') + } catch (exception) { + return null + } + } + /** * 十六进制转b64u *