把 net 改名 world, testnet 改名 moon, mainnet 改名 earth, devnet 改名 w1dev
This commit is contained in:
parent
6154eaef29
commit
4e1d6ae98b
16
index.js
16
index.js
@ -28,7 +28,6 @@ my.INPUT='utf8' // 默认的加密方法的明文格式。utf8 能够兼容 lati
|
||||
my.INPUT_LIST=['utf8', 'ascii', 'latin1'] // ignored for Buffer/TypedArray/DataView
|
||||
my.COIN='TIC' // 默认的币种
|
||||
my.COIN_LIST=['TIC','BTC','ETH']
|
||||
my.CHAINNET='mainnet' // 默认的链网
|
||||
|
||||
module.exports = {
|
||||
isHashable(data, {strict=false}={}){
|
||||
@ -323,8 +322,7 @@ module.exports = {
|
||||
if (kp) {
|
||||
let address
|
||||
if (option.coin === 'ETH') {
|
||||
let uncompressedPubkey = this.decompressPubkey(kp.pubkey)
|
||||
address = this.pubkey2address(uncompressedPubkey,{coin:'ETH'})
|
||||
address = this.pubkey2address(this.decompressPubkey(kp.pubkey), {coin:'ETH'})
|
||||
}else {
|
||||
address = this.pubkey2address(kp.pubkey, option)
|
||||
}
|
||||
@ -389,7 +387,7 @@ module.exports = {
|
||||
return null
|
||||
}
|
||||
,
|
||||
position2address(position, {coin, net}={}){
|
||||
position2address(position, {coin, world}={}){
|
||||
if (!/^[\da-fA-F]{40}$/.test(position)) return null // 不论 tic, btc, eth,其 position 都是 40字符的。
|
||||
coin = my.COIN_LIST.indexOf(coin)>=0?coin:my.COIN
|
||||
let address
|
||||
@ -407,7 +405,7 @@ module.exports = {
|
||||
return address
|
||||
}else if (coin === 'BTC'){ // 对比特币,把纯位置转换为大小写敏感能自我验证的bs58check地址:先加前缀1,再加校验4,共25字节,再转base58。得到26~34个字符,大多数34个。
|
||||
let prefix
|
||||
switch (net) {
|
||||
switch (world) {
|
||||
case 'mainnet': prefix='00'; break; // pubkey hash => 1
|
||||
case 'mainnetSh': prefix='05'; break; // script hash => 3
|
||||
case 'testnet': prefix='6f'; break; // testnet pubkey hash => m or n
|
||||
@ -420,12 +418,12 @@ module.exports = {
|
||||
return address
|
||||
}else { // 默认为 TIC。把纯位置转换为大小写敏感能自我验证的 b64u(base64 for url) 地址。
|
||||
let prefix
|
||||
switch (net){
|
||||
switch (world){
|
||||
// Base58: https://en.bitcoin.it/wiki/List_of_address_prefixes
|
||||
// Base64: https://baike.baidu.com/item/base64
|
||||
case 'mainnet': prefix='4c'; break; // Base58: 0x42=66 => T, Base64: base64 T=0x13=0b00010011 => 0b010011xx = 0x4c~4f
|
||||
case 'testnet': prefix='b4'; break; // Base58: 0x7f=127,0x80=128 => t, Base64: t=0x2d=0b00101101 => 0b101101xx = 0xB4~B7
|
||||
case 'devnet': prefix='74'; break; // Base58: 0x90 => d, Base 64: d=0x1d=0b00011101 => 0b 011101xx = 0x74~77
|
||||
case 'earth': prefix='4c'; break; // Base58: 0x42=66 => T, Base64: base64 T=0x13=0b00010011 => 0b010011xx = 0x4c~4f
|
||||
case 'moon': prefix='b4'; break; // Base58: 0x7f=127,0x80=128 => t, Base64: t=0x2d=0b00101101 => 0b101101xx = 0xB4~B7
|
||||
case 'w1dev': prefix='74'; break; // Base58: 0x90 => d, Base 64: d=0x1d=0b00011101 => 0b 011101xx = 0x74~77
|
||||
default: prefix='4c'
|
||||
}
|
||||
let checksum = this.hash(this.hash(prefix+position)).slice(0,6) // 添加 checksum 使得能够检测大小写错误。[todo] 校验码里要不要包含 prefix?
|
||||
|
Loading…
Reference in New Issue
Block a user