diff --git a/index.js b/index.js index 511981f..1fd1306 100644 --- a/index.js +++ b/index.js @@ -603,6 +603,7 @@ class TICrypto { * @param {*} [{ coin }={}] * @return {*} * @memberof TICrypto + * position 就是通常所说的 PubKeyHash,出现在比特币交易的锁定脚本里 */ static pubkey2position(pubkey, { coin } = {}) { // tic, btc, eth 的 position 都是 20节=40字符的。 @@ -713,16 +714,18 @@ class TICrypto { * @static * @return {*} * @memberof TICrypto + * 地址和PubKeyHash(即position)之间能互相转化 */ static address2position() { - if (/^0x[\da-fA-F]{40}$/.test(address)) { + if (/^0x[\da-fA-F]{40}$/.test(address)) { // ETH + // todo: 如果是大小写敏感的,进行有效性验证 return address.toLowerCase() - } else if (/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{26,34}$/.test(address)) { + } else if (/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{26,34}$/.test(address)) { // BTC let hex = this.b58c2hex(address) if (hex) { 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 [all, prefix, position, checksum] = hex.match(/^([\da-fA-F]{2})([\da-fA-F]{40})([\da-fA-F]{6})$/)