u
This commit is contained in:
parent
53c6603ac4
commit
f0d90036b1
9
index.js
9
index.js
@ -603,6 +603,7 @@ class TICrypto {
|
|||||||
* @param {*} [{ coin }={}]
|
* @param {*} [{ coin }={}]
|
||||||
* @return {*}
|
* @return {*}
|
||||||
* @memberof TICrypto
|
* @memberof TICrypto
|
||||||
|
* position 就是通常所说的 PubKeyHash,出现在比特币交易的锁定脚本里
|
||||||
*/
|
*/
|
||||||
static pubkey2position(pubkey, { coin } = {}) {
|
static pubkey2position(pubkey, { coin } = {}) {
|
||||||
// tic, btc, eth 的 position 都是 20节=40字符的。
|
// tic, btc, eth 的 position 都是 20节=40字符的。
|
||||||
@ -713,16 +714,18 @@ class TICrypto {
|
|||||||
* @static
|
* @static
|
||||||
* @return {*}
|
* @return {*}
|
||||||
* @memberof TICrypto
|
* @memberof TICrypto
|
||||||
|
* 地址和PubKeyHash(即position)之间能互相转化
|
||||||
*/
|
*/
|
||||||
static address2position() {
|
static address2position() {
|
||||||
if (/^0x[\da-fA-F]{40}$/.test(address)) {
|
if (/^0x[\da-fA-F]{40}$/.test(address)) { // ETH
|
||||||
|
// todo: 如果是大小写敏感的,进行有效性验证
|
||||||
return address.toLowerCase()
|
return address.toLowerCase()
|
||||||
} else if (/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{26,34}$/.test(address)) {
|
} else if (/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{26,34}$/.test(address)) { // BTC
|
||||||
let hex = this.b58c2hex(address)
|
let hex = this.b58c2hex(address)
|
||||||
if (hex) {
|
if (hex) {
|
||||||
return hex.slice(2) // 去除网络前缀
|
return hex.slice(2) // 去除网络前缀
|
||||||
}
|
}
|
||||||
} else if (/^[Tt][0-9a-zA-Z\-_]{31}$/.test(address)) {
|
} else if (/^[Tt][0-9a-zA-Z\-_]{31}$/.test(address)) { // TIC
|
||||||
// 格式合法
|
// 格式合法
|
||||||
let hex = this.b64u2hex(address)
|
let hex = this.b64u2hex(address)
|
||||||
let [all, prefix, position, checksum] = hex.match(/^([\da-fA-F]{2})([\da-fA-F]{40})([\da-fA-F]{6})$/)
|
let [all, prefix, position, checksum] = hex.match(/^([\da-fA-F]{2})([\da-fA-F]{40})([\da-fA-F]{6})$/)
|
||||||
|
Loading…
Reference in New Issue
Block a user