コード例 #1
0
        public static void Drive()
        {
            string masterPublickey = "xpub6EadKVNnpzBqV11L1NtEnxik6awzxxmFmGisfZjW73b45iwJJ3LRuZqHZLJodWzja1F2cPQAAMCRkGuBqWm4N21fMM1groibrd7A5nZfSRJ-[p2sh]";
            //  masterPublickey = "xpub6EadKVNnpzBqV11L1NtEnxik6awzxxmFmGisfZjW73b45iwJJ3LRuZqHZLJodWzja1F2cPQAAMCRkGuBqWm4N21fMM1groibrd7A5nZfSRJ-[p2sh]";
            // masterPublickey = "0xf20cAf38A4B1C322b386f58FcC43eeE6915caa0F";
            //   masterPublickey = "tpubDExFqjCUYG9HkoCBTZsKzt47Ri3exMGKJuKB27neSxLwq1c1NGBX41W7oNPbA1wyMumwDxv2hT2USTPoENcJFTTxQwkzYLNqSahZqqMekzo-[p2sh]";
            // masterPublickey = "tpubDExFqjCUYG9HkoCBTZsKzt47Ri3exMGKJuKB27neSxLwq1c1NGBX41W7oNPbA1wyMumwDxv2hT2USTPoENcJFTTxQwkzYLNqSahZqqMekzo";
            Network network = Network.Main;
            var     parser  = new DerivationSchemeParser(network);

            var derivationSchemeSettings = new DerivationSchemeSettings(parser.Parse(masterPublickey), network);

            ShowAddresses(derivationSchemeSettings, network);
        }
コード例 #2
0
        //public static bool TryParseFromJson(string config, Network network, out DerivationSchemeSettings strategy)
        //{
        //    if (network == null)
        //        throw new ArgumentNullException(nameof(network));
        //    if (config == null)
        //        throw new ArgumentNullException(nameof(config));
        //    strategy = null;
        //    try
        //    {
        //        strategy = network.NBXplorerNetwork.Serializer.ToObject<DerivationSchemeSettings>(config);
        //        strategy.Network = network;
        //    }
        //    catch { }
        //    return strategy != null;
        //}

        public static bool TryParseFromColdcard(string coldcardExport, Network network, out DerivationSchemeSettings settings)
        {
            settings = null;
            if (coldcardExport == null)
            {
                throw new ArgumentNullException(nameof(coldcardExport));
            }
            if (network == null)
            {
                throw new ArgumentNullException(nameof(network));
            }
            var result = new DerivationSchemeSettings();

            result.Source = "Coldcard";
            var     derivationSchemeParser = new DerivationSchemeParser(network);
            JObject jobj = null;

            try
            {
                jobj = JObject.Parse(coldcardExport);
                jobj = (JObject)jobj["keystore"];
            }
            catch
            {
                return(false);
            }

            if (jobj.ContainsKey("xpub"))
            {
                try
                {
                    result.AccountOriginal                  = jobj["xpub"].Value <string>().Trim();
                    result.AccountDerivation                = derivationSchemeParser.ParseElectrum(result.AccountOriginal);
                    result.AccountKeySettings               = new AccountKeySettings[1];
                    result.AccountKeySettings[0]            = new AccountKeySettings();
                    result.AccountKeySettings[0].AccountKey = result.AccountDerivation.GetExtPubKeys().Single().GetWif(network);
                    if (result.AccountDerivation is DirectDerivationStrategy direct && !direct.Segwit)
                    {
                        result.AccountOriginal = null; // Saving this would be confusing for user, as xpub of electrum is legacy derivation, but for btcpay, it is segwit derivation
                    }
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            if (jobj.ContainsKey("label"))
            {
                try
                {
                    result.Label = jobj["label"].Value <string>();
                }
                catch { return(false); }
            }

            if (jobj.ContainsKey("ckcc_xfp"))
            {
                try
                {
                    result.AccountKeySettings[0].RootFingerprint = new HDFingerprint(jobj["ckcc_xfp"].Value <uint>());
                }
                catch { return(false); }
            }

            if (jobj.ContainsKey("derivation"))
            {
                try
                {
                    result.AccountKeySettings[0].AccountKeyPath = new KeyPath(jobj["derivation"].Value <string>());
                }
                catch { return(false); }
            }
            settings         = result;
            settings.Network = network;
            return(true);
        }