把 TIC的bip44路径从66改成 60000
This commit is contained in:
parent
fdeb2cca9b
commit
36491d495f
43
index.js
43
index.js
@ -273,8 +273,7 @@ module.exports = {
|
||||
switch(option.coin){
|
||||
case 'BTC': key=hdmaster.derive("m/44'/0'/0'/0/0"); break
|
||||
case 'ETH': key=hdmaster.derive("m/44'/60'/0'/0/0"); break
|
||||
case 'TIC': key=hdmaster.derive("m/44'/66'/0'/0/0"); break
|
||||
default: key=hdmaster.derive("m/44'/99'/0'/0/0"); break
|
||||
case 'TIC': default: key=hdmaster.derive("m/44'/60000'/0'/0/0"); break
|
||||
}
|
||||
}else { // 指定了路径 option.path,例如 "m/44'/0'/0'/0/6" 或 "m/0/2147483647'/1"
|
||||
key=hdmaster.derive(option.path)
|
||||
@ -292,18 +291,19 @@ module.exports = {
|
||||
seed2path(seed, {coin='TIC'}={coin:'TIC'}){
|
||||
// 路径规范 BIP44: m/Purpose'/Coin'/Account'/Change/Index,
|
||||
// 但实际上 Purpose, Coin 都可任意定;' 可有可无;
|
||||
// Account 最大到 parseInt(0x7FFFFFFF, 16), Coin/Index最大到 parseInt(0xFFFFFFFF, 16)
|
||||
// 后面还可继续延伸 /xxx/xxx/xxx/...... let hash=this.hash(seed, {hasher:'md5'})
|
||||
// Account/Change/Index 最大到 parseInt(0x7FFFFFFF, 16)
|
||||
// 后面还可继续延伸 /xxx/xxx/xxx/......
|
||||
let hash=this.hash(seed, {hasher:'md5'})
|
||||
let part0=parseInt(hash.slice(0,6), 16)
|
||||
let part1=parseInt(hash.slice(6,12), 16)
|
||||
let part2=parseInt(hash.slice(12,18), 16)
|
||||
let part3=parseInt(hash.slice(18,24), 16)
|
||||
let part4=parseInt(hash.slice(24,32), 16)
|
||||
let part4=parseInt(hash.slice(24,30), 16)
|
||||
let path=`${part0}'/${part1}/${part2}/${part3}/${part4}/${part5}`
|
||||
switch (coin){
|
||||
case 'BTC': return `m/44'/0'/${part0}'/${part1}/${part2}/${part3}/${part4}`
|
||||
case 'ETH': return `m/44'/60'/${part0}'/${part1}/${part2}/${part3}/${part4}`
|
||||
case 'TIC':
|
||||
default: return `m/44'/66'/${part0}'/${part1}/${part2}/${part3}/${part4}`
|
||||
case 'BTC': return `m/44'/0'/${path}`
|
||||
case 'ETH': return `m/44'/60'/${path}`
|
||||
case 'TIC': default: return `m/44'/60000'/${path}`
|
||||
}
|
||||
}
|
||||
,
|
||||
@ -769,6 +769,31 @@ module.exports = {
|
||||
return null
|
||||
}
|
||||
,
|
||||
aiid2regcode(aiid) {
|
||||
const alphabet = 'e5fcdg3hqa4b1n0pij2rstuv67mwx89klyz'
|
||||
const base = 16367
|
||||
let num = (aiid+base)*(base - alphabet.length)
|
||||
let code = ''
|
||||
let mod
|
||||
while ( num > 0) {
|
||||
mod = num % alphabet.length;
|
||||
num = (num - mod) / alphabet.length
|
||||
code = code+alphabet[mod] // 倒序存放
|
||||
}
|
||||
return code
|
||||
}
|
||||
,
|
||||
regcode2aiid(code) {
|
||||
const alphabet = 'e5fcdg3hqa4b1n0pij2rstuv67mwx89klyz'
|
||||
const base = 16367
|
||||
let len = code.length
|
||||
let num = 0
|
||||
for (let i=0; i < len; i++) {
|
||||
num += alphabet.indexOf(code[i]) * Math.pow(alphabet.length, i)
|
||||
}
|
||||
return num/(base - alphabet.length)-base
|
||||
}
|
||||
,
|
||||
// test: https://iancoleman.io/bitcoin-key-compression/
|
||||
// compress: https://hacpai.com/article/1550844562914
|
||||
compressPubkey(uncompressed){ // 把 04xy 的非压缩公钥 转成 02x 或 03x 的压缩公钥
|
||||
|
Loading…
Reference in New Issue
Block a user