This commit is contained in:
陆柯 2022-06-04 08:17:40 +08:00
parent c2adfd5a14
commit 24450a4022

View File

@ -439,6 +439,7 @@ class TICrypto {
secword: secword, secword: secword,
pubkey: Buffer.from(keypair.publicKey).toString('hex'), // 测试过 不能直接keypair.publicKey.toString('hex')不是buffer类型 pubkey: Buffer.from(keypair.publicKey).toString('hex'), // 测试过 不能直接keypair.publicKey.toString('hex')不是buffer类型
seckey: Buffer.from(keypair.secretKey).toString('hex'), // nacl.sign.keyPair.fromSeed 得到的 seckey 是64字节的不同于比特币/以太坊的32字节密钥。 seckey: Buffer.from(keypair.secretKey).toString('hex'), // nacl.sign.keyPair.fromSeed 得到的 seckey 是64字节的不同于比特币/以太坊的32字节密钥。
tool,
} }
} else { } else {
// 用 bip39 算法从 secword 到种子,再用 bip32 算法从种子到根私钥。这是比特币、以太坊的标准方式,结果一致。 // 用 bip39 算法从 secword 到种子,再用 bip32 算法从种子到根私钥。这是比特币、以太坊的标准方式,结果一致。
@ -448,14 +449,16 @@ class TICrypto {
if (path === 'master') { if (path === 'master') {
key = hdmaster key = hdmaster
} else { } else {
// 指定了路径 path 例如 "m/0/2147483647'/1" 则用 path否则调用 seed2path() 来获取默认的根路径 例如 "m/44'/0'/0'/0/0" 或 "m/44'/60'/0'/0/0" // 指定了路径 path 例如 "m/0/2147483647'/1" 则用 path没有指定路径 则调用 seed2path() 来获取默认的根路径 例如 "m/44'/0'/0'/0/0" 或 "m/44'/60'/0'/0/0"
key = hdmaster.derive(path || this.seed2path({ coin })) path = path || this.seed2path({ coin })
key = hdmaster.derive(path)
} }
return { return {
coin: coin, coin: coin,
secword: secword, secword: secword,
seckey: key.privateKey.toString('hex'), // 或者 key.toJSON().privateKey。或者 key.privateKey.slice(2) 删除开头的'0x'如果是ethers.HDNode.fromMnemonic(secword)的结果 seckey: key.privateKey.toString('hex'), // 或者 key.toJSON().privateKey。或者 key.privateKey.slice(2) 删除开头的'0x'如果是ethers.HDNode.fromMnemonic(secword)的结果
pubkey: key.publicKey.toString('hex'), pubkey: key.publicKey.toString('hex'),
path,
} }
} }
return null return null