add hex2b58 and b582hex
This commit is contained in:
parent
8df15515a6
commit
50a88a7efd
@ -1,6 +1,6 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="tEJiczfqJVlhZvufAVre" name="Page-1">
|
||||
<mxGraphModel dx="1127" dy="723" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<mxGraphModel dx="845" dy="542" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
@ -55,10 +55,10 @@
|
||||
<mxCell id="16" value="椭圆曲线算法<br>secp256k1" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;" parent="1" vertex="1">
|
||||
<mxGeometry x="770" y="250" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="96" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="18" target="53">
|
||||
<mxCell id="96" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="18" target="53" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="98" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="18" target="57">
|
||||
<mxCell id="98" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="18" target="57" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="18" value="public key ^ 公钥<br>264 bits = 33 Bytes = 66 Hex" style="rounded=1;whiteSpace=wrap;html=1;fontColor=#ffffff;strokeColor=#005700;fillColor=#008a00;" parent="1" vertex="1">
|
||||
@ -103,13 +103,13 @@
|
||||
<mxCell id="42" value="" style="edgeStyle=elbowEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;startArrow=classic;startFill=1;" parent="1" source="33" target="41" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="33" value="<ol><li>version prefix +1B</li><li>cksum postfix +4B</li><li>base58btc</li></ol>" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;align=left;" parent="1" vertex="1">
|
||||
<mxCell id="33" value="<ol><li>protocol prefix +1B</li><li>cksum postfix +4B</li><li>base58btc</li></ol>" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;align=left;" parent="1" vertex="1">
|
||||
<mxGeometry x="1340" y="130" width="150" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="39" style="edgeStyle=elbowEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;startArrow=classic;startFill=1;" parent="1" source="35" target="29" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="91" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="35" target="43">
|
||||
<mxCell id="91" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="35" target="43" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="35" value="<ol><li><span>大小写(EIP55)</span><br></li><li><span>'0x' prefix</span></li></ol>" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;align=left;" parent="1" vertex="1">
|
||||
@ -121,13 +121,13 @@
|
||||
<mxCell id="46" value="" style="edgeStyle=elbowEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;startArrow=classic;startFill=1;" parent="1" source="37" target="45" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="37" value="<ol><li>version prefix +1B</li><li>cksum postfix +3B</li><li>base64url</li></ol>" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;align=left;" parent="1" vertex="1">
|
||||
<mxCell id="37" value="<ol><li>world prefix +1B</li><li>cksum postfix +3B</li><li>base64url</li></ol>" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;align=left;" parent="1" vertex="1">
|
||||
<mxGeometry x="1340" y="360" width="150" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="address of BTC<br>26~34 b58" style="rounded=1;whiteSpace=wrap;html=1;fontColor=#ffffff;align=center;strokeColor=#005700;fillColor=#008a00;" parent="1" vertex="1">
|
||||
<mxGeometry x="1520" y="130" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="92" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="43" target="35">
|
||||
<mxCell id="92" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="43" target="35" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="43" value="address of ETH<br>'0x' + 40 Hex" style="rounded=1;whiteSpace=wrap;html=1;fontColor=#ffffff;align=center;strokeColor=#005700;fillColor=#008a00;" parent="1" vertex="1">
|
||||
@ -147,7 +147,7 @@
|
||||
<Array as="points"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="97" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="49" target="53">
|
||||
<mxCell id="97" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="49" target="53" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="49" value="Signature ^ 签印<br>71~72 Bytes = 142/144 Hex" style="rounded=1;whiteSpace=wrap;html=1;fontColor=#ffffff;strokeColor=#005700;fillColor=#008a00;" parent="1" vertex="1">
|
||||
@ -156,7 +156,7 @@
|
||||
<mxCell id="53" value="verify ^ 验签" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;" parent="1" vertex="1">
|
||||
<mxGeometry x="910" y="430" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="103" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;exitX=0.5;exitY=0;exitDx=0;exitDy=0;" edge="1" parent="1" source="57" target="64">
|
||||
<mxCell id="103" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;exitX=0.5;exitY=0;exitDx=0;exitDy=0;" parent="1" source="57" target="64" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="1000" y="40"/>
|
||||
@ -166,7 +166,7 @@
|
||||
<mxCell id="57" value="encrypt ^ 加密" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;" parent="1" vertex="1">
|
||||
<mxGeometry x="910" y="120" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="105" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" target="61">
|
||||
<mxCell id="105" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" target="61" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="710" y="150" as="sourcePoint"/>
|
||||
</mxGeometry>
|
||||
@ -174,7 +174,7 @@
|
||||
<mxCell id="58" value="decrypt ^ 解密" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;" parent="1" vertex="1">
|
||||
<mxGeometry x="620" y="120" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="104" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="64" target="58">
|
||||
<mxCell id="104" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="64" target="58" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="64" value="ciphertext ^ 密文" style="whiteSpace=wrap;html=1;rounded=1;fontColor=#ffffff;strokeColor=#005700;fillColor=#008a00;" parent="1" vertex="1">
|
||||
@ -201,31 +201,31 @@
|
||||
<mxCell id="14" value="private key ^ 私钥<br>256 bits = 32 Bytes = 64 Hex" style="whiteSpace=wrap;html=1;rounded=1;fontColor=#ffffff;strokeColor=#005700;fillColor=#008a00;" parent="1" vertex="1">
|
||||
<mxGeometry x="620" y="250" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="95" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="51" target="47">
|
||||
<mxCell id="95" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="51" target="47" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="51" value="作品=&gt;哈希" style="whiteSpace=wrap;html=1;rounded=1;fontColor=#ffffff;strokeColor=#005700;fillColor=#008a00;" parent="1" vertex="1">
|
||||
<mxGeometry x="770" y="430" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="106" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="61" target="57">
|
||||
<mxCell id="106" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="61" target="57" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="61" value="plaintext ^ 明文" style="whiteSpace=wrap;html=1;rounded=1;fontColor=#ffffff;strokeColor=#005700;fillColor=#008a00;" parent="1" vertex="1">
|
||||
<mxGeometry x="770" y="120" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="111" value="seckey2pubkey" style="shape=partialRectangle;whiteSpace=wrap;html=1;bottom=1;right=1;left=1;top=0;fillColor=#1ba1e2;routingCenterX=-0.5;strokeColor=#006EAF;fontColor=#ffffff;" vertex="1" parent="1">
|
||||
<mxCell id="111" value="seckey2pubkey" style="shape=partialRectangle;whiteSpace=wrap;html=1;bottom=1;right=1;left=1;top=0;fillColor=#1ba1e2;routingCenterX=-0.5;strokeColor=#006EAF;fontColor=#ffffff;" parent="1" vertex="1">
|
||||
<mxGeometry x="680" y="650" width="290" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="112" value="secword2keypair" style="shape=partialRectangle;whiteSpace=wrap;html=1;bottom=1;right=1;left=1;top=0;fillColor=#1ba1e2;routingCenterX=-0.5;strokeColor=#006EAF;fontColor=#ffffff;" vertex="1" parent="1">
|
||||
<mxGeometry x="360" y="690" width="610" height="30" as="geometry"/>
|
||||
<mxCell id="112" value="secword2keypair" style="shape=partialRectangle;whiteSpace=wrap;html=1;bottom=1;right=1;left=1;top=0;fillColor=#1ba1e2;routingCenterX=-0.5;strokeColor=#006EAF;fontColor=#ffffff;" parent="1" vertex="1">
|
||||
<mxGeometry x="420" y="710" width="610" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="113" value="pubkey2address" style="shape=partialRectangle;whiteSpace=wrap;html=1;bottom=1;right=1;left=1;top=0;fillColor=#1ba1e2;routingCenterX=-0.5;strokeColor=#006EAF;fontColor=#ffffff;" vertex="1" parent="1">
|
||||
<mxCell id="113" value="pubkey2address" style="shape=partialRectangle;whiteSpace=wrap;html=1;bottom=1;right=1;left=1;top=0;fillColor=#1ba1e2;routingCenterX=-0.5;strokeColor=#006EAF;fontColor=#ffffff;" parent="1" vertex="1">
|
||||
<mxGeometry x="970" y="650" width="630" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="114" value="seckey2address" style="shape=partialRectangle;whiteSpace=wrap;html=1;bottom=1;right=1;left=1;top=0;fillColor=#1ba1e2;routingCenterX=-0.5;strokeColor=#006EAF;fontColor=#ffffff;" vertex="1" parent="1">
|
||||
<mxCell id="114" value="seckey2address" style="shape=partialRectangle;whiteSpace=wrap;html=1;bottom=1;right=1;left=1;top=0;fillColor=#1ba1e2;routingCenterX=-0.5;strokeColor=#006EAF;fontColor=#ffffff;" parent="1" vertex="1">
|
||||
<mxGeometry x="680" y="730" width="920" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="115" value="secword2address, secword2account" style="shape=partialRectangle;whiteSpace=wrap;html=1;bottom=1;right=1;left=1;top=0;fillColor=#1ba1e2;routingCenterX=-0.5;strokeColor=#006EAF;fontColor=#ffffff;" vertex="1" parent="1">
|
||||
<mxCell id="115" value="secword2address, secword2account" style="shape=partialRectangle;whiteSpace=wrap;html=1;bottom=1;right=1;left=1;top=0;fillColor=#1ba1e2;routingCenterX=-0.5;strokeColor=#006EAF;fontColor=#ffffff;" parent="1" vertex="1">
|
||||
<mxGeometry x="360" y="770" width="1240" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
|
@ -106,7 +106,7 @@
|
||||
<mxCell id="42" value="" style="edgeStyle=elbowEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;startArrow=classic;startFill=1;" parent="1" source="33" target="41" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="33" value="<ol><li>version prefix +1B</li><li>cksum postfix +4B</li><li>base58btc</li></ol>" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;align=left;" parent="1" vertex="1">
|
||||
<mxCell id="33" value="<ol><li>protocol prefix +1B</li><li>cksum postfix +4B</li><li>base58btc</li></ol>" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;align=left;" parent="1" vertex="1">
|
||||
<mxGeometry x="160" y="980" width="150" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="39" style="edgeStyle=elbowEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;startArrow=classic;startFill=1;" parent="1" source="35" target="29" edge="1">
|
||||
@ -128,7 +128,7 @@
|
||||
<mxCell id="46" value="" style="edgeStyle=elbowEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;startArrow=classic;startFill=1;" parent="1" source="37" target="45" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="37" value="<ol><li>version prefix +1B</li><li>cksum postfix +3B</li><li>base64url</li></ol>" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;align=left;" parent="1" vertex="1">
|
||||
<mxCell id="37" value="<ol><li>world prefix +1B</li><li>cksum postfix +3B</li><li>base64url</li></ol>" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;rounded=1;fontColor=#ffffff;strokeColor=#A50040;fillColor=#d80073;align=left;" parent="1" vertex="1">
|
||||
<mxGeometry x="469" y="980" width="150" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="address of BTC<br>26~34 b58" style="rounded=1;whiteSpace=wrap;html=1;fontColor=#ffffff;align=center;strokeColor=#005700;fillColor=#008a00;" parent="1" vertex="1">
|
||||
|
13
index.js
13
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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user