rename pathRoot to pathSeed
This commit is contained in:
parent
dc834c8157
commit
93eb774457
30
ticc.js
30
ticc.js
@ -431,7 +431,7 @@ class TicCrypto {
|
||||
* @return {Object} {pubkey, prikey,}
|
||||
* @memberof TicCrypto
|
||||
*/
|
||||
static secword_to_keypair ({ secword, coin, pass, pathRoot, pathIndex, path, tool, hasher = my.HASHER } = {}) {
|
||||
static secword_to_keypair ({ secword, coin, pass, pathSeed, pathIndex, path, tool, hasher = my.HASHER } = {}) {
|
||||
// coin 币种;
|
||||
// passphase 密码,默认为空;
|
||||
// path 规范为 m/Purpose'/CoinType'/Account'/Change/Index (https://learnblockchain.cn/2018/09/28/hdwallet/), 其中
|
||||
@ -466,11 +466,11 @@ class TicCrypto {
|
||||
// let hdmaster=new BitcoreMnemonic(secword).toHDPrivateKey(pass) // 和 ethers.HDNode.fromMnemonic(secword)的公私钥一样。而 ethers.HDNode.fromMnemonic(secword).derivePath("m/44'/60'/0'/0/0")的公私钥===ethers.Wallet.fromMnemonic(secword [,"m/44'/60'/0'/0/0"])
|
||||
let key = hdmaster
|
||||
if (path) {
|
||||
// 指定了path 例如 "m/0/2147483647'/1" 则用 path 例如 不存在 pathRoot 时获取的是根路径 "m/44'/0'/0'/0/0" 或 "m/44'/60'/0'/0/0"
|
||||
// 指定了path 例如 "m/0/2147483647'/1" 则用 path 例如 不存在 pathSeed 时获取的是根路径 "m/44'/0'/0'/0/0" 或 "m/44'/60'/0'/0/0"
|
||||
key = hdmaster.derive(path)
|
||||
} else if (pathRoot) {
|
||||
// 指定了 pathRoot 则调用 root_to_path() 来获取路径
|
||||
path = this.root_to_path({ pathRoot, pathIndex, coin })
|
||||
} else if (pathSeed) {
|
||||
// 指定了 pathSeed 则调用 root_to_path() 来获取路径
|
||||
path = this.root_to_path({ pathSeed, pathIndex, coin })
|
||||
key = hdmaster.derive(path)
|
||||
} else {
|
||||
// 没有指定 path 或 pathRoot,则返回主钥
|
||||
@ -489,19 +489,19 @@ class TicCrypto {
|
||||
* 从种子到路径
|
||||
*
|
||||
* @static
|
||||
* @param {*} pathRoot
|
||||
* @param {*} pathSeed
|
||||
* @param {string} option [{ coin = my.COIN }={ }]
|
||||
* @return {String} path
|
||||
* @memberof TicCrypto
|
||||
*/
|
||||
static root_to_path ({ pathRoot, pathIndex, coin = my.COIN } = {}) {
|
||||
static root_to_path ({ pathSeed, pathIndex, coin = my.COIN } = {}) {
|
||||
// 路径规范 BIP44: m/Purpose'/Coin'/Account'/Change/Index,
|
||||
// 但实际上 Purpose, Coin 都可任意定;' 可有可无;
|
||||
// 后面还可继续延伸 /xxx/xxx/xxx/......
|
||||
// 每个数字最大到 parseInt("0x7FFFFFFF", 16)=parseInt(0x7FFFFFFF)=2147483647,更大就报错。
|
||||
let path
|
||||
if (pathRoot) {
|
||||
let pathHash = this.hash_easy(pathRoot, { hasher: 'md5' })
|
||||
if (pathSeed) {
|
||||
let pathHash = this.hash_easy(pathSeed, { hasher: 'md5' })
|
||||
let part0 = parseInt(pathHash.slice(0, 6), 16)
|
||||
let part1 = parseInt(pathHash.slice(6, 12), 16)
|
||||
let part2 = parseInt(pathHash.slice(12, 18), 16)
|
||||
@ -554,10 +554,10 @@ class TicCrypto {
|
||||
* @memberof TicCrypto
|
||||
* 只要提供了 path 或 pathRoot,就创建 bip39 账户。如果都不存在,那就创建主账户。
|
||||
*/
|
||||
static secword_to_account ({ secword, coin, world, pass, pathRoot, pathIndex, path, tool, hasher } = {}) {
|
||||
static secword_to_account ({ secword, coin, world, pass, pathSeed, pathIndex, path, tool, hasher } = {}) {
|
||||
// account 比 keypair 多了 address 字段。
|
||||
coin = coin?.toUpperCase?.() || my.COIN
|
||||
let kp = this.secword_to_keypair({ secword, coin, pass, pathRoot, pathIndex, path, tool, hasher })
|
||||
let kp = this.secword_to_keypair({ secword, coin, pass, pathSeed, pathIndex, path, tool, hasher })
|
||||
if (kp) {
|
||||
if (coin === 'ETH') {
|
||||
world = world || 'mainnet'
|
||||
@ -584,8 +584,8 @@ class TicCrypto {
|
||||
* @return {String} address
|
||||
* @memberof TicCrypto
|
||||
*/
|
||||
static secword_to_address ({ secword, coin, world, pass, pathRoot, pathIndex, path, tool, hasher } = {}) {
|
||||
const account = this.secword_to_account({ secword, coin, world, pass, pathRoot, pathIndex, path, tool, hasher })
|
||||
static secword_to_address ({ secword, coin, world, pass, pathSeed, pathIndex, path, tool, hasher } = {}) {
|
||||
const account = this.secword_to_account({ secword, coin, world, pass, pathSeed, pathIndex, path, tool, hasher })
|
||||
return account?.address
|
||||
}
|
||||
|
||||
@ -935,9 +935,9 @@ class TicCrypto {
|
||||
* @return {*}
|
||||
* @memberof TicCrypto
|
||||
*/
|
||||
static randomize_account ({ lang, wordCount, coin, world, pass, pathRoot, pathIndex, path, tool, hasher } = {}) {
|
||||
static randomize_account ({ lang, wordCount, coin, world, pass, pathSeed, pathIndex, path, tool, hasher } = {}) {
|
||||
let secword = this.randomize_secword({ lang, wordCount })
|
||||
return this.secword_to_account({ secword, coin, world, pass, pathRoot, pathIndex, path, tool, hasher })
|
||||
return this.secword_to_account({ secword, coin, world, pass, pathSeed, pathIndex, path, tool, hasher })
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user