Replies: 1 comment
-
|
Sorry for the long delay getting this question answered. Unfortunately, the BIP-32 extended key does not encode the path in any way; it is designed to be of fixed length (which is a medium-to-hard requirement for encoding data using Base58), which doesn't allow for variable-length data to be encoded. Sorry this likely doesn't help, but long story short is that the specification doesn't allow for it. :( |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Ethers Version
6.0.8
Search Terms
fromExtendedKey, extendedKey, derivePath, path null
Describe the Problem
I'm playing with https://iancoleman.io/bip39/ utility and ethers library.
I'm trying to get what is BIP32 Root Key. As I understand I can use BIP32 Root Key to generate all derived keys instead of mnemonic phrase.
And I did it. But the main issue is null value in
pathproperty. Please look to the complete example below.root.pathwhich I got from mnemonic equalsmas I expected.But when I create
restoredRootusingHDNodeWallet.fromExtendedKeymethod,restoredRoot.pathequalsnulland there is no way to override it.When I derive
m/44'/60'/0'/0/0andm/44'/60'/0'/0/1fromrestoredRootI get nulls in theirpaths too.So the question: is there any way to restore wallets with right paths from extended private key?
Code Snippet
import { defaultPath, HDNodeWallet, Mnemonic } from "ethers"; async function main() { const phrase = "service any panther floor desert alcohol brown chair gold such wool swarm" const mnemonic = Mnemonic.fromPhrase(phrase) const hdNodeN = HDNodeWallet.fromMnemonic(mnemonic) console.log("wallet 0:", hdNodeN.path, hdNodeN.address, hdNodeN.privateKey) // m/44'/60'/0'/0/0 0x9e44A0F4F8EC569B8E9aE70acF267C18f143e697 0x253b0161fc932e9836b2b03593ff5521feca6c9e46bd6db43cb04715b7dbe9eb const hdNodeN1 = HDNodeWallet.fromMnemonic(mnemonic, "m/44'/60'/0'/0/1") console.log("wallet 1:", hdNodeN1.path, hdNodeN1.address, hdNodeN1.privateKey) // m/44'/60'/0'/0/1 0x1F0b5E19839E7D87CC0186F240bBDa2E8E3ED62A 0x0e8636c36508b5cf6d24186d8a43cb5a49cd43c2cfc1fdeac3335964bfe4ea98 const root = HDNodeWallet.fromSeed(mnemonic.computeSeed()) console.log("root:", root.path, root.address, root.privateKey) // m 0xa939792Fae4dd0CF141350ab1bcdEf89b0415423 0xffd7442d6a64b27535bfb053879d4599e6b48262be5db0df44c9dd529ccc705f const bip32RootKey = root.extendedKey console.log("BIP32 Root Key:", bip32RootKey) // xprv9s21ZrQH143K48uLpMjXMkv9acwYWXtgqujMZRr57CuQjCiQ7NT5TR7qLk3fYJ8WHjLVGK9uivoVWwU5RyXGavGw2H7X43vBUnPdHceHtnR const restoredRoot = HDNodeWallet.fromExtendedKey(bip32RootKey) as HDNodeWallet console.log("restored root:", restoredRoot.path, restoredRoot.address, restoredRoot.privateKey) // null 0xa939792Fae4dd0CF141350ab1bcdEf89b0415423 0xffd7442d6a64b27535bfb053879d4599e6b48262be5db0df44c9dd529ccc705f const restoredWallet0 = restoredRoot.derivePath(defaultPath) console.log("restored wallet 0:", restoredWallet0.path, restoredWallet0.address, restoredWallet0.privateKey) // null 0x9e44A0F4F8EC569B8E9aE70acF267C18f143e697 0x253b0161fc932e9836b2b03593ff5521feca6c9e46bd6db43cb04715b7dbe9eb const restoredWallet1 = restoredRoot.derivePath(defaultPath.slice(0, -1) + 1) console.log("restored wallet 1:", restoredWallet1.path, restoredWallet1.address, restoredWallet1.privateKey) // null 0x1F0b5E19839E7D87CC0186F240bBDa2E8E3ED62A 0x0e8636c36508b5cf6d24186d8a43cb5a49cd43c2cfc1fdeac3335964bfe4ea98 } main();Contract ABI
No response
Errors
No response
Environment
node.js (v12 or newer)
Environment (Other)
No response
Beta Was this translation helpful? Give feedback.
All reactions