示例#1
0
        public static MnemonicKeyPair RecoverMnemonicKeyPair(List <string> mnemonicSeedWords, string mnemonicSeedPassword)
        {
            if (mnemonicSeedPassword == null)
            {
                mnemonicSeedPassword = "";
            }

            Mnemonic mn = new Mnemonic(string.Join(" ", mnemonicSeedWords), Wordlist.English);

            // generate the seed from words and password
            byte[] seed = mn.DeriveSeed(mnemonicSeedPassword);
            // generate the master key from the seed using bitcoinj implementation of hd
            // wallets
            DeterministicKeyPair master           = new DeterministicKeyPair(seed);
            RawKeyPair           generatedKeyPair = new RawKeyPair(Hex.ToHexString(master.PrivateKey.ToBytes()));

            return(new MnemonicKeyPair(generatedKeyPair, mnemonicSeedWords, master));
        }
示例#2
0
        public MnemonicKeyPair DerivedKey(bool hardened, string path = null)
        {
            DeterministicKeyPair master = DeterministicKeyPair;

            // check if we really have the masterKey at hand
            //mpiva limitation no go back in history
            if (master.Depth != 0)
            {
                throw new AException("Given mnemonicKeyPair object does not contain the master key");
            }

            /**
             * following the BIP32 specification create the following tree purpose -> coin -> account ->
             * external chain -> child address
             */

            /**
             * always set path for purpose {@link BaseConstants.HD_CHAIN_PURPOSE}, coin {@link
             * BaseConstants.HD_CHAIN_CODE_AETERNITY}
             */
            string pathToDerivedKey = "m/" + Constants.BaseConstants.HD_CHAIN_PURPOSE + "'/" + Constants.BaseConstants.HD_CHAIN_CODE_AETERNITY + "'";


            /** if no arguments are given, set default account and external chain (0h, 0h) */
            if (string.IsNullOrEmpty(path))
            {
                pathToDerivedKey += "/0'/0'";
                /** in case arguments are given - add warning */
            }
            else
            {
                pathToDerivedKey += "/" + path;
                pathToDerivedKey  = pathToDerivedKey.Replace("//", "/");
            }

            DeterministicKeyPair nextChildDeterministicKeyPair = master.DeriveNextChild(pathToDerivedKey, hardened);

            // derive a new child
            RawKeyPair childRawKeyPair = new RawKeyPair(Hex.ToHexString(nextChildDeterministicKeyPair.PrivateKey.ToBytes()));

            return(new MnemonicKeyPair(childRawKeyPair, MnemonicSeedWords, nextChildDeterministicKeyPair));
        }
示例#3
0
 public MnemonicKeyPair(RawKeyPair rawKeyPair, List <string> mnemonicSeedWords, DeterministicKeyPair extKeyPair) : base(rawKeyPair.PublicKey, rawKeyPair.PrivateKey)
 {
     MnemonicSeedWords    = mnemonicSeedWords;
     DeterministicKeyPair = extKeyPair;
 }